public static double maximumDiameterLength(Geometry g) { return 2 * (new MinimumBoundingCircle(g)).getRadius(); }
void run(int nPts) { Coordinate[] randPts = createRandomPoints(nPts); Geometry mp = geomFact.createMultiPoint(randPts); MinimumBoundingCircle mbc = new MinimumBoundingCircle(mp); Coordinate centre = mbc.getCentre(); double radius = mbc.getRadius(); System.out.println("Testing " + nPts + " random points. Radius = " + radius); checkWithinCircle(randPts, centre, radius, 0.0001); }
private void doMinimumBoundingCircleTest(String wkt, String expectedWKT, Coordinate expectedCentre, double expectedRadius) throws ParseException { MinimumBoundingCircle mbc = new MinimumBoundingCircle(reader.read(wkt)); Coordinate[] exPts = mbc.getExtremalPoints(); Geometry actual = geometryFactory.createMultiPoint(exPts); double actualRadius = mbc.getRadius(); Coordinate actualCentre = mbc.getCentre(); //System.out.println( // " Centre = " + actualCentre // + " Radius = " + actualRadius); Geometry expected = reader.read(expectedWKT); boolean isEqual = actual.equals(expected); // need this hack because apparently equals does not work for MULTIPOINT EMPTY if (actual.isEmpty() && expected.isEmpty()) isEqual = true; if (!isEqual) { System.out.println("Actual = " + actual + ", Expected = " + expected); } assertTrue(isEqual); if (expectedCentre != null) { assertTrue(expectedCentre.distance(actualCentre) < TOLERANCE); } if (expectedRadius >= 0) { assertTrue(Math.abs(expectedRadius - actualRadius) < TOLERANCE); } }