/// <summary>
 ///
 /// </summary>
 /// <param name="p"></param>
 /// <param name="p1"></param>
 /// <param name="p2"></param>
 public override void ComputeIntersection(Coordinate p, Coordinate p1, Coordinate 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 = IntersectionType.PointIntersection;
             return;
         }
     }
     Result = IntersectionType.NoIntersection;
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <param name="q1"></param>
        /// <param name="q2"></param>
        /// <returns></returns>
        public override IntersectionType ComputeIntersect(Coordinate p1, Coordinate p2, Coordinate q1, Coordinate 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(IntersectionType.NoIntersection);
            }

            // 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(IntersectionType.NoIntersection);
            }

            int qp1 = CgAlgorithms.OrientationIndex(q1, q2, p1);
            int qp2 = CgAlgorithms.OrientationIndex(q1, q2, p2);

            if ((qp1 > 0 && qp2 > 0) || (qp1 < 0 && qp2 < 0))
            {
                return(IntersectionType.NoIntersection);
            }

            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)
                {
                    IntersectionPoints[0] = new Coordinate(q1);
                }
                if (pq2 == 0)
                {
                    IntersectionPoints[0] = new Coordinate(q2);
                }
                if (qp1 == 0)
                {
                    IntersectionPoints[0] = new Coordinate(p1);
                }
                if (qp2 == 0)
                {
                    IntersectionPoints[0] = new Coordinate(p2);
                }
            }
            else
            {
                IsProper = true;
                IntersectionPoints[0] = Intersection(p1, p2, q1, q2);
            }
            return(IntersectionType.PointIntersection);
        }