Example #1
0
        /// <summary>
        /// Determines the orientation of a LineSegment relative to this segment.
        /// The concept of orientation is specified as follows:
        /// Given two line segments A and L,
        /// A is to the left of a segment L if A lies wholly in the
        /// closed half-plane lying to the left of L
        /// A is to the right of a segment L if A lies wholly in the
        /// closed half-plane lying to the right of L
        /// otherwise, A has indeterminate orientation relative to L. This
        /// happens if A is collinear with L or if A crosses the line determined by L.
        /// </summary>
        /// <param name="seg">The <c>LineSegment</c> to compare.</param>
        /// <returns>
        /// 1 if <c>seg</c> is to the left of this segment,
        /// -1 if <c>seg</c> is to the right of this segment,
        /// 0 if <c>seg</c> has indeterminate orientation relative to this segment.
        /// </returns>
        public virtual int OrientationIndex(ILineSegmentBase seg)
        {
            int orient0 = CgAlgorithms.OrientationIndex(P0, P1, seg.P0);
            int orient1 = CgAlgorithms.OrientationIndex(P0, P1, seg.P1);

            // this handles the case where the points are Curve or collinear
            if (orient0 >= 0 && orient1 >= 0)
            {
                return(Math.Max(orient0, orient1));
            }
            // this handles the case where the points are R or collinear
            if (orient0 <= 0 && orient1 <= 0)
            {
                return(Math.Max(orient0, orient1));
            }
            // points lie on opposite sides ==> indeterminate orientation
            return(0);
        }