@leafer/path 1.9.4 → 1.9.6
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 -5
- package/src/BezierHelper.ts +6 -2
- package/src/PathCreator.ts +1 -5
- package/src/index.ts +11 -4
- package/types/index.d.ts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/path",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.6",
|
|
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.9.
|
|
26
|
-
"@leafer/math": "1.9.
|
|
27
|
-
"@leafer/debug": "1.9.
|
|
25
|
+
"@leafer/data": "1.9.6",
|
|
26
|
+
"@leafer/math": "1.9.6",
|
|
27
|
+
"@leafer/debug": "1.9.6"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@leafer/interface": "1.9.
|
|
30
|
+
"@leafer/interface": "1.9.6"
|
|
31
31
|
}
|
|
32
32
|
}
|
package/src/BezierHelper.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { RectHelper } from './RectHelper'
|
|
|
6
6
|
import { PathHelper } from './PathHelper'
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
const { sin, cos, atan2, ceil, abs, PI, sqrt, pow } = Math
|
|
9
|
+
const { sin, cos, hypot, atan2, ceil, abs, PI, sqrt, pow } = Math
|
|
10
10
|
const { setPoint, addPoint } = TwoPointBoundsHelper
|
|
11
11
|
const { set, toNumberPoints } = PointHelper
|
|
12
12
|
const { M, L, C, Q, Z } = PathCommandMap
|
|
@@ -98,10 +98,14 @@ export const BezierHelper = {
|
|
|
98
98
|
|
|
99
99
|
let startRadian = atan2(BAy, BAx)
|
|
100
100
|
let endRadian = atan2(CBy, CBx)
|
|
101
|
+
|
|
102
|
+
const lenBA = hypot(BAx, BAy)
|
|
103
|
+
const lenCB = hypot(CBx, CBy)
|
|
104
|
+
|
|
101
105
|
let totalRadian = endRadian - startRadian
|
|
102
106
|
if (totalRadian < 0) totalRadian += PI2
|
|
103
107
|
|
|
104
|
-
if (
|
|
108
|
+
if (lenBA < 1e-12 || lenCB < 1e-12 || totalRadian < 1e-12 || abs(totalRadian - PI) < 1e-12) {
|
|
105
109
|
if (data) data.push(L, x1, y1)
|
|
106
110
|
if (setPointBounds) {
|
|
107
111
|
setPoint(setPointBounds, fromX, fromY)
|
package/src/PathCreator.ts
CHANGED
|
@@ -19,11 +19,7 @@ export class PathCreator implements IPathCreator { // tip: rewrited Pen
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
public set(path?: IPathCommandData | IPathString): PathCreator {
|
|
22
|
-
|
|
23
|
-
this.__path = isString(path) ? PathHelper.parse(path) : path
|
|
24
|
-
} else {
|
|
25
|
-
this.__path = []
|
|
26
|
-
}
|
|
22
|
+
this.__path = path ? (isString(path) ? PathHelper.parse(path) : path) : []
|
|
27
23
|
return this
|
|
28
24
|
}
|
|
29
25
|
|
package/src/index.ts
CHANGED
|
@@ -16,8 +16,15 @@ import { PathConvert } from './PathConvert'
|
|
|
16
16
|
import { PathCreator } from './PathCreator'
|
|
17
17
|
import { PathHelper } from './PathHelper'
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
import { IPathCommandData, IPathString } from '@leafer/interface'
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
export function path(path?: IPathCommandData | IPathString): PathCreator {
|
|
23
|
+
return new PathCreator(path)
|
|
24
|
+
}
|
|
22
25
|
|
|
23
|
-
export const pen =
|
|
26
|
+
export const pen = path()
|
|
27
|
+
|
|
28
|
+
PathHelper.creator = path()
|
|
29
|
+
PathHelper.parse = PathConvert.parse
|
|
30
|
+
PathHelper.convertToCanvasData = PathConvert.toCanvasData
|
package/types/index.d.ts
CHANGED
|
@@ -104,6 +104,7 @@ declare const NeedConvertToCanvasCommandMap: INumberMap;
|
|
|
104
104
|
declare const PathNumberCommandMap: IStringMap;
|
|
105
105
|
declare const PathNumberCommandLengthMap: INumberMap;
|
|
106
106
|
|
|
107
|
+
declare function path(path?: IPathCommandData | IPathString): PathCreator;
|
|
107
108
|
declare const pen: PathCreator;
|
|
108
109
|
|
|
109
|
-
export { BezierHelper, EllipseHelper, NeedConvertToCanvasCommandMap, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathDrawer, PathHelper, PathNumberCommandLengthMap, PathNumberCommandMap, RectHelper, pen };
|
|
110
|
+
export { BezierHelper, EllipseHelper, NeedConvertToCanvasCommandMap, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathDrawer, PathHelper, PathNumberCommandLengthMap, PathNumberCommandMap, RectHelper, path, pen };
|