#18274 closed enhancement (fixed)
[RFC PATCH] BBox should have a method to determine functional equivalency
Reported by: | taylor.smock | Owned by: | team |
---|---|---|---|
Priority: | normal | Milestone: | 19.10 |
Component: | Core | Version: | |
Keywords: | bbox | Cc: |
Description
When comparing bboxes from different sources (e.g., one from OSM and one from another service, e.g. MapWithAI), sometimes there is a very small difference (in this case, I've had differences of around 0.00001 degrees, which translates to roughly 1.5m). For the purposes of equals
, this is OK, but if the bboxes are close enough to be functionally equal (for the purposes of the calling function), then equals
doesn't work. contains
doesn't always work for this, because sometimes the bboxes are slightly shifted.
So, I would like to add a function to the BBox
class that looks something like this:
public boolean bboxesAreFunctionallyEqual(BBox other, Double maxDifference) { return bboxesAreFunctionallyEqual(this, other, maxDifference); } public static boolean bboxesAreFunctionallyEqual(BBox bbox1, BBox bbox2, Double maxDifference) { if (maxDifference == null) { maxDifference = LatLon.MAX_SERVER_PRECISION; } return (bbox1 != null && bbox2 != null) && (Math.abs(bbox1.getBottomRightLat() - bbox2.getBottomRightLat()) < maxDifference && Math.abs(bbox1.getBottomRightLon() - bbox2.getBottomRightLon()) < maxDifference && Math.abs(bbox1.getTopLeftLat() - bbox2.getTopLeftLat()) < maxDifference && Math.abs(bbox1.getTopLeftLon() - bbox2.getTopLeftLon()) < maxDifference); }
Attachments (1)
Change History (6)
by , 6 years ago
Attachment: | 18274.patch added |
---|
comment:1 by , 6 years ago
Milestone: | → 19.10 |
---|
comment:3 by , 6 years ago
Something that I didn't notice is that error prone is complaining about AmbiguousMethodReference ( https://errorprone.info/bugpattern/AmbiguousMethodReference ).
The two functions are public boolean bboxesAreFunctionallyEqual(BBox other, Double maxDifference)
and public static boolean bboxesAreFunctionallyEqual(BBox bbox1, BBox bbox2, Double maxDifference)
. Since the former calls the latter, I don't think it is a significant issue, but we can rename one method (maybe to bboxIsFunctionallyEqual(BBox other, Double maxDifference)
).
No objection, it's useful