Skip to content

LatLong.compareTo() fix - #1628

Merged
devemux86 merged 4 commits into
mapsforge:masterfrom
Sublimis:latlon-compare-fix
Jan 17, 2025
Merged

devemux86 merged 4 commits into
mapsforge:masterfrom
Sublimis:latlon-compare-fix

Conversation

@Sublimis

Copy link
Copy Markdown
Contributor

LatLong.compareTo() was incorrectly implemented, so it could happen that e.g. latLon1.compareTo(latLon2) == latLon2.compareTo(latLon1) == 1 for coordinates latLon1=(1, 0) and latLon2=(0, 1).

Although the fix is ​​crucial, LatLong.compareTo() does not seem to be used at the moment (is this correct?), so it may not change any current behavior of the library.

@devemux86

Copy link
Copy Markdown
Collaborator

@Sublimis Do you think we need some tests in LatLongTest class?

@Sublimis

Copy link
Copy Markdown
Contributor Author

@Sublimis Do you think we need some tests in LatLongTest class?

This could be useful, yes. Some tests will be crafted.
It's interesting to note that if LatLong were to extend from org.mapsforge.core.model.Point, and encapsulate the fields with getters/setters, we'd have all this automatically :)

@devemux86

Copy link
Copy Markdown
Collaborator

LatLong comparison looks similar to the Point comparison,
except that Point compares the x / longitude coordinate first.

@Sublimis Should we compare latitude first in LatLong?

@Sublimis

Copy link
Copy Markdown
Contributor Author

@devemux86 This probably wouldn't matter while running, but if you think it improves consistency, that's good. It's interesting to note how the latitude always comes first, it's always latlon, not lonlat.

What do you think of this cleanup now?

@devemux86

devemux86 commented Jan 17, 2025 •

Copy link
Copy Markdown
Collaborator

It's interesting to note how the latitude always comes first, it's always latlon, not lonlat.

While it's usually x,y, coordinates in mapping are often latitude,longitude.

What do you think of this cleanup now?

@Sublimis Looks good, we can merge it if it's ready.

@Sublimis

Copy link
Copy Markdown
Contributor Author

It's ready.

@devemux86 devemux86 added this to the 0.24.0 milestone Jan 17, 2025
@devemux86
devemux86 merged commit a1e2606 into mapsforge:master Jan 17, 2025
@devemux86

Copy link
Copy Markdown
Collaborator

@Sublimis Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants