Skip to content

fix: clamp the corner radius in RoundedRectangle.strokeContains - #12333

Merged
Zyie merged 1 commit into
pixijs:devfrom
MaxFreedomPollard:fix/rounded-rect-stroke-radius
Oct 30, 2026
Merged

Zyie merged 1 commit into
pixijs:devfrom
MaxFreedomPollard:fix/rounded-rect-stroke-radius

Conversation

@MaxFreedomPollard

Copy link
Copy Markdown
Contributor
Description of change

RoundedRectangle.strokeContains used radius exactly as given. Everything else that handles the shape clamps it to half of the shorter side first: the WebGL/WebGPU builder (buildRoundedRectangle), the canvas renderer's buildRoundedRectPath, and RoundedRectangle.contains. The radius docs also say it is "Automatically clamped to half of smallest dimension". With an oversized radius, innerWidth/innerHeight went negative, the straight-edge checks stopped matching, and the corner arcs were centered outside the drawn shape, so stroke hit tests (Graphics.containsPoint, pointer events) followed an outline that is never drawn.

// drawn as a pill with radius 20: the top edge runs straight from x = 20 to x = 80
const g = new Graphics().roundRect(0, 0, 100, 40, 50).stroke({ width: 4 });

g.containsPoint({ x: 30, y: 0 });  // was false, now true (top edge)
g.containsPoint({ x: 0, y: 20 });  // was false, now true (left end)
g.containsPoint({ x: 20, y: 10 }); // was true, now false (inside the fill, away from the stroke)

The default radius of 20 hits the same path on any rounded rectangle whose shorter side is under 40, e.g. roundRect(0, 0, 30, 30).

strokeContains now clamps the radius with the same expression as contains. A radius that is already in range is unchanged, so results for those shapes are identical.

Verification

  • New tests in RoundedRectangle.test.ts (radius 20, 50 and 1000 on a 100x40 rectangle must give the same hits) and in Graphics.Bounds.test.ts through Graphics.containsPoint, next to the existing ellipse stroke tests. Both fail on dev and pass with the fix. I ran those two files and the other shape tests in src/maths/__tests__ (Circle, Ellipse, Polygon, Rectangle, Triangle) under Node 22 with a small jest-compatible shim, not the full npm test suite.
  • Compared strokeContains with the triangles buildLine emits for the stroke, on a 0.5px grid inside the hit-test bounds (skipping points within 0.6px of the mesh edge). roundRect(0, 0, 100, 40, 50) with width 4 disagreed at 4802 of 16297 points before and 0 after; roundRect(0, 0, 30, 30) at 648 of 3957 before and 0 after; alignment 0 and 1 also agree everywhere after. An in-range radius (roundRect(0, 0, 100, 100, 10), width 20) agreed at every point both before and after.
Pre-Merge Checklist
  • Tests and/or benchmarks are included
  • Lint process passed (npm run lint)
  • Tests passed (npm run test)

🤖 Generated with Claude Code

@pkg-pr-new

pkg-pr-new Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

commit: f4ff04a

@Zyie Zyie added the ✅ Ready To Merge Helpful when issues are in the queue waiting to get merged. This means the PR is completed and has t label Oct 30, 2026
RoundedRectangle.strokeContains took this.radius as given, at line 355
of src/maths/shapes/RoundedRectangle.ts. Everything else that handles
the shape clamps it to half of the shorter side first: the WebGL/WebGPU
builder (buildCircle.ts line 69), the canvas renderer's
buildRoundedRectPath, and RoundedRectangle.contains at line 296. The
radius property's own docs say it is "Automatically clamped to half of
smallest dimension".

With an oversized radius, innerWidth and innerHeight go negative, the
straight-edge checks stop matching, and the corner arcs are centered
outside the drawn shape. roundRect(0, 0, 100, 40, 50).stroke({ width: 4 })
is drawn as a pill with radius 20, but strokeContains returned false on
its straight edges and at both ends, e.g. (30, 0) and (0, 20), and true
at (20, 10), which is inside the fill. The default radius of 20 takes
the same path on any shape whose shorter side is under 40. The caller is
GraphicsContext.containsPoint, so pointer hit tests on stroked rounded
rectangles followed an outline that was never drawn.

strokeContains now clamps the radius with the same expression as
contains. A radius that is already in range is unchanged, so results for
those shapes stay exactly as they were.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Zyie
Zyie force-pushed the fix/rounded-rect-stroke-radius branch 2 times, most recently from beeed12 to f4ff04a Compare October 30, 2026 22:19
@Zyie
Zyie added this pull request to the merge queue Oct 30, 2026
Merged via the queue into pixijs:dev with commit b57f0ee Oct 30, 2026
11 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✅ Ready To Merge Helpful when issues are in the queue waiting to get merged. This means the PR is completed and has t

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants