private CSG _differenceCSGBoundsOpt(CSG csg) { CSG b = csg; CSG a1 = this._differenceNoOpt(csg.getBounds().toCSG()); CSG a2 = this.intersect(csg.getBounds().toCSG()); return(a2._differenceNoOpt(b)._unionIntersectOpt(a1).optimization(getOptType())); }
private CSG _differencePolygonBoundsOpt(CSG csg) { List <Polygon> inner = new List <Polygon>(); List <Polygon> outer = new List <Polygon>(); Bounds bounds = csg.getBounds(); this.polygons.ForEach(p => { if (bounds.intersects(p.getBounds())) { inner.Add(p); } else { outer.Add(p); } }); CSG innerCSG = CSG.fromPolygons(inner); List <Polygon> allPolygons = new List <Polygon>(); allPolygons.AddRange(outer); allPolygons.AddRange(innerCSG._differenceNoOpt(csg).polygons); return(CSG.fromPolygons(allPolygons).optimization(getOptType())); }
/// <summary> /// Optimizes for intersection. If csgs do not intersect create a new csg that consists of the polygon lists of this /// csg and the specified csg. In this case no further space partitioning is performed. /// </summary> /// /// <param name="csg">csg</param> /// <returns>the union of this csg and the specified csg</returns> /// private CSG _unionIntersectOpt(CSG csg) { bool intersects = false; Bounds bounds = csg.getBounds(); foreach (Polygon p in polygons) { if (bounds.intersects(p.getBounds())) { intersects = true; break; } } List <Polygon> allPolygons = new List <Polygon>(); if (intersects) { return(_unionNoOpt(csg)); } else { allPolygons.AddRange(this.polygons); allPolygons.AddRange(csg.polygons); } return(CSG.fromPolygons(allPolygons).optimization(getOptType())); }
public double eval(IVector3d pos, CSG csg) { if (bounds == null) { this.bounds = csg.getBounds(); sPerUnit = (max - min) / (bounds.getMax().y() - bounds.getMin().y()); } double s = sPerUnit * (pos.y() - bounds.getMin().y()); if (centered) { s = s - (max - min) / 2.0; s = Math.Abs(s) * 2; } return(s); }