}         // 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) }
            });
        }
        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) }
            });
        }