Esempio n. 1
0
        public bool Contains(T item)
        {
            RedBlackTreeIterator iter = new RedBlackTreeIterator(Root.OuterLeft);

            while (iter.IsValid)
            {
                if (iter.Current.Equals(item))
                {
                    return(true);
                }
                iter.MoveNext();
            }
            return(false);
        }
Esempio n. 2
0
        public bool Remove(T item)
        {
            RedBlackTreeIterator iter = new RedBlackTreeIterator(Root.OuterLeft);

            while (iter.IsValid)
            {
                if (iter.Current.Equals(item))
                {
                    this.RemoveAt(iter);
                    return(true);
                }
                iter.MoveNext();
            }
            return(false);
        }
Esempio n. 3
0
        public void RemoveAt(RedBlackTreeIterator iter)
        {
            try {
                Remove(iter.node);
            }  catch(Exception e)
            {
                string s1 = "remove:" + iter.node.value;
                string s2 = this.ToString();

                Console.WriteLine(s1);
                Console.WriteLine(s2);
                Console.WriteLine("----");
                Console.WriteLine(e);
            }
        }
 internal Enumerator(RedBlackTreeIterator <RBNode> it)
 {
     this.it = it;
 }
 internal Enumerator(RedBlackTreeIterator <LineSegmentTree.RBNode> it)
 {
     this.it = it;
 }
Esempio n. 6
0
        ///* eslint-disable no-unused-vars, no-debugger, no-undef */
        //function iteratorEquals(it1, it2) {
        //  return it1._cursor === it2._cursor;
        //}


        //function _renderSweepLine(sweepLine, pos, _event)
        //{
        //var map = window.map;
        //if (!map) return;
        //if (window.sws) window.sws.forEach(function (p) {
        //map.removeLayer(p);
        //});
        //window.sws = [];
        //sweepLine.forEach(function (e) {
        //var poly = L.polyline([
        //    e.point.slice().reverse(),
        //    e.otherEvent.point.slice().reverse()
        //], {color: 'green'}).addTo(map);
        //window.sws.push(poly);
        //});

        //if (window.vt) map.removeLayer(window.vt);
        //var v = pos.slice();
        //var b = map.getBounds();
        //window.vt = L.polyline([
        //[b.getNorth(), v[0]],
        //[b.getSouth(), v[0]]
        //], {color: 'green', weight: 1}).addTo(map);

        //if (window.ps) map.removeLayer(window.ps);
        //window.ps = L.polyline([
        //_event.point.slice().reverse(),
        //_event.otherEvent.point.slice().reverse()
        //], {color: 'black', weight: 9, opacity: 0.4}).addTo(map);
        //debugger;
        //}
        ///* eslint-enable no-unused-vars, no-debugger, no-undef */


        internal static List <SweepEvent> subdivideSegments(TinyQueue eventQueue, Point[][][] subject, Point[][][] clipping, double[] sbbox, double[] cbbox, Operation operation)
        {
            RedBlackTree      sweepLine    = new RedBlackTree(_comp_Segm);
            List <SweepEvent> sortedEvents = new List <SweepEvent>();

            double rightbound = Math.Min(sbbox[2], cbbox[2]);

            RedBlackTreeIterator prev, next;

            SweepEvent prevEvent, prevprevEvent;

            while (eventQueue.length > 0)
            {
                SweepEvent _event = eventQueue.pop();
                sortedEvents.Add(_event);

                // optimization by bboxes for intersection and difference goes here  - коммент оригинала
                if ((operation == Operation.INTERSECTION && _event.point.X > rightbound) || (operation == Operation.DIFFERENCE && _event.point.X > sbbox[2]))
                {
                    break;
                }

                if (_event.left)
                {
                    sweepLine = sweepLine.insert(_event, _event);
                    //_renderSweepLine(sweepLine, _event.point, _event);  - коммент оригинала

                    next            = sweepLine.find(_event);
                    prev            = sweepLine.find(_event);
                    _event.iterator = sweepLine.find(_event);

                    if (!prev.node.Equals(sweepLine.begin.node))                                             // ??? (prev.node !== sweepLine.begin)
                    {
                        prev.prev();
                    }
                    else
                    {
                        prev = sweepLine.begin;
                        prev.prev();
                        prev.next();
                    }
                    next.next();

                    //---  prevEvent = (prev.key || null), prevprevEvent;
                    prevEvent = (SweepEvent)Convert.ChangeType(prev.key, typeof(SweepEvent));
                    computeFields(_event, prevEvent, operation);
                    if (next.node != null)
                    {
                        if (possibleIntersection(_event, (SweepEvent)Convert.ChangeType(next.key, typeof(SweepEvent)), eventQueue) == 2)
                        {
                            computeFields(_event, prevEvent, operation);
                            computeFields(_event, (SweepEvent)Convert.ChangeType(next.key, typeof(SweepEvent)), operation);
                        }
                    }

                    if (prev.node != null)
                    {
                        if (possibleIntersection((SweepEvent)Convert.ChangeType(prev.key, typeof(SweepEvent)), _event, eventQueue) == 2)
                        {
                            RedBlackTreeIterator prevprev = sweepLine.find((SweepEvent)Convert.ChangeType(prev.key, typeof(SweepEvent)));
                            if (!prevprev.node.Equals(sweepLine.begin.node))                            //prevprev.node != sweepLine.begin
                            {
                                prevprev.prev();
                            }
                            else
                            {
                                prevprev = sweepLine.find((SweepEvent)Convert.ChangeType(sweepLine.end.key, typeof(SweepEvent)));
                                prevprev.next();
                            }
                            prevprevEvent = (SweepEvent)Convert.ChangeType(prevprev.key, typeof(SweepEvent));
                            computeFields(prevEvent, prevprevEvent, operation);
                            computeFields(_event, prevEvent, operation);
                        }
                    }
                }
                else
                {
                    _event = _event.otherEvent;
                    next   = sweepLine.find(_event);
                    prev   = sweepLine.find(_event);

                    // _renderSweepLine(sweepLine, _event.otherEvent.point, _event);  - коммент оригинала

                    if (!(prev != null && next != null))
                    {
                        continue;
                    }

                    if (!prev.node.Equals(sweepLine.begin.node))                                        // prev.node !=  sweepLine.begin
                    {
                        prev.prev();
                    }
                    else
                    {
                        prev = sweepLine.begin;
                        prev.prev();
                        prev.next();
                    }
                    next.next();
                    sweepLine = sweepLine.remove(_event);

                    // _renderSweepLine(sweepLine, _event.otherEvent.point, _event);  - коммент оригинала

                    if (next.node != null && prev.node != null)
                    {
                        if (prev.node.value != null && next.node.value != null)    //-- if (typeof prev.node.value != 'undefined' && typeof next.node.value != 'undefined')
                        {
                            possibleIntersection((SweepEvent)Convert.ChangeType(prev.key, typeof(SweepEvent)), (SweepEvent)Convert.ChangeType(next.key, typeof(SweepEvent)), eventQueue);
                        }
                    }
                }
            }
            return(sortedEvents);
        }
Esempio n. 7
0
 internal Enumerator(RedBlackTreeIterator <RBNode> iterator)
 {
     TreeIterator = iterator;
 }