Example #1
0
        public static Dictionary <string, object> CheckPolyNotches(Polygon2d poly, double distance = 10)
        {
            if (!CheckPoly(poly))
            {
                return(null);
            }
            bool      hasNotches = true;
            int       count = 0, maxTry = 2 * poly.Points.Count;
            Polygon2d currentPoly = new Polygon2d(poly.Points);

            while (hasNotches && count < maxTry)
            {
                Dictionary <string, object> notchObject = PolygonUtility.RemoveAnyNotches(currentPoly, distance);
                if (notchObject == null)
                {
                    continue;
                }
                currentPoly = (Polygon2d)notchObject["PolyNotchRemoved"];
                for (int i = 0; i < poly.Lines.Count; i++)
                {
                    int a = i, b = i + 1;
                    if (i == poly.Points.Count - 1)
                    {
                        b = 0;
                    }
                    if (poly.Lines[a].Length < distance && poly.Lines[b].Length < distance)
                    {
                        hasNotches = true; break;
                    }
                    else
                    {
                        hasNotches = false;
                    }
                }
                count += 1;
            }
            return(new Dictionary <string, object>
            {
                { "PolyReduced", (poly) },
                { "HasNotches", (hasNotches) },
                { "Trials", (count) }
            });
        }