Skip to content

fix: handle strokes wider than the shape in Ellipse.strokeContains - #12185

Merged
Zyie merged 3 commits into
pixijs:devfrom
MaxFreedomPollard:fix/ellipse-stroke-contains-thick-stroke
Sep 16, 2026
Merged

Zyie merged 3 commits into
pixijs:devfrom
MaxFreedomPollard:fix/ellipse-stroke-contains-thick-stroke

Conversation

@MaxFreedomPollard

@MaxFreedomPollard MaxFreedomPollard commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Ellipse.strokeContains subtracted the inward part of the stroke from each half-axis without clamping at zero. Squaring a negative half-axis revived it as a smaller positive ellipse, so a stroke wider than the shape excluded a phantom interior and Graphics.containsPoint returned false across the middle of a thickly stroked ellipse. Circle, Rectangle and RoundedRectangle already treat this case as fully stroked; this brings Ellipse in line.

The method now tests the outer edge first and, once either inner half-axis has reached zero or less, treats every point inside the outer edge as stroked. Points where both inner half-axes stay positive follow the same arithmetic as before, and alignment 0 never reaches the new branch.

Fixes

  • Ellipse.strokeContains (and therefore Graphics.containsPoint) reports the whole interior as stroked when the stroke is wider than the shape, instead of punching a hole through the middle
const g = new Graphics().ellipse(0, 0, 10, 10).stroke({ width: 40, alignment: 1 });

g.containsPoint({ x: 0, y: 0 });  // was false, now true
g.containsPoint({ x: 13, y: 0 }); // still false: past the outer edge
Pre-Merge Checklist
  • Tests and/or benchmarks are included
  • Documentation is changed or added

Ellipse.strokeContains derives the unstroked interior by subtracting the
inward part of the stroke from each half-axis, at lines 212 and 213 of
src/maths/shapes/Ellipse.ts, with nothing holding the result at zero.
Lines 221 and 222 then square those half-axes, so a negative one comes
back as a smaller positive ellipse, and line 227 excludes every point
inside that phantom ellipse from the stroke.

That punches a hole through the middle of a stroke which has no hole.
Ellipse(0, 0, 10, 10).strokeContains(0, 0, 40, 1) returned false, and so
did every other point in the shape, while Circle(0, 0, 10) and the
equivalent Rectangle return true throughout for the same stroke. Sampling
a 141 by 141 grid at 0.5 spacing across that circle, the ellipse and the
circle disagreed at 1257 points for a stroke of 20 at alignment 1, and at
5025 points for a stroke of 40 at alignment 0.75. The one caller in src is
GraphicsContext.containsPoint, so a thickly stroked ellipse stopped
answering pointer hit tests across its middle.

strokeContains now tests the outer edge first and returns true for any
point inside it once either inner half-axis has reached zero or less,
which is the conclusion Rectangle.strokeContains already reaches, its
inner rectangle having inverted and so excluding nothing. Points where
both inner half-axes stay positive take exactly the path they took
before, and at alignment 0 the inward part of the stroke is always zero,
so that alignment cannot reach the new branch at all.
@pkg-pr-new

pkg-pr-new Bot commented Sep 6, 2026 •

Copy link
Copy Markdown

commit: 7fc0818

@Zyie
Zyie added this pull request to the merge queue Sep 16, 2026
Merged via the queue into pixijs:dev with commit a86e4e4 Sep 16, 2026
5 of 6 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.

2 participants