use of com.revolsys.geometry.operation.distance.DistanceWithPoints in project com.revolsys.open by revolsys.
the class BufferDistanceValidator method checkMinimumDistance.
/**
* Checks that two geometries are at least a minumum distance apart.
*
* @param g1 a geometry
* @param g2 a geometry
* @param minDist the minimum distance the geometries should be separated by
*/
private void checkMinimumDistance(final Geometry g1, final Geometry g2, final double minDist) {
final DistanceWithPoints distOp = new DistanceWithPoints(g1, g2, minDist);
this.minDistanceFound = distOp.distance();
if (this.minDistanceFound < minDist) {
this.isValid = false;
final List<Point> pts = distOp.nearestPoints();
this.errorLocation = pts.get(1);
this.errorIndicator = g1.getGeometryFactory().lineString(pts);
this.errMsg = "Distance between buffer curve and input is too small " + "(" + this.minDistanceFound + " at " + EWktWriter.lineString(pts.get(0), this.errorLocation) + " )";
}
}
use of com.revolsys.geometry.operation.distance.DistanceWithPoints in project com.revolsys.open by revolsys.
the class DistanceTest method doNearestPointsTest.
private void doNearestPointsTest(final String wkt0, final String wkt1, final double distance, final Point p0, final Point p1) throws ParseException {
final Geometry geometry1 = this.geometryFactory.geometry(wkt0);
final Geometry geometry2 = this.geometryFactory.geometry(wkt1);
final DistanceWithPoints op = new DistanceWithPoints(geometry1, geometry2);
final double tolerance = 1E-10;
final List<Point> nearestPoints = op.nearestPoints();
final Point nearestPoint1 = nearestPoints.get(0);
final Point nearestPoint2 = nearestPoints.get(1);
final double p1p2Distance = nearestPoint1.distancePoint(nearestPoint2);
assertEquals(distance, p1p2Distance, tolerance);
assertEquals(p0.getX(), nearestPoint1.getX(), tolerance);
assertEquals(p0.getY(), nearestPoint1.getY(), tolerance);
assertEquals(p1.getX(), nearestPoint2.getX(), tolerance);
assertEquals(p1.getY(), nearestPoint2.getY(), tolerance);
}
Aggregations