@@ -15,7 +15,7 @@ use crate::vector::{FillId, PointDomain, RegionId};
15
15
use crate :: { CloneVarArgs , Color , Context , Ctx , ExtractAll , GraphicElement , GraphicGroupTable , OwnedContextImpl } ;
16
16
use bezier_rs:: { Join , ManipulatorGroup , Subpath } ;
17
17
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 } ;
19
19
use rand:: { Rng , SeedableRng } ;
20
20
use std:: collections:: hash_map:: DefaultHasher ;
21
21
use std:: f64:: consts:: PI ;
@@ -1591,6 +1591,9 @@ async fn morph(_: impl Ctx, source: VectorDataTable, #[expose] target: VectorDat
1591
1591
}
1592
1592
1593
1593
for segment in new_segments {
1594
+ if bezpath. elements ( ) . is_empty ( ) {
1595
+ bezpath. move_to ( segment. start ( ) )
1596
+ }
1594
1597
bezpath. push ( segment. as_path_el ( ) ) ;
1595
1598
}
1596
1599
@@ -1666,7 +1669,10 @@ async fn morph(_: impl Ctx, source: VectorDataTable, #[expose] target: VectorDat
1666
1669
for mut source_path in source_paths {
1667
1670
source_path. apply_affine ( Affine :: new ( source_transform. to_cols_array ( ) ) ) ;
1668
1671
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
+ } ;
1670
1676
1671
1677
for element in source_path. elements_mut ( ) {
1672
1678
match element {
@@ -1690,20 +1696,23 @@ async fn morph(_: impl Ctx, source: VectorDataTable, #[expose] target: VectorDat
1690
1696
for mut target_path in target_paths {
1691
1697
target_path. apply_affine ( Affine :: new ( source_transform. to_cols_array ( ) ) ) ;
1692
1698
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
+ } ;
1694
1703
1695
1704
for element in target_path. elements_mut ( ) {
1696
1705
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) ,
1699
1708
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) ;
1702
1711
}
1703
1712
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) ;
1707
1716
}
1708
1717
PathEl :: ClosePath => { }
1709
1718
}
0 commit comments