Exemple #1
0
        public bool Intersects(LineF2D line)
        {
            PointF2D[]        corners           = this.Corners;
            LinePointPosition linePointPosition = line.PositionOfPoint(corners[0]);

            for (int index = 1; index <= corners.Length; ++index)
            {
                if (line.PositionOfPoint(corners[index]) != linePointPosition)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #2
0
        public bool Intersects(PointF2D point1, PointF2D point2)
        {
            PointF2D[]        corners           = this.Corners;
            LineF2D           lineF2D           = new LineF2D(point1, point2, true);
            LinePointPosition linePointPosition = lineF2D.PositionOfPoint(corners[0]);

            for (int index = 1; index < corners.Length; ++index)
            {
                if (lineF2D.PositionOfPoint(corners[index]) != linePointPosition)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #3
0
        /// <summary>
        /// Returns true if the line intersects with this bounding box.
        /// </summary>
        /// <param name="line"></param>
        /// <returns></returns>
        public bool Intersects(LineF2D line)
        {
            // if all points have the same relative position with respect to the line
            // there is no intersection. In the other case there is.

            PointF2D[]        corners        = this.Corners;
            LinePointPosition first_position = line.PositionOfPoint(corners[0]);

            for (int idx = 1; idx <= corners.Length; idx++)
            {
                if (line.PositionOfPoint(corners[idx]) != first_position)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #4
0
 /// <summary>
 /// Returns true if the given coordinate is contained in this ring.
 /// 
 /// See: http://geomalgorithms.com/a03-_inclusion.html
 /// </summary>
 /// <param name="coordinate"></param>
 /// <returns></returns>
 public bool Contains(double[] coordinate)
 {
     int number = 0;
     if (this.X[0] == coordinate[0] &&
         this.Y[0] == coordinate[1])
     { // the given point is one of the corners.
         return true;
     }
     // loop over all edges and calculate if they possibly intersect.
     for (int idx = 0; idx < this.X.Length - 1; idx++)
     {
         if (this.X[idx + 1] == coordinate[0] &&
             this.Y[idx + 1] == coordinate[1])
         { // the given point is one of the corners.
             return true;
         }
         bool idxRight = this.X[idx] > coordinate[0];
         bool idx1Right = this.X[idx + 1] > coordinate[0];
         if (idxRight || idx1Right)
         { // at least one of the coordinates is to the right of the point to calculate for.
             if ((this.Y[idx] <= coordinate[1] &&
                 this.Y[idx + 1] >= coordinate[1]) &&
                 !(this.Y[idx] == coordinate[1] &&
                 this.Y[idx + 1] == coordinate[1]))
             { // idx is lower than idx+1
                 if (idxRight && idx1Right)
                 { // no need for the left/right algorithm the result is already known.
                     number++;
                 }
                 else
                 { // one of the coordinates is not to the 'right' now we need the left/right algorithm.
                     LineF2D localLine = new LineF2D(
                         new PointF2D(this.X[idx], this.Y[idx]),
                         new PointF2D(this.X[idx + 1], this.Y[idx + 1]));
                     if (localLine.PositionOfPoint(new PointF2D(coordinate)) == LinePointPosition.Left)
                     {
                         number++;
                     }
                 }
             }
             else if ((this.Y[idx] >= coordinate[1] &&
                 this.Y[idx + 1] <= coordinate[1]) &&
                 !(this.Y[idx] == coordinate[1] &&
                 this.Y[idx + 1] == coordinate[1]))
             { // idx is higher than idx+1
                 if (idxRight && idx1Right)
                 { // no need for the left/right algorithm the result is already known.
                     number--;
                 }
                 else
                 { // one of the coordinates is not to the 'right' now we need the left/right algorithm.
                     LineF2D localLine = new LineF2D(
                         new PointF2D(this.X[idx], this.Y[idx]),
                         new PointF2D(this.X[idx + 1], this.Y[idx + 1]));
                     if (localLine.PositionOfPoint(new PointF2D(coordinate)) == LinePointPosition.Right)
                     {
                         number--;
                     }
                 }
             }
         }
     }
     return number != 0;
 }
 /// <summary>
 /// Returns true if the given coordinate is contained in this ring.
 /// 
 /// See: http://geomalgorithms.com/a03-_inclusion.html
 /// </summary>
 /// <param name="coordinate"></param>
 /// <returns></returns>
 public bool Contains(GeoCoordinate coordinate)
 {
     int number = 0;
     if (this.Coordinates[0] == coordinate)
     { // the given point is one of the corners.
         return true;
     }
     // loop over all edges and calculate if they possibly intersect.
     for (int idx = 0; idx < this.Coordinates.Count - 1; idx++)
     {
         if (this.Coordinates[idx + 1] == coordinate)
         { // the given point is one of the corners.
             return true;
         }
         bool idxRight = this.Coordinates[idx].Longitude > coordinate.Longitude;
         bool idx1Right = this.Coordinates[idx + 1].Longitude > coordinate.Longitude;
         if (idxRight || idx1Right)
         { // at least on of the coordinates is to the right of the point to calculate for.
             if ((this.Coordinates[idx].Latitude <= coordinate.Latitude &&
                 this.Coordinates[idx + 1].Latitude >= coordinate.Latitude) &&
                 !(this.Coordinates[idx].Latitude == coordinate.Latitude &&
                 this.Coordinates[idx + 1].Latitude == coordinate.Latitude))
             { // idx is lower than idx+1
                 if (idxRight && idx1Right)
                 { // no need for the left/right algorithm the result is already known.
                     number++;
                 }
                 else
                 { // one of the coordinates is not to the 'right' now we need the left/right algorithm.
                     LineF2D localLine = new LineF2D(this.Coordinates[idx], this.Coordinates[idx + 1]);
                     if (localLine.PositionOfPoint(coordinate) == LinePointPosition.Left)
                     {
                         number++;
                     }
                 }
             }
             else if ((this.Coordinates[idx].Latitude >= coordinate.Latitude &&
                 this.Coordinates[idx + 1].Latitude <= coordinate.Latitude) &&
                 !(this.Coordinates[idx].Latitude == coordinate.Latitude &&
                 this.Coordinates[idx + 1].Latitude == coordinate.Latitude))
             { // idx is higher than idx+1
                 if (idxRight && idx1Right)
                 { // no need for the left/right algorithm the result is already known.
                     number--;
                 }
                 else
                 { // one of the coordinates is not to the 'right' now we need the left/right algorithm.
                     LineF2D localLine = new LineF2D(this.Coordinates[idx], this.Coordinates[idx + 1]);
                     if (localLine.PositionOfPoint(coordinate) == LinePointPosition.Right)
                     {
                         number--;
                     }
                 }
             }
         }
     }
     return number != 0;
 }
Exemple #6
0
        public void LinePosition2DTest()
        {
            PointF2D a = new PointF2D(0, 0);
            PointF2D b = new PointF2D(1, 1);

            LineF2D line = new LineF2D(a, b);

            // test where the position lie.
            Assert.AreEqual(line.PositionOfPoint(new PointF2D(0, 0.5f)), LinePointPosition.Left, "Point position should be right!");
            Assert.AreEqual(line.PositionOfPoint(new PointF2D(0.5f, 0.5f)), LinePointPosition.On, "Point position should be on!");
            Assert.AreEqual(line.PositionOfPoint(new PointF2D(0.5f, 0)), LinePointPosition.Right, "Point position should be left!");
        }