@antv/util 3.2.3 → 3.2.4
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/dist/util.min.js +1 -1
- package/esm/path/process/normalize-path.js +1 -6
- package/esm/path/process/normalize-path.js.map +1 -1
- package/esm/path/types.d.ts +5 -0
- package/esm/path/util/equalize-segments.js +1 -1
- package/esm/path/util/equalize-segments.js.map +1 -1
- package/esm/path/util/get-path-bbox-total-length.d.ts +2 -2
- package/esm/path/util/get-path-bbox-total-length.js +3 -2
- package/esm/path/util/get-path-bbox-total-length.js.map +1 -1
- package/esm/path/util/get-path-bbox.d.ts +2 -2
- package/esm/path/util/get-path-bbox.js +3 -2
- package/esm/path/util/get-path-bbox.js.map +1 -1
- package/esm/path/util/get-point-at-length.d.ts +2 -2
- package/esm/path/util/get-point-at-length.js +3 -2
- package/esm/path/util/get-point-at-length.js.map +1 -1
- package/esm/path/util/get-total-length.d.ts +2 -2
- package/esm/path/util/get-total-length.js +3 -2
- package/esm/path/util/get-total-length.js.map +1 -1
- package/esm/path/util/path-length-factory.d.ts +2 -2
- package/esm/path/util/path-length-factory.js +4 -4
- package/esm/path/util/path-length-factory.js.map +1 -1
- package/esm/path/util/segment-arc-factory.d.ts +4 -2
- package/esm/path/util/segment-arc-factory.js +11 -5
- package/esm/path/util/segment-arc-factory.js.map +1 -1
- package/esm/path/util/segment-cubic-factory.d.ts +2 -2
- package/esm/path/util/segment-cubic-factory.js +8 -4
- package/esm/path/util/segment-cubic-factory.js.map +1 -1
- package/esm/path/util/segment-quad-factory.d.ts +2 -2
- package/esm/path/util/segment-quad-factory.js +8 -4
- package/esm/path/util/segment-quad-factory.js.map +1 -1
- package/lib/path/process/normalize-path.js +1 -6
- package/lib/path/process/normalize-path.js.map +1 -1
- package/lib/path/types.d.ts +5 -0
- package/lib/path/util/equalize-segments.js +1 -1
- package/lib/path/util/equalize-segments.js.map +1 -1
- package/lib/path/util/get-path-bbox-total-length.d.ts +2 -2
- package/lib/path/util/get-path-bbox-total-length.js +3 -2
- package/lib/path/util/get-path-bbox-total-length.js.map +1 -1
- package/lib/path/util/get-path-bbox.d.ts +2 -2
- package/lib/path/util/get-path-bbox.js +3 -2
- package/lib/path/util/get-path-bbox.js.map +1 -1
- package/lib/path/util/get-point-at-length.d.ts +2 -2
- package/lib/path/util/get-point-at-length.js +3 -2
- package/lib/path/util/get-point-at-length.js.map +1 -1
- package/lib/path/util/get-total-length.d.ts +2 -2
- package/lib/path/util/get-total-length.js +3 -2
- package/lib/path/util/get-total-length.js.map +1 -1
- package/lib/path/util/path-length-factory.d.ts +2 -2
- package/lib/path/util/path-length-factory.js +4 -4
- package/lib/path/util/path-length-factory.js.map +1 -1
- package/lib/path/util/segment-arc-factory.d.ts +4 -2
- package/lib/path/util/segment-arc-factory.js +11 -5
- package/lib/path/util/segment-arc-factory.js.map +1 -1
- package/lib/path/util/segment-cubic-factory.d.ts +2 -2
- package/lib/path/util/segment-cubic-factory.js +8 -4
- package/lib/path/util/segment-cubic-factory.js.map +1 -1
- package/lib/path/util/segment-quad-factory.d.ts +2 -2
- package/lib/path/util/segment-quad-factory.js +8 -4
- package/lib/path/util/segment-quad-factory.js.map +1 -1
- package/package.json +2 -1
- package/src/path/process/normalize-path.ts +1 -7
- package/src/path/types.ts +5 -0
- package/src/path/util/equalize-segments.ts +1 -0
- package/src/path/util/get-path-bbox-total-length.ts +6 -3
- package/src/path/util/get-path-bbox.ts +3 -3
- package/src/path/util/get-point-at-length.ts +7 -3
- package/src/path/util/get-total-length.ts +3 -3
- package/src/path/util/path-length-factory.ts +9 -2
- package/src/path/util/segment-arc-factory.ts +14 -5
- package/src/path/util/segment-cubic-factory.ts +11 -4
- package/src/path/util/segment-quad-factory.ts +11 -4
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import type { PathArray, PathBBoxTotalLength } from '../types';
|
|
1
|
+
import type { PathArray, PathBBoxTotalLength, PathLengthFactoryOptions } from '../types';
|
|
2
2
|
import { pathLengthFactory } from './path-length-factory';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Returns the bounding box of a shape.
|
|
6
6
|
*/
|
|
7
|
-
export function getPathBBoxTotalLength(
|
|
7
|
+
export function getPathBBoxTotalLength(
|
|
8
|
+
path: PathArray,
|
|
9
|
+
options?: Partial<PathLengthFactoryOptions>,
|
|
10
|
+
): PathBBoxTotalLength {
|
|
8
11
|
if (!path) {
|
|
9
12
|
return {
|
|
10
13
|
length: 0,
|
|
@@ -24,7 +27,7 @@ export function getPathBBoxTotalLength(path: PathArray): PathBBoxTotalLength {
|
|
|
24
27
|
length,
|
|
25
28
|
min: { x: xMin, y: yMin },
|
|
26
29
|
max: { x: xMax, y: yMax },
|
|
27
|
-
} = pathLengthFactory(path);
|
|
30
|
+
} = pathLengthFactory(path, undefined, { ...options, bbox: true, length: true });
|
|
28
31
|
|
|
29
32
|
const width = xMax - xMin;
|
|
30
33
|
const height = yMax - yMin;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { PathArray, PathBBox } from '../types';
|
|
1
|
+
import type { PathArray, PathBBox, PathLengthFactoryOptions } from '../types';
|
|
2
2
|
import { pathLengthFactory } from './path-length-factory';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Returns the bounding box of a shape.
|
|
6
6
|
*/
|
|
7
|
-
export function getPathBBox(path: string | PathArray): PathBBox {
|
|
7
|
+
export function getPathBBox(path: string | PathArray, options?: Partial<PathLengthFactoryOptions>): PathBBox {
|
|
8
8
|
if (!path) {
|
|
9
9
|
return {
|
|
10
10
|
x: 0,
|
|
@@ -22,7 +22,7 @@ export function getPathBBox(path: string | PathArray): PathBBox {
|
|
|
22
22
|
const {
|
|
23
23
|
min: { x: xMin, y: yMin },
|
|
24
24
|
max: { x: xMax, y: yMax },
|
|
25
|
-
} = pathLengthFactory(path);
|
|
25
|
+
} = pathLengthFactory(path, undefined, { ...options, length: false });
|
|
26
26
|
|
|
27
27
|
const width = xMax - xMin;
|
|
28
28
|
const height = yMax - yMin;
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import type { PathArray } from '../types';
|
|
1
|
+
import type { PathArray, PathLengthFactoryOptions } from '../types';
|
|
2
2
|
import { pathLengthFactory } from './path-length-factory';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Returns [x,y] coordinates of a point at a given length of a shape.
|
|
6
6
|
*/
|
|
7
|
-
export function getPointAtLength(
|
|
8
|
-
|
|
7
|
+
export function getPointAtLength(
|
|
8
|
+
pathInput: string | PathArray,
|
|
9
|
+
distance: number,
|
|
10
|
+
options?: Partial<PathLengthFactoryOptions>,
|
|
11
|
+
) {
|
|
12
|
+
return pathLengthFactory(pathInput, distance, { ...options, bbox: false, length: true }).point;
|
|
9
13
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PathArray } from '../types';
|
|
1
|
+
import type { PathArray, PathLengthFactoryOptions } from '../types';
|
|
2
2
|
import { pathLengthFactory } from './path-length-factory';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -7,6 +7,6 @@ import { pathLengthFactory } from './path-length-factory';
|
|
|
7
7
|
* The `normalizePath` version is lighter, faster, more efficient and more accurate
|
|
8
8
|
* with paths that are not `curveArray`.
|
|
9
9
|
*/
|
|
10
|
-
export function getTotalLength(pathInput: string | PathArray) {
|
|
11
|
-
return pathLengthFactory(pathInput).length;
|
|
10
|
+
export function getTotalLength(pathInput: string | PathArray, options?: Partial<PathLengthFactoryOptions>) {
|
|
11
|
+
return pathLengthFactory(pathInput, undefined, { ...options, bbox: false, length: true }).length;
|
|
12
12
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { normalizePath } from '../process/normalize-path';
|
|
2
|
-
import type { PathCommand, PathArray, LengthFactory } from '../types';
|
|
2
|
+
import type { PathCommand, PathArray, LengthFactory, PathLengthFactoryOptions } from '../types';
|
|
3
3
|
import { segmentLineFactory } from './segment-line-factory';
|
|
4
4
|
import { segmentArcFactory } from './segment-arc-factory';
|
|
5
5
|
import { segmentCubicFactory } from './segment-cubic-factory';
|
|
@@ -10,7 +10,11 @@ import { segmentQuadFactory } from './segment-quad-factory';
|
|
|
10
10
|
* of a shape, the shape total length and
|
|
11
11
|
* the shape minimum and maximum {x,y} coordinates.
|
|
12
12
|
*/
|
|
13
|
-
export function pathLengthFactory(
|
|
13
|
+
export function pathLengthFactory(
|
|
14
|
+
pathInput: string | PathArray,
|
|
15
|
+
distance?: number,
|
|
16
|
+
options?: Partial<PathLengthFactoryOptions>,
|
|
17
|
+
): LengthFactory {
|
|
14
18
|
const path = normalizePath(pathInput);
|
|
15
19
|
const distanceIsNumber = typeof distance === 'number';
|
|
16
20
|
let isM: boolean;
|
|
@@ -62,6 +66,7 @@ export function pathLengthFactory(pathInput: string | PathArray, distance?: numb
|
|
|
62
66
|
data[7],
|
|
63
67
|
data[8],
|
|
64
68
|
(distance || 0) - LENGTH,
|
|
69
|
+
options || {},
|
|
65
70
|
));
|
|
66
71
|
} else if (pathCommand === 'C') {
|
|
67
72
|
({ length, min, max, point } = segmentCubicFactory(
|
|
@@ -74,6 +79,7 @@ export function pathLengthFactory(pathInput: string | PathArray, distance?: numb
|
|
|
74
79
|
data[6],
|
|
75
80
|
data[7],
|
|
76
81
|
(distance || 0) - LENGTH,
|
|
82
|
+
options || {},
|
|
77
83
|
));
|
|
78
84
|
} else if (pathCommand === 'Q') {
|
|
79
85
|
({ length, min, max, point } = segmentQuadFactory(
|
|
@@ -84,6 +90,7 @@ export function pathLengthFactory(pathInput: string | PathArray, distance?: numb
|
|
|
84
90
|
data[4],
|
|
85
91
|
data[5],
|
|
86
92
|
(distance || 0) - LENGTH,
|
|
93
|
+
options || {},
|
|
87
94
|
));
|
|
88
95
|
} else if (pathCommand === 'Z') {
|
|
89
96
|
data = [x, y, mx, my];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Point, LengthFactory } from '../types';
|
|
1
|
+
import type { Point, LengthFactory, PathLengthFactoryOptions } from '../types';
|
|
2
2
|
import { segmentLineFactory } from './segment-line-factory';
|
|
3
3
|
import { distanceSquareRoot } from './distance-square-root';
|
|
4
4
|
|
|
@@ -120,6 +120,8 @@ function getPointAtArcSegmentLength(
|
|
|
120
120
|
/**
|
|
121
121
|
* Returns a {x,y} point at a given length, the total length and
|
|
122
122
|
* the shape minimum and maximum {x,y} coordinates of an A (arc-to) segment.
|
|
123
|
+
*
|
|
124
|
+
* For better performance, it can skip calculate bbox or length in some scenario.
|
|
123
125
|
*/
|
|
124
126
|
export function segmentArcFactory(
|
|
125
127
|
X1: number,
|
|
@@ -132,7 +134,9 @@ export function segmentArcFactory(
|
|
|
132
134
|
X2: number,
|
|
133
135
|
Y2: number,
|
|
134
136
|
distance: number,
|
|
137
|
+
options: Partial<PathLengthFactoryOptions>,
|
|
135
138
|
): LengthFactory {
|
|
139
|
+
const { bbox = true, length = true, sampleSize = 10 } = options;
|
|
136
140
|
const distanceIsNumber = typeof distance === 'number';
|
|
137
141
|
let x = X1;
|
|
138
142
|
let y = Y1;
|
|
@@ -147,14 +151,19 @@ export function segmentArcFactory(
|
|
|
147
151
|
POINT = { x, y };
|
|
148
152
|
}
|
|
149
153
|
|
|
150
|
-
// bad perf when size
|
|
151
|
-
const sampleSize = 100;
|
|
154
|
+
// bad perf when size > 100
|
|
152
155
|
for (let j = 0; j <= sampleSize; j += 1) {
|
|
153
156
|
t = j / sampleSize;
|
|
154
157
|
|
|
155
158
|
({ x, y } = getPointAtArcSegmentLength(X1, Y1, RX, RY, angle, LAF, SF, X2, Y2, t));
|
|
156
|
-
|
|
157
|
-
|
|
159
|
+
|
|
160
|
+
if (bbox) {
|
|
161
|
+
POINTS.push({ x, y });
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (length) {
|
|
165
|
+
LENGTH += distanceSquareRoot(cur, [x, y]);
|
|
166
|
+
}
|
|
158
167
|
cur = [x, y];
|
|
159
168
|
|
|
160
169
|
if (distanceIsNumber && LENGTH >= distance && distance > prev[2]) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { LengthFactory } from '../types';
|
|
1
|
+
import type { LengthFactory, PathLengthFactoryOptions } from '../types';
|
|
2
2
|
import { distanceSquareRoot } from './distance-square-root';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -37,7 +37,9 @@ export function segmentCubicFactory(
|
|
|
37
37
|
x2: number,
|
|
38
38
|
y2: number,
|
|
39
39
|
distance: number,
|
|
40
|
+
options: Partial<PathLengthFactoryOptions>,
|
|
40
41
|
): LengthFactory {
|
|
42
|
+
const { bbox = true, length = true, sampleSize = 10 } = options;
|
|
41
43
|
const distanceIsNumber = typeof distance === 'number';
|
|
42
44
|
let x = x1;
|
|
43
45
|
let y = y1;
|
|
@@ -53,13 +55,18 @@ export function segmentCubicFactory(
|
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
// bad perf when size = 300
|
|
56
|
-
const sampleSize = 30;
|
|
57
58
|
for (let j = 0; j <= sampleSize; j += 1) {
|
|
58
59
|
t = j / sampleSize;
|
|
59
60
|
|
|
60
61
|
({ x, y } = getPointAtCubicSegmentLength(x1, y1, c1x, c1y, c2x, c2y, x2, y2, t));
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
|
|
63
|
+
if (bbox) {
|
|
64
|
+
POINTS.push({ x, y });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (length) {
|
|
68
|
+
LENGTH += distanceSquareRoot(cur, [x, y]);
|
|
69
|
+
}
|
|
63
70
|
cur = [x, y];
|
|
64
71
|
|
|
65
72
|
if (distanceIsNumber && LENGTH >= distance && distance > prev[2]) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { LengthFactory } from '../types';
|
|
1
|
+
import type { LengthFactory, PathLengthFactoryOptions } from '../types';
|
|
2
2
|
import { distanceSquareRoot } from './distance-square-root';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -35,7 +35,9 @@ export function segmentQuadFactory(
|
|
|
35
35
|
x2: number,
|
|
36
36
|
y2: number,
|
|
37
37
|
distance: number,
|
|
38
|
+
options: Partial<PathLengthFactoryOptions>,
|
|
38
39
|
): LengthFactory {
|
|
40
|
+
const { bbox = true, length = true, sampleSize = 10 } = options;
|
|
39
41
|
const distanceIsNumber = typeof distance === 'number';
|
|
40
42
|
let x = x1;
|
|
41
43
|
let y = y1;
|
|
@@ -50,13 +52,18 @@ export function segmentQuadFactory(
|
|
|
50
52
|
POINT = { x, y };
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
const sampleSize = 30;
|
|
54
55
|
for (let j = 0; j <= sampleSize; j += 1) {
|
|
55
56
|
t = j / sampleSize;
|
|
56
57
|
|
|
57
58
|
({ x, y } = getPointAtQuadSegmentLength(x1, y1, qx, qy, x2, y2, t));
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
|
|
60
|
+
if (bbox) {
|
|
61
|
+
POINTS.push({ x, y });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (length) {
|
|
65
|
+
LENGTH += distanceSquareRoot(cur, [x, y]);
|
|
66
|
+
}
|
|
60
67
|
cur = [x, y];
|
|
61
68
|
|
|
62
69
|
if (distanceIsNumber && LENGTH >= distance && distance > prev[2]) {
|