Skip to content

spatial: make nearest-segment queries sublinear for large networks#18

Merged
blackopsrepl merged 1 commit intomainfrom
issue/5-make-nearest-segment-sublinear
Mar 21, 2026
Merged

spatial: make nearest-segment queries sublinear for large networks#18
blackopsrepl merged 1 commit intomainfrom
issue/5-make-nearest-segment-sublinear

Conversation

@blackopsrepl
Copy link
Copy Markdown
Contributor

Summary

  • replace the centroid-seeded full scan with a dedicated branch-and-bound segment tree using subtree bounding boxes
  • keep exact nearest-segment results while pruning large parts of the tree on big inputs
  • add correctness coverage for the large-input code path by comparing the indexed search to brute force

Validation

  • cargo fmt --all -- --check
  • cargo test spatial --lib
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo test

Fixes #5

@blackopsrepl blackopsrepl merged commit 91a86df into main Mar 21, 2026
3 checks passed
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ef816914d0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +392 to +395
match best {
Some((_, _, best_dist)) if dist < *best_dist => {
*best = Some((node_idx, projection, dist));
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve input-order ties for identical segment geometry

On bidirectional roads we index two directed edges with the same geometry (src/routing/fetch.rs:297-300). This tree now keeps whichever segment it visits first when distances tie, instead of the old linear-scan/input-order tie-break, so snap_to_edge can map two points on the same physical road to opposite directed edges. route_edge_snapped treats edge direction as significant (src/routing/network.rs:343-370), so a simple 1 km two-way segment snapped at 0.2 and 0.8 now routes through the node and charges the full 1 km (or returns NoPath in the opposite order) instead of the expected 600 m same-edge result.

Useful? React with 👍 / 👎.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

spatial: make nearest-segment queries sublinear for large networks

1 participant