Repository navigation
feat(area): answer tables and trips across a plaza the same way as routes - #7686
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends the open-area “geodesic override” (used to make /route agree with the true within-plaza path) to /table and /trip, so all three services return consistent distance/duration results when both endpoints of a leg/cell lie inside the same open area.
Changes:
- Add
area::useGeodesicInTable(...)and invoke it from/tableand/tripto rewrite within-area matrix cells. - Refactor
area::useGeodesicWhereShorter(...)to work from route leg endpoint phantoms and to optionally adjust reported waypoints via pointers. - Add cucumber coverage for foot tables and trips across open areas.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/engine/plugins/viaroute.cpp | Updates /route to pass waypoint-candidate pointers into the geodesic override helper. |
| src/engine/plugins/trip.cpp | Applies geodesic correction both to the duration matrix used for tour selection and to the drawn route legs. |
| src/engine/plugins/table.cpp | Applies geodesic correction to duration/distance tables for within-area coordinate pairs. |
| src/engine/area_route.cpp | Refactors useGeodesicWhereShorter waypoint reporting and adds useGeodesicInTable implementation. |
| include/engine/plugins/trip.hpp | Updates ComputeRoute signature to allow waypoint candidate mutation for correct reporting. |
| include/engine/area_route.hpp | Updates useGeodesicWhereShorter signature and declares useGeodesicInTable. |
| features/foot/area_table_trip.feature | Adds cucumber scenarios validating corrected tables and trips across plazas/obstacles. |
Suppressed comments (2)
src/engine/area_route.cpp:353
useGeodesicInTabledoes anGetOpenAreasAt(from)lookup per row, but then callscommonArea(facade, from, to)per cell, which repeatsGetOpenAreasAt(from)(and sorts) for every column. This negates the intended row-level short-circuit and can become expensive for larger tables. Consider reusing the row’sfromareas and only looking up areas fortoinside the inner loop.
const auto from = coordinates[sources.empty() ? row : sources[row]];
// one lookup for the whole row: a table over one plaza asks about the same area
// again and again
if (facade.GetOpenAreasAt(from).empty())
{
src/engine/area_route.cpp:344
useGeodesicInTablevalidatesdurations.size()but, whendistancesis non-empty, it writesdistances[cell]without verifying thatdistances.size()matchesrows*columns. If a caller passes a non-empty but mismatched distances vector, this can go out of bounds. Consider adding a symmetric size check fordistances(when present).
const auto rows = sources.empty() ? coordinates.size() : sources.size();
const auto columns = destinations.empty() ? coordinates.size() : destinations.size();
if (durations.size() != rows * columns)
{
return;
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| return std::nullopt; | ||
| } | ||
|
|
||
| /** Say that a waypoint is where it was asked for, when the caller is tracking waypoints. */ |
| # same answer as /route or the three services contradict each other. | ||
| # | ||
| # Only pairs with *both* ends on the plaza are asserted here. A pair with one end on | ||
| # it is a separate matter and is not yet right -- see plans/area-table-trip.md. |
3fd7da7 to
bb94715
Compare
a0387d5 to
aea31fc
Compare
bb94715 to
71294a8
Compare
aea31fc to
3e76217
Compare
71294a8 to
2696589
Compare
1b93bc2 to
758d0d2
Compare
2696589 to
076f27d
Compare
…utes /route works out the geodesic when both ends of a leg lie on one plaza, because the mesh holds shortest paths *out* of an area and such a journey never leaves. /table and /trip did not, so the three services disagreed about the same journey. Table needs only the numbers put right: useGeodesicInTable rewrites any cell whose two coordinates lie in one area, in both matrices. There is no route to synthesise. One area lookup per row short-cuts the ordinary case of a table over coordinates nowhere near a plaza. Trip needs both halves of what it does: the duration matrix it picks its tour from, so the tour is chosen from real costs, and the route it draws afterwards, through the same code /route uses. Its legs run in tour order, so the waypoints they answer to are the original candidates picked out in that order. On a plaza with a central obstacle, two interior points either side of it: /route 386.5 m and 276.1 s, /table 386.5 m and 276.0 s, /trip 773.0 m there and back. useGeodesicWhereShorter now takes the coordinates from the phantoms it was given rather than a parallel vector, since trip's legs are not in parameter order, and takes its waypoints as pointers so a caller that has none can say so. Two faults this made visible are described in plans/area-table-trip.md and are not addressed here: * a coordinate in a table is a source *and* a destination, while the walk across an area is charged to the phantom with a sign that depends on which it is. The row comes out right and the column wrong. It predates this change -- the same numbers come out with it stashed -- and fixing it means carrying the approach cost on the phantom rather than folding it into an offset, which changes the length of the public hint string. * three coordinates on a plain plaza can all snap to one vertex, and the search over identical candidates returns a route with no legs at all, which leaves nothing to rewrite and a tour of 0 m. features/foot/area_table_trip.feature accordingly asserts only pairs with both ends on one plaza, and a trip fixture shaped to avoid the degenerate case; pinning the others would bless a wrong answer.
076f27d to
f96a813
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7686 +/- ##
==========================================
- Coverage 94.47% 94.46% -0.01%
==========================================
Files 516 516
Lines 40336 40379 +43
==========================================
+ Hits 38106 38146 +40
- Misses 2230 2233 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
#7684 and #7685 have merged, so this now targets master and is its own single commit.
#7685 made
/routework out the real path when both ends of a leg lie on one plaza./tableand
/tripdid not, so the three services disagreed about the same journey. 243 lines,including the tests.
Table. Any cell whose two coordinates lie in one area is rewritten, in both the duration
and the distance matrix. There is nothing to draw here, a table is numbers, so that is the
whole of it. One area lookup per row short-cuts the common case of a table nowhere near an
area.
Trip. Two places, because a trip does two things: the duration matrix it picks its tour
from, so the tour is chosen from the real costs, and the route it draws afterwards, through
the same path
/routetakes.TripPlugin::ComputeRoutenow takes its candidates bynon-const reference, since the legs run in tour order and the waypoints they answer to are the
original candidates picked out in that order.
On a plaza with a central obstacle and one pair of interior points either side of it, the
three now agree:
/route/table/trip, roundtrip773.0 being twice 386.5, and the trip reporting the coordinates that were asked for rather
than the vertices they snapped to.
Two faults this exposes without fixing
Both predate this change and are in #7683. They are described here because wiring the table is
what made them visible.
A coordinate in a table is a source and a destination. The walk into an area is charged to
the phantom's weight offset, and the sign depends on which end of the journey the coordinate
is. That works for a route. In a table, coordinate 0 is the source of row 0 and the
destination of column 0, so one of the two is charged the wrong way round. The fix is to carry
the approach cost on the phantom instead, which grows
PhantomNodefrom 80 to 84 bytes andthe public hint string from 112 to 120 characters, so it wants its own PR.
A trip whose coordinates all snap to one vertex reports 0 m. On an empty plaza several
coordinates can share a cheapest way out. The search over identical candidate sets returns a
result with no legs, and there is then nothing for the geodesic pass to correct.
Tests
features/foot/area_table_trip.feature, three scenarios: a distance and a time table across aplain plaza, a distance table either side of an obstacle (311.8 m, the way round, not the
300 m straight line), and a trip round three points. Nothing asserts a pair with one end off
the plaza, or a trip whose points all snap together; pinning either would bless the wrong
answer.
Written with AI assistance: Claude Code, Claude Opus 5 🤖