コード例 #1
0
ファイル: SweepEventSet.cs プロジェクト: VadimCat/Map-project
        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 (Misc.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 (Misc.PointEquals(e1.p, e2.p))             // Segments colinear
            {
                return(false);
            }

            return(CompareSweepEvent(e1, e2));
        }
コード例 #2
0
ファイル: EventQueue.cs プロジェクト: VadimCat/Map-project
        // 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);
        }