示例#1
0
        public bool TryFindSmallestSegmentAbove(ISpatiallyComparable x, out Segment result)
        {
            ISpatiallyComparable segment;
            bool success = segBundle.TryGetSmallestAbove(x, out segment);

            result = (Segment)segment;
            return(success);
        }
示例#2
0
        public bool TryFindLargestSegmentBelow(ISpatiallyComparable x, out Segment result)
        {
            ISpatiallyComparable segment;
            bool success = segBundle.TryGetLargestBelow(x, out segment);

            result = (Segment)segment;
            return(success);
        }
示例#3
0
        public bool TryFindLgBBelow(ISpatiallyComparable x, out Bundle result)
        {
            ISpatiallyComparable bundle;
            bool success = bTree.TryGetLargestBelow(x, out bundle);

            result = (Bundle)bundle;
            return(success);
        }
示例#4
0
        private static bool Witnessed(Bundle lower, Bundle upper, ISpatiallyComparable sweepEvent)
        {
            int  lComp  = lower.Bottom.CompareTo(sweepEvent);
            int  uComp  = upper.Top.CompareTo(sweepEvent);
            bool result = lComp > uComp;

            return(result);
        }
示例#5
0
        public bool TryFindSmBAbove(ISpatiallyComparable x, out Bundle result)
        {
            ISpatiallyComparable bundle;
            bool success = bTree.TryGetSmallestAbove(x, out bundle);

            result = (Bundle)bundle;
            return(success);
        }
示例#6
0
 public int CompareTo(ISpatiallyComparable obj)
 {
     // TODO: Refactor all this to use double-dispatch
     if (obj is Bundle || obj is Segment)
     {
         return(-obj.CompareTo(this));
     }
     return(CompareTo((FPoint)obj));
 }
示例#7
0
        public Bundle FindLgBBelow(ISpatiallyComparable x)
        {
            Bundle result;
            bool   success = TryFindLgBBelow(x, out result);

            if (!success)
            {
                throw new IndexOutOfRangeException();
            }
            return(result);
        }
示例#8
0
 public int CompareTo(ISpatiallyComparable rhs)
 {
     if (rhs is Bundle)
     {
         return(-((rhs as Bundle).CompareTo(this)));
     }
     if (rhs is FPoint)
     {
         return(CompareTo(rhs as FPoint));
     }
     if (rhs is Segment)
     {
         return(CompareTo(rhs as Segment));
     }
     throw new ArgumentException();
 }
示例#9
0
        public int CompareTo(ISpatiallyComparable rhs)
        {
            if (rhs is Bundle)
            {
                return(Top.CompareTo(((Bundle)rhs).Top));
            }

            int comp = Top.CompareTo(rhs);

            if (comp <= 0)
            {
                return(comp);
            }

            comp = Bottom.CompareTo(rhs);
            return(comp < 0 ? 0 : comp);
        }
示例#10
0
 public Segment FindLargestSegmentBelow(ISpatiallyComparable x)
 {
     return((Segment)segBundle.LargestBelow(x));
 }
示例#11
0
 public Segment FindSmallestSegmentAbove(ISpatiallyComparable x)
 {
     return((Segment)segBundle.SmallestAbove(x));
 }
示例#12
0
        private static int MakeNewEqTree(BundleTree tree, IList <Segment> slist, int sIdx, Segment[] contS, ISpatiallyComparable sweepEvent)
        {
            // TODO: Refactor this horrible method!
            Bundle currB = null;
            int    nc    = 0;
            int    ic    = 0;

            while (nc < 2 && contS[nc] != null)
            {
                ++nc;
            }

            int iss = sIdx;

            while (sIdx < slist.Count && slist[sIdx].CompareTo(sweepEvent) <= 0)
            {
                ++sIdx;
            }

            if (ic >= nc && iss >= sIdx)
            {
                return(sIdx);
            }

            Segment currS = ic < nc && (iss >= sIdx || contS[ic].CompareTo(slist[iss]) <= 0) ? contS[ic++] : slist[iss++];

            bool currBIsRed = currS.IsRed ^ true;

            do
            {
                if (currBIsRed == currS.IsRed)
                {
                    Debug.Assert(currB != null);
                    currB.insertSegAtTop(currS);
                }
                else
                {
                    currBIsRed = currS.IsRed;
                    currB      = new Bundle(currBIsRed, null, currB, currS);
                    tree.InsertBAtTop(currB);
                }
                currS.useStart = false;
                if (ic < nc || iss < sIdx)
                {
                    if (ic < nc && (iss >= sIdx || contS[ic].CompareTo(slist[iss]) <= 0))
                    {
                        currS = contS[ic++];
                    }
                    else
                    {
                        currS = slist[iss++];
                    }
                }
                else
                {
                    return(sIdx);
                }
            }while(true);
        }
示例#13
0
        public BundleTree Split(ISpatiallyComparable splitPos, bool keep)
        {
            BundleTree upperPart = null;
            Segment    splitSeg;
            Bundle     splitB;

            if (keep)
            {
                splitB = FindSmBAbove(splitPos);
                if (splitB.PurpleDown != null && splitB.PurpleDown.CompareTo(splitPos) > 0)
                {
                    splitB = splitB.PurpleDown;
                }

                if (splitB.PurpleDown != null)
                {
                    splitB = splitB.PurpleDown;
                    bool found = splitB.TryFindSmallestSegmentAbove(splitPos, out splitSeg);
                    Debug.Assert(found == (splitSeg != null));
                }
                else
                {
                    upperPart = new BundleTree(bTree, top, bottom);
                    bTree     = null;
                    top       = bottom = null;
                    return(upperPart);
                }
            }
            else
            {
                splitB = FindLgBBelow(splitPos);
                if (splitB.PurpleUp != null && splitB.PurpleUp.CompareTo(splitPos) < 0)
                {
                    splitB = splitB.PurpleUp;
                }

                if (splitB.PurpleUp != null)
                {
                    bool found = splitB.PurpleUp.TryFindLargestSegmentBelow(splitPos, out splitSeg);
                    if (found)
                    {
                        splitB = splitB.PurpleUp;
                    }
                }
                else
                {
                    return(new BundleTree());
                }
            }

            if (splitSeg != null)
            {
                splitB.Split(splitSeg, keep ^ true);
                PlainInsert(splitB.PurpleUp);
            }
            SplayTree <ISpatiallyComparable> s = splitB.IsRed ? bTree.SplitAt(splitB, true) : bTree.SplitAt(splitB.PurpleDown, true);

            upperPart    = new BundleTree(s, top, splitB.PurpleUp);
            top          = splitB;
            top.PurpleUp = upperPart.bottom.PurpleDown = null;
            return(upperPart);
        }