Repository navigation
fix(g): polyline containsPoint through a vertex, curve negative length, path pointAtLength copy - #3609
Merged
Conversation
…h, path pointAtLength copy
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the geometry edge-case fixes.
No open issues 🎉
What changed in this PR
This PR fixes four geometry-library edge cases in @joint/core without changing the public API.
Changes:
- Corrects polyline containment when a horizontal ray passes through a vertex and supports plain
{ x, y }points. - Fixes negative-length curve traversal and returns independent point copies for out-of-range path queries.
- Adds regression tests and patch changesets for all four fixes.
| File | Description |
|---|---|
| packages/joint-core/test/geometry/polyline.js | Tests vertex crossings, horizontal boundaries, and plain points. |
| packages/joint-core/test/geometry/path.js | Tests that out-of-range results cannot mutate the path. |
| packages/joint-core/test/geometry/curve.js | Tests negative distances on an asymmetric curve. |
| packages/joint-core/src/g/polyline.mjs | Rewrites containment using cross products and coordinate comparisons. |
| packages/joint-core/src/g/path.mjs | Clones endpoints returned for out-of-range lengths. |
| packages/joint-core/src/g/curve.mjs | Selects the correct subdivision during backward traversal. |
| .changeset/g-polyline-contains-point-vertex.md | Records the vertex-crossing containment fix. |
| .changeset/g-polyline-contains-point-plain.md | Records plain-point support. |
| .changeset/g-path-point-at-length-copy.md | Records independent path-point results. |
| .changeset/g-curve-t-at-length-negative.md | Records corrected negative-length curve queries. |
Review effort: Balanced
kumilingus
marked this pull request as ready for review
November 14, 2026 21:32
… the points, use it in Path.containsPoint()
Geliogabalus
approved these changes
Nov 16, 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.
Summary
Four fixes in the geometry library (
src/g). No public API changes.g.Polyline.containsPoint()returnedfalsefor a point inside the shape when the horizontal ray from the point went through a vertex. The ray was cut to end exactly at the far end of the segment, so the rounding of the intersection decided the result. For a regular polygon of 16 points with the radius 50 around0,0, the points-17.5,0,-15,0,-10,0and-7.5,0were reported as outside. The method is rewritten: the side of the segment the point is on (one cross product) decides both "the point lies on the segment" and "the ray crosses the segment". The rules are the same (even-odd, a point on the boundary is inside, a vertex on the ray is counted with one of its two segments).g.Polygon,g.Curve,g.Pathandg.intersection.exists()use this method.g.Polyline.containsPoint()threw for a plain{ x, y }object (p.equals is not a function). It reads onlyxandynow.g.Curve.tAtLength()read the wrong subdivision for a negative length (subdivisions[i]instead ofsubdivisions[index]), sopointAtLength(-30)andpointAtLength(length - 30)were up to 35 px apart on a curve that is not symmetric.g.Path.pointAtLength()returned the point of the last visible segment itself for a length beyond the path. Changing the result changed the path. It returns a copy now.containsPoint()no longer creates lines and points, so it is also faster (16 points: 161 ns to 25 ns in a micro-benchmark on one machine).Test plan
test/geometry(polyline.js,curve.js,path.js): four of them fail ondevand pass with the fixes; the fifth covers a vertex and a horizontal side on the ray.containsPoint()compared with the previous implementation on 400 000 random points (half of them on an integer grid, to get points on vertices, on sides and collinear with sides): no difference.grunt karma:geometry: 406 of 406.grunt karma:joint: 2274 of 2274.eslint src/g test/geometry: clean.