示例#1
0
 // resets Iterators if they are used.
 private bool WeakIntersectionTest_(com.epl.geometry.Geometry geometryA, com.epl.geometry.Geometry geometryB, com.epl.geometry.SegmentIterator segIterA, com.epl.geometry.SegmentIterator segIterB)
 {
     /* const */
     /* const */
     if (geometryA.GetType() == com.epl.geometry.Geometry.Type.Polygon)
     {
         // test PolygonA vs. first segment of each of geometryB's paths
         while (segIterB.NextPath())
         {
             if (segIterB.HasNextSegment())
             {
                 /* const */
                 com.epl.geometry.Segment segmentB = segIterB.NextSegment();
                 if (com.epl.geometry.PolygonUtils.IsPointInPolygon2D((com.epl.geometry.Polygon)geometryA, segmentB.GetEndXY(), 0) != com.epl.geometry.PolygonUtils.PiPResult.PiPOutside)
                 {
                     return(true);
                 }
             }
         }
         segIterB.ResetToFirstPath();
     }
     if (geometryB.GetType() == com.epl.geometry.Geometry.Type.Polygon)
     {
         // test PolygonB vs. first segment of each of geometryA's paths
         while (segIterA.NextPath())
         {
             if (segIterA.HasNextSegment())
             {
                 /* const */
                 com.epl.geometry.Segment segmentA = segIterA.NextSegment();
                 if (com.epl.geometry.PolygonUtils.IsPointInPolygon2D((com.epl.geometry.Polygon)geometryB, segmentA.GetEndXY(), 0) != com.epl.geometry.PolygonUtils.PiPResult.PiPOutside)
                 {
                     return(true);
                 }
             }
         }
         segIterA.ResetToFirstPath();
     }
     return(false);
 }
示例#2
0
            private double BruteForceMultiPathMultiPath_(com.epl.geometry.MultiPath geometryA, com.epl.geometry.MultiPath geometryB, bool geometriesAreDisjoint)
            {
                /* const */
                /* const */
                // It may be beneficial to have the geometry with less vertices
                // always be geometryA.
                com.epl.geometry.SegmentIterator segIterA      = geometryA.QuerySegmentIterator();
                com.epl.geometry.SegmentIterator segIterB      = geometryB.QuerySegmentIterator();
                com.epl.geometry.Envelope2D      env2DSegmentA = new com.epl.geometry.Envelope2D();
                com.epl.geometry.Envelope2D      env2DSegmentB = new com.epl.geometry.Envelope2D();
                double minSqrDistance = com.epl.geometry.NumberUtils.DoubleMax();

                if (!geometriesAreDisjoint)
                {
                    // Geometries might be non-disjoint. Check if they intersect
                    // using point-in-polygon tests
                    if (this.WeakIntersectionTest_(geometryA, geometryB, segIterA, segIterB))
                    {
                        return(0.0);
                    }
                }
                // if geometries are known disjoint, don't bother to do any tests
                // for polygon containment
                // nested while-loop insanity
                while (segIterA.NextPath())
                {
                    while (segIterA.HasNextSegment())
                    {
                        /* const */
                        com.epl.geometry.Segment segmentA = segIterA.NextSegment();
                        segmentA.QueryEnvelope2D(env2DSegmentA);
                        if (env2DSegmentA.SqrDistance(this.m_env2DgeometryB) > minSqrDistance)
                        {
                            continue;
                        }
                        while (segIterB.NextPath())
                        {
                            while (segIterB.HasNextSegment())
                            {
                                /* const */
                                com.epl.geometry.Segment segmentB = segIterB.NextSegment();
                                segmentB.QueryEnvelope2D(env2DSegmentB);
                                if (env2DSegmentA.SqrDistance(env2DSegmentB) < minSqrDistance)
                                {
                                    // get distance between segments
                                    double sqrDistance = segmentA.Distance(segmentB, geometriesAreDisjoint);
                                    sqrDistance *= sqrDistance;
                                    if (sqrDistance < minSqrDistance)
                                    {
                                        if (sqrDistance == 0.0)
                                        {
                                            return(0.0);
                                        }
                                        minSqrDistance = sqrDistance;
                                    }
                                }
                            }
                        }
                        segIterB.ResetToFirstPath();
                    }
                }
                return(System.Math.Sqrt(minSqrDistance));
            }