mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-07-07 15:55:00 +00:00
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:
parent
63d44f22e3
commit
dae6b2f239
5 changed files with 243 additions and 7 deletions
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue