Skip to content

Fix polygon feathering artifacts at sharp corners#7901

Open
segeljakt wants to merge 2 commits intoemilk:mainfrom
segeljakt:fix/feathering-sharp-corners
Open

Fix polygon feathering artifacts at sharp corners#7901
segeljakt wants to merge 2 commits intoemilk:mainfrom
segeljakt:fix/feathering-sharp-corners

Conversation

@segeljakt
Copy link

@segeljakt segeljakt commented Feb 11, 2026

The miter join normal in add_line_loop has magnitude 1/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

  • Added test_feathering_no_artifacts_on_sharp_triangles with a few sharp polygon cases that fail without the fix
  • Verified visually with the Bézier curve demo

Fixes #7424

Example

Before the fix:
image

After the fix:
image

Disclosure

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

@github-actions
Copy link

github-actions bot commented Feb 11, 2026

Preview available at https://egui-pr-preview.github.io/pr/7901-fixfeathering-sharp-corners
Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.

View snapshot changes at kitdiff

@segeljakt segeljakt force-pushed the fix/feathering-sharp-corners branch 3 times, most recently from 348df70 to 2b5b7e7 Compare February 11, 2026 20:09
@segeljakt segeljakt force-pushed the fix/feathering-sharp-corners branch from 2b5b7e7 to 78abfb5 Compare February 26, 2026 09:32
@emilk
Copy link
Owner

emilk commented Mar 2, 2026

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?

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.
@segeljakt segeljakt force-pushed the fix/feathering-sharp-corners branch from 62bc1f5 to 2908786 Compare March 2, 2026 11:20
@emilk
Copy link
Owner

emilk commented Mar 2, 2026

This looks pretty bad 😬
image

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

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.

Bug in polygon tessellator with feathering

2 participants