mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-02 20:18:11 +08:00
Bezier-rs: Add SubpathTValue and euclidean parameterization for subpaths (#1027)
* Added SubpathTValue and euclidean parameterization for subpaths * Small fix * Added bounds checking to get_segment * Code review * code review nit for clarity --------- Co-authored-by: Hannah Li <hannahli2010@gmail.com> Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
committed by
Keavon Chambers
co-authored by
Hannah Li
Keavon Chambers
parent
344f243432
commit
9a52cae9b9
@@ -50,16 +50,12 @@ 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 a copy of the bezier segment at the given segment index, if this segment exists.
|
||||
pub fn get_segment(&self, segment_index: usize) -> Option<Bezier> {
|
||||
if segment_index >= self.len_segments() {
|
||||
return None;
|
||||
}
|
||||
Some(self[segment_index].to_bezier(&self[(segment_index + 1) % self.len()]))
|
||||
}
|
||||
|
||||
/// Returns an iterator of the [Bezier]s along the `Subpath`.
|
||||
|
||||
Reference in New Issue
Block a user