コード例 #1
0
        /// <summary>
        /// Initialize the event queue with the given items.
        /// </summary>
        /// <param name="items"></param>
        /// <returns></returns>
        public IBST <ISweepEvent <T> > InitializeEvents(IEnumerable <ISweepEvent <T> > items)
        {
            Events.Clear();

            foreach (var item in items)
            {
                Events.Insert(item);
            }

            return(Events);
        }
コード例 #2
0
ファイル: SweepLine.cs プロジェクト: Maurice2499/GeoAlg
        /// <summary>
        /// Initialize the status tree with the given items.
        /// </summary>
        /// <param name="items"></param>
        /// <returns></returns>
        public IBST <T> InitializeStatus(IEnumerable <T> items)
        {
            Status.Clear();

            foreach (var item in items)
            {
                Status.Insert(item);
            }

            return(Status);
        }
コード例 #3
0
ファイル: SweepLine.cs プロジェクト: Maurice2499/GeoAlg
        /// <summary>
        /// Initialize the event queue with the given items.
        /// </summary>
        /// <param name="items"></param>
        /// <returns></returns>
        public IBST <E> InitializeEvents(IEnumerable <E> items)
        {
            Events.Clear();

            foreach (var item in items)
            {
                if (!Events.Insert(item))
                {
                    throw new ArgumentException(string.Format("Failed to insert event {0}", item));
                }
            }

            return(Events);
        }
コード例 #4
0
        public void HandleEvent(IBST <IntersectionSweepEvent> events, IBST <IntersectionStatusItem> status,
                                IntersectionSweepEvent ev)
        {
            if (ev.IsStart)
            {
                ev.StatusItem = new IntersectionStatusItem(ev);
                status.Insert(ev.StatusItem);

                IntersectionStatusItem prev, next;
                bool prevFound = status.FindNextSmallest(ev.StatusItem, out prev);
                bool nextFound = status.FindNextBiggest(ev.StatusItem, out next);

                if (prevFound)
                {
                    LineSegment otherSegment = prev.SweepEvent.Segment;
                    Vector2?    intersection = ev.Segment.IntersectProper(otherSegment);
                    if (intersection != null)
                    {
                        events.Insert(new IntersectionSweepEvent(intersection.Value, false, false,
                                                                 ev.Segment, otherSegment));
                    }
                }

                if (nextFound)
                {
                    LineSegment otherSegment = next.SweepEvent.Segment;
                    Vector2?    intersection = ev.Segment.IntersectProper(otherSegment);
                    if (intersection != null)
                    {
                        events.Insert(new IntersectionSweepEvent(intersection.Value, false, false,
                                                                 ev.Segment, otherSegment));
                    }
                }
            }
            else if (ev.IsEnd)
            {
                ev = ev.OtherEvent;
                if (ev.StatusItem == null)
                {
                    return;
                }

                IntersectionStatusItem prev, next;
                bool prevFound = status.FindNextSmallest(ev.StatusItem, out prev);
                bool nextFound = status.FindNextBiggest(ev.StatusItem, out next);

                status.Delete(ev.StatusItem);

                if (nextFound && prevFound)
                {
                    LineSegment segment      = prev.SweepEvent.Segment;
                    LineSegment otherSegment = next.SweepEvent.Segment;
                    Vector2?    intersection = segment.IntersectProper(otherSegment);
                    if (intersection != null)
                    {
                        events.Insert(new IntersectionSweepEvent(intersection.Value, false, false,
                                                                 segment, otherSegment));
                    }
                }
            }
            else if (ev.IsIntersection)
            {
                // stop on first intersection
                intersected = new List <Edge>
                {
                    new Edge(new Vertex(ev.Segment.Point1), new Vertex(ev.Segment.Point2)),
                    new Edge(new Vertex(ev.OtherSegment.Point1), new Vertex(ev.OtherSegment.Point2))
                };
                events.Clear();
                status.Clear();
            }
            else
            {
                throw new Exception("Invalid event type");
            }
        }