@leafer/path 2.0.0 → 2.0.2

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": "2.0.0",
3
+ "version": "2.0.2",
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.0.0",
26
- "@leafer/math": "2.0.0",
27
- "@leafer/debug": "2.0.0"
25
+ "@leafer/data": "2.0.2",
26
+ "@leafer/math": "2.0.2",
27
+ "@leafer/debug": "2.0.2"
28
28
  },
29
29
  "devDependencies": {
30
- "@leafer/interface": "2.0.0"
30
+ "@leafer/interface": "2.0.2"
31
31
  }
32
32
  }
@@ -79,10 +79,10 @@ export const PathCommandDataHelper = {
79
79
  }
80
80
  },
81
81
 
82
- arcTo(data: IPathCommandData, x1: number, y1: number, x2: number, y2: number, radius: number, lastX?: number, lastY?: number): void {
82
+ arcTo(data: IPathCommandData, x1: number, y1: number, x2: number, y2: number, radius: number, lastX?: number, lastY?: number, fullRadius?: boolean): void {
83
83
  if (!isUndefined(lastX)) {
84
- const d = getMinDistanceFrom(lastX, lastY, x1, y1, x2, y2)
85
- radius = min(radius, min(d / 2, d / 2 * abs(tan(getRadianFrom(lastX, lastY, x1, y1, x2, y2) / 2))))
84
+ const r = getMinDistanceFrom(lastX, lastY, x1, y1, x2, y2) / (fullRadius ? 1 : 2)
85
+ radius = min(radius, min(r, r * abs(tan(getRadianFrom(lastX, lastY, x1, y1, x2, y2) / 2))))
86
86
  }
87
87
  data.push(U, x1, y1, x2, y2, radius)
88
88
  },
package/src/PathCorner.ts CHANGED
@@ -18,7 +18,7 @@ export const PathCorner = {
18
18
  let i = 0, x = 0, y = 0, startX = 0, startY = 0, secondX = 0, secondY = 0, lastX = 0, lastY = 0
19
19
  if (isArray(cornerRadius)) cornerRadius = cornerRadius[0] || 0
20
20
 
21
- const len = data.length
21
+ const len = data.length, three = len === 9 // 3个点时可以加大圆角
22
22
  const smooth: IPathCommandData = []
23
23
 
24
24
  while (i < len) {
@@ -31,7 +31,7 @@ export const PathCorner = {
31
31
  if (data[i] === L) { // next lineTo
32
32
  secondX = data[i + 1]
33
33
  secondY = data[i + 2]
34
- smooth.push(M, getCenterX(startX, secondX), getCenterY(startY, secondY))
34
+ three ? smooth.push(M, startX, startY) : smooth.push(M, getCenterX(startX, secondX), getCenterY(startY, secondY))
35
35
  } else {
36
36
  smooth.push(M, startX, startY)
37
37
  }
@@ -42,10 +42,10 @@ export const PathCorner = {
42
42
  i += 3
43
43
  switch (data[i]) { // next command
44
44
  case L: // lineTo()
45
- arcTo(smooth, x, y, data[i + 1], data[i + 2], cornerRadius, lastX, lastY) // use arcTo(x1, y1, x2, y2, radius)
45
+ arcTo(smooth, x, y, data[i + 1], data[i + 2], cornerRadius, lastX, lastY, three) // use arcTo(x1, y1, x2, y2, radius)
46
46
  break
47
47
  case Z: // closePath()
48
- arcTo(smooth, x, y, startX, startY, cornerRadius, lastX, lastY) // use arcTo(x1, y1, x2, y2, radius)
48
+ arcTo(smooth, x, y, startX, startY, cornerRadius, lastX, lastY, three) // use arcTo(x1, y1, x2, y2, radius)
49
49
  break
50
50
  default:
51
51
  smooth.push(L, x, y)
@@ -55,7 +55,7 @@ export const PathCorner = {
55
55
  break
56
56
  case Z: //closepath()
57
57
  if (lastCommand !== Z) { // fix: 重复的 Z 导致的问题
58
- arcTo(smooth, startX, startY, secondX, secondY, cornerRadius, lastX, lastY) // use arcTo(x1, y1, x2, y2, radius)
58
+ arcTo(smooth, startX, startY, secondX, secondY, cornerRadius, lastX, lastY, three) // use arcTo(x1, y1, x2, y2, radius)
59
59
  smooth.push(Z)
60
60
  }
61
61
  i += 1
package/types/index.d.ts CHANGED
@@ -57,7 +57,7 @@ declare const PathCommandDataHelper: {
57
57
  roundRect(data: IPathCommandData, x: number, y: number, width: number, height: number, cornerRadius: number | number[]): void;
58
58
  ellipse(data: IPathCommandData, x: number, y: number, radiusX: number, radiusY: number, rotation?: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): void;
59
59
  arc(data: IPathCommandData, x: number, y: number, radius: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): void;
60
- arcTo(data: IPathCommandData, x1: number, y1: number, x2: number, y2: number, radius: number, lastX?: number, lastY?: number): void;
60
+ arcTo(data: IPathCommandData, x1: number, y1: number, x2: number, y2: number, radius: number, lastX?: number, lastY?: number, fullRadius?: boolean): void;
61
61
  drawEllipse(data: IPathCommandData, x: number, y: number, radiusX: number, radiusY: number, rotation?: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): void;
62
62
  drawArc(data: IPathCommandData, x: number, y: number, radius: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): void;
63
63
  drawPoints(data: IPathCommandData, points: number[] | IPointData[], curve?: boolean | number, close?: boolean): void;