Fix InsideStrokedRectangle to inset stroke under any transform#1061
Merged
Conversation
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.
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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.
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.