Ejemplo n.º 1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="p"></param>
 /// <param name="p1"></param>
 /// <param name="p2"></param>
 public override void ComputeIntersection(ICoordinate p, ICoordinate p1, ICoordinate p2)
 {
     isProper = false;
     // do between check first, since it is faster than the orientation test
     if (Envelope.Intersects(p1, p2, p))
     {
         if ((CGAlgorithms.OrientationIndex(p1, p2, p) == 0) &&
             (CGAlgorithms.OrientationIndex(p2, p1, p) == 0))
         {
             isProper = true;
             if (p.Equals(p1) || p.Equals(p2))
             {
                 isProper = false;
             }
             result = DoIntersect;
             return;
         }
     }
     result = DontIntersect;
 }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <param name="q1"></param>
        /// <param name="q2"></param>
        /// <returns></returns>
        public override int ComputeIntersect(ICoordinate p1, ICoordinate p2, ICoordinate q1, ICoordinate q2)
        {
            isProper = false;

            // first try a fast test to see if the envelopes of the lines intersect
            if (!Envelope.Intersects(p1, p2, q1, q2))
            {
                return(DontIntersect);
            }

            // for each endpoint, compute which side of the other segment it lies
            // if both endpoints lie on the same side of the other segment,
            // the segments do not intersect
            int Pq1 = CGAlgorithms.OrientationIndex(p1, p2, q1);
            int Pq2 = CGAlgorithms.OrientationIndex(p1, p2, q2);

            if ((Pq1 > 0 && Pq2 > 0) || (Pq1 < 0 && Pq2 < 0))
            {
                return(DontIntersect);
            }

            int Qp1 = CGAlgorithms.OrientationIndex(q1, q2, p1);
            int Qp2 = CGAlgorithms.OrientationIndex(q1, q2, p2);

            if ((Qp1 > 0 && Qp2 > 0) || (Qp1 < 0 && Qp2 < 0))
            {
                return(DontIntersect);
            }

            bool collinear = (Pq1 == 0 && Pq2 == 0 && Qp1 == 0 && Qp2 == 0);

            if (collinear)
            {
                return(ComputeCollinearIntersection(p1, p2, q1, q2));
            }

            /*
             *  Check if the intersection is an endpoint. If it is, copy the endpoint as
             *  the intersection point. Copying the point rather than computing it
             *  ensures the point has the exact value, which is important for
             *  robustness. It is sufficient to simply check for an endpoint which is on
             *  the other line, since at this point we know that the inputLines must
             *  intersect.
             */
            if (Pq1 == 0 || Pq2 == 0 || Qp1 == 0 || Qp2 == 0)
            {
                isProper = false;
                if (Pq1 == 0)
                {
                    intPt[0] = new Coordinate(q1);
                }
                if (Pq2 == 0)
                {
                    intPt[0] = new Coordinate(q2);
                }
                if (Qp1 == 0)
                {
                    intPt[0] = new Coordinate(p1);
                }
                if (Qp2 == 0)
                {
                    intPt[0] = new Coordinate(p2);
                }
            }
            else
            {
                isProper = true;
                intPt[0] = Intersection(p1, p2, q1, q2);
            }
            return(DoIntersect);
        }