Skip to content

Fix zero tangents at polyline endpoints in simplify_bezpath - #606

Open
mlwilkerson wants to merge 2 commits into
linebender:mainfrom
FortAwesome:fix-simplify-bezpath-more
Open

Fix zero tangents at polyline endpoints in simplify_bezpath#606
mlwilkerson wants to merge 2 commits into
linebender:mainfrom
FortAwesome:fix-simplify-bezpath-more

Conversation

@mlwilkerson

Copy link
Copy Markdown
Contributor

Closes #605

Claude's fix here and Claude's description follows:


SimplifyBezPath::sample_pt_tangent returned the zero vector at the endpoints of line segments (their to_cubic form
has a vanishing derivative at t = 0 and t = 1), which fit_to_cubic turned into a spurious +x-axis tangent
constraint via atan2(0, 0). Fall back to the cubic's chord when the sampled derivative is zero — exact for the
line-segment case, the only way these degenerate cubics arise here.

Adds a regression test: a quarter-circle polyline now fits with correct end tangents (as a single cubic) instead of a
hairpin.

mlwilkerson and others added 2 commits August 15, 2026 02:30
Line segments converted via `to_cubic` have a derivative that vanishes
at t = 0 and t = 1, so `SimplifyBezPath::sample_pt_tangent` returned the
zero vector at run endpoints. `fit_to_cubic` then took `atan2(0, 0) == 0`,
silently constraining the fit to the world +x axis and producing
degenerate or reversed end tangents (hairpins past the endpoint).

Fall back to the cubic's chord when the sampled derivative is zero; the
chord is the exact tangent for the line-segment case, the only way these
non-regular cubics arise here.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

simplify_bezpath samples zero tangents at polyline run endpoints, fitting curves that leave or arrive in arbitrary axis-aligned directions

1 participant