Beispiel #1
0
 public static bool PointInSegment(Rational p, SegRat1 s)
 {
     s.NormalizeOrientation();
     return((s.AClosed && p == s.A) ||
            (s.BClosed && p == s.B) ||
            (s.A < p && p < s.B));
 }
Beispiel #2
0
        public static SegmentIntersectionType ColinearSegmentIntersection(SegRat2 s, SegRat2 t, ref VecRat2 pointIntersection, ref SegRat2 segmentIntersection)
        {
            //This check is important for handling degenerate cases like s = [(x,y), (x,y)).
            if (s.IsEmpty() || t.IsEmpty())
            {
                return(SegmentIntersectionType.None);
            }

            //This check is important because the LineProjectionTransform can only be formed with a non-point segment.
            if (s.IsPoint())
            {
                if (ColinearPointInSegment(s.A, t))
                {
                    pointIntersection = s.A;
                    return(SegmentIntersectionType.Point);
                }
                else
                {
                    return(SegmentIntersectionType.None);
                }
            }

            LineProjectionTransform transform = new LineProjectionTransform(s);
            SegRat1 proj_s = transform.Project(s);
            SegRat1 proj_t = transform.Project(t);

            Rational proj_pointIntersection   = new Rational();
            SegRat1  proj_segmentIntersection = new SegRat1();

            SegmentIntersectionType result = SegmentIntersection(
                proj_s, proj_t, ref proj_pointIntersection, ref proj_segmentIntersection);

            if (result == SegmentIntersectionType.Point)
            {
                pointIntersection = transform.Unproject(proj_pointIntersection);
            }
            else if (result == SegmentIntersectionType.Segment)
            {
                segmentIntersection = transform.Unproject(proj_segmentIntersection);
            }

            return(result);
        }
Beispiel #3
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);
        }
 public SegRat2 Unproject(SegRat1 dot_s)
 {
     return(new SegRat2(Unproject(dot_s.A), Unproject(dot_s.B), dot_s.AClosed, dot_s.BClosed));
 }