Skip to content

Commit 86da69e

Browse files
indierustyKeavon
andauthored
Fix 'Morph' node lerping the target paths to its end point instead of start point (#2754)
* fix lerping the target paths to the point at the end of path instead of the start. * comment * append a MoveTo element first if the bezpath is empty --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
1 parent 02afd08 commit 86da69e

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

node-graph/gcore/src/vector/vector_nodes.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::vector::{FillId, PointDomain, RegionId};
1515
use crate::{CloneVarArgs, Color, Context, Ctx, ExtractAll, GraphicElement, GraphicGroupTable, OwnedContextImpl};
1616
use bezier_rs::{Join, ManipulatorGroup, Subpath};
1717
use glam::{DAffine2, DVec2};
18-
use kurbo::{Affine, BezPath, DEFAULT_ACCURACY, ParamCurve, PathEl, PathSeg, Point, Shape};
18+
use kurbo::{Affine, BezPath, DEFAULT_ACCURACY, ParamCurve, PathEl, PathSeg, Shape};
1919
use rand::{Rng, SeedableRng};
2020
use std::collections::hash_map::DefaultHasher;
2121
use std::f64::consts::PI;
@@ -1591,6 +1591,9 @@ async fn morph(_: impl Ctx, source: VectorDataTable, #[expose] target: VectorDat
15911591
}
15921592

15931593
for segment in new_segments {
1594+
if bezpath.elements().is_empty() {
1595+
bezpath.move_to(segment.start())
1596+
}
15941597
bezpath.push(segment.as_path_el());
15951598
}
15961599

@@ -1666,7 +1669,10 @@ async fn morph(_: impl Ctx, source: VectorDataTable, #[expose] target: VectorDat
16661669
for mut source_path in source_paths {
16671670
source_path.apply_affine(Affine::new(source_transform.to_cols_array()));
16681671

1669-
let end: Point = source_path.elements().last().and_then(|element| element.end_point()).unwrap_or_default();
1672+
// Skip if the path has no segments else get the point at the end of the path.
1673+
let Some(end) = source_path.segments().last().and_then(|element| Some(element.end())) else {
1674+
continue;
1675+
};
16701676

16711677
for element in source_path.elements_mut() {
16721678
match element {
@@ -1690,20 +1696,23 @@ async fn morph(_: impl Ctx, source: VectorDataTable, #[expose] target: VectorDat
16901696
for mut target_path in target_paths {
16911697
target_path.apply_affine(Affine::new(source_transform.to_cols_array()));
16921698

1693-
let end: Point = target_path.elements().last().and_then(|element| element.end_point()).unwrap_or_default();
1699+
// Skip if the path has no segments else get the point at the start of the path.
1700+
let Some(start) = target_path.segments().next().and_then(|element| Some(element.start())) else {
1701+
continue;
1702+
};
16941703

16951704
for element in target_path.elements_mut() {
16961705
match element {
1697-
PathEl::MoveTo(point) => *point = point.lerp(end, time),
1698-
PathEl::LineTo(point) => *point = point.lerp(end, time),
1706+
PathEl::MoveTo(point) => *point = start.lerp(*point, time),
1707+
PathEl::LineTo(point) => *point = start.lerp(*point, time),
16991708
PathEl::QuadTo(point, point1) => {
1700-
*point = point.lerp(end, time);
1701-
*point1 = point1.lerp(end, time);
1709+
*point = start.lerp(*point, time);
1710+
*point1 = start.lerp(*point1, time);
17021711
}
17031712
PathEl::CurveTo(point, point1, point2) => {
1704-
*point = point.lerp(end, time);
1705-
*point1 = point1.lerp(end, time);
1706-
*point2 = point2.lerp(end, time);
1713+
*point = start.lerp(*point, time);
1714+
*point1 = start.lerp(*point1, time);
1715+
*point2 = start.lerp(*point2, time);
17071716
}
17081717
PathEl::ClosePath => {}
17091718
}

0 commit comments

Comments
 (0)