@leafer/path 1.7.0 → 1.9.0
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 +5 -4
- package/src/PathCommandDataHelper.ts +10 -9
- package/src/PathCreator.ts +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/path",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "@leafer/path",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,10 +22,11 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/
|
|
26
|
-
"@leafer/
|
|
25
|
+
"@leafer/data": "1.9.0",
|
|
26
|
+
"@leafer/math": "1.9.0",
|
|
27
|
+
"@leafer/debug": "1.9.0"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
|
-
"@leafer/interface": "1.
|
|
30
|
+
"@leafer/interface": "1.9.0"
|
|
30
31
|
}
|
|
31
32
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IPathCommandData, IPointData } from '@leafer/interface'
|
|
2
2
|
import { MathHelper, PointHelper } from '@leafer/math'
|
|
3
|
+
import { isNumber, isUndefined, isNull } from '@leafer/data'
|
|
3
4
|
|
|
4
5
|
import { PathCommandMap } from './PathCommandMap'
|
|
5
6
|
import { BezierHelper } from './BezierHelper'
|
|
@@ -45,7 +46,7 @@ export const PathCommandDataHelper = {
|
|
|
45
46
|
},
|
|
46
47
|
|
|
47
48
|
roundRect(data: IPathCommandData, x: number, y: number, width: number, height: number, cornerRadius: number | number[]): void {
|
|
48
|
-
if (
|
|
49
|
+
if (isNumber(cornerRadius)) {
|
|
49
50
|
data.push(X, x, y, width, height, cornerRadius)
|
|
50
51
|
} else {
|
|
51
52
|
const fourCorners = MathHelper.fourNumber(cornerRadius)
|
|
@@ -58,26 +59,26 @@ export const PathCommandDataHelper = {
|
|
|
58
59
|
},
|
|
59
60
|
|
|
60
61
|
ellipse(data: IPathCommandData, x: number, y: number, radiusX: number, radiusY: number, rotation?: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): void {
|
|
61
|
-
if (rotation
|
|
62
|
+
if (isNull(rotation)) {
|
|
62
63
|
data.push(F, x, y, radiusX, radiusY)
|
|
63
64
|
} else {
|
|
64
|
-
if (startAngle
|
|
65
|
-
if (endAngle
|
|
65
|
+
if (isNull(startAngle)) startAngle = 0
|
|
66
|
+
if (isNull(endAngle)) endAngle = 360
|
|
66
67
|
data.push(G, x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise ? 1 : 0)
|
|
67
68
|
}
|
|
68
69
|
},
|
|
69
70
|
|
|
70
71
|
arc(data: IPathCommandData, x: number, y: number, radius: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): void {
|
|
71
|
-
if (startAngle
|
|
72
|
+
if (isNull(startAngle)) {
|
|
72
73
|
data.push(P, x, y, radius)
|
|
73
74
|
} else {
|
|
74
|
-
if (endAngle
|
|
75
|
+
if (isNull(endAngle)) endAngle = 360
|
|
75
76
|
data.push(O, x, y, radius, startAngle, endAngle, anticlockwise ? 1 : 0)
|
|
76
77
|
}
|
|
77
78
|
},
|
|
78
79
|
|
|
79
80
|
arcTo(data: IPathCommandData, x1: number, y1: number, x2: number, y2: number, radius: number, lastX?: number, lastY?: number): void {
|
|
80
|
-
if (lastX
|
|
81
|
+
if (!isUndefined(lastX)) {
|
|
81
82
|
const d = getMinDistanceFrom(lastX, lastY, x1, y1, x2, y2)
|
|
82
83
|
radius = min(radius, min(d / 2, d / 2 * abs(tan(getRadianFrom(lastX, lastY, x1, y1, x2, y2) / 2))))
|
|
83
84
|
}
|
|
@@ -87,13 +88,13 @@ export const PathCommandDataHelper = {
|
|
|
87
88
|
// new
|
|
88
89
|
|
|
89
90
|
drawEllipse(data: IPathCommandData, x: number, y: number, radiusX: number, radiusY: number, rotation?: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): void {
|
|
90
|
-
BezierHelper.ellipse(null, x, y, radiusX, radiusY, rotation
|
|
91
|
+
BezierHelper.ellipse(null, x, y, radiusX, radiusY, isNull(rotation) ? 0 : rotation, isNull(startAngle) ? 0 : startAngle, isNull(endAngle) ? 360 : endAngle, anticlockwise, null, null, startPoint)
|
|
91
92
|
data.push(M, startPoint.x, startPoint.y)
|
|
92
93
|
ellipse(data, x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise)
|
|
93
94
|
},
|
|
94
95
|
|
|
95
96
|
drawArc(data: IPathCommandData, x: number, y: number, radius: number, startAngle?: number, endAngle?: number, anticlockwise?: boolean): void {
|
|
96
|
-
BezierHelper.arc(null, x, y, radius, startAngle
|
|
97
|
+
BezierHelper.arc(null, x, y, radius, isNull(startAngle) ? 0 : startAngle, isNull(endAngle) ? 360 : endAngle, anticlockwise, null, null, startPoint)
|
|
97
98
|
data.push(M, startPoint.x, startPoint.y)
|
|
98
99
|
arc(data, x, y, radius, startAngle, endAngle, anticlockwise)
|
|
99
100
|
},
|
package/src/PathCreator.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { IPathCommandData, IPathCreator, IPathString, IPointData } from '@leafer/interface'
|
|
2
|
+
import { isString } from '@leafer/data'
|
|
3
|
+
|
|
2
4
|
import { PathCommandDataHelper } from './PathCommandDataHelper'
|
|
3
5
|
import { PathHelper } from './PathHelper'
|
|
4
6
|
|
|
@@ -18,7 +20,7 @@ export class PathCreator implements IPathCreator { // tip: rewrited Pen
|
|
|
18
20
|
|
|
19
21
|
public set(path?: IPathCommandData | IPathString): PathCreator {
|
|
20
22
|
if (path) {
|
|
21
|
-
this.__path =
|
|
23
|
+
this.__path = isString(path) ? PathHelper.parse(path) : path
|
|
22
24
|
} else {
|
|
23
25
|
this.__path = []
|
|
24
26
|
}
|