//checks if two points are within a certain threshold region internal static bool CheckPointsWithinRange(Point2d ptA, Point2d ptB, double threshold = 2) { List <Point2d> squarePts = new List <Point2d>(); squarePts.Add(Point2d.ByCoordinates(ptA.X + threshold, ptA.Y - threshold)); //LR squarePts.Add(Point2d.ByCoordinates(ptA.X + threshold, ptA.Y + threshold)); //UR squarePts.Add(Point2d.ByCoordinates(ptA.X - threshold, ptA.Y + threshold)); //UL squarePts.Add(Point2d.ByCoordinates(ptA.X - threshold, ptA.Y - threshold)); //LLl Polygon2d squarePoly = Polygon2d.ByPoints(squarePts); return(GraphicsUtility.PointInsidePolygonTest(squarePoly, ptB)); }
//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); }
} // end of function //makes intersections and returns the two polygon2ds after intersection internal static Dictionary <string, object> MakeIntersections(List <Point2d> poly, Line2d splitLine, double space = 0) { List <Point2d> intersectedPoints = GraphicsUtility.LinePolygonIntersection(poly, splitLine); //List<Point2d> intersectedPoints = TestGraphicsUtility.LinePolygonIntersectionIndex(poly, splitLine); // find all points on poly which are to the left or to the right of the line List <int> pIndexA = new List <int>(); List <int> pIndexB = new List <int>(); for (int i = 0; i < poly.Count; i++) { bool check = ValidateObject.CheckPointSide(splitLine, poly[i]); if (check) { pIndexA.Add(i); } else { pIndexB.Add(i); } } //organize the points to make closed poly List <Point2d> sortedA = PointUtility.DoSortClockwise(poly, intersectedPoints, pIndexA); List <Point2d> sortedB = PointUtility.DoSortClockwise(poly, intersectedPoints, pIndexB); /*List<Polygon2d> splittedPoly = new List<Polygon2d>(); * if (space == 0) splittedPoly = new List<Polygon2d> { new Polygon2d(sortedA, 0), new Polygon2d(sortedB, 0) }; * else * { * sortedA = PolygonUtility.SmoothPolygon(new Polygon2d(sortedA,0).Points, space); * sortedB = PolygonUtility.SmoothPolygon(new Polygon2d(sortedB,0).Points, space); * splittedPoly = new List<Polygon2d> { new Polygon2d(sortedA, 0), new Polygon2d(sortedB, 0) }; * } */ List <Polygon2d> splittedPoly = new List <Polygon2d> { new Polygon2d(sortedA, 0), new Polygon2d(sortedB, 0) }; return(new Dictionary <string, object> { { "PolyAfterSplit", (splittedPoly) }, { "IntersectedPoints", (intersectedPoints) }, { "PointASide", (sortedA) }, { "PointBSide", (sortedB) } }); }
// 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); }
//################################################################################################################ //this class stores methods realted to GraphicsUtility class which needs to be tested further for reliability //################################################################################################################ // checks if two lines are collinear - not using internal static bool CheckLineCollinear(Line2d lineA, Line2d lineB) { Point2d p1 = lineA.StartPoint; Point2d p2 = lineA.EndPoint; Point2d q1 = lineB.StartPoint; Point2d q2 = lineB.EndPoint; // Find the four orientations needed for general and special cases int o1 = GraphicsUtility.Orientation(p1, q1, p2); int o2 = GraphicsUtility.Orientation(p1, q1, q2); int o3 = GraphicsUtility.Orientation(p2, q2, p1); int o4 = GraphicsUtility.Orientation(p2, q2, q1); // General case if (o1 != o2 && o3 != o4) { return(false); } // p1, q1 and p2 are colinear and p2 lies on segment p1q1 if (o1 == 0 && ValidateObject.CheckOnSegment(p1, p2, q1)) { return(true); } // p1, q1 and p2 are colinear and q2 lies on segment p1q1 if (o2 == 0 && ValidateObject.CheckOnSegment(p1, q2, q1)) { return(true); } // p2, q2 and p1 are colinear and p1 lies on segment p2q2 if (o3 == 0 && ValidateObject.CheckOnSegment(p2, p1, q2)) { return(true); } // p2, q2 and q1 are colinear and q1 lies on segment p2q2 if (o4 == 0 && ValidateObject.CheckOnSegment(p2, q1, q2)) { return(true); } return(false); // Doesn't fall in any of the above cases }
//offsets an input line by a given distance internal static int DirectionForPointInPoly(Line2d lineInp, Polygon2d poly, double distance) { if (lineInp == null || !ValidateObject.CheckPoly(poly)) { return(0); } Point2d midPt = LineMidPoint(lineInp); Point2d pt1 = OffsetLinePoint(lineInp, midPt, distance); Point2d pt2 = OffsetLinePoint(lineInp, midPt, -1 * distance); if (GraphicsUtility.PointInsidePolygonTest(poly, pt1)) { return(1); } else { return(-1); } }
//checks a polygon2d if it has self intersecting lines public static bool CheckPolygonSelfIntersection(Polygon2d poly) { if (!CheckPoly(poly)) { return(false); } Polygon2d polyNew = new Polygon2d(poly.Points); List <Line2d> lineList = polyNew.Lines; for (int i = 0; i < lineList.Count; i++) { int a = i + 1, b = i - 1; if (a > lineList.Count - 1) { a = 0; } if (b < 0) { b = lineList.Count - 1; } for (int j = 0; j < lineList.Count; j++) { if (i == j) { continue; } if (j == a || j == b) { continue; } Point2d intersectPt = GraphicsUtility.LineLineIntersection(lineList[i], lineList[j]); if (intersectPt == null) { continue; } else if (CheckOnSegment(lineList[i], intersectPt) && CheckOnSegment(lineList[j], intersectPt)) { return(true); } } } return(false); }
//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); }
internal static Dictionary <string, object> AddPointToFitPoly(Polygon2d poly, Polygon2d containerPoly, double distance = 16, double area = 0, double thresDistance = 10, double recompute = 5) { if (!ValidateObject.CheckPoly(poly)) { return(null); } if (distance < 1) { return(null); } Dictionary <string, object> lineOffsetCheckObj = ValidateObject.CheckLinesOffsetInPoly(poly, containerPoly, distance); List <int> indicesFalse = (List <int>)lineOffsetCheckObj["IndicesFalse"]; List <List <Point2d> > pointsFalse = (List <List <Point2d> >)lineOffsetCheckObj["PointsOutside"]; List <Point2d> probPointList = new List <Point2d>(); List <Point2d> polyNewPoints = new List <Point2d>(); List <Line2d> falseLines = new List <Line2d>(); Point2d ptNewEnd = new Point2d(0, 0); Point2d otherPt = new Point2d(0, 0); Point2d probPt = new Point2d(0, 0); Line2d line = new Line2d(ptNewEnd, otherPt); int count = 0, maxTry = 50; double ratio = 0, increment = .25; bool added = false, checkOffPtNew = false; for (int i = 0; i < poly.Points.Count; i++) { int a = i, b = i + 1; if (i == poly.Points.Count - 1) { b = 0; } polyNewPoints.Add(poly.Points[a]); if (indicesFalse[i] > -1) { falseLines.Add(poly.Lines[i]); } if (poly.Lines[i].Length > thresDistance && indicesFalse[i] > -1 && pointsFalse[i] != null && pointsFalse[i].Count == 1 && !added && LayoutUtility.CheckLineGetsExternalWall(poly.Lines[i], containerPoly)) { probPointList.AddRange(pointsFalse[i]); probPt = pointsFalse[i][0]; line = poly.Lines[i]; Point2d midPt = LineUtility.LineMidPoint(line); if (line.StartPoint.Compare(probPt)) { otherPt = line.EndPoint; } else { otherPt = line.StartPoint; } Vector2d vecToOther = new Vector2d(probPt, otherPt); while (!checkOffPtNew && count < maxTry && ratio < 0.9) { ratio += increment; ptNewEnd = VectorUtility.VectorAddToPoint(probPt, vecToOther, ratio); Point2d offPtNew = LineUtility.OffsetLinePointInsidePoly(line, ptNewEnd, poly, distance); checkOffPtNew = GraphicsUtility.PointInsidePolygonTest(poly, offPtNew); count += 1; } polyNewPoints.Add(ptNewEnd); added = true; } } Polygon2d polyAdded = new Polygon2d(polyNewPoints, 0); return(new Dictionary <string, object> { { "PolyAddedPts", (polyAdded) }, { "ProblemPoint", (probPt) }, { "IsAdded", (added) }, { "PointAdded", (ptNewEnd) }, { "Trials", (count) }, { "FinalRatio", (ratio) }, { "ProblemLine", (line) }, { "ProblemPtsList", (probPointList) }, { "FalseLineList", (falseLines) } }); }
//make the given poly all points orthonogonal to each other internal static Polygon2d MakePolyPointsOrtho(Polygon2d poly) { Polygon2d polyReg = new Polygon2d(poly.Points); List <Point2d> ptForOrthoPoly = new List <Point2d>(); for (int i = 0; i < polyReg.Points.Count; i++) { Point2d pt = Point2d.ByCoordinates(polyReg.Points[i].X, polyReg.Points[i].Y); ptForOrthoPoly.Add(pt); } for (int i = 0; i < polyReg.Points.Count; i++) { int a = i, b = i + 1; double eps = 50; if (i == polyReg.Points.Count - 1) { b = 0; } Line2d line = new Line2d(polyReg.Points[a], polyReg.Points[b]); if (ValidateObject.CheckLineOrient(line) == -1) { //double diffX = Math.Abs(line.StartPoint.X - line.EndPoint.X); //double diffY = Math.Abs(line.StartPoint.Y - line.EndPoint.Y); Point2d cenPoly = PolygonUtility.CentroidOfPoly(polyReg); Point2d ptEndA = Point2d.ByCoordinates(polyReg.Points[a].X + eps, polyReg.Points[a].Y); Line2d refLineA = Line2d.ByStartPointEndPoint(polyReg.Points[a], ptEndA); Point2d ptEndB = Point2d.ByCoordinates(polyReg.Points[b].X + eps, polyReg.Points[b].Y); Line2d refLineB = Line2d.ByStartPointEndPoint(polyReg.Points[b], ptEndB); Point2d projectedPtA = GraphicsUtility.ProjectedPointOnLine(refLineB, polyReg.Points[a]); Point2d projectedPtB = GraphicsUtility.ProjectedPointOnLine(refLineA, polyReg.Points[b]); Vector2d vecA = new Vector2d(projectedPtA, cenPoly); Vector2d vecB = new Vector2d(projectedPtB, cenPoly); double vecALength = vecA.Length; double vecBLength = vecB.Length; if (vecALength > vecBLength) { //ptForOrthoPoly[i] = projectedPtA; ptForOrthoPoly.Insert(b, projectedPtB); } else { //ptForOrthoPoly[i] = projectedPtB; ptForOrthoPoly.Insert(b, projectedPtA); } /* * if (diffX > diffY) * { * Point2d ptEndA = Point2d.ByCoordinates(polyReg.Points[a].X, polyReg.Points[a].Y + eps); * Line2d refLineA = Line2d.ByStartPointEndPoint(polyReg.Points[a], ptEndA); * refLineA = LineUtility.extend(refLineA); * * Point2d ptEndB = Point2d.ByCoordinates(polyReg.Points[b].X, polyReg.Points[b].Y + eps); * Line2d refLineB = Line2d.ByStartPointEndPoint(polyReg.Points[b], ptEndB); * refLineB = LineUtility.extend(refLineB); * * Point2d projectedPtA = GraphicsUtility.ProjectedPointOnLine(refLineB, polyReg.Points[a]); * Point2d projectedPtB = GraphicsUtility.ProjectedPointOnLine(refLineA, polyReg.Points[b]); * * Vector2d vecA = new Vector2d(projectedPtA, cenPoly); * Vector2d vecB = new Vector2d(projectedPtB, cenPoly); * double vecALength = vecA.Length; * double vecBLength = vecB.Length; * if(vecALength < vecBLength) * { * //ptForOrthoPoly[i] = projectedPtA; * ptForOrthoPoly.Insert(b, projectedPtB); * } * else * { * //ptForOrthoPoly[i] = projectedPtB; * ptForOrthoPoly.Insert(b, projectedPtA); * } * } * else * { * * Point2d ptEndA = Point2d.ByCoordinates(polyReg.Points[a].X + eps, polyReg.Points[a].Y); * Line2d refLineA = Line2d.ByStartPointEndPoint(polyReg.Points[a], ptEndA); * refLineA = LineUtility.extend(refLineA); * * Point2d ptEndB = Point2d.ByCoordinates(polyReg.Points[b].X + eps, polyReg.Points[b].Y); * Line2d refLineB = Line2d.ByStartPointEndPoint(polyReg.Points[b], ptEndB); * refLineB = LineUtility.extend(refLineB); * * Point2d projectedPtA = GraphicsUtility.ProjectedPointOnLine(refLineB, polyReg.Points[a]); * Point2d projectedPtB = GraphicsUtility.ProjectedPointOnLine(refLineA, polyReg.Points[b]); * * Vector2d vecA = new Vector2d(projectedPtA, cenPoly); * Vector2d vecB = new Vector2d(projectedPtB, cenPoly); * double vecALength = vecA.Length; * double vecBLength = vecB.Length; * if (vecALength < vecBLength) * { * //ptForOrthoPoly[i] = projectedPtA; * ptForOrthoPoly.Insert(b, projectedPtB); * } * else * { * //ptForOrthoPoly[i] = projectedPtB; * ptForOrthoPoly.Insert(b, projectedPtB); * } * } */ } } return(new Polygon2d(ptForOrthoPoly)); }
public static Dictionary <string, object> MakeProgCirculationPolys(List <Line2d> circulationNetwork, List <Polygon2d> polyProgList, double circulationWidth = 8, double circulationFrequency = 0.5, int designSeed = 10) { if (!ValidateObject.CheckPolyList(polyProgList)) { return(null); } if (circulationNetwork == null || circulationNetwork.Count == 0) { return(null); } List <Line2d> flatLineList = new List <Line2d>(); List <bool> IsDuplicateList = new List <bool>(); polyProgList = PolygonUtility.SmoothPolygonList(polyProgList, 5); //flatten all the polys in each depts to make it one list List <Polygon2d> circulationPolyList = new List <Polygon2d>(); List <Polygon2d> updatedProgPolyList = new List <Polygon2d>(); List <int> deptIdList = new List <int>(); double allowedCircRatio = 4; List <double> areaProgPolyList = new List <double>(); for (int i = 0; i < polyProgList.Count; i++) { areaProgPolyList.Add(PolygonUtility.AreaPolygon(polyProgList[i])); } double maxArea = areaProgPolyList.Max(); areaProgPolyList.Sort(); int value = (int)(areaProgPolyList.Count / 3); double areaThresh = areaProgPolyList[value]; Random ran = new Random(designSeed); for (int i = 0; i < circulationNetwork.Count; i++) { Line2d splitter = circulationNetwork[i]; double someNumber = BasicUtility.RandomBetweenNumbers(ran, 1, 0); if (someNumber > circulationFrequency) { continue; } for (int j = 0; j < polyProgList.Count; j++) { Polygon2d progPoly = polyProgList[j]; double areaPoly = PolygonUtility.AreaPolygon(progPoly); Point2d midPt = LineUtility.LineMidPoint(splitter); Point2d nudgedMidPt = LineUtility.NudgeLineMidPt(splitter, progPoly, 0.5); bool checkInside = GraphicsUtility.PointInsidePolygonTest(progPoly, nudgedMidPt); if (checkInside) { Dictionary <string, object> splitResult = SplitObject.SplitByLine(progPoly, splitter, circulationWidth); List <Polygon2d> polyAfterSplit = (List <Polygon2d>)(splitResult["PolyAfterSplit"]); if (ValidateObject.CheckPolyList(polyAfterSplit)) { double areaA = PolygonUtility.AreaPolygon(polyAfterSplit[0]), areaB = PolygonUtility.AreaPolygon(polyAfterSplit[1]); if (areaA < areaB) { if (polyAfterSplit[0].Points != null) { if (ValidateObject.CheckPolyBBox(polyAfterSplit[0], allowedCircRatio)) { circulationPolyList.Add(polyAfterSplit[0]); } } updatedProgPolyList.Add(polyAfterSplit[1]); } else { if (polyAfterSplit[1].Points != null) { if (ValidateObject.CheckPolyBBox(polyAfterSplit[1], allowedCircRatio)) { circulationPolyList.Add(polyAfterSplit[1]); } } updatedProgPolyList.Add(polyAfterSplit[0]); } } // end of if loop checking polylist } // end of check inside } // end of for loop j } // end of for loop i return(new Dictionary <string, object> { { "ProgCirculationPoly", (circulationPolyList) } }); }
public static Dictionary <string, object> FindProgCirculationNetwork(List <DeptData> deptData, Polygon2d buildingOutline, List <Polygon2d> leftOverPoly = null) { if (!ValidateObject.CheckPoly(buildingOutline)) { return(null); } if (deptData == null) { return(null); } List <Polygon2d> polygonsAllProgList = new List <Polygon2d>(); List <DeptData> deptDataAllDeptList = new List <DeptData>(); List <List <Line2d> > lineCollection = new List <List <Line2d> >(); for (int i = 0; i < deptData.Count; i++) { if ((deptData[i].DepartmentType.IndexOf(BuildLayout.KPU.ToLower()) != -1 || deptData[i].DepartmentType.IndexOf(BuildLayout.KPU.ToUpper()) != -1)) { continue; // dont add for KPU } if (deptData[i].PolyAssignedToDept == null) { continue; } polygonsAllProgList.AddRange(deptData[i].PolyAssignedToDept); } if (leftOverPoly != null) { polygonsAllProgList.AddRange(leftOverPoly); } for (int i = 0; i < polygonsAllProgList.Count; i++) { polygonsAllProgList[i] = new Polygon2d(polygonsAllProgList[i].Points); } List <Line2d> networkLine = new List <Line2d>(); for (int i = 0; i < polygonsAllProgList.Count; i++) { Polygon2d poly1 = polygonsAllProgList[i]; for (int j = i + 1; j < polygonsAllProgList.Count; j++) { Polygon2d poly2 = polygonsAllProgList[j]; Dictionary <string, object> checkNeighbor = PolygonUtility.FindPolyAdjacentEdge(poly1, poly2); if (checkNeighbor != null) { if ((bool)checkNeighbor["Neighbour"] == true) { networkLine.Add((Line2d)checkNeighbor["SharedEdge"]); } } } } List <Line2d> cleanNetworkLines = LineUtility.RemoveDuplicateLines(networkLine); cleanNetworkLines = GraphicsUtility.RemoveDuplicateslinesWithPoly(buildingOutline, cleanNetworkLines); List <List <string> > deptNeighborNames = new List <List <string> >(); List <Line2d> onlyOrthoLineList = new List <Line2d>(); for (int i = 0; i < cleanNetworkLines.Count; i++) { bool checkOrtho = ValidateObject.CheckLineOrthogonal(cleanNetworkLines[i]); if (checkOrtho == true) { onlyOrthoLineList.Add(cleanNetworkLines[i]); } } return(new Dictionary <string, object> { { "CirculationNetwork", (onlyOrthoLineList) }, { "PolygonsForAllPrograms", (polygonsAllProgList) } }); }
public static Dictionary <string, object> MakeDeptCirculationPolys(List <DeptData> deptData, List <List <Line2d> > circulationNetwork, double circulationWidth = 8) { if (deptData == null || deptData.Count == 0 || circulationNetwork == null || circulationNetwork.Count == 0) { return(null); } List <Line2d> cleanLineList = LineUtility.FlattenLine2dList(circulationNetwork); List <Polygon2d> allDeptPolyList = new List <Polygon2d>(); List <Polygon2d> circulationPolyList = new List <Polygon2d>(); List <Polygon2d> updatedDeptPolyList = new List <Polygon2d>(); List <int> deptIdList = new List <int>(); for (int i = 0; i < deptData.Count; i++) { List <Polygon2d> deptPolyList = deptData[i].PolyAssignedToDept; if (!ValidateObject.CheckPolyList(deptPolyList)) { continue; } for (int j = 0; j < deptPolyList.Count; j++) { deptIdList.Add(i); allDeptPolyList.Add(deptPolyList[j]); } } for (int i = 0; i < cleanLineList.Count; i++) { Line2d splitter = cleanLineList[i]; for (int j = 0; j < allDeptPolyList.Count; j++) { Polygon2d deptPoly = allDeptPolyList[j]; Point2d midPt = LineUtility.LineMidPoint(splitter); Point2d nudgedMidPt = LineUtility.NudgeLineMidPt(splitter, deptPoly, 0.5); if (GraphicsUtility.PointInsidePolygonTest(deptPoly, nudgedMidPt)) { Dictionary <string, object> splitResult = SplitObject.SplitByLine(deptPoly, splitter, circulationWidth); List <Polygon2d> polyAfterSplit = (List <Polygon2d>)(splitResult["PolyAfterSplit"]); if (ValidateObject.CheckPolyList(polyAfterSplit)) { double areaA = PolygonUtility.AreaPolygon(polyAfterSplit[0]); double areaB = PolygonUtility.AreaPolygon(polyAfterSplit[1]); if (areaA < areaB) { circulationPolyList.Add(polyAfterSplit[0]); updatedDeptPolyList.Add(polyAfterSplit[1]); } else { circulationPolyList.Add(polyAfterSplit[1]); updatedDeptPolyList.Add(polyAfterSplit[0]); } } } // end of check inside } // end of for loop j } // end of for loop i List <List <Polygon2d> > deptPolyBranchedInList = new List <List <Polygon2d> >(); List <int> distinctIdList = deptIdList.Distinct().ToList(); for (int i = 0; i < distinctIdList.Count; i++) { List <Polygon2d> polyForDeptBranch = new List <Polygon2d>(); for (int j = 0; j < deptIdList.Count; j++) { if (deptIdList[j] == i) { if (j < updatedDeptPolyList.Count) { polyForDeptBranch.Add(updatedDeptPolyList[j]); } } } deptPolyBranchedInList.Add(polyForDeptBranch); } return(new Dictionary <string, object> { { "DeptCirculationPoly", (circulationPolyList) }, { "UpdatedDeptPolys", (deptPolyBranchedInList) } }); }
internal static Dictionary <string, object> PolygonPolygonCommonEdgeDict(Polygon2d poly, Polygon2d other) { bool check = false; if (poly == null || other == null) { return(null); } double eps = 200; Polygon2d polyReg = new Polygon2d(poly.Points); Polygon2d otherReg = new Polygon2d(other.Points); Dictionary <string, object> UpdatedCenters = ComputePolyCentersAlign(polyReg, otherReg); Point2d centerPoly = (Point2d)UpdatedCenters["CenterPolyA"]; Point2d centerOther = (Point2d)UpdatedCenters["CenterPolyB"]; polyReg = (Polygon2d)UpdatedCenters["PolyA"]; otherReg = (Polygon2d)UpdatedCenters["PolyB"]; //make vectors Vector2d centerToCen = new Vector2d(centerPoly, centerOther); Vector2d centerToCenX = new Vector2d(centerToCen.X, 0); Vector2d centerToCenY = new Vector2d(0, centerToCen.Y); //make centerLine Line2d centerLine = new Line2d(centerPoly, centerOther); Vector2d keyVec; if (centerToCenX.Length > centerToCenY.Length) { keyVec = new Vector2d(centerToCenX.X, centerToCenX.Y); } else { keyVec = new Vector2d(centerToCenY.X, centerToCenY.Y); } //check line poly intersection between centertocen vector and each polys Line2d lineInPolyReg = CodeToBeTested.LinePolygonIntersectionReturnLine(polyReg.Points, centerLine, centerOther); Line2d lineInOtherReg = CodeToBeTested.LinePolygonIntersectionReturnLine(otherReg.Points, centerLine, centerPoly); //find distance d1 and d2 from two centers to linepolyintersection line Point2d projectedPtOnPolyReg = GraphicsUtility.ProjectedPointOnLine(lineInPolyReg, centerPoly); Point2d projectedPtOnOtherReg = GraphicsUtility.ProjectedPointOnLine(lineInOtherReg, centerOther); double dist1 = PointUtility.DistanceBetweenPoints(centerPoly, projectedPtOnPolyReg); double dist2 = PointUtility.DistanceBetweenPoints(centerOther, projectedPtOnOtherReg); double totalDistance = 2 * (dist1 + dist2); Line2d lineMoved = new Line2d(lineInPolyReg.StartPoint, lineInPolyReg.EndPoint); lineMoved = LineUtility.Move(lineMoved, centerPoly); Point2d projectedPt = GraphicsUtility.ProjectedPointOnLine(lineMoved, centerOther); double distance = PointUtility.DistanceBetweenPoints(projectedPt, centerOther); bool isNeighbour = false; if (totalDistance - eps < distance && distance < totalDistance + eps) { isNeighbour = true; } else { isNeighbour = false; } return(new Dictionary <string, object> { { "Neighbour", (isNeighbour) }, { "SharedEdgeA", (lineInPolyReg) }, { "SharedEdgeB", (lineInOtherReg) }, { "LineMoved", (lineMoved) }, { "CenterToCenterLine", (centerLine) }, { "CenterPolyPoint", (centerPoly) }, { "CenterPolyOtherPoint", (centerOther) }, }); }
internal static Dictionary <string, object> CheckLinesOffsetInPoly(Polygon2d poly, Polygon2d containerPoly, double distance = 10, bool tag = false) { if (!CheckPoly(poly)) { return(null); } Polygon2d oPoly = PolygonUtility.OffsetPoly(poly, 0.2); List <bool> offsetAble = new List <bool>(); List <List <Point2d> > pointsOutsideList = new List <List <Point2d> >(); List <Line2d> linesNotOffset = new List <Line2d>(); List <int> indicesFalse = new List <int>(); for (int i = 0; i < poly.Points.Count; i++) { bool offsetAllow = false; int a = i, b = i + 1; if (i == poly.Points.Count - 1) { b = 0; } Line2d line = poly.Lines[i]; Point2d offStartPt = LineUtility.OffsetLinePointInsidePoly(line, line.StartPoint, oPoly, distance); Point2d offEndPt = LineUtility.OffsetLinePointInsidePoly(line, line.EndPoint, oPoly, distance); bool checkStartPt = GraphicsUtility.PointInsidePolygonTest(oPoly, offStartPt); bool checkEndPt = GraphicsUtility.PointInsidePolygonTest(oPoly, offEndPt); bool checkExtEdge = LayoutUtility.CheckLineGetsExternalWall(line, containerPoly); if (tag) { checkExtEdge = true; } List <Point2d> pointsDefault = new List <Point2d>(); if (checkStartPt && checkEndPt && checkExtEdge) { offsetAllow = true; indicesFalse.Add(-1); pointsDefault.Add(null); } else { if (!checkStartPt) { pointsDefault.Add(line.StartPoint); } if (!checkEndPt) { pointsDefault.Add(line.EndPoint); } linesNotOffset.Add(line); indicesFalse.Add(i); offsetAllow = false; } pointsOutsideList.Add(pointsDefault); offsetAble.Add(offsetAllow); } return(new Dictionary <string, object> { { "LinesFalse", (linesNotOffset) }, { "Offsetables", (offsetAble) }, { "IndicesFalse", (indicesFalse) }, { "PointsOutside", (pointsOutsideList) } }); }