Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="ev0"></param>
        /// <param name="si"></param>
        private void ProcessOverlaps(int start, int end, SweepLineEvent ev0, SegmentIntersector si)
        {
            SweepLineSegment ss0 = (SweepLineSegment)ev0.Object;

            /*
             * Since we might need to test for self-intersections,
             * include current INSERT event object in list of event objects to test.
             * Last index can be skipped, because it must be a Delete event.
             */
            for (int i = start; i < end; i++)
            {
                SweepLineEvent ev1 = _events[i];
                if (ev1.IsInsert)
                {
                    SweepLineSegment ss1 = (SweepLineSegment)ev1.Object;
                    // don't compare edges in same group, if labels are present
                    if (!ev0.IsSameLabel(ev1))
                    {
                        {
                            ss0.ComputeIntersections(ss1, si);
                            _nOverlaps++;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public bool IsSameLabel(SweepLineEvent ev)
 {
     // no label set indicates single group
     if (_label == null)
     {
         return(false);
     }
     return(_label == ev._label);
 }
Ejemplo n.º 3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="edge"></param>
 /// <param name="edgeSet"></param>
 private void Add(Edge edge, object edgeSet)
 {
     Coordinate[] pts = edge.Coordinates;
     for (int i = 0; i < pts.Length - 1; i++)
     {
         SweepLineSegment ss          = new SweepLineSegment(edge, i);
         SweepLineEvent   insertEvent = new SweepLineEvent(edgeSet, ss.MinX, null);
         _events.Add(insertEvent);
         _events.Add(new SweepLineEvent(ss.MaxX, insertEvent));
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Because DELETE events have a link to their corresponding INSERT event,
 /// it is possible to compute exactly the range of events which must be
 /// compared to a given INSERT event object.
 /// </summary>
 private void PrepareEvents()
 {
     _events.Sort();
     // set DELETE event indexes
     for (int i = 0; i < _events.Count; i++)
     {
         SweepLineEvent ev = _events[i];
         if (ev.IsDelete)
         {
             ev.InsertEvent.DeleteEventIndex = i;
         }
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="edge"></param>
        /// <param name="edgeSet"></param>
        private void AddEdge(Edge edge, object edgeSet)
        {
            MonotoneChainEdge mce = edge.MonotoneChainEdge;

            int[] startIndex = mce.StartIndexes;
            for (int i = 0; i < startIndex.Length - 1; i++)
            {
                MonotoneChain  mc          = new MonotoneChain(mce, i);
                SweepLineEvent insertEvent = new SweepLineEvent(edgeSet, mce.GetMinX(i), mc);
                _events.Add(insertEvent);
                _events.Add(new SweepLineEvent(mce.GetMaxX(i), insertEvent));
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="si"></param>
        private void ComputeIntersections(SegmentIntersector si)
        {
            _nOverlaps = 0;
            PrepareEvents();

            for (int i = 0; i < _events.Count; i++)
            {
                SweepLineEvent ev = _events[i];
                if (ev.IsInsert)
                {
                    ProcessOverlaps(i, ev.DeleteEventIndex, ev, si);
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="si"></param>
        private void ComputeIntersections(SegmentIntersector si)
        {
            _nOverlaps = 0;
            PrepareEvents();

            for (int i = 0; i < _events.Count; i++)
            {
                SweepLineEvent ev = _events[i];
                if (ev.IsInsert)
                {
                    // Console.WriteLine("Processing event " + i);
                    ProcessOverlaps(i, ev.DeleteEventIndex, ev, si);
                }
                if (si.IsDone)
                {
                    break;
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Events are ordered first by their x-value, and then by their eventType.
        /// Insert events are sorted before Delete events, so that
        /// items whose Insert and Delete events occur at the same x-value will be
        /// correctly handled.
        /// </summary>
        /// <param name="o"></param>
        public int CompareTo(object o)
        {
            SweepLineEvent pe = (SweepLineEvent)o;

            if (_xValue < pe._xValue)
            {
                return(-1);
            }
            if (_xValue > pe._xValue)
            {
                return(1);
            }
            if (_eventType < pe._eventType)
            {
                return(-1);
            }
            if (_eventType > pe._eventType)
            {
                return(1);
            }
            return(0);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Creates a DELETE event.
 /// </summary>
 /// <param name="x">The event location</param>
 /// <param name="insertEvent">The corresponding INSERT event</param>
 public SweepLineEvent(double x, SweepLineEvent insertEvent)
 {
     _eventType   = Delete;
     _xValue      = x;
     _insertEvent = insertEvent;
 }