Example #1
0
 //=====================================================================
 // Validate() : void
 //=====================================================================
 /// <summary>
 /// The validate method check if the XYPolyline is valid. The checks
 /// made are:
 ///   - is number of points >= 3
 ///   - is the length of all line segments positiv
 ///   - do any lines cross
 ///   - is the area positiv
 /// Exception is raised if the constraints are not met.
 /// </summary>
 public new void Validate()
 {
     if (Points.Count < 3)
     {
         throw new Exception("Number of vertices in polygon element is less than 3.");
     }
     if (GetArea() <= 0)
     {
         throw new Exception("Area of polygon is negative or zero. XYPolygons must be ordered counter clockwise.");
     }
     for (int j = 0; j < Points.Count; j++)
     {
         if (GetLine(j).GetLength() == 0)
         {
             throw new Exception("Length of line segment no: " +
                                 j + " (0-based) of XYPolygon is zero.");
         }
     }
     for (int j = 0; j < Points.Count; j++)
     {
         for (int m = 0; m < j; m++)
         {
             if (XYGeometryTools.DoLineSegmentsIntersect(GetLine(j), GetLine(m)))
             {
                 throw new Exception("Line no: " + j + " and line no: " +
                                     m + " of XYPolygon crosses.");
             }
         }
     }
 }
Example #2
0
        //=====================================================================
        // IsIntersected(integer i) : bool
        //=====================================================================
        /// <summary>
        /// The method decides if the triangle formed by  P(i-1), P(i) and
        /// P(i+1) from Polygon are intersected by any of the other points
        /// of the polygon.
        /// </summary>
        /// <param name="i">Middle index for the three points that forms the triangle</param>
        /// <returns>
        ///	<p>true: If the triangle P(i-1), P(i), P(i+1) is intersected by other parts of Polygon</p>
        ///	<p>false: otherwise</p>
        /// </returns>
        protected bool IsIntersected(int i)
        {
            int n = Points.Count;

            int im1 = i - 1;
            int ip1 = i + 1;

            if (i == 0)
            {
                im1 = n - 1;
            }
            else if (i == n - 1)
            {
                ip1 = 0;
            }

            XYPoint   nodeim1      = new XYPoint((XYPoint)Points[im1]);
            XYPoint   nodei        = new XYPoint((XYPoint)Points[i]);
            XYPoint   nodeip1      = new XYPoint((XYPoint)Points[ip1]);
            XYPolygon localPolygon = new XYPolygon();

            localPolygon.Points.Add(nodeim1);
            localPolygon.Points.Add(nodei);
            localPolygon.Points.Add(nodeip1);

            int j = 0;

            while (((j < n - 1)))
            {
                double x = ((XYPoint)Points[j]).X;
                double y = ((XYPoint)Points[j]).Y;

                if (((((j != im1) && (j != i)) && (j != ip1)) && XYGeometryTools.IsPointInPolygon(x, y, localPolygon)))
                {
                    return(true);
                }
                else
                {
                    j++;
                }
            }
            return(false);
        }