Exemple #1
0
 public bool Contains(Vertex2 point, out int wn)
 {
     wn = 0;
     for (int i = 0; i < Count; i++)
     {
         if (this[i].y <= point.y)
         {
             // start y <= P.y
             if (this[i + 1].y > point.y)                                        // an upward crossing
             {
                 if (PGUtils.LocatePointOnLine(this[i], this[i + 1], point) > 0) // P left of edge
                 {
                     ++wn;                                                       // have a valid up intersect
                 }
             }
         }
         else
         {
             // start y > P.y (no test needed)
             if (this[i + 1].y <= point.y)                                       // a downward crossing
             {
                 if (PGUtils.LocatePointOnLine(this[i], this[i + 1], point) < 0) // P right of edge
                 {
                     --wn;                                                       // have a valid down intersect
                 }
             }
         }
     }
     return(wn != 0);
 }
Exemple #2
0
        public static Polygon RemoveCollinearVertices(Polygon polygon)
        {
            if (polygon.Count <= 3)
            {
                return(polygon);
            }

            var newPolygon = new Polygon();

            for (int i = 0; i < polygon.Count; i++)
            {
                if (PGUtils.LocatePointOnLine(polygon[i - 1], polygon[i + 1], polygon[i]) != 0)
                {
                    newPolygon.Add(polygon[i]);
                }
            }
            return(newPolygon);
        }