Beispiel #1
0
 internal RBNode <BasicObstacleSide> Find(BasicObstacleSide side)
 {
     // Sides that start after the current position cannot be in the scanline.
     if (-1 == scanDirection.ComparePerpCoord(this.linePositionAtLastInsertOrRemove, side.Start))
     {
         return(null);
     }
     return(SideTree.Find(side));
 }
Beispiel #2
0
        /// <summary>
        /// For ordering events in the event list.
        /// Assuming vertical sweep (sweeping up from bottom, scanning horizontally) then order events
        /// first by lowest Y coord, then by lowest X coord (thus assuming we use Cartesian coordinates
        /// (negative is downward == bottom).
        /// </summary>
        /// <param name="lhs"></param>
        /// <param name="rhs"></param>
        /// <returns></returns>
        public int Compare(SweepEvent lhs, SweepEvent rhs)
        {
            if (lhs == rhs)
            {
                return(0);
            }

            if (lhs == null)
            {
                return(-1);
            }

            if (rhs == null)
            {
                return(1);
            }

            // First see if it's at the same scanline level (perpendicular coordinate).
            int cmp = scanDirection.ComparePerpCoord(lhs.Site, rhs.Site);

            if (0 == cmp)
            {
                // Event sites are at the same scanline level. Make sure that any reflection events are lowest (come before
                // any side events, which could remove the side the reflection event was queued for).  We may have two
                // reflection events at same coordinate, because we enqueue in two situations: when a side is opened,
                // and when a side that is within that side's scanline-parallel span is closed.
                bool lhsIsNotReflection = !(lhs is BasicReflectionEvent);
                bool rhsIsNotReflection = !(rhs is BasicReflectionEvent);
                cmp = lhsIsNotReflection.CompareTo(rhsIsNotReflection);

                // If the scanline-parallel coordinate is the same these events are at the same point.
                if (0 == cmp)
                {
                    cmp = scanDirection.CompareScanCoord(lhs.Site, rhs.Site);
                }
            }
            return(cmp);
        }