//check if a given polygon2d has any of its longer edges aligned with any edge of the containerpolygon2d internal static bool CheckLineGetsExternalWall(Line2d lineA, Polygon2d containerPoly) { bool check = false; if (!ValidateObject.CheckPoly(containerPoly)) { return(check); } Polygon2d containerPolyReg = new Polygon2d(containerPoly.Points); for (int i = 0; i < containerPoly.Points.Count; i++) { int a = i, b = i + 1; if (i == containerPolyReg.Points.Count - 1) { b = 0; } Line2d lineB = Line2d.ByStartPointEndPoint(containerPolyReg.Points[a], containerPolyReg.Points[b]); check = GraphicsUtility.LineAdjacencyCheck(lineA, lineB); if (check) { break; } } return(check); }
//check if a given polygon2d has any of its longer edges aligned with any edge of the containerpolygon2d internal static bool CheckPolyGetsExternalWall(Polygon2d poly, Polygon2d containerPoly, double shortEdgeDist = 16, bool tag = true) { bool check = false; if (!ValidateObject.CheckPoly(poly)) { return(check); } Polygon2d polyReg = new Polygon2d(null); //make given polys reduce number of points if (tag) { polyReg = new Polygon2d(poly.Points); } else { polyReg = poly; } Polygon2d containerPolyReg = new Polygon2d(containerPoly.Points); for (int i = 0; i < polyReg.Points.Count; i++) { int a = i, b = i + 1; double eps = 0; if (i == polyReg.Points.Count - 1) { b = 0; } double distance = PointUtility.DistanceBetweenPoints(polyReg.Points[a], polyReg.Points[b]); List <double> spansSorted = PolygonUtility.GetPolySpan(containerPolyReg); if (distance <= spansSorted[0] * 0.75) { continue; } Line2d lineA = Line2d.ByStartPointEndPoint(polyReg.Points[a], polyReg.Points[b]); for (int j = 0; j < containerPolyReg.Points.Count; j++) { int c = j, d = j + 1; if (j == containerPolyReg.Points.Count - 1) { d = 0; } Line2d lineB = Line2d.ByStartPointEndPoint(containerPolyReg.Points[c], containerPolyReg.Points[d]); check = GraphicsUtility.LineAdjacencyCheck(lineA, lineB, eps); if (check) { break; } } if (check) { break; } } return(check); }
//removes duplicate lines from the list internal static List <Line2d> RemoveDuplicateLines(List <Line2d> networkLine) { List <Line2d> dummyLineList = new List <Line2d>(); List <bool> duplicateList = new List <bool>(); for (int i = 0; i < networkLine.Count; i++) { Line2d line = new Line2d(networkLine[i].StartPoint, networkLine[i].EndPoint); dummyLineList.Add(line); duplicateList.Add(false); } List <Line2d> cleanLines = new List <Line2d>(); for (int i = 0; i < networkLine.Count; i++) { Line2d lineA = networkLine[i]; for (int j = i + 1; j < networkLine.Count; j++) { Line2d lineB = networkLine[j]; bool checkDuplicacy = GraphicsUtility.LineAdjacencyCheck(lineA, lineB);; if (checkDuplicacy) { double lenA = lineA.Length; double lenB = lineB.Length; if (lenA > lenB) { duplicateList[j] = true; } else { duplicateList[i] = true; } } } } int count = 0; for (int i = 0; i < duplicateList.Count; i++) { if (duplicateList[i] == true) { dummyLineList.RemoveAt(i - count); count += 1; } } return(dummyLineList); }
// Removes the lines which are on the poly lines internal static List <Line2d> RemoveDuplicateslinesWithPoly(Polygon2d poly, List <Line2d> lineList) { List <Line2d> cleanLineList = new List <Line2d>(); List <bool> duplicateList = new List <bool>(); for (int i = 0; i < lineList.Count; i++) { Line2d line = new Line2d(lineList[i].StartPoint, lineList[i].EndPoint); cleanLineList.Add(line); duplicateList.Add(false); } for (int i = 0; i < poly.Points.Count; i++) { int b = i + 1; if (i == poly.Points.Count - 1) { b = 0; } Line2d lineA = new Line2d(poly.Points[i], poly.Points[b]); for (int j = 0; j < lineList.Count; j++) { Line2d lineB = lineList[j]; bool checkAdj = GraphicsUtility.LineAdjacencyCheck(lineA, lineB); if (checkAdj) { duplicateList[j] = true; break; } // end of if loop } // end of 2nd for loop } // end of 1st for loop int count = 0; for (int i = 0; i < duplicateList.Count; i++) { if (duplicateList[i] == true) { cleanLineList.RemoveAt(i - count); count += 1; } } return(cleanLineList); }
//removes duplicate lines from a list, based on line adjacency check internal static List <Line2d> RemoveDuplicateLinesBasedOnAdjacency(List <Line2d> lineListOrig, List <Line2d> otherLineList) { List <Line2d> lineEditedList = new List <Line2d>(); for (int i = 0; i < lineListOrig.Count; i++) { lineEditedList.Add(lineListOrig[i]); } List <bool> duplicateTagList = new List <bool>(); for (int i = 0; i < lineListOrig.Count; i++) { bool duplicate = false; for (int j = 0; j < otherLineList.Count; j++) { Point2d midPtOrig = LineUtility.LineMidPoint(lineListOrig[i]); Point2d midPtOther = LineUtility.LineMidPoint(otherLineList[j]); if (GraphicsUtility.LineAdjacencyCheck(lineListOrig[i], otherLineList[j])) { duplicate = true; break; } } duplicateTagList.Add(duplicate); } int count = 0; for (int i = 0; i < duplicateTagList.Count; i++) { if (duplicateTagList[i]) { lineEditedList.RemoveAt(i - count); count += 1; } } return(lineEditedList); }