Skip to content

fix(g): polyline containsPoint through a vertex, curve negative length, path pointAtLength copy - #3609

Merged
kumilingus merged 2 commits into
clientIO:devfrom
kumilingus:fix/g-hot-path-bugs
Nov 16, 2026
Merged

kumilingus merged 2 commits into
clientIO:devfrom
kumilingus:fix/g-hot-path-bugs

Conversation

@kumilingus

Copy link
Copy Markdown
Contributor

Summary

Four fixes in the geometry library (src/g). No public API changes.

  • g.Polyline.containsPoint() returned false for 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 around 0,0, the points -17.5,0, -15,0, -10,0 and -7.5,0 were 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.Path and g.intersection.exists() use this method.
  • g.Polyline.containsPoint() threw for a plain { x, y } object (p.equals is not a function). It reads only x and y now.
  • g.Curve.tAtLength() read the wrong subdivision for a negative length (subdivisions[i] instead of subdivisions[index]), so pointAtLength(-30) and pointAtLength(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

  • New tests in test/geometry (polyline.js, curve.js, path.js): four of them fail on dev and 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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
kumilingus marked this pull request as ready for review November 14, 2026 21:32
@kumilingus
kumilingus merged commit 1cb8f5f into clientIO:dev Nov 16, 2026
3 checks passed
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.

3 participants