public static Geometry maximumDiameter(Geometry g) { return g.getFactory().createLineString((new MinimumBoundingCircle(g)).getExtremalPoints()); } public static Geometry farthestPoints(Geometry g) {
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); } }