Repository navigation
Conversation
knipknap
force-pushed
the
fix/contour-self-intersection
branch
from
August 24, 2026 19:29
c042f87 to
5d395d8
Compare
Some fonts contain glyphs whose outlines self-intersect or consist of overlapping contours (e.g. a plus sign drawn as two crossing rectangles). The resulting geometry renders fine with fill rules, but breaks winding analysis, containment hierarchies and polygon offsetting downstream — e.g. the contour assembler could emit incomplete or empty ops, and face classification could split a crossed glyph into separate pockets. Add geo::algo::self_intersect::resolve_self_intersections, which detects affected closed contours and rebuilds them as the Clipper2 NonZero union of their linearised outlines. Unaffected contours (including their arcs and Beziers) pass through untouched. text_to_geometry now applies it to each glyph outline individually, so adjacent glyphs are never merged and text geometry is clean from the start. Expose it as Geometry.remove_self_intersections() and pin the behaviour with geo and text-level tests.
knipknap
force-pushed
the
fix/contour-self-intersection
branch
3 times, most recently
from
August 26, 2026 10:45
637cc8f to
ad26ed4
Compare
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.
Problem
Some fonts contain glyphs whose outlines self-intersect or have overlapping contours. The resulting
Geometryrenders fine (fill rules handle it), which is why the sketcher and the workpiece look correct, but the contour assembler relies on winding analysis, containment hierarchies and polygon offsetting — all of which break on such input. Text set in those fonts could produce incomplete or even empty ops from the Contour step.Scanning 528 system font families, 38 produce self-intersecting text geometry (e.g. Kustom Kar, Gunplay 3D, Zekton Dots, German Participants).
Solution
geo::algo::self_intersect::resolve_self_intersections: detects closed contours that intersect themselves or each other, linearizes only those at a given tolerance, and rebuilds them via a Clipper2 NonZero union. Clean contours pass through untouched, so arcs and Béziers are preserved for well-behaved input. Properly wound holes survive; if the union fails the original geometry is kept as fallback.assemble_contourapplies the resolution to its input before splitting and winding normalization.Geometry.remove_self_intersections(tolerance=0.01)(stubs regenerated).Verification
cut_side="outside", offset_mm=0.25, text in German Participants went from 95.8 mm to 122.8 mm of cut path (~27 mm was silently missing); Peatloaf from 27.2 to 31.3 mm.