1
- import { getSplinePath } from '../../../src/utils/path' ;
1
+ import { points2Path , smoothBezier , catmullRom2bezier , getSplinePath } from '../../../src/utils/path' ;
2
2
3
- describe ( 'PathUtil' , ( ) => {
4
- test ( 'getSplinePath(), two points' , ( ) => {
3
+ describe ( 'path' , ( ) => {
4
+ it ( 'points2Path' , ( ) => {
5
+ expect ( points2Path ( [ ] , false ) ) . toEqual ( [ ] ) ;
6
+ expect ( points2Path ( [ { x : 100 , y : 100 } ] , false ) ) . toEqual ( [ [ 'M' , 100 , 100 ] ] ) ;
7
+ expect ( points2Path ( [ { x : 100 , y : 100 } ] , true ) ) . toEqual ( [ [ 'M' , 100 , 100 ] , [ 'Z' ] ] ) ;
8
+ } ) ;
9
+
10
+ it ( 'smoothBezier' , ( ) => {
11
+ expect (
12
+ smoothBezier (
13
+ [
14
+ [ 0 , 0 ] ,
15
+ [ 0.1 , 0.1 ] ,
16
+ ] ,
17
+ 0.4 ,
18
+ true ,
19
+ [
20
+ [ 0.04 , 0.04 ] ,
21
+ [ 0.1 , 0.1 ] ,
22
+ ]
23
+ )
24
+ ) . toEqual ( [
25
+ [ 0 , 0 ] ,
26
+ [ 0.1 , 0.1 ] ,
27
+ [ 0.1 , 0.1 ] ,
28
+ [ 0 , 0 ] ,
29
+ ] ) ;
30
+ expect (
31
+ smoothBezier (
32
+ [
33
+ [ 0 , 0 ] ,
34
+ [ 0.1 , 0.1 ] ,
35
+ ] ,
36
+ 0.4 ,
37
+ false ,
38
+ [
39
+ [ 0.04 , 0.04 ] ,
40
+ [ 0.1 , 0.1 ] ,
41
+ ]
42
+ )
43
+ ) . toEqual ( [
44
+ [ 0 , 0 ] ,
45
+ [ 0.1 , 0.1 ] ,
46
+ ] ) ;
47
+ expect (
48
+ smoothBezier (
49
+ [
50
+ [ 0 , 0 ] ,
51
+ [ 0.1 , 0.1 ] ,
52
+ ] ,
53
+ 0.4 ,
54
+ false ,
55
+ undefined
56
+ )
57
+ ) . toEqual ( [
58
+ [ 0 , 0 ] ,
59
+ [ 0.1 , 0.1 ] ,
60
+ ] ) ;
61
+ expect (
62
+ smoothBezier (
63
+ [
64
+ [ 0 , 0 ] ,
65
+ [ 0.1 , 0.1 ] ,
66
+ ] ,
67
+ 0.4 ,
68
+ true ,
69
+ undefined
70
+ )
71
+ ) . toEqual ( [
72
+ [ 0 , 0 ] ,
73
+ [ 0.1 , 0.1 ] ,
74
+ [ 0.1 , 0.1 ] ,
75
+ [ 0 , 0 ] ,
76
+ ] ) ;
77
+
78
+ expect (
79
+ smoothBezier (
80
+ [
81
+ [ 0 , 0 ] ,
82
+ [ 0.1 , 0.1 ] ,
83
+ [ 0 , 0 ] ,
84
+ ] ,
85
+ 1 ,
86
+ false ,
87
+ undefined
88
+ )
89
+ ) . toEqual ( [
90
+ [ 0 , 0 ] ,
91
+ [ 0.1 , 0.1 ] ,
92
+ [ 0.1 , 0.1 ] ,
93
+ [ 0 , 0 ] ,
94
+ ] ) ;
95
+ } ) ;
96
+
97
+ it ( 'catmullRom2bezier' , ( ) => {
98
+ expect (
99
+ catmullRom2bezier ( [ 0 , 0 , 0.1 , 0.1 ] , true , [
100
+ [ 0.04 , 0.04 ] ,
101
+ [ 0.1 , 0.1 ] ,
102
+ ] )
103
+ ) . toEqual ( [
104
+ [ 'C' , 0 , 0 , 0.1 , 0.1 , 0.1 , 0.1 ] ,
105
+ [ 'C' , 0.1 , 0.1 , 0 , 0 , 0 , 0 ] ,
106
+ ] ) ;
107
+ expect (
108
+ catmullRom2bezier ( [ 0 , 0 , 0.1 , 0.1 ] , false , [
109
+ [ 0.04 , 0.04 ] ,
110
+ [ 0.1 , 0.1 ] ,
111
+ ] )
112
+ ) . toEqual ( [ [ 'C' , 0 , 0 , 0.1 , 0.1 , 0.1 , 0.1 ] ] ) ;
113
+
114
+ expect ( catmullRom2bezier ( [ 0 , 0 , 0.1 , 0.1 ] , true , undefined ) ) . toEqual ( [
115
+ [ 'C' , 0 , 0 , 0.1 , 0.1 , 0.1 , 0.1 ] ,
116
+ [ 'C' , 0.1 , 0.1 , 0 , 0 , 0 , 0 ] ,
117
+ ] ) ;
118
+ expect ( catmullRom2bezier ( [ 0 , 0 , 0.1 , 0.1 ] , false , undefined ) ) . toEqual ( [ [ 'C' , 0 , 0 , 0.1 , 0.1 , 0.1 , 0.1 ] ] ) ;
119
+ } ) ;
120
+
121
+ it ( 'getSplinePath same points' , ( ) => {
122
+ const points = [
123
+ { x : 0 , y : 0 } ,
124
+ { x : 0.1 , y : 0.1 } ,
125
+ { x : 0.1 , y : 0.1 } ,
126
+ { x : 0.2 , y : 0.2 } ,
127
+ ] ;
128
+ const path = getSplinePath ( points ) ;
129
+ expect ( path ) . toEqual ( [
130
+ [ 'M' , 0 , 0 ] ,
131
+ [ 'C' , 0 , 0 , 0.06 , 0.06 , 0.1 , 0.1 ] ,
132
+ [ 'C' , 0.14 , 0.14 , 0.2 , 0.2 , 0.2 , 0.2 ] ,
133
+ ] ) ;
134
+ } ) ;
135
+
136
+ it ( 'getSplinePath(), two points' , ( ) => {
5
137
const points = [
6
138
{ x : 0 , y : 0 } ,
7
139
{ x : 0.1 , y : 0.1 } ,
@@ -13,7 +145,7 @@ describe('PathUtil', () => {
13
145
] ) ;
14
146
} ) ;
15
147
16
- test ( 'getSplinePath(), two points isInCircle' , ( ) => {
148
+ it ( 'getSplinePath(), two points isInCircle' , ( ) => {
17
149
const points = [
18
150
{ x : 0 , y : 0 } ,
19
151
{ x : 0.1 , y : 0.1 } ,
@@ -22,7 +154,7 @@ describe('PathUtil', () => {
22
154
expect ( path ) . toEqual ( [ [ 'M' , 0 , 0 ] , [ 'L' , 0.1 , 0.1 ] , [ 'Z' ] ] ) ;
23
155
} ) ;
24
156
25
- test ( 'getSplinePath(), more than two points' , ( ) => {
157
+ it ( 'getSplinePath(), more than two points' , ( ) => {
26
158
const points = [
27
159
{ x : 0 , y : 0 } ,
28
160
{ x : 0.1 , y : 0.5 } ,
@@ -32,7 +164,7 @@ describe('PathUtil', () => {
32
164
expect ( path . length ) . toBe ( 3 ) ;
33
165
} ) ;
34
166
35
- test ( 'getSplinePath(), more than two points isInCircle' , ( ) => {
167
+ it ( 'getSplinePath(), more than two points isInCircle' , ( ) => {
36
168
const points = [
37
169
{ x : 0 , y : 0 } ,
38
170
{ x : 0.1 , y : 0.1 } ,
0 commit comments