示例#1
0
        // The ordering is reversed because push and pop are faster.
        int CompareSweepEvent(SweepEvent e1, SweepEvent e2)
        {
            if (e1.Equals(e2))
            {
                return(0);
            }

            if (e1.p.x > e2.p.x)             // Different x coordinate
            {
                return(-1);
            }

            if (e1.p.x < e2.p.x)             // Different x coordinate
            {
                return(1);
            }

            if (e1.p != e2.p)             // Different points, but same x coordinate. The event with lower y coordinate is processed first
            {
                return((e1.p.y > e2.p.y) ? -1 : 1);
            }

            if (e1.isLeft != e2.isLeft)             // Same point, but one is a left endpoint and the other a right endpoint. The right endpoint is processed first
            {
                return((e1.isLeft) ? -1 : 1);
            }

            // Same point, both events are left endpoints or both are right endpoints. The event associate to the bottom segment is processed first
            return(e1.isAbove(e2.otherSE.p) ? -1 : 1);
        }
示例#2
0
        // Should only be called by segmentCompare
        private bool CompareSweepEvent(SweepEvent e1, SweepEvent e2)
        {
//			if (e1.p.x > e2.p.x) // Different x coordinate
//				return true;
//
//			if (e2.p.x > e1.p.x) // Different x coordinate
//				return false;
//
//			if (e1.p != e2.p) // Different points, but same x coordinate. The event with lower y coordinate is processed first
//				return e1.p.y > e2.p.y;

            if (e1.p.x > e2.p.x + Point.PRECISION)
            {
                return(true);
            }

            if (e2.p.x > e1.p.x + Point.PRECISION)
            {
                return(false);
            }

            if (!Point.PointEquals(e1.p, e2.p))
            {
                return(e1.p.y > e2.p.y + Point.PRECISION);
            }

            if (e1.isLeft != e2.isLeft)             // Same point, but one is a left endpoint and the other a right endpoint. The right endpoint is processed first
            {
                return(e1.isLeft);
            }

            // Same point, both events are left endpoints or both are right endpoints. The event associate to the bottom segment is processed first
            return(e1.isAbove(e2.otherSE.p));
        }
示例#3
0
        bool Sec(SweepEvent e1, SweepEvent e2)
        {
            // Different x coordinate
//			if (e1.p.x != e2.p.x) {
            if (e1.p.x - e2.p.x > Point.PRECISION || e1.p.x - e2.p.x < -Point.PRECISION)
            {
                return(e1.p.x > e2.p.x);
            }

            // Same x coordinate. The event with lower y coordinate is processed first
//			if (e1.p.y != e2.p.y) {
            if (e1.p.y - e2.p.y > Point.PRECISION || e1.p.y - e2.p.y < -Point.PRECISION)
            {
                return(e1.p.y > e2.p.y);
            }

            // Same point, but one is a left endpoint and the other a right endpoint. The right endpoint is processed first
            if (e1.isLeft != e2.isLeft)
            {
                return(e1.isLeft);
            }

            // Same point, both events are left endpoints or both are right endpoints. The event associate to the bottom segment is processed first
            return(e1.isAbove(e2.otherSE.p));
        }
示例#4
0
        private bool SegmentCompare(SweepEvent e1, SweepEvent e2)
        {
            if (e1.Equals(e2))
            {
                return(false);
            }

            if (signedArea(e1.p, e1.otherSE.p, e2.p) != 0 || signedArea(e1.p, e1.otherSE.p, e2.otherSE.p) != 0)
            {
                // Segments are not collinear
                // If they share their left endpoint use the right endpoint to sort
                if (Point.PointEquals(e1.p, e2.p))
                {
                    return(e1.isBelow(e2.otherSE.p));
                }

                if (CompareSweepEvent(e1, e2))
                {
                    return(e2.isAbove(e1.p));
                }

                return(e1.isBelow(e2.p));
            }

            if (Point.PointEquals(e1.p, e2.p))             // Segments colinear
            {
                return(false);
            }

            return(CompareSweepEvent(e1, e2));
        }