Skip to content

Fix isPointInPath() with a transform and outside the fill - #2636

Merged
zbjornson merged 1 commit into
Automattic:masterfrom
bardrop-oss:fix-is-point-in-path-transform
Nov 13, 2026
Merged

zbjornson merged 1 commit into
Automattic:masterfrom
bardrop-oss:fix-is-point-in-path-transform

Conversation

@bardrop

@bardrop bardrop commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Thanks for contributing!

  • Have you updated CHANGELOG.md?

Fixes #2634

Context2d::IsPointInPath passed (x, y) straight to cairo_in_fill(), which takes user-space coordinates, so with any transform the point was moved by the CTM. It also OR'ed in cairo_in_stroke(), so points that are only inside the stroke (with the current lineWidth) counted as inside. Per the spec, the point is in canvas coordinates and only the fill area counts.

The fix maps the point with cairo_device_to_user() and tests the fill only. cairo_in_fill() already counts points on the path edge as inside, so the edge behaviour stays.

Testing

  • Two new tests in test/canvas.test.js (translate, scale, and a wide stroke). Both fail on master, pass with the fix. npm test: 307 passing.
  • WPT (npx mocha test/wpt/generated/*.js): 5 more tests pass with the fix (2d.path.isPointInPath.edge and 2d.path.isPointInPath.transform.1 to .4) and none newly fail (119 → 114 failing, the rest fail the same way on master).
  • The existing Context2d#isPointInPath() test still passes.

Built locally on macOS arm64 with zig 0.16.0.

isPointInPath() passed canvas coordinates straight to cairo_in_fill(),
which expects user space, so any transform moved the test point. It
also returned true for points only inside the stroke. Map the point
with cairo_device_to_user() and test the fill only.

Fixes Automattic#2634

@zbjornson zbjornson left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Great, thank you.

I misunderstood the spec where it says "Points on the path itself must be considered to be inside the path."

@zbjornson
zbjornson merged commit 9bcb388 into Automattic:master Nov 13, 2026
10 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.

isPointInPath() applies the current transform to the test point and includes the stroke outline

2 participants