@ceale/util 1.11.0 → 1.12.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/README.md +3 -1
- package/dist/cjs/index.js +14 -0
- package/dist/esm/index.js +14 -0
- package/dist/types/bezier.d.ts +2 -2
- package/dist/types/error.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/cjs/index.js
CHANGED
|
@@ -273,6 +273,10 @@ var quadraticCurve;
|
|
|
273
273
|
return 2 * oneMinusT * t * p1y + t * t;
|
|
274
274
|
};
|
|
275
275
|
quadraticCurve.solveTForX = (p1, x, iterations = 15) => {
|
|
276
|
+
if (x <= 0)
|
|
277
|
+
return 0;
|
|
278
|
+
if (x >= 1)
|
|
279
|
+
return 1;
|
|
276
280
|
let tMin = 0;
|
|
277
281
|
let tMax = 1;
|
|
278
282
|
let tGuess;
|
|
@@ -309,6 +313,10 @@ var cubicCurve;
|
|
|
309
313
|
return 3 * oneMinusT * oneMinusT * t * p1y + 3 * oneMinusT * t2 * p2y + t2 * t;
|
|
310
314
|
};
|
|
311
315
|
cubicCurve.solveTForX = ([p1, p2], x, iterations = 20) => {
|
|
316
|
+
if (x <= 0)
|
|
317
|
+
return 0;
|
|
318
|
+
if (x >= 1)
|
|
319
|
+
return 1;
|
|
312
320
|
let tMin = 0;
|
|
313
321
|
let tMax = 1;
|
|
314
322
|
let tGuess;
|
|
@@ -339,6 +347,9 @@ class QuadraticBezier {
|
|
|
339
347
|
if (this.p1[0] < 0 || this.p1[0] > 1) {
|
|
340
348
|
throw new BezierError("控制点P1的x坐标必须在[0, 1]之间");
|
|
341
349
|
}
|
|
350
|
+
if (accuracy !== -1) {
|
|
351
|
+
this.accuracy = 10 ** accuracy;
|
|
352
|
+
}
|
|
342
353
|
}
|
|
343
354
|
solveX(t) {
|
|
344
355
|
return quadraticCurve.solveX(this.p1, t);
|
|
@@ -375,6 +386,9 @@ class CubicBezier {
|
|
|
375
386
|
if (this.p2[0] < 0 || this.p2[0] > 1) {
|
|
376
387
|
throw new BezierError("控制点P2的x坐标必须在[0, 1]之间");
|
|
377
388
|
}
|
|
389
|
+
if (accuracy !== -1) {
|
|
390
|
+
this.accuracy = 10 ** accuracy;
|
|
391
|
+
}
|
|
378
392
|
}
|
|
379
393
|
solveX(t) {
|
|
380
394
|
return cubicCurve.solveX([this.p1, this.p2], t);
|
package/dist/esm/index.js
CHANGED
|
@@ -227,6 +227,10 @@ var quadraticCurve;
|
|
|
227
227
|
return 2 * oneMinusT * t * p1y + t * t;
|
|
228
228
|
};
|
|
229
229
|
quadraticCurve.solveTForX = (p1, x, iterations = 15) => {
|
|
230
|
+
if (x <= 0)
|
|
231
|
+
return 0;
|
|
232
|
+
if (x >= 1)
|
|
233
|
+
return 1;
|
|
230
234
|
let tMin = 0;
|
|
231
235
|
let tMax = 1;
|
|
232
236
|
let tGuess;
|
|
@@ -263,6 +267,10 @@ var cubicCurve;
|
|
|
263
267
|
return 3 * oneMinusT * oneMinusT * t * p1y + 3 * oneMinusT * t2 * p2y + t2 * t;
|
|
264
268
|
};
|
|
265
269
|
cubicCurve.solveTForX = ([p1, p2], x, iterations = 20) => {
|
|
270
|
+
if (x <= 0)
|
|
271
|
+
return 0;
|
|
272
|
+
if (x >= 1)
|
|
273
|
+
return 1;
|
|
266
274
|
let tMin = 0;
|
|
267
275
|
let tMax = 1;
|
|
268
276
|
let tGuess;
|
|
@@ -293,6 +301,9 @@ class QuadraticBezier {
|
|
|
293
301
|
if (this.p1[0] < 0 || this.p1[0] > 1) {
|
|
294
302
|
throw new BezierError("控制点P1的x坐标必须在[0, 1]之间");
|
|
295
303
|
}
|
|
304
|
+
if (accuracy !== -1) {
|
|
305
|
+
this.accuracy = 10 ** accuracy;
|
|
306
|
+
}
|
|
296
307
|
}
|
|
297
308
|
solveX(t) {
|
|
298
309
|
return quadraticCurve.solveX(this.p1, t);
|
|
@@ -329,6 +340,9 @@ class CubicBezier {
|
|
|
329
340
|
if (this.p2[0] < 0 || this.p2[0] > 1) {
|
|
330
341
|
throw new BezierError("控制点P2的x坐标必须在[0, 1]之间");
|
|
331
342
|
}
|
|
343
|
+
if (accuracy !== -1) {
|
|
344
|
+
this.accuracy = 10 ** accuracy;
|
|
345
|
+
}
|
|
332
346
|
}
|
|
333
347
|
solveX(t) {
|
|
334
348
|
return cubicCurve.solveX([this.p1, this.p2], t);
|
package/dist/types/bezier.d.ts
CHANGED
|
@@ -72,7 +72,7 @@ export declare namespace cubicCurve {
|
|
|
72
72
|
*/
|
|
73
73
|
export declare class QuadraticBezier {
|
|
74
74
|
private readonly p1;
|
|
75
|
-
private
|
|
75
|
+
private accuracy;
|
|
76
76
|
cache: Map<number, number>;
|
|
77
77
|
/**
|
|
78
78
|
* @param p1 控制点 P1
|
|
@@ -98,7 +98,7 @@ export declare class QuadraticBezier {
|
|
|
98
98
|
export declare class CubicBezier {
|
|
99
99
|
private readonly p1;
|
|
100
100
|
private readonly p2;
|
|
101
|
-
private
|
|
101
|
+
private accuracy;
|
|
102
102
|
cache: Map<number, number>;
|
|
103
103
|
/**
|
|
104
104
|
* @param p1 控制点 P1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED