Divide the large Bezier-rs implementation file into smaller ones (#751)

* Refactor bezier lib file into a separate folder

* Add better implementation comments

* Update import of Subpath from bezier-rs

* Add comment to describe compare.rs

* Remove printlns and adjust spacing
This commit is contained in:
Hannah Li
2022-08-18 15:47:36 -07:00
committed by GitHub
parent dd3d33e523
commit d8424fc0af
11 changed files with 1908 additions and 1451 deletions
+7 -9
View File
@@ -58,16 +58,14 @@ pub fn solve_linear(a: f64, b: f64) -> Vec<f64> {
/// Precompute the `discriminant` (`b^2 - 4ac`) and `two_times_a` arguments prior to calling this function for efficiency purposes.
pub fn solve_quadratic(discriminant: f64, two_times_a: f64, b: f64, c: f64) -> Vec<f64> {
let mut roots = Vec::new();
if two_times_a != 0. {
if discriminant > 0. {
let root_discriminant = discriminant.sqrt();
roots.push((-b + root_discriminant) / (two_times_a));
roots.push((-b - root_discriminant) / (two_times_a));
} else if discriminant == 0. {
roots.push(-b / (two_times_a));
}
} else {
if two_times_a.abs() <= STRICT_MAX_ABSOLUTE_DIFFERENCE {
roots = solve_linear(b, c);
} else if discriminant.abs() <= STRICT_MAX_ABSOLUTE_DIFFERENCE {
roots.push(-b / (two_times_a));
} else if discriminant > 0. {
let root_discriminant = discriminant.sqrt();
roots.push((-b + root_discriminant) / (two_times_a));
roots.push((-b - root_discriminant) / (two_times_a));
}
roots
}