Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent ways to represent coordinates #6013

Open
habrahamsson-skanetrafiken opened this issue Aug 21, 2024 · 1 comment
Open

Inconsistent ways to represent coordinates #6013

habrahamsson-skanetrafiken opened this issue Aug 21, 2024 · 1 comment

Comments

@habrahamsson-skanetrafiken
Copy link
Contributor

Is your feature request related to a problem? Please describe.

Different parts of the OTP code base are using different ways to represent coordinates.

These are the main ways:

  • WgsCoordinate - an internal value object class. Takes parameters as lat, lon.
  • jts Coordinate class. Takes parameters as x, y.
  • Unstructured lat, lon values.
  • Unstructured x, y values. Here x = longitude and y = latitude.

Using unstructured x, y and lat, long values are a bit error prone since it is easy to get the order wrong. At the call site it's not obvious which of these is the correct:
new Vertex(lat, lon) or new Vertex(lon, lat) since it depends on if the Vertex class operates on x, y or on lat, lon.

Goal / high level use-case

Treating coordinates in a consistent way within OTP would make code less brittle and easier to maintain.

Describe the solution you'd like

Consistently use our internal data object WgsCoordinate for representing coordinates.

Describe alternatives you've considered

  • We could leave the code as it is.
  • We could use the jts Coordinate class instead of the WgsCoordinate class.
@t2gran
Copy link
Member

t2gran commented Aug 22, 2024

The jts Coordinate uses (x, y, z) while the WgsCoordinate only has (lat,long), all doubles. The memory footprint would be 16 + 3 x 8 vs 16 + 2 x 8 bytes. In addition there is 8 bytes for each reference. If memory is an issue, we could also change the WgsCoordinate to use integers for the lat/long - the precision is good enough. Hopefully we will be able to inline WgsCoordinate later.

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

No branches or pull requests

2 participants