@@ -5,11 +5,24 @@ use super::*;
5
5
use glam:: DVec2 ;
6
6
use kurbo:: PathSeg ;
7
7
8
- pub fn pathseg_points ( segment : PathSeg ) -> ( DVec2 , Option < DVec2 > , Option < DVec2 > , DVec2 ) {
8
+ pub struct PathSegPoints {
9
+ p0 : DVec2 ,
10
+ p1 : Option < DVec2 > ,
11
+ p2 : Option < DVec2 > ,
12
+ p3 : DVec2 ,
13
+ }
14
+
15
+ impl PathSegPoints {
16
+ pub fn new ( p0 : DVec2 , p1 : Option < DVec2 > , p2 : Option < DVec2 > , p3 : DVec2 ) -> Self {
17
+ Self { p0, p1, p2, p3 }
18
+ }
19
+ }
20
+
21
+ pub fn pathseg_points ( segment : PathSeg ) -> PathSegPoints {
9
22
match segment {
10
- PathSeg :: Line ( line) => ( point_to_dvec2 ( line. p0 ) , None , None , point_to_dvec2 ( line. p1 ) ) ,
11
- PathSeg :: Quad ( quad) => ( point_to_dvec2 ( quad. p0 ) , None , Some ( point_to_dvec2 ( quad. p1 ) ) , point_to_dvec2 ( quad. p1 ) ) ,
12
- PathSeg :: Cubic ( cube) => ( point_to_dvec2 ( cube. p0 ) , Some ( point_to_dvec2 ( cube. p1 ) ) , Some ( point_to_dvec2 ( cube. p2 ) ) , point_to_dvec2 ( cube. p1 ) ) ,
23
+ PathSeg :: Line ( line) => PathSegPoints :: new ( point_to_dvec2 ( line. p0 ) , None , None , point_to_dvec2 ( line. p1 ) ) ,
24
+ PathSeg :: Quad ( quad) => PathSegPoints :: new ( point_to_dvec2 ( quad. p0 ) , None , Some ( point_to_dvec2 ( quad. p1 ) ) , point_to_dvec2 ( quad. p1 ) ) ,
25
+ PathSeg :: Cubic ( cube) => PathSegPoints :: new ( point_to_dvec2 ( cube. p0 ) , Some ( point_to_dvec2 ( cube. p1 ) ) , Some ( point_to_dvec2 ( cube. p2 ) ) , point_to_dvec2 ( cube. p1 ) ) ,
13
26
}
14
27
}
15
28
@@ -25,8 +38,8 @@ impl<PointId: Identifier> Subpath<PointId> {
25
38
26
39
/// Create a `Subpath` consisting of 2 manipulator groups from a `Bezier`.
27
40
pub fn from_bezier ( segment : PathSeg ) -> Self {
28
- let ( p1 , h1 , h2 , p2) = pathseg_points ( segment) ;
29
- Subpath :: new ( vec ! [ ManipulatorGroup :: new( p1 , None , h1 ) , ManipulatorGroup :: new( p2 , h2 , None ) ] , false )
41
+ let PathSegPoints { p0 , p1 , p2, p3 } = pathseg_points ( segment) ;
42
+ Subpath :: new ( vec ! [ ManipulatorGroup :: new( p0 , None , p1 ) , ManipulatorGroup :: new( p3 , p2 , None ) ] , false )
30
43
}
31
44
32
45
/// Creates a subpath from a slice of [Bezier]. When two consecutive Beziers do not share an end and start point, this function
@@ -41,17 +54,17 @@ impl<PointId: Identifier> Subpath<PointId> {
41
54
42
55
let first = beziers. first ( ) . unwrap ( ) ;
43
56
let mut manipulator_groups = vec ! [ ManipulatorGroup {
44
- anchor: first. 0 ,
57
+ anchor: first. p0 ,
45
58
in_handle: None ,
46
- out_handle: first. 1 ,
59
+ out_handle: first. p1 ,
47
60
id: PointId :: new( ) ,
48
61
} ] ;
49
62
let mut inner_groups: Vec < ManipulatorGroup < PointId > > = beziers
50
63
. windows ( 2 )
51
64
. map ( |bezier_pair| ManipulatorGroup {
52
- anchor : bezier_pair[ 1 ] . 0 ,
53
- in_handle : bezier_pair[ 0 ] . 2 ,
54
- out_handle : bezier_pair[ 1 ] . 1 ,
65
+ anchor : bezier_pair[ 1 ] . p0 ,
66
+ in_handle : bezier_pair[ 0 ] . p2 ,
67
+ out_handle : bezier_pair[ 1 ] . p1 ,
55
68
id : PointId :: new ( ) ,
56
69
} )
57
70
. collect :: < Vec < ManipulatorGroup < PointId > > > ( ) ;
@@ -60,15 +73,15 @@ impl<PointId: Identifier> Subpath<PointId> {
60
73
let last = beziers. last ( ) . unwrap ( ) ;
61
74
if !closed {
62
75
manipulator_groups. push ( ManipulatorGroup {
63
- anchor : last. 3 ,
64
- in_handle : last. 2 ,
76
+ anchor : last. p3 ,
77
+ in_handle : last. p2 ,
65
78
out_handle : None ,
66
79
id : PointId :: new ( ) ,
67
80
} ) ;
68
81
return Subpath :: new ( manipulator_groups, false ) ;
69
82
}
70
83
71
- manipulator_groups[ 0 ] . in_handle = last. 2 ;
84
+ manipulator_groups[ 0 ] . in_handle = last. p2 ;
72
85
Subpath :: new ( manipulator_groups, true )
73
86
}
74
87
0 commit comments