/// <summary>
 /// 
 /// </summary>
 /// <param name="edges"></param>
 /// <param name="si"></param>
 /// <param name="testAllSegments"></param>
 public override void ComputeIntersections(IList edges, SegmentIntersector si, bool testAllSegments)
 {
     if (testAllSegments)
          Add(edges, null);
     else Add(edges);
     ComputeIntersections(si);
 }
 /// <summary>
 /// Performs a brute-force comparison of every segment in each Edge.
 /// This has n^2 performance, and is about 100 times slower than using
 /// monotone chains.
 /// </summary>
 /// <param name="e0"></param>
 /// <param name="e1"></param>
 /// <param name="si"></param>
 private void ComputeIntersects(Edge e0, Edge e1, SegmentIntersector si)
 {
     ICoordinate[] pts0 = e0.Coordinates;
     ICoordinate[] pts1 = e1.Coordinates;
     for (int i0 = 0; i0 < pts0.Length - 1; i0++)
         for (int i1 = 0; i1 < pts1.Length - 1; i1++)
             si.AddIntersections(e0, i0, e1, i1);
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="edges0"></param>
 /// <param name="edges1"></param>
 /// <param name="si"></param>
 public override void ComputeIntersections(IList edges0, IList edges1, SegmentIntersector si)
 {
     for (IEnumerator i0 = edges0.GetEnumerator(); i0.MoveNext(); )
     {
         Edge edge0 = (Edge) i0.Current;
         for (IEnumerator i1 = edges1.GetEnumerator(); i1.MoveNext(); )
         {
             Edge edge1 = (Edge) i1.Current;
                 ComputeIntersects(edge0, edge1, si);
         }
     }
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="edges"></param>
 /// <param name="si"></param>
 /// <param name="testAllSegments"></param>
 public override void ComputeIntersections(IList edges, SegmentIntersector si, bool testAllSegments)
 {
     for (IEnumerator i0 = edges.GetEnumerator(); i0.MoveNext(); )
     {
         Edge edge0 = (Edge) i0.Current;
         for (IEnumerator i1 = edges.GetEnumerator(); i1.MoveNext(); )
         {
             Edge edge1 = (Edge) i1.Current;
             if (testAllSegments || edge0 != edge1)
                 ComputeIntersects(edge0, edge1, si);
         }
     }
 }
 /// <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);
 }
        /// <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);
            }
        }
Exemple #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="edges0"></param>
 /// <param name="edges1"></param>
 /// <param name="si"></param>
 public override void ComputeIntersections(IList edges0, IList edges1, SegmentIntersector si)
 {
     Add(edges0, edges0);
     Add(edges1, edges1);
     ComputeIntersections(si);
 }
 /// <summary>
 /// Computes all self-intersections between edges in a set of edges,
 /// allowing client to choose whether self-intersections are computed.
 /// </summary>
 /// <param name="edges">A list of edges to test for intersections.</param>
 /// <param name="si">The SegmentIntersector to use.</param>
 /// <param name="testAllSegments"><c>true</c> if self-intersections are to be tested as well.</param>
 public abstract void ComputeIntersections(IList edges, SegmentIntersector si, bool testAllSegments);
        /// <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);
            }
        }
Exemple #10
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="g"></param>
 /// <param name="li"></param>
 /// <param name="includeProper"></param>
 /// <returns></returns>
 public SegmentIntersector ComputeEdgeIntersections(GeometryGraph g, 
     LineIntersector li, bool includeProper)
 {
     SegmentIntersector si = new SegmentIntersector(li, includeProper, true);
     si.SetBoundaryNodes(BoundaryNodes, g.BoundaryNodes);
     EdgeSetIntersector esi = CreateEdgeSetIntersector();
     esi.ComputeIntersections(edges, g.edges, si);
     return si;
 }
        /// <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);
                }
            }
        }
 /// <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);
 }
Exemple #13
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="ss"></param>
 /// <param name="si"></param>
 public void ComputeIntersections(SweepLineSegment ss, SegmentIntersector si)
 {
     si.AddIntersections(edge, ptIndex, ss.edge, ss.ptIndex);
 }
        /// <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 || (ev0.EdgeSet != ev1.EdgeSet))
                    {
                        mc0.ComputeIntersections(mc1, si);
                        nOverlaps++;
                    }
                }
            }
        }
 /// <summary>
 /// Computes all self-intersections between edges in a set of edges,
 /// allowing client to choose whether self-intersections are computed.
 /// </summary>
 /// <param name="edges">A list of edges to test for intersections.</param>
 /// <param name="si">The SegmentIntersector to use.</param>
 /// <param name="testAllSegments"><c>true</c> if self-intersections are to be tested as well.</param>
 abstract public void ComputeIntersections(IList edges, SegmentIntersector si, bool testAllSegments);
 /// <summary>
 /// Computes all mutual intersections between two sets of edges.
 /// </summary>
 abstract public void ComputeIntersections(IList edges0, IList edges1, SegmentIntersector si);
Exemple #17
0
 /// <summary>
 /// Compute self-nodes, taking advantage of the Geometry type to
 /// minimize the number of intersection tests.  (E.g. rings are
 /// not tested for self-intersection, since they are assumed to be valid).
 /// </summary>
 /// <param name="li">The <c>LineIntersector</c> to use.</param>
 /// <param name="computeRingSelfNodes">If <c>false</c>, intersection checks are optimized to not test rings for self-intersection.</param>
 /// <returns>The SegmentIntersector used, containing information about the intersections found.</returns>
 public SegmentIntersector ComputeSelfNodes(LineIntersector li, bool computeRingSelfNodes)
 {
     SegmentIntersector si = new SegmentIntersector(li, true, false);
     EdgeSetIntersector esi = CreateEdgeSetIntersector();
     // optimized test for Polygons and Rings
     if (!computeRingSelfNodes &&
        (parentGeom is ILinearRing || parentGeom is IPolygon || parentGeom is IMultiPolygon))
          esi.ComputeIntersections(edges, si, false);
     else esi.ComputeIntersections(edges, si, true);
     AddSelfIntersectionNodes(argIndex);
     return si;
 }
 /// <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++;
         }
     }
 }
Exemple #19
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="mc"></param>
 /// <param name="si"></param>
 public void ComputeIntersections(MonotoneChain mc, SegmentIntersector si)
 {
     this.mce.ComputeIntersectsForChain(chainIndex, mc.mce, mc.chainIndex, si);
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="edges0"></param>
 /// <param name="edges1"></param>
 /// <param name="si"></param>
 public override void ComputeIntersections(IList edges0, IList edges1, SegmentIntersector si)
 {
     Add(edges0, edges0);
     Add(edges1, edges1);
     ComputeIntersections(si);
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="ss"></param>
 /// <param name="si"></param>
 public void ComputeIntersections(SweepLineSegment ss, SegmentIntersector si)
 {
     si.AddIntersections(edge, ptIndex, ss.edge, ss.ptIndex);
 }
 /// <summary> 
 /// Computes all mutual intersections between two sets of edges.
 /// </summary>
 public abstract void ComputeIntersections(IList edges0, IList edges1, SegmentIntersector si);
Exemple #23
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="intersector"></param>
        /// <param name="im"></param>
        private void ComputeProperIntersectionIM(SegmentIntersector intersector, IntersectionMatrix im)
        {
            // If a proper intersection is found, we can set a lower bound on the IM.
            Dimensions dimA = arg[0].Geometry.Dimension;
            Dimensions dimB = arg[1].Geometry.Dimension;
            bool hasProper = intersector.HasProperIntersection;
            bool hasProperInterior = intersector.HasProperInteriorIntersection;

            // For Geometry's of dim 0 there can never be proper intersections.
            /*
             * If edge segments of Areas properly intersect, the areas must properly overlap.
             */
            if (dimA == Dimensions.Surface && dimB == Dimensions.Surface)
            {
                if (hasProper)
                    im.SetAtLeast("212101212");
            }

            /*
             * If an Line segment properly intersects an edge segment of an Area,
             * it follows that the Interior of the Line intersects the Boundary of the Area.
             * If the intersection is a proper <i>interior</i> intersection, then
             * there is an Interior-Interior intersection too.
             * Note that it does not follow that the Interior of the Line intersects the Exterior
             * of the Area, since there may be another Area component which contains the rest of the Line.
             */
            else if (dimA == Dimensions.Surface && dimB == Dimensions.Curve)
            {
                if (hasProper)
                    im.SetAtLeast("FFF0FFFF2");
                if (hasProperInterior)
                    im.SetAtLeast("1FFFFF1FF");
            }

            else if (dimA == Dimensions.Curve && dimB == Dimensions.Surface)
            {
                if (hasProper)
                    im.SetAtLeast("F0FFFFFF2");
                if (hasProperInterior)
                    im.SetAtLeast("1F1FFFFFF");
            }

            /* If edges of LineStrings properly intersect *in an interior point*, all
               we can deduce is that
               the interiors intersect.  (We can NOT deduce that the exteriors intersect,
               since some other segments in the geometries might cover the points in the
               neighbourhood of the intersection.)
               It is important that the point be known to be an interior point of
               both Geometries, since it is possible in a self-intersecting point to
               have a proper intersection on one segment that is also a boundary point of another segment.
            */
            else if (dimA == Dimensions.Curve && dimB == Dimensions.Curve)
            {
                if (hasProperInterior)
                    im.SetAtLeast("0FFFFFFFF");
            }
        }
Exemple #24
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="mc"></param>
 /// <param name="si"></param>
 public void ComputeIntersections(MonotoneChain mc, SegmentIntersector si)
 {
     this.mce.ComputeIntersectsForChain(chainIndex, mc.mce, mc.chainIndex, si);
 }
Exemple #25
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);
 }