Exemple #1
0
        public static SegmentIntersectionType SegmentIntersection(SegRat1 s, SegRat1 t, ref Rational pointIntersection, ref SegRat1 segmentIntersection)
        {
            //This check is important for handling degenerate cases like s = [x, x).
            if (s.IsEmpty() || t.IsEmpty())
            {
                return(SegmentIntersectionType.None);
            }

            s.NormalizeOrientation();
            t.NormalizeOrientation();

            if (s.A > t.A)
            {
                MathAid.Swap(ref s, ref t);
            }

            if (s.B < t.A)
            {
                return(SegmentIntersectionType.None);
            }

            if (s.B == t.A)
            {
                if (s.BClosed && t.AClosed)
                {
                    pointIntersection = s.B;
                    return(SegmentIntersectionType.Point);
                }
                else
                {
                    return(SegmentIntersectionType.None);
                }
            }

            Rational b = Rational.Min(s.B, t.B);

            segmentIntersection.A       = t.A;
            segmentIntersection.B       = b;
            segmentIntersection.AClosed = (t.AClosed && (s.A < t.A || (s.AClosed && s.A == t.A)));
            segmentIntersection.BClosed = ((s.BClosed && t.BClosed) || (s.BClosed && b < t.B) || (t.BClosed && b < s.B));
            return(SegmentIntersectionType.Segment);
        }
Exemple #2
0
 //Flip the orientation of this segment
 public void Flip()
 {
     MathAid.Swap(ref A, ref B);
     MathAid.Swap(ref AClosed, ref BClosed);
 }