Repository navigation
Fix isPointInPath() with a transform and outside the fill - #2636
Merged
zbjornson merged 1 commit intoNov 13, 2026
Merged
Conversation
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
approved these changes
Nov 13, 2026
zbjornson
left a comment
Collaborator
There was a problem hiding this comment.
Great, thank you.
I misunderstood the spec where it says "Points on the path itself must be considered to be inside the path."
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.
Thanks for contributing!
Fixes #2634
Context2d::IsPointInPathpassed(x, y)straight tocairo_in_fill(), which takes user-space coordinates, so with any transform the point was moved by the CTM. It also OR'ed incairo_in_stroke(), so points that are only inside the stroke (with the currentlineWidth) 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
test/canvas.test.js(translate, scale, and a wide stroke). Both fail on master, pass with the fix.npm test: 307 passing.npx mocha test/wpt/generated/*.js): 5 more tests pass with the fix (2d.path.isPointInPath.edgeand2d.path.isPointInPath.transform.1to.4) and none newly fail (119 → 114 failing, the rest fail the same way on master).Context2d#isPointInPath()test still passes.Built locally on macOS arm64 with zig 0.16.0.