private static List <Vertices> DetectVertices(ref PolygonCreationAssistance pca) { List <Vertices> polygons = new List <Vertices>(); Vertices polygon; Vertices holePolygon; Vector2?holeEntrance = null; Vector2?polygonEntrance = null; List <Vector2> blackList = new List <Vector2>(); // Check the array you just got. Debug.Assert(pca.IsValid(), "Sizes don't match: Color array must contain texture width * texture height elements."); bool searchOn; do { if (polygons.Count == 0) { polygon = CreateSimplePolygon(pca, Vector2.Zero, Vector2.Zero); if (polygon != null && polygon.Count > 2) { polygonEntrance = GetTopMostVertex(polygon); } } else if (polygonEntrance.HasValue) { polygon = CreateSimplePolygon(pca, polygonEntrance.Value, new Vector2(polygonEntrance.Value.X - 1f, polygonEntrance.Value.Y)); } else { break; } searchOn = false; if (polygon != null && polygon.Count > 2) { if (pca.HoleDetection) { do { holeEntrance = GetHoleHullEntrance(pca, polygon, holeEntrance); if (holeEntrance.HasValue) { if (!blackList.Contains(holeEntrance.Value)) { blackList.Add(holeEntrance.Value); holePolygon = CreateSimplePolygon(pca, holeEntrance.Value, new Vector2(holeEntrance.Value.X + 1, holeEntrance.Value.Y)); if (holePolygon != null && holePolygon.Count > 2) { holePolygon.Add(holePolygon[0]); int vertex2Index; int vertex1Index; if (SplitPolygonEdge(polygon, EdgeAlignment.Vertical, holeEntrance.Value, out vertex1Index, out vertex2Index)) { polygon.InsertRange(vertex2Index, holePolygon); } } } else { break; } } else { break; } } while (true); } polygons.Add(polygon); if (pca.MultipartDetection) { // 1: 95 / 151 // 2: 232 / 252 // while (GetNextHullEntrance(pca, polygonEntrance.Value, out polygonEntrance)) { bool inPolygon = false; for (int i = 0; i < polygons.Count; i++) { polygon = polygons[i]; if (InPolygon(pca, polygon, polygonEntrance.Value)) { inPolygon = true; break; } } if (!inPolygon) { searchOn = true; break; } } } } } while (searchOn); return(polygons); }
private static List<Vertices> DetectVertices(ref PolygonCreationAssistance pca) { List<Vertices> polygons = new List<Vertices>(); Vertices polygon; Vertices holePolygon; Vector2? holeEntrance = null; Vector2? polygonEntrance = null; List<Vector2> blackList = new List<Vector2>(); // Check the array you just got. Debug.Assert(pca.IsValid(), "Sizes don't match: Color array must contain texture width * texture height elements."); bool searchOn; do { if (polygons.Count == 0) { polygon = CreateSimplePolygon(pca, Vector2.Zero, Vector2.Zero); if (polygon != null && polygon.Count > 2) { polygonEntrance = GetTopMostVertex(polygon); } } else if (polygonEntrance.HasValue) { polygon = CreateSimplePolygon(pca, polygonEntrance.Value, new Vector2(polygonEntrance.Value.X - 1f, polygonEntrance.Value.Y)); } else { break; } searchOn = false; if (polygon != null && polygon.Count > 2) { if (pca.HoleDetection) { do { holeEntrance = GetHoleHullEntrance(pca, polygon, holeEntrance); if (holeEntrance.HasValue) { if (!blackList.Contains(holeEntrance.Value)) { blackList.Add(holeEntrance.Value); holePolygon = CreateSimplePolygon(pca, holeEntrance.Value, new Vector2(holeEntrance.Value.X + 1, holeEntrance.Value.Y)); if (holePolygon != null && holePolygon.Count > 2) { holePolygon.Add(holePolygon[0]); int vertex2Index; int vertex1Index; if (SplitPolygonEdge(polygon, EdgeAlignment.Vertical, holeEntrance.Value, out vertex1Index, out vertex2Index)) { polygon.InsertRange(vertex2Index, holePolygon); } } } else { break; } } else { break; } } while (true); } polygons.Add(polygon); if (pca.MultipartDetection) { // 1: 95 / 151 // 2: 232 / 252 // while (GetNextHullEntrance(pca, polygonEntrance.Value, out polygonEntrance)) { bool inPolygon = false; for (int i = 0; i < polygons.Count; i++) { polygon = polygons[i]; if (InPolygon(pca, polygon, polygonEntrance.Value)) { inPolygon = true; break; } } if (!inPolygon) { searchOn = true; break; } } } } } while (searchOn); return polygons; }