Repository navigation
Compute cubic bézier extrema without cancellation - #985
Merged
Merged
Conversation
`for_each_local_extremum` solved the derivative with the textbook quadratic formula. When its leading coefficient is small compared to the others, `-b + sqrt(discriminant)` subtracts two close values and the f32 result loses most of its precision. For a curve whose y control points are 0.001, 3000, 4000 and 3000, `y_maximum_t` returned 0.8138 instead of 0.75, so `bounding_box` stopped at y = 3350.6 while the curve reaches 3375. Use the same q / a and c / q form as `cubic_polynomial_roots`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner
|
Thanks! |
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.
CubicBezierSegment::for_each_local_extremumsolves the derivative with the textbook quadratic formula. When the derivative's leading coefficient is small compared to the other two,-b ± sqrt(discriminant)subtracts nearly equal values and the f32 result loses most of its precision.Example: y control points 0.001, 3000, 4000, 3000. The y maximum is at t = 0.75 (y = 3375), but
y_maximum_treturned 0.8138, sobounding_box().max.ywas 3350.6 and the box didn't contain the curve.This switches to the
q / aandc / qform thatcubic_polynomial_rootsuses since #978, and adds a regression test for that curve. Found by fuzzingbounding_boxagainst sampled points; with the change, 900k random curves found no point outside the box.I used Claude Code to write this change.