Exemple #1
0
        /// <summary>
        /// Check for edge crossings
        /// </summary>
        /// <returns></returns>
        public bool IsSimple()
        {
            var elements = this.Elements;

            for (int i = 0; i < count; ++i)
            {
                int     iplus = (i + 1 > Count - 1) ? 0 : i + 1;
                Vector2 a1    = new Vector2(elements[i].X, elements[i].Y);
                Vector2 a2    = new Vector2(elements[iplus].X, elements[iplus].Y);
                for (int j = i + 1; j < Count; ++j)
                {
                    int     jplus = (j + 1 > Count - 1) ? 0 : j + 1;
                    Vector2 b1    = new Vector2(elements[j].X, elements[j].Y);
                    Vector2 b2    = new Vector2(elements[jplus].X, elements[jplus].Y);

                    Vector2 temp;

                    if (LineTools.LineIntersect2(a1, a2, b1, b2, out temp))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
        /// <summary>
        /// Checks if the vertices forms an simple polygon by checking for edge crossings.
        /// </summary>
        public bool IsSimple()
        {
            //The simplest polygon which can exist in the Euclidean plane has 3 sides.
            if (Count < 3)
            {
                return(false);
            }

            for (int i = 0; i < Count; ++i)
            {
                Vector2 a1 = this[i];
                Vector2 a2 = NextVertex(i);
                for (int j = i + 1; j < Count; ++j)
                {
                    Vector2 b1 = this[j];
                    Vector2 b2 = NextVertex(j);

                    Vector2 temp;

                    if (LineTools.LineIntersect2(ref a1, ref a2, ref b1, ref b2, out temp))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
        /// <summary>
        /// Checks if the vertices forms an simple polygon by checking for edge crossings.
        /// </summary>
        public bool IsSimple()
        {
            //TODO: Check for something like Bentley–Ottmann for simple polygon test, around O(n + log n), but with fewer assumptions.

            //The simplest polygon which can exist in the Euclidean plane has 3 sides.
            if (Count < 3)
            {
                return(false);
            }

            for (int i = 0; i < Count; ++i)
            {
                Vector2 a1 = this[i];
                Vector2 a2 = NextVertex(i);
                for (int j = i + 1; j < Count; ++j)
                {
                    Vector2 b1 = this[j];
                    Vector2 b2 = NextVertex(j);

                    Vector2 temp;

                    if (LineTools.LineIntersect2(ref a1, ref a2, ref b1, ref b2, out temp))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }