Solid Retesselated() { if (IsRetesselated) { return(this); } else { var csg = this; var polygonsPerPlane = new Dictionary <string, List <Polygon> >(); var isCanonicalized = csg.IsCanonicalized; var fuzzyFactory = new FuzzyCsgFactory(); foreach (var polygon in csg.Polygons) { var plane = polygon.Plane; var shared = polygon.Shared; if (!isCanonicalized) { plane = fuzzyFactory.GetPlane(plane); shared = fuzzyFactory.GetPolygonShared(shared); } var tag = plane.Tag + "/" + shared.Tag; List <Polygon> ppp; if (polygonsPerPlane.TryGetValue(tag, out ppp)) { ppp.Add(polygon); } else { ppp = new List <Polygon>(); ppp.Add(polygon); polygonsPerPlane.Add(tag, ppp); } } var destpolygons = new List <Polygon>(); foreach (var planetag in polygonsPerPlane) { var sourcepolygons = planetag.Value; if (sourcepolygons.Count < 2) { destpolygons.AddRange(sourcepolygons); } else { var retesselatedpolygons = new List <Polygon>(); Solid.RetesselateCoplanarPolygons(sourcepolygons, retesselatedpolygons); destpolygons.AddRange(retesselatedpolygons); } } var result = Solid.FromPolygons(destpolygons); result.IsRetesselated = true; result.Properties = Properties; return(result); } }
static List <Polygon> Reteselate(IReadOnlyList <Polygon> polygons, bool canonicalize) { var polygonsPerPlane = new Dictionary <PolygonsPerPlaneKey, List <Polygon> > (polygonsPerPlaneKeyComparer); var fuzzyFactory = canonicalize ? new FuzzyCsgFactory() : null; foreach (var polygon in polygons) { var plane = polygon.Plane; var shared = polygon.Shared; if (fuzzyFactory != null) { plane = fuzzyFactory.GetPlane(plane); shared = fuzzyFactory.GetPolygonShared(shared); } var tag = new PolygonsPerPlaneKey { PlaneTag = plane.Tag, SharedTag = shared.Tag }; List <Polygon> ppp; if (polygonsPerPlane.TryGetValue(tag, out ppp)) { ppp.Add(polygon); } else { ppp = new List <Polygon> (1); ppp.Add(polygon); polygonsPerPlane.Add(tag, ppp); } } var destpolygons = new List <Polygon> (); //var retess = new List<PlanePolygons> (); foreach (var planetag in polygonsPerPlane) { var sourcepolygons = planetag.Value; if (sourcepolygons.Count < 2) { destpolygons.AddRange(sourcepolygons); } else { var retesselatedpolygons = new List <Polygon> (sourcepolygons.Count); //retess.Add (new PlanePolygons { Source = sourcepolygons, Retesselated = retesselatedpolygons }); Solid.RetesselateCoplanarPolygons(sourcepolygons, retesselatedpolygons); destpolygons.AddRange(retesselatedpolygons); } } //System.Threading.Tasks.Parallel.ForEach (retess, x => { // Solid.RetesselateCoplanarPolygons (x.Source, x.Retesselated); //}); //foreach (var x in retess) { // destpolygons.AddRange (x.Retesselated); //} return(destpolygons); }