@leafer/path 1.12.1 → 1.12.3

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer/path",
3
- "version": "1.12.1",
3
+ "version": "1.12.3",
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": "1.12.1",
26
- "@leafer/math": "1.12.1",
27
- "@leafer/debug": "1.12.1"
25
+ "@leafer/data": "1.12.3",
26
+ "@leafer/math": "1.12.3",
27
+ "@leafer/debug": "1.12.3"
28
28
  },
29
29
  "devDependencies": {
30
- "@leafer/interface": "1.12.1"
30
+ "@leafer/interface": "1.12.3"
31
31
  }
32
32
  }
@@ -23,7 +23,7 @@ export const BezierHelper = {
23
23
  if (curve && points.length > 5) {
24
24
 
25
25
  let aX: number, aY: number, bX: number, bY: number, cX: number, cY: number, c1X: number, c1Y: number, c2X: number, c2Y: number
26
- let ba: number, cb: number, d: number, len = points.length
26
+ let baX: number, baY: number, ba: number, cb: number, d: number, len = points.length
27
27
  const t = curve === true ? 0.5 : curve as number
28
28
 
29
29
  if (close) {
@@ -41,7 +41,10 @@ export const BezierHelper = {
41
41
  cX = points[i + 2]
42
42
  cY = points[i + 3]
43
43
 
44
- ba = sqrt(pow(bX - aX, 2) + pow(bY - aY, 2))
44
+ baX = bX - aX
45
+ baY = bY - aY
46
+
47
+ ba = sqrt(pow(baX, 2) + pow(baY, 2))
45
48
  cb = sqrt(pow(cX - bX, 2) + pow(cY - bY, 2))
46
49
 
47
50
  if (!ba && !cb) continue
@@ -59,7 +62,7 @@ export const BezierHelper = {
59
62
  if (i === 2) {
60
63
  if (!close) data.push(Q, c1X, c1Y, bX, bY)
61
64
  } else {
62
- data.push(C, c2X, c2Y, c1X, c1Y, bX, bY)
65
+ if (baX || baY) data.push(C, c2X, c2Y, c1X, c1Y, bX, bY) // 当前点与上一个点距离为0时,需要过滤
63
66
  }
64
67
 
65
68
  c2X = bX + cb * cX
@@ -59,6 +59,7 @@ export const PathCommandDataHelper = {
59
59
  },
60
60
 
61
61
  ellipse(data: IPathCommandData, x: number, y: number, radiusX: number, radiusY: number, rotation?: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): void {
62
+ if (radiusX === radiusY) return arc(data, x, y, radiusX, startAngle, endAngle, anticlockwise)
62
63
  if (isNull(rotation)) {
63
64
  data.push(F, x, y, radiusX, radiusY)
64
65
  } else {
@@ -72,6 +73,7 @@ export const PathCommandDataHelper = {
72
73
  if (isNull(startAngle)) {
73
74
  data.push(P, x, y, radius)
74
75
  } else {
76
+ if (isNull(startAngle)) startAngle = 0
75
77
  if (isNull(endAngle)) endAngle = 360
76
78
  data.push(O, x, y, radius, startAngle, endAngle, anticlockwise ? 1 : 0)
77
79
  }
package/src/PathCorner.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { IPathCommandData } from '@leafer/interface'
2
2
  import { PointHelper } from '@leafer/math'
3
+ import { isArray } from '@leafer/data'
3
4
 
4
5
  import { PathCommandMap as Command, PathNumberCommandLengthMap } from './PathCommandMap'
5
6
  import { PathCommandDataHelper } from './PathCommandDataHelper'
@@ -15,6 +16,7 @@ export const PathCorner = {
15
16
 
16
17
  let command: number, lastCommand: number, commandLen
17
18
  let i = 0, x = 0, y = 0, startX = 0, startY = 0, secondX = 0, secondY = 0, lastX = 0, lastY = 0
19
+ if (isArray(cornerRadius)) cornerRadius = cornerRadius[0] || 0
18
20
 
19
21
  const len = data.length
20
22
  const smooth: IPathCommandData = []