feat: add via option to force routes through named passages - #21
Merged
Conversation
Adds a `via` option to seaRoute — the inverse of `restrictions`. Instead of blocking a passage it requires one, routing origin → passage → destination through each passage's PASSAGE_BBOXES centroid via the multi-leg machinery. - `via` accepts the same Passage names as `restrictions` and visits multiple passages in order. - A passage named in `via` is excluded from the effective per-leg restriction set, so a required passage is never blocked out from under the requirement (e.g. via: ['northeast'] needs no allowArctic). - Naming a passage in both `via` and `restrictions` (after alias canonicalisation) throws NoRouteError. - greatCircleLength/detourRatio remain measured against the direct origin→destination geodesic. Adds passageCentroid() helper. Tests, README, DOCS and CHANGELOG updated.
mayurrawte
force-pushed
the
feat/issue-8-via-passages
branch
from
July 9, 2026 09:06
e4aa1e0 to
cfe1830
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds a
viaoption toseaRoute— the inverse ofrestrictions.restrictionsblocks a passage;viarequires one, so users can force and compare explicit routings (e.g. "via Suez" vs "via Panama"):Design (as suggested in the issue — reuse the multi-leg machinery):
origin → passage₁ → … → passageₙ → destination, snapping each passage'sPASSAGE_BBOXEScentroid to the network as an intermediate waypoint viaseaRouteMulti. No new routing logic. NewpassageCentroid()helper inrestrictions.ts.viaaccepts the samePassagenames asrestrictionsand visits multiple passages in the order given.viais dropped from the effective per-leg restriction set, so a required passage is never blocked out from under the requirement —via: ['northeast']reaches the Northeast Passage without also needingallowArctic.viaandrestrictions(compared after alias canonicalisation, sovia:['babalmandab']+restrictions:['babelmandeb']counts) is a contradiction and throwsNoRouteError.greatCircleLength/detourRatiostay measured against the direct origin→destination geodesic, matching plainseaRoute.Acceptance criteria (from #8)
viaaccepts the samePassagenames asrestrictions.viaandrestrictionswith a contradiction throwsNoRouteError.via: ['panama']routes across the Pacific + Panama, not Suez.Checklist
npm run lintandnpm testpassValidation (all steps CI runs, from a clean tree)
npm cinpm run lint✅npm run format:check✅npm run build✅npm test✅ (74 tests; 7 new covering via-Panama across the Pacific/not-Suez, via-Magellan rounding Cape Horn, via-Suez staying on the default route, via-Northeast withoutallowArctic, the origin→destination great-circle reference, and both contradiction cases including the alias)Also verified end-to-end against the built
dist(CJS):via:['panama']= 25,315 km through Panama with no Suez,via:['suez']= 19,753 km, and the contradiction case throwsNoRouteError.Closes #8
Generated by Claude Code