Skip to content

Commit e97617b

Browse files
committed
Refactor tolerance factors
1 parent 67f65d1 commit e97617b

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

modules/core/src/main/java/org/locationtech/jts/algorithm/distance/DirectedHausdorffDistance.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@
8383
*
8484
*/
8585
public class DirectedHausdorffDistance {
86-
87-
private static final double EMPTY_DISTANCE = Double.NaN;
8886

8987
/**
9088
* Computes the directed Hausdorff distance
@@ -235,15 +233,28 @@ private static Coordinate[] pair(Coordinate p0, Coordinate p1) {
235233
return new Coordinate[] { p0.copy(), p1.copy() };
236234
}
237235

236+
private static final double EMPTY_DISTANCE = Double.NaN;
237+
238+
/**
239+
* Heuristic automatic tolerance factor
240+
*/
241+
private static final double AUTO_TOLERANCE_FACTOR = 1.0e4;
242+
238243
/**
239244
* Heuristic factor to improve performance of area interior farthest point computation.
245+
* The LargestEmptyCircle computation is much slower than the boundary one,
246+
* is unlikely to occur, and accuracy is less critical (and obvious).
247+
* Improve performance by using a coarser distance tolerance.
240248
*/
241-
private static final double AREA_INTERIOR_PERFORMANCE_FACTOR = 20;
249+
private static final double AREA_INTERIOR_TOLERANCE_FACTOR = 20;
242250

243251
/**
244-
* Heuristic automatic tolerance factor
252+
* Tolerance factor for isFullyWithinDistance.
253+
* A larger factor is used to increase accuracy.
254+
* The operation will usually short-circuit, so performance impact is low.
245255
*/
246-
private static final double AUTO_TOLERANCE_FACTOR = 1.0e4;
256+
private static final double FULLY_WITHIN_TOLERANCE_FACTOR = 10 * AUTO_TOLERANCE_FACTOR;
257+
247258

248259
private static double computeTolerance(Geometry geom) {
249260
return geom.getEnvelopeInternal().getDiameter() / AUTO_TOLERANCE_FACTOR;
@@ -273,9 +284,7 @@ public DirectedHausdorffDistance(Geometry geom) {
273284
* @return true if the query geometry lies fully within the distance of the target
274285
*/
275286
public boolean isFullyWithinDistance(Geometry geom, double maxDistance) {
276-
//TODO: should the tolerance be computed as a fraction of the maxDistance?
277-
//return isFullyWithinDistance(a, maxDistance, computeTolerance(a));
278-
double tolerance = maxDistance / AUTO_TOLERANCE_FACTOR;
287+
double tolerance = maxDistance / FULLY_WITHIN_TOLERANCE_FACTOR;
279288
return isFullyWithinDistance(geom, maxDistance, tolerance);
280289
}
281290

@@ -569,11 +578,9 @@ private Coordinate[] computeForAreaInterior(Geometry geom, double tolerance) {
569578
* and accuracy is probably less critical (or obvious).
570579
* So improve performance by using a coarser distance tolerance.
571580
*/
572-
double lecTol = AREA_INTERIOR_PERFORMANCE_FACTOR * tolerance;
573-
574581
//TODO: add short-circuiting based on maxDistanceLimit?
575582

576-
Point centerPt = LargestEmptyCircle.getCenter(target, polygonal, lecTol);
583+
Point centerPt = LargestEmptyCircle.getCenter(target, polygonal, tolerance * AREA_INTERIOR_TOLERANCE_FACTOR);
577584
Coordinate ptA = centerPt.getCoordinate();
578585
/**
579586
* If LEC centre is in B, the max distance is zero, so return null.

0 commit comments

Comments
 (0)