/// <summary> /// The ringCoord is assumed to contain no repeated points. /// It may be degenerate (i.e. contain only 1, 2, or 3 points). /// In this case it has no area, and hence has a minimum diameter of 0. /// </summary> /// <param name="ringCoord"></param> /// <param name="bufferDistance"></param> /// <returns></returns> private bool IsErodedCompletely(Coordinate[] ringCoord, double bufferDistance) { // degenerate ring has no area if (ringCoord.Length < 4) { return(bufferDistance < 0); } // important test to eliminate inverted triangle bug // also optimizes erosion test for triangles if (ringCoord.Length == 4) { return(IsTriangleErodedCompletely(ringCoord, bufferDistance)); } /* * The following is a heuristic test to determine whether an * inside buffer will be eroded completely. * It is based on the fact that the minimum diameter of the ring pointset * provides an upper bound on the buffer distance which would erode the * ring. * If the buffer distance is less than the minimum diameter, the ring * may still be eroded, but this will be determined by * a full topological computation. * */ var ring = _inputGeom.Factory.CreateLinearRing(ringCoord); var md = new MinimumDiameter(ring); double minDiam = md.Length; return(minDiam < 2 * Math.Abs(bufferDistance)); }
private void DoMinimumDiameterTest(bool convex, String wkt, Coordinate c0, Coordinate c1) { Coordinate[] minimumDiameter = new MinimumDiameter(new WKTReader().Read(wkt), convex).Diameter.Coordinates; double tolerance = 1E-10; Assert.AreEqual(c0.X, minimumDiameter[0].X, tolerance); Assert.AreEqual(c0.Y, minimumDiameter[0].Y, tolerance); Assert.AreEqual(c1.X, minimumDiameter[1].X, tolerance); Assert.AreEqual(c1.Y, minimumDiameter[1].Y, tolerance); }