Repository navigation
Improve intersection performance - #33
Merged
Merged
Conversation
Walk each path once, extracting bezier segments with their bounding boxes, instead of re-walking path2 and recomputing every bezier bounding box for each segment pair. Non-overlapping segment pairs are now skipped via a cheap bounding box check before the expensive subdivision-based intersection. Also push results instead of repeatedly concat()-ing arrays. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The rotate helper inside arcToCurve was wrapped in a cacher whose cache was rebuilt on every arcToCurve invocation, caching at most a handful of lookups while paying string key joins on each call. Replace it with a plain closure over precomputed sin/cos and drop the now unused cacher machinery. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Guards the bounding box precheck that skips non-overlapping segment pairs: intersections must be found exactly where segments overlap, no more, no less. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
Consolidate the duplicate bounding-box intersection check in intersect.js.
Review effort: Lite
Findings: None
What changed in this PR
Improves path intersection performance while preserving output by reducing repeated geometry calculations.
Changes:
- Precomputes Bézier segments and bounding boxes.
- Adds bounding-box filtering and more efficient result collection.
- Simplifies arc rotation calculations and adds regression coverage.
| File | Summary |
|---|---|
test/intersect.spec.js |
Adds regression coverage for disjoint segment bounding boxes. |
intersect.js |
Implements intersection performance optimizations. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
barmac
approved these changes
Sep 21, 2026
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.
Proposed Changes
Speeds up path intersection computation without changing results (verified bit-identical output against
mainacross 500 randomized path pairs):path2and recomputing bounding boxes per segment pairconcat()Measured on 60-segment mixed paths: ~25% faster overall, ~57% faster on arc-heavy paths.
Try out:
Checklist
Ensure you provide everything we need to review your contribution:
Closes {LINK_TO_ISSUE}orRelated to {LINK_TO_ISSUE}@bpmn-io/srtool