Repository navigation
fix(area): try every area holding a coordinate, not just the first - #7718
Conversation
A plaza route could leave by a corner and come back, and a plaza request cost about 288 ms against 0.8 ms for a comparable route touching no area. Those are the same defect seen from two sides: the engine gave up on an area rather than trying the next, and it did so only after paying the full price of deciding it could not use that one. Areas overlap, and one holding a coordinate can have nothing to offer. The extractor records a polygon into `.osrm.openareas` sixteen lines before the `AreaMesher::max_vertices` valve decides whether to mesh it, so a plaza too large to mesh is stored with no way on any of its vertices. The r-tree also answers with bounding boxes, so a coordinate is filed under areas it is not inside at all. Three places then gave up on the first candidate: * `SnapInsideOpenArea` returned inside its own loop over the areas, so only the first one containing the coordinate was ever considered. The `return` after the loop, which exists for "none of them had anything", was unreachable whenever any area contained it. The request fell back to ordinary snapping, which projects onto the perimeter, and that is the route that goes out and comes back. * `commonArea` returned the first shared area, and `useGeodesicWhereShorter` and `useGeodesicInTable` moved on when `geodesic_between` declined it. It is now `commonAreas`, and `geodesicAcross` tries each in turn. * `geodesic_between` built the visibility graph before testing containment, deliberately, so a run of queries against one area paid for the graph once. That only holds while exactly one area is ever asked about. Building is cubic in the vertex count and the containment test is linear, so every bounding-box near miss was charged the full price of an answer already lost -- and trying several areas would have multiplied it. The test now comes first. No answer changes; only when the cache is populated does. `crosses_ring` and `on_any_ring` also scanned an entire ring after the answer was known, because `for_each_edge` cannot stop early. `visible_vertices` calls them once per vertex per ring, so that was a factor of the ring's length on the snapping path. Neither `area_snapping.cpp` nor `area_route.cpp` had any test, which is how this survived. Both have one now, sharing a facade mock that carries polygons: an area whose vertices carry no way, standing for one the mesher declined, and a triangle whose bounding box claims coordinates it does not hold. Reverting the three source files fails exactly the three new regression cases and nothing else. Refs #7683
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Pull request overview
This PR fixes open-area routing/snapping regressions by iterating over all candidate open areas instead of prematurely giving up on the first match, and by avoiding expensive geodesic work for bounding-box near misses.
Changes:
- Update snapping and table/route geodesic selection to try all overlapping/shared areas before falling back.
- Reorder geodesic computation to test containment before building/caching the visibility graph; add early-exit ring scans.
- Add unit tests and a new mock facade to reproduce the reported regressions.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| unit_tests/mocks/mock_area_facade.hpp | Adds a lightweight facade mock to supply open areas/rings/phantoms for new tests. |
| unit_tests/engine/area_snapping.cpp | Adds snapping regression coverage for overlapping areas and “unmeshed” areas. |
| unit_tests/engine/area_route.cpp | Adds table/geodesic regression coverage for bounding-box near misses and shared-area iteration. |
| unit_tests/engine/area_geodesic.cpp | Adds coverage to ensure near misses don’t populate the geodesic cache. |
| src/engine/area_visibility.cpp | Reworks ring scanning to stop early to reduce snapping-path overhead. |
| src/engine/area_snapping.cpp | Ensures snapping continues to later areas if an earlier one yields no candidates. |
| src/engine/area_route.cpp | Replaces “first common area” logic with “try all common areas” geodesic selection. |
| src/engine/area_geodesic.cpp | Avoids building/caching the visibility graph until after containment is confirmed. |
| include/engine/area_snapping.hpp | Updates docs to reflect trying all areas holding the coordinate. |
Suppressed comments (1)
src/engine/area_geodesic.cpp:1
build_adjacencynow operates on a pre-existingSolvedArea, but it onlyresizesarea.adjacency. If this helper is ever called on an area that already has adjacency lists populated, the existing per-vertex lists won’t be cleared, risking duplicated edges and incorrect paths. Consider resetting adjacency withassign(area.size(), {})(or explicitly clearing each list) before repopulating.
#include "engine/area_geodesic.hpp"
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| auto here = facade.GetOpenAreasAt(from); | ||
| if (here.empty()) | ||
| { | ||
| return std::nullopt; | ||
| return {}; | ||
| } | ||
| const auto there = facade.GetOpenAreasAt(to); | ||
| if (there.empty()) | ||
| { | ||
| return std::nullopt; | ||
| return {}; | ||
| } |
There was a problem hiding this comment.
The two lists are the areas whose bounding boxes hold one coordinate, which is one or two in practice and a handful where plazas nest; the product is a few comparisons against a partition lookup per relaxed node in the search that follows. A sort would cost more than it saves at these sizes, so the plain loop stays.
| std::vector<extractor::AreaPolygonSegment> shared; | ||
| for (const auto &area : here) | ||
| { | ||
| const auto shared = std::any_of(there.begin(), | ||
| there.end(), | ||
| [&](const auto &other) | ||
| { return other.vertices_offset == area.vertices_offset; }); | ||
| if (!shared) | ||
| if (std::any_of(there.begin(), | ||
| there.end(), | ||
| [&](const auto &other) | ||
| { return other.vertices_offset == area.vertices_offset; })) | ||
| { | ||
| continue; | ||
| // a bounding box is not the area; geodesic_between checks containment properly | ||
| shared.push_back(area); | ||
| } | ||
| } | ||
| return shared; |
There was a problem hiding this comment.
The two lists are the areas whose bounding boxes hold one coordinate, which is one or two in practice and a handful where plazas nest; the product is a few comparisons against a partition lookup per relaxed node in the search that follows. A sort would cost more than it saves at these sizes, so the plain loop stays.
| std::vector<engine::PhantomNodeWithDistance> | ||
| NearestPhantomNodes(const util::Coordinate coordinate, | ||
| const size_t /*max_results*/, | ||
| const std::optional<double> /*max_distance*/, | ||
| const std::optional<engine::Bearing> /*bearing*/, | ||
| const engine::Approach /*approach*/) const override | ||
| { | ||
| std::vector<engine::PhantomNodeWithDistance> found; | ||
| NodeID id = 1; | ||
| for (const auto &area : areas) | ||
| { | ||
| for (const auto vertex : area.outer) | ||
| { | ||
| if (area.reachable && | ||
| util::coordinate_calculation::greatCircleDistance(vertex, coordinate) < 0.5) | ||
| { | ||
| found.push_back({standing_at(vertex, id), 0.0}); | ||
| } | ||
| id += 2; | ||
| } | ||
| } | ||
| return found; | ||
| } |
There was a problem hiding this comment.
Deliberate: the mock answers by construction, a phantom on a vertex exactly when the mesher gave that vertex a way, and the tests here want every one of them so that the claim per vertex can be checked. Truncation and the radius belong to the r-tree, which has its own tests; honouring them here would make the mock a second implementation of it.
| constexpr double AREA_METRE = 1.0 / 111319.49; | ||
|
|
||
| inline util::Coordinate at(double x, double y) | ||
| { return {util::FloatLongitude{x * AREA_METRE}, util::FloatLatitude{y * AREA_METRE}}; } |
There was a problem hiding this comment.
It is a conversion factor, and the name is chosen for the one place it is read: at(x, y) multiplies metres by it, so x * AREA_METRE reads as x metres of area coordinate. The same convention is in unit_tests/engine/area_geodesic.cpp; changing it in one file would leave the two disagreeing, so it stays.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7718 +/- ##
==========================================
+ Coverage 94.79% 94.84% +0.04%
==========================================
Files 526 529 +3
Lines 42085 42219 +134
==========================================
+ Hits 39896 40042 +146
+ Misses 2189 2177 -12 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
| for (std::size_t i = 0; i < ring.size(); ++i) | ||
| { | ||
| if (distance_squared_to_segment(point, ring[i], ring[(i + 1) % ring.size()]) <= limit) | ||
| return true; | ||
| } |
| for (std::size_t i = 0; i < ring.size(); ++i) | ||
| { | ||
| const Point &a = ring[i]; | ||
| const Point &b = ring[(i + 1) % ring.size()]; |
| std::vector<extractor::AreaPolygonSegment> shared; | ||
| for (const auto &area : here) | ||
| { | ||
| const auto shared = std::any_of(there.begin(), | ||
| there.end(), | ||
| [&](const auto &other) | ||
| { return other.vertices_offset == area.vertices_offset; }); | ||
| if (!shared) | ||
| if (std::any_of(there.begin(), | ||
| there.end(), | ||
| [&](const auto &other) | ||
| { return other.vertices_offset == area.vertices_offset; })) | ||
| { | ||
| continue; | ||
| // a bounding box is not the area; geodesic_between checks containment properly | ||
| shared.push_back(area); | ||
| } | ||
| } | ||
| return shared; |
| std::vector<engine::PhantomNodeWithDistance> | ||
| NearestPhantomNodes(const util::Coordinate coordinate, | ||
| const size_t /*max_results*/, | ||
| const std::optional<double> /*max_distance*/, | ||
| const std::optional<engine::Bearing> /*bearing*/, | ||
| const engine::Approach /*approach*/) const override | ||
| { | ||
| std::vector<engine::PhantomNodeWithDistance> found; | ||
| NodeID id = 1; | ||
| for (const auto &area : areas) | ||
| { | ||
| for (const auto vertex : area.outer) | ||
| { | ||
| if (area.reachable && | ||
| util::coordinate_calculation::greatCircleDistance(vertex, coordinate) < 0.5) | ||
| { | ||
| found.push_back({standing_at(vertex, id), 0.0}); | ||
| } | ||
| id += 2; | ||
| } | ||
| } | ||
| return found; | ||
| } |
There was a problem hiding this comment.
🔵 Needs a closer look
It changes core routing/snapshot/geodesic selection behavior in performance-sensitive engine paths, and needs a final human review for broader algorithmic and edge-case assurance despite the added unit tests.
Review details
- Files reviewed: 9/9 changed files
- Comments generated: 0 new
- Review effort level: Lite
Issue
Refs #7683, the first of its known defects.
Problem
A plaza route could leave by a corner and come back, and a plaza request cost about 288 ms against 0.8 ms for a comparable route touching no area. Those are one defect seen from two sides: the engine gave up on an area rather than trying the next, and did so only after paying the full price of deciding it could not use that one.
Areas overlap, and one holding a coordinate can have nothing to offer. The extractor records a polygon into
.osrm.openareasbefore theAreaMesher::max_verticesvalve decides whether to mesh it, so a plaza too large to mesh is stored with no way on any of its vertices. The r-tree also answers with bounding boxes, so a coordinate is filed under areas it is not inside at all. Three places then gave up on the first candidate:SnapInsideOpenAreareturned inside its loop over the areas, so only the first one containing the coordinate was considered; the request fell back to ordinary snapping onto the perimeter, which is the route that goes out and comes back.commonAreareturned the first shared area, and the geodesic replacement moved on whengeodesic_betweendeclined it.geodesic_betweenbuilt the visibility graph before testing containment, so every bounding-box near miss was charged the cubic price of an answer already lost.crosses_ringandon_any_ringalso scanned a whole ring after the answer was known, once per vertex per ring on the snapping path.Fix
Every area holding the coordinate is tried before giving up,
commonAreasandgeodesicAcrosstry each shared area in turn, containment is tested before the graph is built, and the ring scans stop early.Verification
Neither
area_snapping.cppnorarea_route.cpphad a test. Both have one now, sharing a facade mock that carries polygons: an area whose vertices carry no way, standing for one the mesher declined, and a triangle whose bounding box claims coordinates it does not hold. Reverting the three source files fails exactly the three new cases. Area scenarios pass on CH and MLD.Tasklist
Requirements / Relations
None.
🤖 Claude Code, Claude Fable 5.1