@leafer/path 2.1.5 → 2.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +5 -5
  2. package/src/PathCorner.ts +13 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer/path",
3
- "version": "2.1.5",
3
+ "version": "2.1.7",
4
4
  "description": "@leafer/path",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,11 +22,11 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/data": "2.1.5",
26
- "@leafer/math": "2.1.5",
27
- "@leafer/debug": "2.1.5"
25
+ "@leafer/data": "2.1.7",
26
+ "@leafer/math": "2.1.7",
27
+ "@leafer/debug": "2.1.7"
28
28
  },
29
29
  "devDependencies": {
30
- "@leafer/interface": "2.1.5"
30
+ "@leafer/interface": "2.1.7"
31
31
  }
32
32
  }
package/src/PathCorner.ts CHANGED
@@ -15,7 +15,7 @@ export const PathCorner = {
15
15
 
16
16
  smooth(data: IPathCommandData, cornerRadius: number, _cornerSmoothing?: number): IPathCommandData {
17
17
 
18
- let command: number, lastCommand: number, commandLen
18
+ let command: number, lastCommand: number, commandLen: number, startXIndex: number, startYIndex: number, smoothLen: number
19
19
  let i = 0, x = 0, y = 0, startX = 0, startY = 0, secondX = 0, secondY = 0, lastX = 0, lastY = 0
20
20
  if (isArray(cornerRadius)) cornerRadius = cornerRadius[0] || 0
21
21
 
@@ -26,6 +26,13 @@ export const PathCorner = {
26
26
  command = data[i]
27
27
  switch (command) {
28
28
  case M: //moveto(x, y)
29
+ smoothLen = smooth.length
30
+
31
+ if (smoothLen && lastCommand !== Z) {
32
+ smooth[startXIndex] = startX
33
+ smooth[startYIndex] = startY
34
+ }
35
+
29
36
  startX = lastX = data[i + 1]
30
37
  startY = lastY = data[i + 2]
31
38
  i += 3
@@ -36,6 +43,9 @@ export const PathCorner = {
36
43
  } else {
37
44
  smooth.push(M, startX, startY)
38
45
  }
46
+
47
+ startXIndex = smoothLen + 1
48
+ startYIndex = smoothLen + 2
39
49
  break
40
50
  case L: //lineto(x, y)
41
51
  x = data[i + 1]
@@ -70,8 +80,8 @@ export const PathCorner = {
70
80
  }
71
81
 
72
82
  if (command !== Z) {
73
- smooth[1] = startX
74
- smooth[2] = startY
83
+ smooth[startXIndex] = startX
84
+ smooth[startYIndex] = startY
75
85
  }
76
86
 
77
87
  return smooth