示例#1
0
        public void TestGrid()
        {
            // Use fixed PM to try and get at least some points hitting the boundary
            var geomFactory = GeometryFactory.Fixed;
            // GeometryFactory geomFactory = new GeometryFactory();

            var gridBuilder = new PerturbedGridPolygonBuilder(geomFactory)
            {
                NumLines  = 20,
                LineWidth = 10.0,
                Seed      = 1185072199
                , Verbose = false
            };
            // gridBuilder.SetSeed(1185072199562);
            var area = gridBuilder.Geometry;

            // PointInAreaLocator pia = new IndexedPointInAreaLocator(area);
            IPointOnGeometryLocator pia = new IndexedPointInAreaLocator(area);

            var gridTester = new PointInAreaStressTester(geomFactory, area)
            {
                NumPoints = 100000,
                TestPointInAreaLocator = pia
            };

            bool isCorrect = gridTester.Run();

            Assert.IsTrue(isCorrect);
        }
        public void TestGrid()
        {
            // Use fixed PM to try and get at least some points hitting the boundary
            var geomFactory = GeometryFactory.Fixed;
            //		GeometryFactory geomFactory = new GeometryFactory();

            var gridBuilder = new PerturbedGridPolygonBuilder(geomFactory)
                                  {
                                      NumLines = 20,
                                      LineWidth = 10.0,
                                      Seed = 1185072199
                                      , Verbose =  false
                                  };
            //gridBuilder.SetSeed(1185072199562);
            var area = gridBuilder.Geometry;

            //    PointInAreaLocator pia = new IndexedPointInAreaLocator(area); 
            IPointOnGeometryLocator pia = new IndexedPointInAreaLocator(area);

            var gridTester = new PointInAreaStressTester(geomFactory, area)
                                 {
                                     NumPoints = 100000,
                                     TestPointInAreaLocator = pia
                                 };

            Boolean isCorrect = gridTester.Run();
            Assert.IsTrue(isCorrect);
        }
示例#3
0
        /// <summary>
        /// Tests that each hole is inside the polygon shell.
        /// This routine assumes that the holes have previously been tested
        /// to ensure that all vertices lie on the shell or inside it.
        /// A simple test of a single point in the hole can be used,
        /// provide the point is chosen such that it does not lie on the
        /// boundary of the shell.
        /// </summary>
        /// <param name="p">The polygon to be tested for hole inclusion.</param>
        /// <param name="graph">A GeometryGraph incorporating the polygon.</param>
        private void CheckHolesInShell(IPolygon p, GeometryGraph graph)
        {
            var shell = p.Shell;

            //IPointInRing pir = new MCPointInRing(shell);
            var pir = new IndexedPointInAreaLocator(shell);

            for (int i = 0; i < p.NumInteriorRings; i++)
            {
                var hole   = p.Holes[i];
                var holePt = FindPointNotNode(hole.Coordinates, shell, graph);

                /*
                 * If no non-node hole vertex can be found, the hole must
                 * split the polygon into disconnected interiors.
                 * This will be caught by a subsequent check.
                 */
                if (holePt == null)
                {
                    return;
                }

                var outside = Location.Exterior == pir.Locate(holePt);
                if (outside)
                {
                    _validErr = new TopologyValidationError(TopologyValidationErrors.HoleOutsideShell, holePt);
                    return;
                }
            }
        }
示例#4
0
        protected override void RunPtInRing(Location expectedLoc, Coordinate pt, string wkt)
        {
            var geom   = _reader.Read(wkt);
            var loc    = new IndexedPointInAreaLocator(geom);
            var result = loc.Locate(pt);

            Assert.AreEqual(expectedLoc, result);
        }
示例#5
0
 public void RunIndexPointInAreaLocator()
 {
     for (int i = 0; i < NUM_ITER; i++)
     {
         var ipa = new IndexedPointInAreaLocator(sinePoly);
         foreach (var pt in testPoints)
         {
             ipa.Locate(pt.Coordinate);
         }
     }
 }
示例#6
0
 /// <summary>
 /// Sets the area boundary as the convex hull
 /// of the obstacles.
 /// </summary>
 private void SetBoundary(Geometry obstacles)
 {
     // TODO: allow this to be set by client as arbitrary polygon
     this._boundary = obstacles.ConvexHull();
     // if boundary does not enclose an area cannot create a ptLocater
     if (_boundary.Dimension >= Dimension.Surface)
     {
         _ptLocater        = new IndexedPointInAreaLocator(_boundary);
         _boundaryDistance = new IndexedFacetDistance(_boundary);
     }
 }
        /// <summary>
        /// Creates a new instance of a Maximum Inscribed Circle computation.
        /// </summary>
        /// <param name="polygonal">An areal geometry</param>
        /// <param name="tolerance">The distance tolerance for computing the centre point</param>
        public MaximumInscribedCircle(Geometry polygonal, double tolerance)
        {
            if (!(polygonal is IPolygonal))
            {
                throw new ArgumentException("Input geometry must be a Polygon or MultiPolygon");
            }
            if (polygonal.IsEmpty)
            {
                throw new ArgumentException("Empty input geometry is not supported");
            }

            _inputGeom       = polygonal;
            _factory         = polygonal.Factory;
            _tolerance       = tolerance;
            _ptLocater       = new IndexedPointInAreaLocator(polygonal);
            _indexedDistance = new IndexedFacetDistance(polygonal.Boundary);
        }
示例#8
0
        private void AddResultVertices(Geometry geom0, Geometry geom1)
        {
            /*
             * Compute rays originating at vertices inside the resultant
             * (i.e. A vertices inside B, and B vertices inside A)
             */
            var  locator = new IndexedPointInAreaLocator(geom1);
            var  seq     = GetVertices(geom0);
            bool isCW    = !Orientation.IsCCW(seq);

            for (int i = 0; i < seq.Count - 1; i++)
            {
                var vPrev = i == 0 ? seq.GetCoordinate(seq.Count - 2) : seq.GetCoordinate(i - 1);
                var v     = seq.GetCoordinate(i);
                var vNext = seq.GetCoordinate(i + 1);
                if (Location.Interior == locator.Locate(v))
                {
                    _area += EdgeRay.AreaTerm(v, vPrev, !isCW);
                    _area += EdgeRay.AreaTerm(v, vNext, isCW);
                }
            }
        }