// Return a new CSG solid representing space both this solid and in the // solid `csg`. Neither this solid nor the solid `csg` are modified. // // A.intersect(B) // // +-------+ // | | // | A | // | +--+----+ = +--+ // +----+--+ | +--+ // | B | // | | // +-------+ // public CSG intersect(CSG csg) { CSGNode a = new CSGNode(this.clone().polygons); CSGNode b = new CSGNode(csg.clone().polygons); a.invert(); b.clipTo(a); b.invert(); a.clipTo(b); b.clipTo(a); a.addPolygons(b.allPolygons()); a.invert(); return(CSG.fromPolygons(a.allPolygons())); }
// Return a new CSG solid representing space in either this solid or in the // solid `csg`. Neither this solid nor the solid `csg` are modified. // // A.union(B) // // +-------+ +-------+ // | | | | // | A | | | // | +--+----+ = | +----+ // +----+--+ | +----+ | // | B | | | // | | | | // +-------+ +-------+ // public CSG union(CSG csg) { CSGNode a = new CSGNode(this.clone().polygons); CSGNode b = new CSGNode(csg.clone().polygons); a.clipTo(b); b.clipTo(a); b.invert(); b.clipTo(a); b.invert(); List <CSGPolygon> result = a.allPolygons(); result.AddRange(b.allPolygons()); return(CSG.fromPolygons(result)); }
// Convert solid space to empty space and empty space to solid space. public void invert() { for (int i = 0; i < polygons.Count; i++) { polygons[i].flip(); } plane.flip(); if (front != null) { front.invert(); } if (back != null) { back.invert(); } CSGNode temp = front; front = back; back = temp; }