---
slug: 3d-diffs
title: 3d-diffs - CAD code reviews
author: Kurt Hutten
author_title: CadHub Core Team
author_url: https://github.com/Irev-Dev
author_image_url: https://avatars.githubusercontent.com/u/29681384?v=4
tags: []
---

import Image from '@theme/IdealImage';

import example3dDiffCode from '../static/img/blog/3d-diff/3dDiffExampleCode.jpg';
import example3dDiff from '../static/img/blog/3d-diff/3dDiffExample.jpg';


When making a change to a repo, we're all familiar with code diffs, so common we don't give them a second thought.
What's so powerful about code-diffs is they let us to apply our entire conceptual model of how the software functions to a laser focused section the code, to both check that the change is good, as well as giving us a chance to update that mental model incrementally.

CodeCAD is in a unique position that it outputs a 3d artifact, but we can also produce diff artifacts for the purpose of reviewing, it's so intuitive that it needs little explanation, so here's an example:

<Image img={example3dDiffCode} className="bg-contain rounded-md overflow-hidden" />
<Image img={example3dDiff} className="mb-8 bg-contain rounded-md overflow-hidden" />

<!--truncate-->

Green represents where material has been added to the model, and red where it's been removed. Because the hole count has decreased from 3 to 2, the middle hole has been filled in. The holes have also increased in diameter which is why there are red rings around the two outer holes where material has been removed.

The process for creating these diffs is rather elegant, here's some pseudo-code:

```
noChange =    intersection(newShape, oldShape)
addedMaterial =   subtract(newShape, oldShape)
removedMaterial = subtract(oldShape, newShape)

colorGray(noChange)
colorGreen(addedMaterial)
colorRed(removedMaterial)
```

3d diffs are part of the reason why Github integration is on the [road-map](https://github.com/Irev-Dev/cadhub/discussions/212) for Cadhub, it's such a low hanging fruit that will immediately make code reviews better, I'm excited to make them happen.
