Bezier-rs: Add normal and tangent to subpath (#1003)

tangent and normal for subpath

Co-authored-by: Rob Nadal <Robnadal44@gmail.com>
This commit is contained in:
Jackie Chen
2023-01-31 00:15:37 -05:00
committed by Keavon Chambers
co-authored by Rob Nadal
parent beab0f01c6
commit 511a8aa164
4 changed files with 77 additions and 7 deletions
+12
View File
@@ -50,6 +50,18 @@ impl Subpath {
number_of_curves
}
pub fn find_curve_parametric(&self, t: f64) -> (Option<Bezier>, f64) {
assert!((0.0..=1.).contains(&t));
let number_of_curves = self.len_segments() as f64;
let scaled_t = t * number_of_curves;
let target_curve_index = scaled_t.floor() as i32;
let target_curve_t = scaled_t % 1.;
(self.iter().nth(target_curve_index as usize), target_curve_t)
}
/// Returns an iterator of the [Bezier]s along the `Subpath`.
pub fn iter(&self) -> SubpathIter {
SubpathIter { sub_path: self, index: 0 }