Exemplo n.º 1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="mce"></param>
 /// <param name="si"></param>
 public void ComputeIntersects(MonotoneChainEdge mce, SegmentIntersector si)
 {
     for (int i = 0; i < startIndex.Length - 1; i++)
     {
         for (int j = 0; j < mce.startIndex.Length - 1; j++)
         {
             ComputeIntersectsForChain(i, mce, j, si);
         }
     }
 }
Exemplo n.º 2
0
        /// <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));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="start0"></param>
        /// <param name="end0"></param>
        /// <param name="mce"></param>
        /// <param name="start1"></param>
        /// <param name="end1"></param>
        /// <param name="ei"></param>
        private void ComputeIntersectsForChain(int start0, int end0, MonotoneChainEdge mce, int start1, int end1, SegmentIntersector ei)
        {
            ICoordinate p00 = pts[start0];
            ICoordinate p01 = pts[end0];
            ICoordinate p10 = mce.pts[start1];
            ICoordinate p11 = mce.pts[end1];

            // terminating condition for the recursion
            if (end0 - start0 == 1 && end1 - start1 == 1)
            {
                ei.AddIntersections(e, start0, mce.e, start1);
                return;
            }

            // nothing to do if the envelopes of these chains don't overlap
            env1.Init(p00, p01);
            env2.Init(p10, p11);
            if (!env1.Intersects(env2))
            {
                return;
            }

            // the chains overlap, so split each in half and iterate  (binary search)
            int mid0 = (start0 + end0) / 2;
            int mid1 = (start1 + end1) / 2;

            // check terminating conditions before recursing
            if (start0 < mid0)
            {
                if (start1 < mid1)
                {
                    ComputeIntersectsForChain(start0, mid0, mce, start1, mid1, ei);
                }
                if (mid1 < end1)
                {
                    ComputeIntersectsForChain(start0, mid0, mce, mid1, end1, ei);
                }
            }
            if (mid0 < end0)
            {
                if (start1 < mid1)
                {
                    ComputeIntersectsForChain(mid0, end0, mce, start1, mid1, ei);
                }
                if (mid1 < end1)
                {
                    ComputeIntersectsForChain(mid0, end0, mce, mid1, end1, ei);
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="mce"></param>
 /// <param name="chainIndex"></param>
 public MonotoneChain(MonotoneChainEdge mce, int chainIndex)
 {
     this.mce = mce;
     this.chainIndex = chainIndex;
 }
Exemplo n.º 5
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="mce"></param>
 /// <param name="si"></param>
 public void ComputeIntersects(MonotoneChainEdge mce, SegmentIntersector si)
 {
     for (int i = 0; i < startIndex.Length - 1; i++)
         for (int j = 0; j < mce.startIndex.Length - 1; j++)
             ComputeIntersectsForChain(i, mce, j, si);
 }
Exemplo n.º 6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="start0"></param>
        /// <param name="end0"></param>
        /// <param name="mce"></param>
        /// <param name="start1"></param>
        /// <param name="end1"></param>
        /// <param name="ei"></param>
        private void ComputeIntersectsForChain( int start0, int end0, MonotoneChainEdge mce, int start1, int end1, SegmentIntersector ei)
        {
            ICoordinate p00 = pts[start0];
            ICoordinate p01 = pts[end0];
            ICoordinate p10 = mce.pts[start1];
            ICoordinate p11 = mce.pts[end1];

            // terminating condition for the recursion
            if (end0 - start0 == 1 && end1 - start1 == 1)
            {
                ei.AddIntersections(e, start0, mce.e, start1);
                return;
            }

            // nothing to do if the envelopes of these chains don't overlap
            env1.Init(p00, p01);
            env2.Init(p10, p11);
            if (!env1.Intersects(env2))
                return;

            // the chains overlap, so split each in half and iterate  (binary search)
            int mid0 = (start0 + end0) / 2;
            int mid1 = (start1 + end1) / 2;

            // check terminating conditions before recursing
            if (start0 < mid0)
            {
                if (start1 < mid1)
                    ComputeIntersectsForChain(start0, mid0, mce, start1, mid1, ei);
                if (mid1 < end1)
                    ComputeIntersectsForChain(start0, mid0, mce, mid1, end1, ei);
            }
            if (mid0 < end0)
            {
                if (start1 < mid1)
                    ComputeIntersectsForChain(mid0, end0, mce, start1, mid1, ei);
                if (mid1 < end1)
                    ComputeIntersectsForChain(mid0, end0, mce, mid1, end1, ei);
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="chainIndex0"></param>
 /// <param name="mce"></param>
 /// <param name="chainIndex1"></param>
 /// <param name="si"></param>
 public void ComputeIntersectsForChain(int chainIndex0, MonotoneChainEdge mce, int chainIndex1, SegmentIntersector si)
 {
     ComputeIntersectsForChain(startIndex[chainIndex0], startIndex[chainIndex0 + 1], mce,
                               mce.startIndex[chainIndex1], mce.startIndex[chainIndex1 + 1], si);
 }
Exemplo n.º 8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="mce"></param>
 /// <param name="chainIndex"></param>
 public MonotoneChain(MonotoneChainEdge mce, int chainIndex)
 {
     this.mce        = mce;
     this.chainIndex = chainIndex;
 }
Exemplo n.º 9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="chainIndex0"></param>
 /// <param name="mce"></param>
 /// <param name="chainIndex1"></param>
 /// <param name="si"></param>
 public void ComputeIntersectsForChain(int chainIndex0, MonotoneChainEdge mce, int chainIndex1, SegmentIntersector si)
 {
     ComputeIntersectsForChain(startIndex[chainIndex0], startIndex[chainIndex0 + 1], mce,
                               mce.startIndex[chainIndex1], mce.startIndex[chainIndex1 + 1], si);
 }