Fix polygon feathering artifacts at sharp corners#7901
Open
segeljakt wants to merge 2 commits intoemilk:mainfrom
Open
Fix polygon feathering artifacts at sharp corners#7901segeljakt wants to merge 2 commits intoemilk:mainfrom
segeljakt wants to merge 2 commits intoemilk:mainfrom
Conversation
|
Preview available at https://egui-pr-preview.github.io/pr/7901-fixfeathering-sharp-corners View snapshot changes at kitdiff |
348df70 to
2b5b7e7
Compare
2b5b7e7 to
78abfb5
Compare
Owner
|
Thanks for working on this! in #7554 @podusowski added some tests for this - could you add them to this PR too, so we can compare the fixes? |
279fddd to
62bc1f5
Compare
The miter join normal in `add_line_loop` has magnitude `1/cos(θ/2)`, which grows without bound at sharp corners, causing feathering vertices to be placed far outside the polygon. Clamp the miter factor to 2.0, which prevents artifacts while preserving correct feathering for corners wider than ~60°. Fixes emilk#7424
Visual test from @podusowski's emilk#7554 to allow comparing the two fix approaches.
62bc1f5 to
2908786
Compare
Owner
|
Looks like this PR, just like #7554, fixes the extrusions by nuking the feathering. I believe a proper fix that handles both requires adding another vertex to sharp corners |
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 miter join normal in
add_line_loophas magnitude1/cos(θ/2), which blows up at sharp corners. For a nearly-degenerate triangle this can push feathering vertices 100+ px outside the polygon, creating visible line artifacts.This clamps the miter factor to 2.0 (same idea as SVG's
stroke-miterlimit). Corners wider than ~60° are unaffected. Sharper corners get beveled feathering instead of mitered. This barely has a visual impact since the corners are sub-pixel.Snapshot diffs are just sub-pixel changes in menu bar tabs.
Tests
test_feathering_no_artifacts_on_sharp_triangleswith a few sharp polygon cases that fail without the fixFixes #7424
Example
Before the fix:

After the fix:

Disclosure
I used Claude Code to diagnose the error and come up with the fix. I hope this is ok.