Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add failing test for quadbez panic and add fix. #316

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.vscode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this intentional? I think it's ok but am wondering if it accidentally got picked up.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was seeing it in my git status and thought I'd add it to .gitignore so that I don't accidentally include it with git add -A which I use from time to time. I don't think we'll want to include vscode stuff in kurbo in the future but if we do we can always remove it from .gitignore :)


/target
**/*.rs.bk
Cargo.lock
16 changes: 16 additions & 0 deletions src/quadbez.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ impl ParamCurveNearest for QuadBez {
let mut r_best = None;
let mut t_best = 0.0;
let mut need_ends = false;
if roots.is_empty() {
need_ends = true;
}
for &t in &roots {
need_ends |= try_t(self, p, &mut t_best, &mut r_best, t);
}
Expand Down Expand Up @@ -508,6 +511,19 @@ mod tests {
verify(q.nearest((0.0, 1.0).into(), 1e-3), 0.5);
}

#[test]
fn quadbez_nearest_rounding_panic() {
let quad = QuadBez::new(
(-1.0394736842105263, 0.0),
(0.8210526315789474, -1.511111111111111),
(0.0, 1.9333333333333333),
);
let test = Point::new(-1.7976931348623157e308, 0.8571428571428571);
// accuracy ignored
let _res = quad.nearest(test, 1e-6);
// if we got here then we didn't panic
}

#[test]
fn quadbez_extrema() {
// y = x^2
Expand Down