public static List <PolygroupModifier> AdvancedCreatePolygroups(DTConvexPolygroup originalPolygroup, List <int> keptIndices, List <List <Vector2> > newPolygons) { DTProfilerMarkers.Polygrouper.Begin(); // Construct a list of point sets to identify unique groups of connected output polygons List <HashSet <Vector2> > outputPointGroups = new List <HashSet <Vector2> >(); foreach (int i in keptIndices) { originalPolygroup[i].MergeIntoPointGroups(outputPointGroups); } foreach (var poly in newPolygons) { poly.MergeIntoPointGroups(outputPointGroups); } // Use the point sets to create polygroups List <PolygroupModifier> outputPolygroups = new List <PolygroupModifier>(outputPointGroups.Count); // Initialize the polygroups for (int i = 0; i < outputPointGroups.Count; ++i) { outputPolygroups.Add(new PolygroupModifier(originalPolygroup)); } // Add each existing polygon to the first polygroup it matches foreach (int i in keptIndices) { // Find the correct place to put this polygon in the output structure int outputGroupIndex = originalPolygroup[i].GetFirstPointGroupIndex(outputPointGroups); if (outputGroupIndex >= 0) { outputPolygroups[outputGroupIndex].keptIndices.Add(i); } else { throw new Exception("Polygon failed to match a point group"); } } // Add each new polygon to the first polygroup it matches foreach (var poly in newPolygons) { // Find the correct place to put this polygon in the output structure int outputGroupIndex = poly.GetFirstPointGroupIndex(outputPointGroups); if (outputGroupIndex >= 0) { outputPolygroups[outputGroupIndex].newPolygons.Add(poly); } else { throw new Exception("Polygon failed to match a point group"); } } DTProfilerMarkers.Polygrouper.End(); return(outputPolygroups); }
public PolygroupModifier(DTConvexPolygroup originalPolygroup, List <int> keptIndices, List <List <Vector2> > newPolygons) { this.originalPolygroup = originalPolygroup; this.keptIndices = keptIndices; this.newPolygons = newPolygons; }
public PolygroupModifier(DTConvexPolygroup originalPolygroup) { this.originalPolygroup = originalPolygroup; keptIndices = new List <int>(); newPolygons = new List <List <Vector2> >(); }