Fix zero tangents at polyline endpoints in simplify_bezpath - #606
Open
mlwilkerson wants to merge 2 commits into
Open
Fix zero tangents at polyline endpoints in simplify_bezpath#606mlwilkerson wants to merge 2 commits into
mlwilkerson wants to merge 2 commits into
Conversation
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>
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.
Closes #605
Claude's fix here and Claude's description follows:
SimplifyBezPath::sample_pt_tangentreturned the zero vector at the endpoints of line segments (theirto_cubicformhas a vanishing derivative at
t = 0andt = 1), whichfit_to_cubicturned into a spurious +x-axis tangentconstraint via
atan2(0, 0). Fall back to the cubic's chord when the sampled derivative is zero — exact for theline-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.