public static Dictionary <string, object> FindDeptCirculationNetwork(List <DeptData> deptData, Polygon2d leftOverPoly = null, bool noExternalWall = false, double circulationFrequency = 0.75)
        {
            if (deptData == null || deptData.Count == 0)
            {
                return(null);
            }
            double                limit = 0;
            List <Polygon2d>      polygonsAllDeptList = new List <Polygon2d>();
            List <DeptData>       deptDataAllDeptList = new List <DeptData>();
            List <List <string> > deptNamesNeighbors  = new List <List <string> >();
            List <List <Line2d> > lineCollection      = new List <List <Line2d> >();

            //make flattened list of all dept data and dept polys
            for (int i = 0; i < deptData.Count; i++)
            {
                List <Polygon2d> polyList = deptData[i].PolyAssignedToDept;
                if (!ValidateObject.CheckPolyList(polyList))
                {
                    continue;
                }
                for (int j = 0; j < polyList.Count; j++)
                {
                    polygonsAllDeptList.Add(polyList[j]);
                    deptDataAllDeptList.Add(deptData[i]);
                }
            }
            if (leftOverPoly != null)
            {
                polygonsAllDeptList.Add(leftOverPoly);
            }
            //else Trace.WriteLine("leftover poly found null, so not added");
            List <Line2d> networkLine = new List <Line2d>();

            for (int i = 0; i < polygonsAllDeptList.Count; i++)
            {
                Polygon2d polyA = polygonsAllDeptList[i];
                for (int j = i + 1; j < polygonsAllDeptList.Count; j++)
                {
                    Polygon2d polyB = polygonsAllDeptList[j];
                    Dictionary <string, object> checkNeighbor = PolygonUtility.FindPolyAdjacentEdge(polyA, polyB, limit);
                    if (checkNeighbor != null)
                    {
                        if ((bool)checkNeighbor["Neighbour"] == true)
                        {
                            networkLine.Add((Line2d)checkNeighbor["SharedEdge"]);
                        }
                    }
                }
            }

            // if externalWalls not necessary
            List <Line2d>    extraLines  = new List <Line2d>();
            List <Polygon2d> polyKeyList = new List <Polygon2d>();

            if (noExternalWall)
            {
                polyKeyList = deptData[0].PolyAssignedToDept;
                for (int i = 0; i < polyKeyList.Count; i++)
                {
                    Polygon2d polyA = polyKeyList[i];
                    for (int j = i + 1; j < polyKeyList.Count; j++)
                    {
                        Polygon2d polyB = polyKeyList[j];
                        Dictionary <string, object> checkNeighbor = PolygonUtility.FindPolyAdjacentEdgeEdit(polyA, polyB, 0.05);
                        if (checkNeighbor != null)
                        {
                            if ((bool)checkNeighbor["Neighbour"] == true)
                            {
                                networkLine.Add((Line2d)checkNeighbor["SharedEdge"]);
                                extraLines.Add((Line2d)checkNeighbor["SharedEdge"]);
                            }
                        }
                    }
                }
            }
            List <Line2d> cleanNetworkLines = LineUtility.RemoveDuplicateLines(networkLine);

            // extend the lines found
            for (int i = 0; i < cleanNetworkLines.Count; i++)
            {
                cleanNetworkLines[i] = LineUtility.ExtendLine(cleanNetworkLines[i], 2000);
            }

            cleanNetworkLines = RemoveNetworkRedundancy(cleanNetworkLines, circulationFrequency);

            //return cleanNetworkLines;
            return(new Dictionary <string, object>
            {
                { "CirculationNetworkLines", (cleanNetworkLines) }
            });
        }
        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) }
            });
        }