You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,18 +24,18 @@ Example usage:
24
24
25
25
All CSG operations are implemented in terms of two functions, `clipTo()` and `invert()`, which remove parts of a BSP tree inside another BSP tree and swap solid and empty space, respectively. To find the union of `a` and `b`, we want to remove everything in `a` inside `b` and everything in `b` inside `a`, then combine polygons from `a` and `b` into one solid:
26
26
27
-
a.root.clipTo(b.root);
28
-
b.root.clipTo(a.root);
29
-
a.root.build(b.root.allPolygons());
27
+
a.clipTo(b);
28
+
b.clipTo(a);
29
+
a.build(b.allPolygons());
30
30
31
31
The only tricky part is handling overlapping coplanar polygons in both trees. The code above keeps both copies, but we need to keep them in one tree and remove them in the other tree. To remove them from `b` we can clip the inverse of `b` against `a`. The code for union now looks like this:
32
32
33
-
a.root.clipTo(b.root);
34
-
b.root.clipTo(a.root);
35
-
b.root.invert();
36
-
b.root.clipTo(a.root);
37
-
b.root.invert();
38
-
a.root.build(b.root.allPolygons());
33
+
a.clipTo(b);
34
+
b.clipTo(a);
35
+
b.invert();
36
+
b.clipTo(a);
37
+
b.invert();
38
+
a.build(b.allPolygons());
39
39
40
40
Subtraction and intersection naturally follow from set operations. If union is `A | B`, subtraction is `A - B = ~(~A | B)` and intersection is `A & B = ~(~A | ~B)` where `~` is the complement operator.
0 commit comments