Пример #1
0
 /// <summary>
 /// Constructs a SweepLineEvent object.
 /// </summary>
 /// <param name="geomIndex"></param>
 /// <param name="x"></param>
 /// <param name="insertEvent"></param>
 /// <param name="obj"></param>
 public SweepLineEvent(int geomIndex, double x, SweepLineEvent insertEvent, Object obj)
 {
     _geomIndex = geomIndex;
     _xValue = x;
     _insertEvent = insertEvent;
     _eventType = Insert;
     if ( _insertEvent != null )
     {
         _eventType = Delete;
     }
     _obj = obj;
 }
Пример #2
0
 /// <summary>
 /// Constructs a SweepLineEvent object.
 /// </summary>
 /// <param name="geomIndex"></param>
 /// <param name="x"></param>
 /// <param name="insertEvent"></param>
 /// <param name="obj"></param>
 public SweepLineEvent(int geomIndex, double x, SweepLineEvent insertEvent, Object obj)
 {
     _geomIndex   = geomIndex;
     _xValue      = x;
     _insertEvent = insertEvent;
     _eventType   = Insert;
     if (_insertEvent != null)
     {
         _eventType = Delete;
     }
     _obj = obj;
 }
        }         // private void Add(ArrayList edges, int geomIndex)

        private void Add(Edge edge, int geomIndex)
        {
            MonotoneChainEdge mce = edge.GetMonotoneChainEdge();

            int[] startIndex = mce.StartIndex;
            for (int i = 0; i < startIndex.Length - 1; i++)
            {
                MonotoneChain  mc          = new MonotoneChain(mce, i, geomIndex);
                SweepLineEvent insertEvent = new SweepLineEvent(geomIndex, mce.GetMinX(i), null, mc);
                _events.Add(insertEvent);
                _events.Add(new SweepLineEvent(geomIndex, mce.GetMaxX(i), insertEvent, mc));
            }
        }         // private void Add(Edge edge, int geomIndex)
        }         // private void Add(Edge edge, int geomIndex)

        private void ComputeIntersections(SegmentIntersector si, bool doMutualOnly)
        {
            _nOverlaps = 0;
            PrepareEvents();

            for (int i = 0; i < _events.Count; i++)
            {
                SweepLineEvent ev = (SweepLineEvent)_events[i];
                MonotoneChain  mc = (MonotoneChain)ev.Object;
                if (ev.IsInsert)
                {
                    ProcessOverlaps(i, ev.DeleteEventIndex, mc, si, doMutualOnly);
                }
            }
        }         // private void ComputeIntersections(SegmentIntersector si, bool doMutualOnly)
        }         // private void PrepareEvents()

        private void ProcessOverlaps(int start, int end, MonotoneChain mc0, SegmentIntersector si, bool doMutualOnly)
        {
            // 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 ev = (SweepLineEvent)_events[i];
                if (ev.IsInsert)
                {
                    MonotoneChain mc1 = (MonotoneChain)ev.Object;
                    if (!doMutualOnly || (mc0.GeomIndex != mc1.GeomIndex))
                    {
                        mc0.ComputeIntersections(mc1, si);
                        _nOverlaps++;
                    }
                }
            }     // for ( int i = start; i < end; i++ )
        }         // private void ProcessOverlaps(int start, int end, MonotoneChain mc0, SegmentIntersector si, bool doMutualOnly)
Пример #6
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="b">The first object to compare.</param>
        /// <returns>
        /// <list type="table">
        /// <listheader><term>Items</term><description>Descriptions</description></listheader>
        /// <item><term>Less than zero</term><description>a is less than b.</description></item>
        /// <item><term>Zero</term><description>a equals b.</description></item>
        /// <item><term>Greater than zero</term><description>a is greater than b.</description></item>
        /// </list>
        /// </returns>
        public int CompareTo(object b)
        {
            SweepLineEvent pe = (SweepLineEvent)b;

            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);
        }
        }         // private void ComputeIntersections(SegmentIntersector si, bool doMutualOnly)

        /// <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();
            //TODO:remove this bubble sort!!!! AWC, LAK, RAB - we should find this!!!!!!
            //**************************************************************************8

            // remove this bubble sort.

            //************************************************************************

            /*int count=0;
             * for (int a=0;a<_events.Count;a++)
             * {
             *      for (int b=0;b<_events.Count-1;b++)
             *      {
             *              SweepLineEvent ev1 = (SweepLineEvent) _events[b];
             *              SweepLineEvent ev2 = (SweepLineEvent) _events[b+1];
             *              if (ev1.CompareTo(ev2)==1)
             *              {
             *                      SweepLineEvent temp = ev1;
             *                      _events[b]=ev2;
             *                      _events[b+1]=temp;
             *                      count++;
             *              }
             *      }
             * }
             */
            for (int i = 0; i < _events.Count; i++)
            {
                SweepLineEvent ev = (SweepLineEvent)_events[i];
                if (ev.IsDelete)
                {
                    ev.InsertEvent.DeleteEventIndex = i;
                }
            }
        }         // private void PrepareEvents()
 private void Add(Edge edge, int geomIndex)
 {
     MonotoneChainEdge mce = edge.GetMonotoneChainEdge();
     int[] startIndex = mce.StartIndex;
     for (int i = 0; i < startIndex.Length - 1; i++)
     {
         MonotoneChain mc = new MonotoneChain( mce, i, geomIndex );
         SweepLineEvent insertEvent = new SweepLineEvent( geomIndex, mce.GetMinX(i), null, mc);
         _events.Add( insertEvent );
         _events.Add( new SweepLineEvent( geomIndex, mce.GetMaxX(i), insertEvent, mc) );
     }
 }