New node: Bevel (#2067)

* Bevel node

* Fix clippy lints

* Prevent negative values

* Rename flipped() -> reversed()

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
James Lindsay 2024-10-26 03:25:41 +01:00 committed by GitHub
parent 63d44f22e3
commit dae6b2f239
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 243 additions and 7 deletions

View file

@ -201,8 +201,11 @@ impl Bezier {
/// Returns true if the corresponding points of the two `Bezier`s are within the provided absolute value difference from each other.
/// The points considered includes the start, end, and any relevant handles.
pub fn abs_diff_eq(&self, other: &Bezier, max_abs_diff: f64) -> bool {
let self_points = self.get_points().collect::<Vec<DVec2>>();
let other_points = other.get_points().collect::<Vec<DVec2>>();
let a = if self.is_linear() { Self::from_linear_dvec2(self.start, self.end) } else { *self };
let b = if other.is_linear() { Self::from_linear_dvec2(other.start, other.end) } else { *other };
let self_points = a.get_points().collect::<Vec<DVec2>>();
let other_points = b.get_points().collect::<Vec<DVec2>>();
self_points.len() == other_points.len() && self_points.into_iter().zip(other_points).all(|(a, b)| a.abs_diff_eq(b, max_abs_diff))
}

View file

@ -102,7 +102,7 @@ impl BezierHandles {
}
#[must_use]
pub fn flipped(self) -> Self {
pub fn reversed(self) -> Self {
match self {
BezierHandles::Cubic { handle_start, handle_end } => Self::Cubic {
handle_start: handle_end,

View file

@ -605,6 +605,16 @@ impl Bezier {
(arcs, low)
}
/// Reverses the direction of the bézier.
#[must_use]
pub fn reversed(self) -> Self {
Self {
start: self.end,
end: self.start,
handles: self.handles.reversed(),
}
}
}
#[cfg(test)]