@@ -100,7 +100,7 @@ public static double distance(Geometry a, Geometry b, double tolerance)
100100 }
101101
102102 /**
103- * Computes a pair of points which attain the directed Hausdorff distance
103+ * Computes a line containing a pair of points which attain the directed Hausdorff distance
104104 * of a query geometry A from a target one B.
105105 *
106106 * @param a the query geometry
@@ -113,27 +113,9 @@ public static LineString distanceLine(Geometry a, Geometry b, double tolerance)
113113 DirectedHausdorffDistance hd = new DirectedHausdorffDistance (b );
114114 return a .getFactory ().createLineString (hd .maximumDistancePoints (a , tolerance ));
115115 }
116-
117- /**
118- * Computes whether a query geometry lies fully within a give distance of a target geometry.
119- * Equivalently, detects whether any point of the query geometry is farther
120- * from the target than the specified distance.
121- * This is the case if <tt>DHD(A, B) > maxDistance</tt>.
122- *
123- * @param a the query geometry
124- * @param b the target geometry
125- * @param maxDistance the distance limit
126- * @param tolerance the approximation distance tolerance
127- * @return true if the query geometry lies fully within the distance of the target
128- */
129- public static boolean isFullyWithinDistance (Geometry a , Geometry b , double maxDistance , double tolerance )
130- {
131- DirectedHausdorffDistance hd = new DirectedHausdorffDistance (b );
132- return hd .isFullyWithinDistance (a , maxDistance , tolerance );
133- }
134116
135117 /**
136- * Computes a pair of points which attain the Hausdorff distance
118+ * Computes a pair of points which attain the symmetric Hausdorff distance
137119 * between two geometries.
138120 *
139121 * @param a a geometry
@@ -159,6 +141,24 @@ public static LineString hausdorffDistanceLine(Geometry a, Geometry b, double to
159141 return a .getFactory ().createLineString (pts );
160142 }
161143
144+ /**
145+ * Computes whether a query geometry lies fully within a give distance of a target geometry.
146+ * Equivalently, detects whether any point of the query geometry is farther
147+ * from the target than the specified distance.
148+ * This is the case if <tt>DHD(A, B) > maxDistance</tt>.
149+ *
150+ * @param a the query geometry
151+ * @param b the target geometry
152+ * @param maxDistance the distance limit
153+ * @param tolerance the approximation distance tolerance
154+ * @return true if the query geometry lies fully within the distance of the target
155+ */
156+ public static boolean isFullyWithinDistance (Geometry a , Geometry b , double maxDistance , double tolerance )
157+ {
158+ DirectedHausdorffDistance hd = new DirectedHausdorffDistance (b );
159+ return hd .isFullyWithinDistance (a , maxDistance , tolerance );
160+ }
161+
162162 private static double distance (Coordinate [] pts ) {
163163 return pts [0 ].distance (pts [1 ]);
164164 }
@@ -239,10 +239,10 @@ public Coordinate[] maximumDistancePoints(Geometry geomA, double tolerance) {
239239
240240 private Coordinate [] computeDistancePoints (Geometry geomA , double tolerance , double maxDistanceLimit ) {
241241 if (geomA .getDimension () == Dimension .P ) {
242- return computeAtPoints (geomA , maxDistanceLimit );
242+ return computeForPoints (geomA , maxDistanceLimit );
243243 }
244244 //TODO: handle mixed geoms with points
245- Coordinate [] maxDistPtsEdge = computeAtEdges (geomA , tolerance , maxDistanceLimit );
245+ Coordinate [] maxDistPtsEdge = computeForEdges (geomA , tolerance , maxDistanceLimit );
246246
247247 if (isBeyondLimit (distance (maxDistPtsEdge ), maxDistanceLimit )) {
248248 return maxDistPtsEdge ;
@@ -252,7 +252,7 @@ private Coordinate[] computeDistancePoints(Geometry geomA, double tolerance, dou
252252 * Polygonal query geometry may have an interior point as the farthest point.
253253 */
254254 if (geomA .getDimension () == Dimension .A ) {
255- Coordinate [] maxDistPtsInterior = computeAtAreaInterior (geomA , tolerance );
255+ Coordinate [] maxDistPtsInterior = computeForAreaInterior (geomA , tolerance );
256256 if (maxDistPtsInterior != null
257257 && distance (maxDistPtsInterior ) > distance (maxDistPtsEdge )) {
258258 return maxDistPtsInterior ;
@@ -261,7 +261,7 @@ && distance(maxDistPtsInterior) > distance(maxDistPtsEdge)) {
261261 return maxDistPtsEdge ;
262262 }
263263
264- private Coordinate [] computeAtPoints (Geometry geomA , double maxDistanceLimit ) {
264+ private Coordinate [] computeForPoints (Geometry geomA , double maxDistanceLimit ) {
265265 double maxDist = -1.0 ;;
266266 Coordinate [] maxDistPtsAB = null ;
267267 Iterator geomi = new GeometryCollectionIterator (geomA );
@@ -291,7 +291,7 @@ private Coordinate[] computeAtPoints(Geometry geomA, double maxDistanceLimit) {
291291 return maxDistPtsAB ;
292292 }
293293
294- private Coordinate [] computeAtEdges (Geometry geomA , double tolerance , double maxDistanceLimit ) {
294+ private Coordinate [] computeForEdges (Geometry geomA , double tolerance , double maxDistanceLimit ) {
295295 PriorityQueue <DHDSegment > segQueue = createSegQueue (geomA );
296296
297297 DHDSegment segMaxDist = null ;
@@ -313,16 +313,16 @@ private Coordinate[] computeAtEdges(Geometry geomA, double tolerance, double max
313313 * Save if segment is farther than most distant so far
314314 */
315315 if (segMaxDist == null
316- || segMaxBound .maxDistance () > segMaxDist .maxDistance ()) {
316+ || segMaxBound .getMaxDistance () > segMaxDist .getMaxDistance ()) {
317317 segMaxDist = segMaxBound ;
318318 }
319319 /**
320320 * If maxDistanceLimit is specified, short-circuit if:
321321 * - if segment distance bound is less than distance limit, no other segment can be farther
322322 * - if a point of segment is farther than limit, isFulyWithin must be false
323323 */
324- if (isWithinLimit (segMaxBound .maxDistanceBound (), maxDistanceLimit )
325- || isBeyondLimit (segMaxBound .maxDistance (), maxDistanceLimit )
324+ if (isWithinLimit (segMaxBound .getMaxDistanceBound (), maxDistanceLimit )
325+ || isBeyondLimit (segMaxBound .getMaxDistance (), maxDistanceLimit )
326326 ) {
327327 break ;
328328 }
@@ -334,7 +334,7 @@ private Coordinate[] computeAtEdges(Geometry geomA, double tolerance, double max
334334 * have identical or collinear segments
335335 * (in particular, the case when the inputs are identical).
336336 */
337- if (segMaxBound .maxDistance () == 0.0 ) {
337+ if (segMaxBound .getMaxDistance () == 0.0 ) {
338338 if (isSameOrCollinear (segMaxBound ))
339339 continue ;
340340 }
@@ -346,13 +346,17 @@ private Coordinate[] computeAtEdges(Geometry geomA, double tolerance, double max
346346 * and it might provide a better max distance point,
347347 * bisect and keep searching
348348 */
349- if ((segMaxBound .length () > tolerance )
350- && segMaxBound .maxDistanceBound () > segMaxDist .maxDistance ()) {
349+ if ((segMaxBound .getLength () > tolerance )
350+ && segMaxBound .getMaxDistanceBound () > segMaxDist .getMaxDistance ()) {
351351 DHDSegment [] bisects = segMaxBound .bisect (distanceToB );
352352 addNonInterior (bisects [0 ], segQueue );
353353 addNonInterior (bisects [1 ], segQueue );
354354 }
355355 }
356+ /**
357+ * A segment at maximum distance was found.
358+ * Return the farthest point pair
359+ */
356360 if (segMaxDist != null )
357361 return segMaxDist .getMaxDistPts ();
358362
@@ -395,7 +399,7 @@ private void addNonInterior(DHDSegment segment, PriorityQueue<DHDSegment> segQue
395399 * @return
396400 */
397401 private boolean isInterior (DHDSegment segment ) {
398- if (segment .maxDistance () > 0.0 ) {
402+ if (segment .getMaxDistance () > 0.0 ) {
399403 return false ;
400404 }
401405 return distanceToB .isInterior (segment .getEndpoint (0 ), segment .getEndpoint (1 ));
@@ -418,7 +422,7 @@ private boolean isInterior(DHDSegment segment) {
418422 * @return the maximum distance point pair at an interior point of A,
419423 * or null if it is known to not occur at an interior point
420424 */
421- private Coordinate [] computeAtAreaInterior (Geometry geomA , double tolerance ) {
425+ private Coordinate [] computeForAreaInterior (Geometry geomA , double tolerance ) {
422426 //TODO: extract polygonal geoms from A
423427 Geometry polygonalA = geomA ;
424428
@@ -492,15 +496,15 @@ private void addSegments(Coordinate[] pts, PriorityQueue<DHDSegment> priq) {
492496
493497 //-- don't add segment if it can't be further away then current max
494498 if (segMaxDist == null
495- || seg .maxDistanceBound () > segMaxDist .maxDistance ()) {
499+ || seg .getMaxDistanceBound () > segMaxDist .getMaxDistance ()) {
496500 /**
497501 * Don't add interior segments, since their distance must be zero.
498502 */
499503 addNonInterior (seg , priq );
500504 }
501505
502506 if (segMaxDist == null
503- || seg .maxDistance () > segMaxDist .maxDistance ()) {
507+ || seg .getMaxDistance () > segMaxDist .getMaxDistance ()) {
504508 segMaxDist = seg ;;
505509 }
506510 //System.out.println(seg.distance());
@@ -608,15 +612,15 @@ public Coordinate getEndpoint(int index) {
608612 return index == 0 ? p0 : p1 ;
609613 }
610614
611- public double length () {
615+ public double getLength () {
612616 return p0 .distance (p1 );
613617 }
614618
615- public double maxDistance () {
619+ public double getMaxDistance () {
616620 return maxDistance ;
617621 }
618622
619- public double maxDistanceBound () {
623+ public double getMaxDistanceBound () {
620624 return maxDistanceBound ;
621625 }
622626
@@ -640,7 +644,7 @@ private void computeMaxDistances() {
640644 double dist0 = p0 .distance (nearPt0 );
641645 double dist1 = p1 .distance (nearPt1 );
642646 maxDistance = Math .max (dist0 , dist1 );
643- maxDistanceBound = maxDistance + length () / 2 ;
647+ maxDistanceBound = maxDistance + getLength () / 2 ;
644648 }
645649
646650 public DHDSegment [] bisect (TargetDistance dist ) {
0 commit comments