Skip to content

Fix InsideStrokedRectangle to inset stroke under any transform#1061

Merged
has2k1 merged 1 commit into
mainfrom
inside-rectangle
May 6, 2026
Merged

Fix InsideStrokedRectangle to inset stroke under any transform#1061
has2k1 merged 1 commit into
mainfrom
inside-rectangle

Conversation

@has2k1
Copy link
Copy Markdown
Owner

@has2k1 has2k1 commented May 6, 2026

The previous implementation shrank the rectangle's bounds by lw/2 in data units, which only happens to be correct in the DrawingArea's points-as-units transform; under transData, transAxes, or any other transform it inset by the wrong amount. It also failed to restore the bounds after drawing, so each redraw shrank the patch further.

Replace it with a clip-to-self approach: stroke at 2*lw centred on the path, then clip to the patch's own boundary so the outer half is erased. The visible stroke ends up fully inside the rectangle with its outer edge on the original boundary, in any transform, idempotently across redraws. Snapshot and restore _dash_pattern around the linewidth change so dashed strokes render at the requested length rather than 2× longer.

The previous implementation shrank the rectangle's bounds by lw/2 in data
units, which only happens to be correct in the DrawingArea's
points-as-units transform; under transData, transAxes, or any other
transform it inset by the wrong amount. It also failed to restore the
bounds after drawing, so each redraw shrank the patch further.

Replace it with a clip-to-self approach: stroke at 2·lw centred on the
path, then clip to the patch's own boundary so the outer half is erased.
The visible stroke ends up fully inside the rectangle with its outer edge
on the original boundary, in any transform, idempotently across redraws.
Snapshot and restore _dash_pattern around the linewidth change so dashed
strokes render at the requested length rather than 2× longer.
@has2k1 has2k1 force-pushed the inside-rectangle branch from f465514 to 35e658a Compare May 6, 2026 20:12
@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.88%. Comparing base (efed6a9) to head (35e658a).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1061      +/-   ##
==========================================
+ Coverage   86.87%   86.88%   +0.01%     
==========================================
  Files         203      203              
  Lines       13757    13768      +11     
  Branches     1688     1689       +1     
==========================================
+ Hits        11952    11963      +11     
  Misses       1256     1256              
  Partials      549      549              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@has2k1 has2k1 merged commit 35e658a into main May 6, 2026
14 checks passed
@has2k1 has2k1 deleted the inside-rectangle branch May 6, 2026 20:22
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.

1 participant