Modify

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#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)

18274.patch (3.0 KB ) - added by taylor.smock 6 years ago.

Download all attachments as: .zip

Change History (6)

by taylor.smock, 6 years ago

Attachment: 18274.patch added

comment:1 by Don-vip, 6 years ago

Milestone: 19.10

No objection, it's useful

comment:2 by Don-vip, 6 years ago

Resolution: fixed
Status: newclosed

In 15483/josm:

fix #18274 - BBox should have a method to determine functional equivalency (patch by taylor.smock)

comment:3 by taylor.smock, 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)).

comment:4 by Don-vip, 6 years ago

In 15486/josm:

see #18274 - rename new method to make error_prone happy

comment:5 by Don-vip, 6 years ago

In 15487/josm:

see #18274 - forgot to update unit test

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.