FeatureDistanceFn implements DistanceFn<SimpleFeature> { @Override public double measure(final SimpleFeature x, final SimpleFeature y) { double dist = Double.MAX_VALUE; final Coordinate[] coords = new DistanceOp(getGeometry(x), getGeometry(y)).nearestPoints(); for (int i = 0; i < coords.length; i++) { for (int j = i + 1; j < coords.length; j++) { dist = Math.min(dist, coordinateDistanceFunction.measure(coords[j], coords[i])); } } return dist; } FeatureDistanceFn();  FeatureDistanceFn(final DistanceFn<Coordinate> coordinateDistanceFunction); DistanceFn<Coordinate> getCoordinateDistanceFunction(); void setCoordinateDistanceFunction(
      final DistanceFn<Coordinate> coordinateDistanceFunction); @Override double measure(final SimpleFeature x, final SimpleFeature y);  }
@Test public void testPoint() { final SimpleFeature feature1 = createFeature(factory.createPoint(new Coordinate(0, 0))); final SimpleFeature feature2 = createFeature(factory.createPoint(new Coordinate(0.001, 0.001))); testBounds(functionUnderTest.measure(feature1, feature2), 100, 200); }
@Test public void testPointWithPoly() { final SimpleFeature feature1 = createFeature(factory.createPoint(new Coordinate(0, 0))); final SimpleFeature feature2 = createFeature( factory.createPolygon( new Coordinate[] { new Coordinate(0.001, 0.001), new Coordinate(0.001, 0.002), new Coordinate(0.002, 0.002), new Coordinate(0.001, 0.001)})); testBounds(functionUnderTest.measure(feature1, feature2), 100, 200); }
@Test public void testPolyWithPoly() { final SimpleFeature feature1 = createFeature( factory.createPolygon( new Coordinate[] { new Coordinate(0.000, 0.000), new Coordinate(-0.000, -0.001), new Coordinate(-0.001, -0.001), new Coordinate(0.00, 0.00)})); final SimpleFeature feature2 = createFeature( factory.createPolygon( new Coordinate[] { new Coordinate(0.001, 0.001), new Coordinate(0.001, 0.002), new Coordinate(0.002, 0.002), new Coordinate(0.001, 0.001)})); testBounds(functionUnderTest.measure(feature1, feature2), 100, 200); }
@Test public void testIntersectingPoly() { final SimpleFeature feature1 = createFeature( factory.createPolygon( new Coordinate[] { new Coordinate(0.000, 0.000), new Coordinate(0.0012, 0.000), new Coordinate(0.0013, 0.0015), new Coordinate(0.00, 0.00)})); final SimpleFeature feature2 = createFeature( factory.createPolygon( new Coordinate[] { new Coordinate(0.001, 0.001), new Coordinate(0.002, 0.001), new Coordinate(0.002, 0.002), new Coordinate(0.001, 0.001)})); testBounds(functionUnderTest.measure(feature1, feature2), 0, 0.00001); final SimpleFeature feature3 = createFeature( factory.createPolygon( new Coordinate[] { new Coordinate(0.000, 0.000), new Coordinate(0.001, 0.001), new Coordinate(0.000, 0.001), new Coordinate(0.00, 0.00)})); final SimpleFeature feature4 = createFeature( factory.createPolygon( new Coordinate[] { new Coordinate(0.001, 0.001), new Coordinate(0.002, 0.001), new Coordinate(0.002, 0.002), new Coordinate(0.001, 0.001)})); testBounds(functionUnderTest.measure(feature3, feature4), 0.0, 0.00001); }