Пример #1
0
        //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);
        }
        public static Dictionary <string, object> SplitByDistance(Polygon2d polyOutline, Random ran, double distance = 10, int dir = 0, double spacing = 0)
        {
            if (!ValidateObject.CheckPoly(polyOutline))
            {
                return(null);
            }
            double         extents = 5000, spacingProvided;
            List <Point2d> polyOrig = polyOutline.Points;

            if (spacing == 0)
            {
                spacingProvided = BuildLayout.SPACING;
            }
            else
            {
                spacingProvided = spacing;
            }

            List <Point2d> poly = PolygonUtility.SmoothPolygon(polyOrig, spacingProvided);

            if (!ValidateObject.CheckPointList(poly))
            {
                return(null);
            }
            Dictionary <int, object> obj = PointUtility.PointSelector(ran, poly);
            Point2d pt        = (Point2d)obj[0];
            int     orient    = (int)obj[1];
            Line2d  splitLine = new Line2d(pt, extents, dir);

            // push this line right or left or up or down based on ratio
            if (dir == 0)
            {
                splitLine = LineUtility.Move(splitLine, 0, orient * distance);
            }
            else
            {
                splitLine = LineUtility.Move(splitLine, orient * distance, 0);
            }

            Dictionary <string, object> intersectionReturn = MakeIntersections(poly, splitLine, spacingProvided);
            List <Point2d>   intersectedPoints             = (List <Point2d>)intersectionReturn["IntersectedPoints"];
            List <Polygon2d> splittedPoly = (List <Polygon2d>)intersectionReturn["PolyAfterSplit"];
            List <Point2d>   ptA = (List <Point2d>)intersectionReturn["PointASide"];
            List <Point2d>   ptB = (List <Point2d>)intersectionReturn["PointBSide"];
            Polygon2d        polyA = new Polygon2d(ptA, 0), polyB = new Polygon2d(ptB, 0);

            //List<Polygon2d> splittedPoly = new List<Polygon2d>();
            //splittedPoly.Add(polyA); splittedPoly.Add(polyB);
            return(new Dictionary <string, object>
            {
                { "PolyAfterSplit", (splittedPoly) },
                { "SplitLine", (splitLine) },
                { "IntersectedPoints", (intersectedPoints) },
                { "PointASide", (ptA) },
                { "PointBSide", (ptB) }
            });
        }
Пример #3
0
        //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);
        }
        //offsets an input line by a given distance inside a poly
        public static Line2d OffsetLineInsidePoly(Line2d lineInp, Polygon2d poly, double distance)
        {
            if (lineInp == null || !ValidateObject.CheckPoly(poly))
            {
                return(null);
            }
            Point2d  ptStart = OffsetLinePointInsidePoly(lineInp, lineInp.StartPoint, poly, distance);
            Vector2d vec     = new Vector2d(lineInp.StartPoint, ptStart);
            Point2d  ptEnd   = VectorUtility.VectorAddToPoint(lineInp.EndPoint, vec);

            return(new Line2d(ptStart, ptEnd));
        }
        //offsets an input point by a given distance inside a poly
        internal static Point2d OffsetLinePointInsidePoly(Line2d lineInp, Point2d testPoint, Polygon2d poly, double distance)
        {
            if (lineInp == null || !ValidateObject.CheckPoly(poly))
            {
                return(null);
            }
            int dir = DirectionForPointInPoly(lineInp, poly, distance);

            if (dir == 0)
            {
                return(null);
            }
            return(OffsetLinePoint(lineInp, testPoint, dir * distance));
        }
Пример #6
0
        internal static Dictionary <string, object> ExtLinesAndOffsetsFromBBox(Polygon2d poly, double patientRoomDepth = 16, double recompute = 5)
        {
            if (!ValidateObject.CheckPoly(poly))
            {
                return(null);
            }
            Polygon2d     polyReg       = new Polygon2d(poly.Points);
            List <Line2d> allSplitLines = new List <Line2d>();
            Polygon2d     polyBBox      = Polygon2d.ByPoints(ReadData.FromPointsGetBoundingPoly(polyReg.Points));

            allSplitLines = polyBBox.Lines;
            List <double> splitLineLength = new List <double>();

            for (int i = 0; i < allSplitLines.Count; i++)
            {
                splitLineLength.Add(allSplitLines[i].Length);
            }
            List <int> sortedIndices = BasicUtility.Quicksort(splitLineLength);

            if (sortedIndices != null)
            {
                sortedIndices.Reverse();
            }

            List <Line2d>  offsetLines   = new List <Line2d>();
            List <Point2d> midPtsOffsets = new List <Point2d>();

            for (int i = 0; i < allSplitLines.Count; i++)
            {
                offsetLines.Add(LineUtility.Offset(allSplitLines[i], patientRoomDepth));
                midPtsOffsets.Add(LineUtility.NudgeLineMidPt(allSplitLines[i], poly, patientRoomDepth));
            }

            List <Line2d> offsetSortedLines = new List <Line2d>();

            for (int i = 0; i < offsetLines.Count; i++)
            {
                offsetSortedLines.Add(offsetLines[sortedIndices[i]]);
            }
            return(new Dictionary <string, object>
            {
                { "SplittableLines", (allSplitLines) },
                { "OffsetLines", (offsetSortedLines) },
                { "SortedIndices", (sortedIndices) },
                { "OffsetMidPts", (midPtsOffsets) }
            });
        }
        public static Dictionary <string, object> SplitByLine(Polygon2d polyOutline, Line2d inputLine, double distance = 5)
        {
            if (!ValidateObject.CheckPoly(polyOutline))
            {
                return(null);
            }
            List <Point2d> polyOrig   = polyOutline.Points;
            List <Point2d> poly       = PolygonUtility.SmoothPolygon(polyOrig, BuildLayout.SPACING);
            Line2d         splitLine  = new Line2d(inputLine);
            Point2d        centerPoly = PointUtility.CentroidInPointLists(poly);
            bool           checkSide  = ValidateObject.CheckPointSide(splitLine, centerPoly);
            int            orient     = ValidateObject.CheckLineOrient(splitLine);

            if (orient == 0)
            {
                if (!checkSide)
                {
                    splitLine = LineUtility.Move(splitLine, 0, -1 * distance);
                }
                else
                {
                    splitLine = LineUtility.Move(splitLine, 0, 1 * distance);
                }
            }
            else
            {
                if (checkSide)
                {
                    splitLine = LineUtility.Move(splitLine, -1 * distance, 0);
                }
                else
                {
                    splitLine = LineUtility.Move(splitLine, 1 * distance, 0);
                }
            }

            Dictionary <string, object> intersectionReturn = MakeIntersections(poly, splitLine, BuildLayout.SPACING);
            List <Polygon2d>            splittedPoly       = (List <Polygon2d>)intersectionReturn["PolyAfterSplit"];

            return(new Dictionary <string, object>
            {
                { "PolyAfterSplit", (splittedPoly) },
                { "SplitLine", (splitLine) }
            });
        }
        internal static Polygon2d AddpointToPoly(Polygon2d poly, int lineId = 0)
        {
            if (!ValidateObject.CheckPoly(poly))
            {
                return(null);
            }
            List <Point2d> ptList = new List <Point2d>();

            for (int i = 0; i < poly.Points.Count; i++)
            {
                if (i == lineId)
                {
                    Line2d line = poly.Lines[lineId];
                }

                ptList.Add(poly.Points[i]);
            }
            return(null);
        }
        //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 if a point is inside a polygon or not
        public static bool PointInsidePolygonTest(Polygon2d poly, Point2d testPoint)
        {
            if (!ValidateObject.CheckPoly(poly) || testPoint == null)
            {
                return(false);
            }
            bool           check         = false;
            List <Point2d> pointsPolygon = poly.Points;
            int            numPolyPts    = pointsPolygon.Count;

            for (int i = 0, j = numPolyPts - 1; i < numPolyPts; j = i++)
            {
                if (((pointsPolygon[i].Y > testPoint.Y) != (pointsPolygon[j].Y > testPoint.Y)) &&
                    (testPoint.X < (pointsPolygon[j].X - pointsPolygon[i].X) * (testPoint.Y - pointsPolygon[i].Y) / (pointsPolygon[j].Y - pointsPolygon[i].Y) + pointsPolygon[i].X))
                {
                    check = !check;
                }
            }
            return(check);
        }
Пример #11
0
        internal static Dictionary <string, object> FindOuterLinesAndOffsets(Polygon2d poly, double patientRoomDepth = 16, double extension = 8000, double recompute = 5)
        {
            if (!ValidateObject.CheckPoly(poly))
            {
                return(null);
            }
            Polygon2d      polyReg = new Polygon2d(poly.Points);
            List <Line2d>  hLines = new List <Line2d>();
            List <Line2d>  vLines = new List <Line2d>();
            List <Point2d> hMidPt = new List <Point2d>();
            List <Point2d> vMidPt = new List <Point2d>();
            List <Line2d>  nonOrthoLines = new List <Line2d>();
            int            countOrtho = 0, countNonOrtho = 0;

            for (int i = 0; i < polyReg.Points.Count; i++)
            {
                int a = i, b = i + 1;
                if (i == polyReg.Points.Count - 1)
                {
                    b = 0;
                }
                Line2d line     = new Line2d(polyReg.Points[a], polyReg.Points[b]);
                int    lineType = ValidateObject.CheckLineOrient(line);
                if (lineType > -1)
                {
                    if (lineType == 0)
                    {
                        Line2d extendedLine = LineUtility.ExtendLine(line, extension);
                        hLines.Add(extendedLine);
                        hMidPt.Add(LineUtility.LineMidPoint(line));
                    }
                    if (lineType == 1)
                    {
                        Line2d extendedLine = LineUtility.ExtendLine(line, extension);
                        vLines.Add(extendedLine);
                        vMidPt.Add(LineUtility.LineMidPoint(line));
                    }
                    countOrtho += 1;
                }
                else
                {
                    countNonOrtho += 1;
                    nonOrthoLines.Add(line);
                }
            }
            List <Line2d> selectedHLines = new List <Line2d>();
            List <Line2d> selectedVLines = new List <Line2d>();
            int           hIndLow        = CodeToBeTested.ReturnLowestPointFromList(hMidPt);
            int           hIndHigh       = CodeToBeTested.ReturnHighestPointFromList(hMidPt);
            int           vIndLow        = PointUtility.LowestPointFromList(vMidPt);
            int           vIndHigh       = PointUtility.HighestPointFromList(vMidPt);

            if (hIndLow > -1)
            {
                selectedHLines.Add(hLines[hIndLow]);
            }
            if (hIndHigh > -1)
            {
                selectedHLines.Add(hLines[hIndHigh]);
            }
            if (vIndLow > -1)
            {
                selectedVLines.Add(vLines[vIndLow]);
            }
            if (vIndHigh > -1)
            {
                selectedVLines.Add(vLines[vIndHigh]);
            }

            List <Line2d> allSplitLines = new List <Line2d>();

            allSplitLines.AddRange(selectedHLines);
            allSplitLines.AddRange(selectedVLines);
            List <double> splitLineLength = new List <double>();

            for (int i = 0; i < allSplitLines.Count; i++)
            {
                splitLineLength.Add(allSplitLines[i].Length);
            }
            List <int> sortedIndices = BasicUtility.Quicksort(splitLineLength);

            if (sortedIndices != null)
            {
                sortedIndices.Reverse();
            }

            List <Line2d>  offsetLines   = new List <Line2d>();
            List <Point2d> midPtsOffsets = new List <Point2d>();

            for (int i = 0; i < allSplitLines.Count; i++)
            {
                offsetLines.Add(LineUtility.Offset(allSplitLines[i], patientRoomDepth));
                midPtsOffsets.Add(LineUtility.NudgeLineMidPt(allSplitLines[i], poly, patientRoomDepth));
            }

            List <Line2d> offsetSortedLines = new List <Line2d>();

            for (int i = 0; i < offsetLines.Count; i++)
            {
                offsetSortedLines.Add(offsetLines[sortedIndices[i]]);
            }
            return(new Dictionary <string, object>
            {
                { "SplittableLines", (allSplitLines) },
                { "OffsetLines", (offsetSortedLines) },
                { "SortedIndices", (sortedIndices) },
                { "OffsetMidPts", (midPtsOffsets) },
                { "NonOrthoLines", (nonOrthoLines) }
            });
        }
Пример #12
0
        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) }
            });
        }
        public static Dictionary <string, object> SplitByOffsetFromLine(Polygon2d polyOutline, int lineId, double distance = 10, double minDist = 0)
        {
            if (!ValidateObject.CheckPoly(polyOutline))
            {
                return(null);
            }
            Polygon2d poly = new Polygon2d(polyOutline.Points, 0);

            List <Point2d> pointForBlock = new List <Point2d>();
            List <Point2d> polyPtsCopy   = poly.Points.Select(pt => new Point2d(pt.X, pt.Y)).ToList();//deep copy

            for (int i = 0; i < poly.Points.Count; i++)
            {
                int a = i, b = i + 1, c = i - 1;
                if (c < 0)
                {
                    c = poly.Points.Count - 1;
                }
                if (i == poly.Points.Count - 1)
                {
                    b = 0;
                }
                Line2d prevLine = poly.Lines[c];
                Line2d currLine = poly.Lines[a];
                Line2d nextLine = poly.Lines[b];
                if (i == lineId)
                {
                    Line2d line = new Line2d(poly.Points[a], poly.Points[b]);
                    if (line.Length < minDist)
                    {
                        continue;
                    }
                    Line2d offsetLine = LineUtility.OffsetLineInsidePoly(line, poly, distance);
                    pointForBlock.Add(poly.Points[a]);
                    pointForBlock.Add(poly.Points[b]);
                    pointForBlock.Add(offsetLine.EndPoint);
                    pointForBlock.Add(offsetLine.StartPoint);
                    int orientPrev = ValidateObject.CheckLineOrient(prevLine);
                    int orientCurr = ValidateObject.CheckLineOrient(currLine);
                    int orientNext = ValidateObject.CheckLineOrient(nextLine);

                    // case 1
                    if (orientPrev == orientCurr && orientCurr == orientNext)
                    {
                        polyPtsCopy.Insert(b, offsetLine.EndPoint);
                        polyPtsCopy.Insert(b, offsetLine.StartPoint);
                    }

                    // case 2
                    if (orientPrev != orientCurr && orientCurr == orientNext)
                    {
                        polyPtsCopy[a] = offsetLine.StartPoint;
                        polyPtsCopy.Insert(b, offsetLine.EndPoint);
                    }

                    // case 3
                    if (orientPrev == orientCurr && orientCurr != orientNext)
                    {
                        polyPtsCopy.Insert(b, offsetLine.StartPoint);
                        polyPtsCopy[b + 1] = offsetLine.EndPoint;
                    }

                    // case 4
                    if (orientPrev != orientCurr && orientCurr != orientNext)
                    {
                        polyPtsCopy[a] = offsetLine.StartPoint;
                        polyPtsCopy[b] = offsetLine.EndPoint;
                    }
                }
            }
            Polygon2d polySplit = new Polygon2d(pointForBlock, 0);
            Polygon2d leftPoly  = new Polygon2d(polyPtsCopy, 0); //poly.Points

            return(new Dictionary <string, object>
            {
                { "PolyAfterSplit", (polySplit) },
                { "LeftOverPoly", (leftPoly) },
            });
        }
        //subdivide a given poly into smaller parts till acceptable width is met, returns list of polydept grids and list of polys to compute circulation
        public static List <List <Polygon2d> > SplitRecursivelyToSubdividePoly(List <Polygon2d> polyList, double acceptableWidth = 10, double circulationFreq = 10, double ratio = 0.5, bool tag = false)
        {
            if (!ValidateObject.CheckPolyList(polyList))
            {
                return(null);
            }

            int count = 0;
            Queue <Polygon2d>        polyQueue = new Queue <Polygon2d>();
            List <List <Polygon2d> > polyAllReturn = new List <List <Polygon2d> >();
            List <Polygon2d>         polyBrokenList = new List <Polygon2d>(), polyCirculationList = new List <Polygon2d>();
            double totalArea = 0; // cirFac = Math.Ceiling(acceptableWidth/ circulationFreq);
            double cirFac = circulationFreq;

            for (int i = 0; i < polyList.Count; i++)
            {
                totalArea += PolygonUtility.AreaPolygon(polyList[i]);
                polyQueue.Enqueue(polyList[i]);
            }
            Random rand = new Random();
            double targetArea = totalArea / cirFac;

            while (polyQueue.Count > 0)
            {
                Polygon2d currentPoly = polyQueue.Dequeue();
                Dictionary <string, object> splitObj = SplitByRatio(currentPoly, ratio, 0);
                if (tag)
                {
                    ratio = BasicUtility.RandomBetweenNumbers(rand, 0.7, 0.35);
                }
                if (splitObj == null)
                {
                    continue;
                }
                List <Polygon2d> polySplitList = (List <Polygon2d>)splitObj["PolyAfterSplit"];
                if (ValidateObject.CheckPolyList(polySplitList) && polySplitList.Count > 1)
                {
                    polySplitList = PolygonUtility.SmoothPolygonList(polySplitList, 2);
                    Polygon2d bbox1 = Polygon2d.ByPoints(ReadData.FromPointsGetBoundingPoly(polySplitList[0].Points));
                    Polygon2d bbox2 = Polygon2d.ByPoints(ReadData.FromPointsGetBoundingPoly(polySplitList[1].Points));
                    if (!ValidateObject.CheckPoly(bbox1) || !ValidateObject.CheckPoly(bbox2))
                    {
                        continue;
                    }

                    if (PolygonUtility.AreaPolygon(polySplitList[0]) > targetArea)
                    {
                        polyCirculationList.Add(polySplitList[0]);
                    }
                    if (PolygonUtility.AreaPolygon(polySplitList[1]) > targetArea)
                    {
                        polyCirculationList.Add(polySplitList[1]);
                    }

                    if (bbox1.Lines[0].Length < acceptableWidth || bbox1.Lines[1].Length < acceptableWidth)
                    {
                        polyBrokenList.Add(polySplitList[0]);
                    }
                    else
                    {
                        polyQueue.Enqueue(polySplitList[0]);
                    }
                    if (bbox2.Lines[0].Length < acceptableWidth || bbox2.Lines[1].Length < acceptableWidth)
                    {
                        polyBrokenList.Add(polySplitList[1]);
                    }
                    else
                    {
                        polyQueue.Enqueue(polySplitList[1]);
                    }
                }
                if (ValidateObject.CheckPolyList(polySplitList) && polySplitList.Count < 2)
                {
                    Polygon2d bbox1 = Polygon2d.ByPoints(ReadData.FromPointsGetBoundingPoly(polySplitList[0].Points));
                    if (!ValidateObject.CheckPoly(bbox1))
                    {
                        continue;
                    }
                    if (bbox1.Lines[0].Length < acceptableWidth || bbox1.Lines[1].Length < acceptableWidth)
                    {
                        polyBrokenList.Add(polySplitList[0]);
                    }
                    if (PolygonUtility.AreaPolygon(polySplitList[0]) > targetArea)
                    {
                        polyCirculationList.Add(polySplitList[0]);
                    }
                    else
                    {
                        polyQueue.Enqueue(polySplitList[0]);
                    }
                }
                count += 1;
            }

            for (int i = 0; i < polyQueue.Count; i++)
            {
                polyBrokenList.Add(polyQueue.Dequeue());
            }
            polyAllReturn.Add(polyBrokenList);
            polyAllReturn.Add(polyCirculationList);
            return(polyAllReturn);
        }
        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) }
            });
        }