Example #1
0
        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) }
            });
        }