/// <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)
        {
            MonotoneChain mc0 = (MonotoneChain)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 = (SweepLineEvent)_events[i];
                if (ev1.IsInsert)
                {
                    MonotoneChain mc1 = (MonotoneChain)ev1.Object;
                    // don't compare edges in same group
                    // null group indicates that edges should be compared
                    if (ev0.EdgeSet == null)
                    {
                        // This null situation is problematic
                    }
                    if (ev0.EdgeSet == null || (ev0.EdgeSet != ev1.EdgeSet))
                    {
                        mc0.ComputeIntersections(mc1, si);
                        _nOverlaps++;
                    }
                }
            }
        }
Esempio n. 2
0
        private object _edgeSet;    // used for red-blue intersection detection

        /// <summary>
        ///
        /// </summary>
        /// <param name="edgeSet"></param>
        /// <param name="x"></param>
        /// <param name="insertEvent"></param>
        /// <param name="obj"></param>
        public SweepLineEvent(object edgeSet, double x, SweepLineEvent insertEvent, object obj)
        {
            _edgeSet = edgeSet;
            _xValue = x;
            _insertEvent = insertEvent;
            _eventType = INSERT;
            if (insertEvent != null)
                _eventType = DELETE;
            _obj = obj;
        }
Esempio n. 3
0
        private object _edgeSet;    // used for red-blue intersection detection

        /// <summary>
        ///
        /// </summary>
        /// <param name="edgeSet"></param>
        /// <param name="x"></param>
        /// <param name="insertEvent"></param>
        /// <param name="obj"></param>
        public SweepLineEvent(object edgeSet, double x, SweepLineEvent insertEvent, object obj)
        {
            _edgeSet     = edgeSet;
            _xValue      = x;
            _insertEvent = insertEvent;
            _eventType   = INSERT;
            if (insertEvent != null)
            {
                _eventType = DELETE;
            }
            _obj = obj;
        }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="edge"></param>
        /// <param name="edgeSet"></param>
        private void Add(Edge edge, object edgeSet)
        {
            IList <Coordinate> pts = edge.Coordinates;

            for (int i = 0; i < pts.Count - 1; i++)
            {
                SweepLineSegment ss          = new SweepLineSegment(edge, i);
                SweepLineEvent   insertEvent = new SweepLineEvent(edgeSet, ss.MinX, null, ss);
                _events.Add(insertEvent);
                _events.Add(new SweepLineEvent(edgeSet, ss.MaxX, insertEvent, ss));
            }
        }
 /// <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();
     for (int i = 0; i < _events.Count; i++)
     {
         SweepLineEvent ev = (SweepLineEvent)_events[i];
         if (ev.IsDelete)
         {
             ev.InsertEvent.DeleteEventIndex = i;
         }
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="edge"></param>
        /// <param name="edgeSet"></param>
        private void Add(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), null, mc);
                _events.Add(insertEvent);
                _events.Add(new SweepLineEvent(edgeSet, mce.GetMaxX(i), insertEvent, mc));
            }
        }
Esempio n. 7
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 = (SweepLineEvent)_events[i];
                if (ev.IsInsert)
                {
                    ProcessOverlaps(i, ev.DeleteEventIndex, ev, si);
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// ProjectionEvents are ordered first by their x-value, and then by their eventType.
        /// It is important that 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 virtual 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);
        }
Esempio n. 9
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 = (SweepLineEvent)_events[i];
                if (ev1.IsInsert)
                {
                    SweepLineSegment ss1 = (SweepLineSegment)ev1.Object;
                    if (ev0.EdgeSet == null || (ev0.EdgeSet != ev1.EdgeSet))
                    {
                        ss0.ComputeIntersections(ss1, si);
                    }
                    _nOverlaps++;
                }
            }
        }
 /// <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 = (SweepLineEvent)_events[i];
         if (ev1.IsInsert)
         {
             SweepLineSegment ss1 = (SweepLineSegment)ev1.Object;
             if (ev0.EdgeSet == null || (ev0.EdgeSet != ev1.EdgeSet))
                 ss0.ComputeIntersections(ss1, si);
             _nOverlaps++;
         }
     }
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="edge"></param>
 /// <param name="edgeSet"></param>
 private void Add(Edge edge, object edgeSet)
 {
     IList<Coordinate> pts = edge.Coordinates;
     for (int i = 0; i < pts.Count - 1; i++)
     {
         SweepLineSegment ss = new SweepLineSegment(edge, i);
         SweepLineEvent insertEvent = new SweepLineEvent(edgeSet, ss.MinX, null, ss);
         _events.Add(insertEvent);
         _events.Add(new SweepLineEvent(edgeSet, ss.MaxX, insertEvent, ss));
     }
 }
        /// <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)
        {
            MonotoneChain mc0 = (MonotoneChain)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 = (SweepLineEvent)_events[i];
                if (ev1.IsInsert)
                {
                    MonotoneChain mc1 = (MonotoneChain)ev1.Object;
                    // don't compare edges in same group
                    // null group indicates that edges should be compared
                    if (ev0.EdgeSet == null)
                    {
                        // This null situation is problematic
                    }
                    if (ev0.EdgeSet == null || (ev0.EdgeSet != ev1.EdgeSet))
                    {
                        mc0.ComputeIntersections(mc1, si);
                        _nOverlaps++;
                    }
                }
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="edge"></param>
 /// <param name="edgeSet"></param>
 private void Add(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), null, mc);
         _events.Add(insertEvent);
         _events.Add(new SweepLineEvent(edgeSet, mce.GetMaxX(i), insertEvent, mc));
     }
 }