conveyal / r5

Developed to power Conveyal's web-based interface for scenario planning and land-use/transport accessibility analysis, R5 is our routing engine for multimodal (transit/bike/walk/car) networks with a particular focus on public transit
https://conveyal.com/learn
MIT License
272 stars 71 forks source link

Make repeated WGS84-Mercator conversion stable #897

Closed abyrd closed 8 months ago

abyrd commented 8 months ago

This PR supersedes #892, which has been split into multiple PRs. This is a more minimal changeset than originally proposed, to facilitate review and contain any risk from changing heavily used math functions.

As recently discussed: regional request bounds are specified in WGS84 coordinates, which are converted to web Mercator extents when regional tasks are processed. Repeating a regional analysis with the same bounds as an existing one requires the the UI to look at the web Mercator bounds of an existing analysis, then convert them to WGS84 to create the new regional analysis request. This creates a feedback loop between WGS84 and web Mercator where WGS84 bounding boxes lie exactly on the edges of Mercator pixels, creating a literal edge case for the function WebMercatorExtents#forWgsEnvelope and populateTask.

This PR revises the way web Mercator extents are created to handle this edge case. This change is reinforced with additional factory methods that should handle any numerical instability or lack of precision in the repeated conversions.

The eventual real fix for this is https://github.com/conveyal/r5/issues/893.

This PR includes a test of repeated conversions, which fails without these changes and passes with these changes. Javadoc was also added and updated.

abyrd commented 8 months ago

A corresponding or related UI PR is https://github.com/conveyal/ui/pull/1985, where I made some comments about coordinating behavior between the two sides.