|
83 | 83 | * |
84 | 84 | */ |
85 | 85 | public class DirectedHausdorffDistance { |
86 | | - |
87 | | - private static final double EMPTY_DISTANCE = Double.NaN; |
88 | 86 |
|
89 | 87 | /** |
90 | 88 | * Computes the directed Hausdorff distance |
@@ -235,15 +233,28 @@ private static Coordinate[] pair(Coordinate p0, Coordinate p1) { |
235 | 233 | return new Coordinate[] { p0.copy(), p1.copy() }; |
236 | 234 | } |
237 | 235 |
|
| 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 | + |
238 | 243 | /** |
239 | 244 | * 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. |
240 | 248 | */ |
241 | | - private static final double AREA_INTERIOR_PERFORMANCE_FACTOR = 20; |
| 249 | + private static final double AREA_INTERIOR_TOLERANCE_FACTOR = 20; |
242 | 250 |
|
243 | 251 | /** |
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. |
245 | 255 | */ |
246 | | - private static final double AUTO_TOLERANCE_FACTOR = 1.0e4; |
| 256 | + private static final double FULLY_WITHIN_TOLERANCE_FACTOR = 10 * AUTO_TOLERANCE_FACTOR; |
| 257 | + |
247 | 258 |
|
248 | 259 | private static double computeTolerance(Geometry geom) { |
249 | 260 | return geom.getEnvelopeInternal().getDiameter() / AUTO_TOLERANCE_FACTOR; |
@@ -273,9 +284,7 @@ public DirectedHausdorffDistance(Geometry geom) { |
273 | 284 | * @return true if the query geometry lies fully within the distance of the target |
274 | 285 | */ |
275 | 286 | 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; |
279 | 288 | return isFullyWithinDistance(geom, maxDistance, tolerance); |
280 | 289 | } |
281 | 290 |
|
@@ -569,11 +578,9 @@ private Coordinate[] computeForAreaInterior(Geometry geom, double tolerance) { |
569 | 578 | * and accuracy is probably less critical (or obvious). |
570 | 579 | * So improve performance by using a coarser distance tolerance. |
571 | 580 | */ |
572 | | - double lecTol = AREA_INTERIOR_PERFORMANCE_FACTOR * tolerance; |
573 | | - |
574 | 581 | //TODO: add short-circuiting based on maxDistanceLimit? |
575 | 582 |
|
576 | | - Point centerPt = LargestEmptyCircle.getCenter(target, polygonal, lecTol); |
| 583 | + Point centerPt = LargestEmptyCircle.getCenter(target, polygonal, tolerance * AREA_INTERIOR_TOLERANCE_FACTOR); |
577 | 584 | Coordinate ptA = centerPt.getCoordinate(); |
578 | 585 | /** |
579 | 586 | * If LEC centre is in B, the max distance is zero, so return null. |
|
0 commit comments