plotboilerplate 1.23.3 → 1.24.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 +6 -0
- package/dist/index.esm.js +1390 -265
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/plotboilerplate.browser.min.js +1 -1
- package/dist/plotboilerplate.browser.min.js.map +1 -1
- package/dist/plotboilerplate.js +1264 -99
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +1 -1
- package/src/cjs/BezierPath.d.ts +41 -5
- package/src/cjs/BezierPath.js +52 -2
- package/src/cjs/BezierPath.js.map +1 -1
- package/src/cjs/Bounds.d.ts +67 -3
- package/src/cjs/Bounds.js +101 -3
- package/src/cjs/Bounds.js.map +1 -1
- package/src/cjs/Circle.d.ts +46 -4
- package/src/cjs/Circle.js +82 -3
- package/src/cjs/Circle.js.map +1 -1
- package/src/cjs/CircleSector.d.ts +51 -2
- package/src/cjs/CircleSector.js +112 -3
- package/src/cjs/CircleSector.js.map +1 -1
- package/src/cjs/CubicBezierCurve.d.ts +113 -7
- package/src/cjs/CubicBezierCurve.js +281 -33
- package/src/cjs/CubicBezierCurve.js.map +1 -1
- package/src/cjs/Line.d.ts +38 -3
- package/src/cjs/Line.js +64 -1
- package/src/cjs/Line.js.map +1 -1
- package/src/cjs/PlotBoilerplate.js +2 -9
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/Polygon.d.ts +48 -4
- package/src/cjs/Polygon.js +91 -16
- package/src/cjs/Polygon.js.map +1 -1
- package/src/cjs/Triangle.d.ts +52 -3
- package/src/cjs/Triangle.js +80 -1
- package/src/cjs/Triangle.js.map +1 -1
- package/src/cjs/VEllipse.d.ts +62 -3
- package/src/cjs/VEllipse.js +181 -17
- package/src/cjs/VEllipse.js.map +1 -1
- package/src/cjs/VEllipseSector.d.ts +86 -2
- package/src/cjs/VEllipseSector.js +148 -4
- package/src/cjs/VEllipseSector.js.map +1 -1
- package/src/cjs/Vector.d.ts +12 -2
- package/src/cjs/Vector.js +15 -2
- package/src/cjs/Vector.js.map +1 -1
- package/src/cjs/VertTuple.d.ts +28 -4
- package/src/cjs/VertTuple.js +36 -3
- package/src/cjs/VertTuple.js.map +1 -1
- package/src/cjs/Vertex.d.ts +17 -2
- package/src/cjs/Vertex.js +18 -1
- package/src/cjs/Vertex.js.map +1 -1
- package/src/cjs/interfaces/core.d.ts +39 -0
- package/src/cjs/interfaces/core.js +2 -0
- package/src/cjs/interfaces/core.js.map +1 -1
- package/src/cjs/utils/algorithms/convexPolygonIncircle.d.ts +2 -1
- package/src/cjs/utils/algorithms/convexPolygonIncircle.js +14 -6
- package/src/cjs/utils/algorithms/convexPolygonIncircle.js.map +1 -1
- package/src/cjs/utils/createRandomizedPolygon.d.ts +14 -0
- package/src/cjs/utils/createRandomizedPolygon.js +32 -0
- package/src/cjs/utils/createRandomizedPolygon.js.map +1 -0
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.d.ts +9 -7
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.js +37 -23
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
- package/src/cjs/utils/helpers/CircleSectorHelper.d.ts +10 -1
- package/src/cjs/utils/helpers/CircleSectorHelper.js +19 -20
- package/src/cjs/utils/helpers/CircleSectorHelper.js.map +1 -1
- package/src/cjs/utils/helpers/VEllipseHelper.d.ts +30 -0
- package/src/cjs/utils/helpers/VEllipseHelper.js +86 -0
- package/src/cjs/utils/helpers/VEllipseHelper.js.map +1 -0
- package/src/cjs/utils/helpers/VEllipseSectorHelper.d.ts +42 -3
- package/src/cjs/utils/helpers/VEllipseSectorHelper.js +107 -25
- package/src/cjs/utils/helpers/VEllipseSectorHelper.js.map +1 -1
- package/src/createDemoDrawables.js +3 -1
- package/src/esm/BezierPath.d.ts +41 -5
- package/src/esm/BezierPath.js +50 -2
- package/src/esm/BezierPath.js.map +1 -1
- package/src/esm/Bounds.d.ts +67 -3
- package/src/esm/Bounds.js +101 -3
- package/src/esm/Bounds.js.map +1 -1
- package/src/esm/Circle.d.ts +46 -4
- package/src/esm/Circle.js +79 -3
- package/src/esm/Circle.js.map +1 -1
- package/src/esm/CircleSector.d.ts +51 -2
- package/src/esm/CircleSector.js +108 -3
- package/src/esm/CircleSector.js.map +1 -1
- package/src/esm/CubicBezierCurve.d.ts +113 -7
- package/src/esm/CubicBezierCurve.js +277 -33
- package/src/esm/CubicBezierCurve.js.map +1 -1
- package/src/esm/Line.d.ts +38 -3
- package/src/esm/Line.js +62 -1
- package/src/esm/Line.js.map +1 -1
- package/src/esm/PlotBoilerplate.js +2 -9
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/Polygon.d.ts +48 -4
- package/src/esm/Polygon.js +89 -16
- package/src/esm/Polygon.js.map +1 -1
- package/src/esm/Triangle.d.ts +52 -3
- package/src/esm/Triangle.js +77 -1
- package/src/esm/Triangle.js.map +1 -1
- package/src/esm/VEllipse.d.ts +62 -3
- package/src/esm/VEllipse.js +178 -17
- package/src/esm/VEllipse.js.map +1 -1
- package/src/esm/VEllipseSector.d.ts +86 -2
- package/src/esm/VEllipseSector.js +146 -7
- package/src/esm/VEllipseSector.js.map +1 -1
- package/src/esm/Vector.d.ts +12 -2
- package/src/esm/Vector.js +15 -2
- package/src/esm/Vector.js.map +1 -1
- package/src/esm/VertTuple.d.ts +28 -4
- package/src/esm/VertTuple.js +36 -3
- package/src/esm/VertTuple.js.map +1 -1
- package/src/esm/Vertex.d.ts +17 -2
- package/src/esm/Vertex.js +18 -1
- package/src/esm/Vertex.js.map +1 -1
- package/src/esm/interfaces/core.d.ts +39 -0
- package/src/esm/interfaces/core.js +2 -0
- package/src/esm/interfaces/core.js.map +1 -1
- package/src/esm/utils/algorithms/convexPolygonIncircle.d.ts +2 -1
- package/src/esm/utils/algorithms/convexPolygonIncircle.js +15 -7
- package/src/esm/utils/algorithms/convexPolygonIncircle.js.map +1 -1
- package/src/esm/utils/algorithms/createRandomizedPolygon.d.ts +14 -0
- package/src/esm/utils/algorithms/createRandomizedPolygon.js +28 -0
- package/src/esm/utils/algorithms/createRandomizedPolygon.js.map +1 -0
- package/src/esm/utils/createRandomizedPolygon.d.ts +14 -0
- package/src/esm/utils/createRandomizedPolygon.js +28 -0
- package/src/esm/utils/createRandomizedPolygon.js.map +1 -0
- package/src/esm/utils/helpers/BezierPathInteractionHelper.d.ts +9 -7
- package/src/esm/utils/helpers/BezierPathInteractionHelper.js +35 -22
- package/src/esm/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
- package/src/esm/utils/helpers/CircleSectorHelper.d.ts +10 -1
- package/src/esm/utils/helpers/CircleSectorHelper.js +19 -20
- package/src/esm/utils/helpers/CircleSectorHelper.js.map +1 -1
- package/src/esm/utils/helpers/VEllipseHelper.d.ts +30 -0
- package/src/esm/utils/helpers/VEllipseHelper.js +81 -0
- package/src/esm/utils/helpers/VEllipseHelper.js.map +1 -0
- package/src/esm/utils/helpers/VEllipseSectorHelper.d.ts +42 -3
- package/src/esm/utils/helpers/VEllipseSectorHelper.js +106 -24
- package/src/esm/utils/helpers/VEllipseSectorHelper.js.map +1 -1
- package/src/ts/BezierPath.ts +58 -5
- package/src/ts/Bounds.ts +110 -6
- package/src/ts/Circle.ts +87 -5
- package/src/ts/CircleSector.ts +115 -5
- package/src/ts/CubicBezierCurve.ts +332 -42
- package/src/ts/Line.ts +66 -3
- package/src/ts/PlotBoilerplate.ts +3 -9
- package/src/ts/Polygon.ts +103 -22
- package/src/ts/Triangle.ts +85 -3
- package/src/ts/VEllipse.ts +214 -19
- package/src/ts/VEllipseSector.ts +154 -8
- package/src/ts/Vector.ts +16 -2
- package/src/ts/VertTuple.ts +39 -4
- package/src/ts/Vertex.ts +20 -2
- package/src/ts/interfaces/core.ts +42 -0
- package/src/ts/utils/algorithms/convexPolygonIncircle.ts +82 -78
- package/src/ts/utils/createRandomizedPolygon.ts +31 -0
- package/src/ts/utils/helpers/BezierPathInteractionHelper.ts +45 -29
- package/src/ts/utils/helpers/CircleSectorHelper.ts +115 -125
- package/src/ts/utils/helpers/VEllipseHelper.ts +113 -0
- package/src/ts/utils/helpers/VEllipseSectorHelper.ts +142 -25
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CircleSector.js","sourceRoot":"","sources":["../ts/CircleSector.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"CircleSector.js","sourceRoot":"","sources":["../ts/CircleSector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;IAeI;AAEJ,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC;;;;;;;;IAQI;AACJ,MAAM,OAAO,YAAY;IA6CvB;;;;;;;;OAQG;IACH,YAAY,MAAc,EAAE,UAAkB,EAAE,QAAgB;QArDhE;;YAEI;QACK,cAAS,GAAW,cAAc,CAAC;QAmD1C,IAAI,CAAC,GAAG,GAAG,YAAY,CAAC,IAAI,EAAE,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,8CAA8C;IAC9C;;;;;;;;;;QAUI;IACJ,SAAS;QACP,MAAM,KAAK,GAAG,IAAI,CAAC;QACnB,MAAM,YAAY,GAAY,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;QACtD,4FAA4F;QAC5F,MAAM,UAAU,GAAmB;YACjC,YA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CAAC,CAAC,CAAC,CAAC;QAC7E,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,AA9EuB,CA8EtB"}
|
|
@@ -23,14 +23,26 @@
|
|
|
23
23
|
* @modified 2022-10-17 The `CubicBezierCurve` class now implements the new `PathSegment` interface.
|
|
24
24
|
* @modified 2023-09-30 Added the function `CubicbezierCurve.getSubCurve(number,number)` – similar to `getSubCurveAt(...)` but with absolute position parameters.
|
|
25
25
|
* @modified 2023-10-07 Added the `trimEnd`, `trimEndAt`, `trimStart`, `trimStartAt` methods.
|
|
26
|
-
* @
|
|
26
|
+
* @modified 2025-04-09 Added the `CubicBezierCurve.move` method to match the convention – which just calls `translate`.
|
|
27
|
+
* @modified 2025-04-09 Modified the `CubicBezierCurve.translate` method: chaning parameter `Vertex` to more generalized `XYCoords`.
|
|
28
|
+
* @modified 2025-04-13 Changed visibility of `CubicBezierCurve.utils` from 'private' to 'public'.
|
|
29
|
+
* @modified 2025-04-13 Added helper function `CubicBezierCurve.utils.bezierCoeffs`.
|
|
30
|
+
* @modified 2025-04-13 Added helper functopn `CubicBezierCurve.utils.sgn(number)` for division safe sign calculation.
|
|
31
|
+
* @modified 2025-03-13 Class `CubicBezierCurve` is now implementing interface `Intersectable`.
|
|
32
|
+
* @modified 2025-04-18 Added evaluation method for cubic Bézier curves `CubicBezierCurve.utils.evaluateT`.
|
|
33
|
+
* @modified 2025-04-18 Refactored method `CubicBezierCurve.getPointAt` to use `evaluateT`.
|
|
34
|
+
* @modified 2025-04-18 Fixed the `CubicBezierCurve.getBounds` method: now returning the real bounding box. Before it was an approximated one.
|
|
35
|
+
* @modified 2025-ß4-18 Added helper methods for bounding box calculation `CubucBezierCurve.util.cubicPolyMinMax` and `cubicPoly`.
|
|
36
|
+
* @version 2.9.0
|
|
27
37
|
*
|
|
28
38
|
* @file CubicBezierCurve
|
|
29
39
|
* @public
|
|
30
40
|
**/
|
|
31
41
|
import { Bounds } from "./Bounds";
|
|
32
42
|
import { Vertex } from "./Vertex";
|
|
33
|
-
import {
|
|
43
|
+
import { Vector } from "./Vector";
|
|
44
|
+
import { XYCoords, UID, PathSegment, Intersectable, IBounded } from "./interfaces";
|
|
45
|
+
import { VertTuple } from "./VertTuple";
|
|
34
46
|
/**
|
|
35
47
|
* @classdesc A refactored cubic bezier curve class.
|
|
36
48
|
*
|
|
@@ -41,7 +53,7 @@ import { XYCoords, UID, PathSegment } from "./interfaces";
|
|
|
41
53
|
* @requires UID
|
|
42
54
|
* @requires UIDGenerator
|
|
43
55
|
*/
|
|
44
|
-
export declare class CubicBezierCurve implements PathSegment {
|
|
56
|
+
export declare class CubicBezierCurve implements IBounded, Intersectable, PathSegment {
|
|
45
57
|
/** @constant {number} */
|
|
46
58
|
static readonly START_POINT: number;
|
|
47
59
|
/** @constant {number} */
|
|
@@ -151,12 +163,22 @@ export declare class CubicBezierCurve implements PathSegment {
|
|
|
151
163
|
* Translate the whole curve by the given {x,y} amount: moves all four points.
|
|
152
164
|
*
|
|
153
165
|
* @method translate
|
|
154
|
-
* @param {
|
|
166
|
+
* @param {XYCoords} amount - The amount to translate this curve by.
|
|
155
167
|
* @instance
|
|
156
168
|
* @memberof CubicBezierCurve
|
|
157
169
|
* @return {CubicBezierCurve} this (for chaining).
|
|
158
170
|
**/
|
|
159
|
-
translate(amount:
|
|
171
|
+
translate(amount: XYCoords): CubicBezierCurve;
|
|
172
|
+
/**
|
|
173
|
+
* Translate the whole curve by the given {x,y} amount: moves all four points.
|
|
174
|
+
*
|
|
175
|
+
* @method translate
|
|
176
|
+
* @param {XYCoords} amount - The amount to translate this curve by.
|
|
177
|
+
* @instance
|
|
178
|
+
* @memberof CubicBezierCurve
|
|
179
|
+
* @return {CubicBezierCurve} this (for chaining).
|
|
180
|
+
**/
|
|
181
|
+
move(amount: XYCoords): CubicBezierCurve;
|
|
160
182
|
/**
|
|
161
183
|
* Reverse this curve, means swapping start- and end-point and swapping
|
|
162
184
|
* start-control- and end-control-point.
|
|
@@ -203,6 +225,9 @@ export declare class CubicBezierCurve implements PathSegment {
|
|
|
203
225
|
*
|
|
204
226
|
* This function uses a recursive approach by cutting the curve into several linear segments.
|
|
205
227
|
*
|
|
228
|
+
* @method getClosestT
|
|
229
|
+
* @instance
|
|
230
|
+
* @memberof CubicBezierCurve
|
|
206
231
|
* @param {Vertex} p - The point to find the closest position ('t' on the curve).
|
|
207
232
|
* @return {number}
|
|
208
233
|
**/
|
|
@@ -228,7 +253,10 @@ export declare class CubicBezierCurve implements PathSegment {
|
|
|
228
253
|
* The bounds are approximated by the underlying segment buffer; the more segment there are,
|
|
229
254
|
* the more accurate will be the returned bounds.
|
|
230
255
|
*
|
|
231
|
-
* @
|
|
256
|
+
* @method getClosestT
|
|
257
|
+
* @instance
|
|
258
|
+
* @memberof CubicBezierCurve
|
|
259
|
+
* @return {Bounds} The bounds of this ellipse.
|
|
232
260
|
**/
|
|
233
261
|
getBounds(): Bounds;
|
|
234
262
|
/**
|
|
@@ -470,6 +498,27 @@ export declare class CubicBezierCurve implements PathSegment {
|
|
|
470
498
|
* @return {Vertex} The end point of the ending point's tangent.
|
|
471
499
|
*/
|
|
472
500
|
getEndTangent(): Vertex;
|
|
501
|
+
/**
|
|
502
|
+
* Get all line intersections with this shape.
|
|
503
|
+
*
|
|
504
|
+
* This method returns all intersections (as vertices) with this shape. The returned array of vertices is in no specific order.
|
|
505
|
+
*
|
|
506
|
+
* @param {VertTuple} line - The line to find intersections with.
|
|
507
|
+
* @param {boolean} inVectorBoundsOnly - If set to true only intersecion points on the passed vector are returned (located strictly between start and end vertex).
|
|
508
|
+
* @returns {Array<Vertex>} - An array of all intersections with the shape outline.
|
|
509
|
+
*/
|
|
510
|
+
lineIntersections(line: VertTuple<any>, inVectorBoundsOnly?: boolean): Array<Vertex>;
|
|
511
|
+
/**
|
|
512
|
+
* Get all line intersections of this polygon and their tangents along the shape.
|
|
513
|
+
*
|
|
514
|
+
* This method returns all intersection tangents (as vectors) with this shape. The returned array of vectors is in no specific order.
|
|
515
|
+
*
|
|
516
|
+
* @param line
|
|
517
|
+
* @param lineIntersectionTangents
|
|
518
|
+
* @returns
|
|
519
|
+
*/
|
|
520
|
+
lineIntersectionTangents(line: VertTuple<any>, inVectorBoundsOnly?: boolean): Array<Vector>;
|
|
521
|
+
lineIntersectionTs(line: VertTuple<any>): Array<number>;
|
|
473
522
|
/**
|
|
474
523
|
* Check if this and the specified curve are equal.<br>
|
|
475
524
|
* <br>
|
|
@@ -546,5 +595,62 @@ export declare class CubicBezierCurve implements PathSegment {
|
|
|
546
595
|
/**
|
|
547
596
|
* Helper utils.
|
|
548
597
|
*/
|
|
549
|
-
|
|
598
|
+
static utils: {
|
|
599
|
+
evaluateT: (p0: number, p1: number, p2: number, p3: number, t: number) => number;
|
|
600
|
+
cubicPolyMinMax: (p0: number, p1: number, p2: number, p3: number) => {
|
|
601
|
+
min: number;
|
|
602
|
+
max: number;
|
|
603
|
+
};
|
|
604
|
+
/**
|
|
605
|
+
* Get the points of a sub curve at the given start end end offsets (values between 0.0 and 1.0).
|
|
606
|
+
*
|
|
607
|
+
* tStart >= tEnd is allowed, you will get a reversed sub curve then.
|
|
608
|
+
*
|
|
609
|
+
* @method getSubCurvePointsAt
|
|
610
|
+
* @param {CubicBezierCurve} curve – The curve to get the sub curve points from.
|
|
611
|
+
* @param {number} tStart – The start offset of the desired sub curve (must be in [0..1]).
|
|
612
|
+
* @param {number} tEnd – The end offset if the desired cub curve (must be in [0..1]).
|
|
613
|
+
* @instance
|
|
614
|
+
* @memberof CubicBezierCurve
|
|
615
|
+
* @return {CubicBezierCurve} The sub curve as a new curve.
|
|
616
|
+
**/
|
|
617
|
+
getSubCurvePointsAt: (curve: CubicBezierCurve, tStart: number, tEnd: number) => [Vertex, Vertex, Vertex, Vertex];
|
|
618
|
+
/**
|
|
619
|
+
* Compute the cubic roots for the given cubic polynomial coefficients.
|
|
620
|
+
*
|
|
621
|
+
* Based on
|
|
622
|
+
* http://mysite.verizon.net/res148h4j/javascript/script_exact_cubic.html#the%20source%20code
|
|
623
|
+
* Inspired by
|
|
624
|
+
* https://www.particleincell.com/2013/cubic-line-intersection/
|
|
625
|
+
* Thanks to Stephan Schmitt and Particle-In-Cell!
|
|
626
|
+
*
|
|
627
|
+
* @param poly
|
|
628
|
+
* @returns
|
|
629
|
+
*/
|
|
630
|
+
cubicRoots: (poly: number[]) => number[];
|
|
631
|
+
/**
|
|
632
|
+
* Compute the Bézier coefficients from the given Bézier point coordinates.
|
|
633
|
+
*
|
|
634
|
+
* @param {number} p0 - The start point coordinate.
|
|
635
|
+
* @param {number} p1 - The start control point coordinate.
|
|
636
|
+
* @param {number} p2 - The end control point coordinate.
|
|
637
|
+
* @param {number} p3 - The end point coordinate.
|
|
638
|
+
* @returns {[number,number,number,number]}
|
|
639
|
+
*/
|
|
640
|
+
bezierCoeffs: (p0: number, p1: number, p2: number, p3: number) => [number, number, number, number];
|
|
641
|
+
/**
|
|
642
|
+
* Calculate the cubic polynomial coefficients used to find the bounding box.
|
|
643
|
+
*
|
|
644
|
+
* @param {number} p0 - The start point coordinate.
|
|
645
|
+
* @param {number} p1 - The start control point coordinate.
|
|
646
|
+
* @param {number} p2 - The end control point coordinate.
|
|
647
|
+
* @param {number} p3 - The end point coordinate.
|
|
648
|
+
* @returns {[number,number,number]}
|
|
649
|
+
*/
|
|
650
|
+
cubicPoly: (p0: number, p1: number, p2: number, p3: number) => [number, number, number];
|
|
651
|
+
/**
|
|
652
|
+
* sign of number, but is division safe: no zero returned :)
|
|
653
|
+
*/
|
|
654
|
+
sgn(x: number): number;
|
|
655
|
+
};
|
|
550
656
|
}
|
|
@@ -23,7 +23,17 @@
|
|
|
23
23
|
* @modified 2022-10-17 The `CubicBezierCurve` class now implements the new `PathSegment` interface.
|
|
24
24
|
* @modified 2023-09-30 Added the function `CubicbezierCurve.getSubCurve(number,number)` – similar to `getSubCurveAt(...)` but with absolute position parameters.
|
|
25
25
|
* @modified 2023-10-07 Added the `trimEnd`, `trimEndAt`, `trimStart`, `trimStartAt` methods.
|
|
26
|
-
* @
|
|
26
|
+
* @modified 2025-04-09 Added the `CubicBezierCurve.move` method to match the convention – which just calls `translate`.
|
|
27
|
+
* @modified 2025-04-09 Modified the `CubicBezierCurve.translate` method: chaning parameter `Vertex` to more generalized `XYCoords`.
|
|
28
|
+
* @modified 2025-04-13 Changed visibility of `CubicBezierCurve.utils` from 'private' to 'public'.
|
|
29
|
+
* @modified 2025-04-13 Added helper function `CubicBezierCurve.utils.bezierCoeffs`.
|
|
30
|
+
* @modified 2025-04-13 Added helper functopn `CubicBezierCurve.utils.sgn(number)` for division safe sign calculation.
|
|
31
|
+
* @modified 2025-03-13 Class `CubicBezierCurve` is now implementing interface `Intersectable`.
|
|
32
|
+
* @modified 2025-04-18 Added evaluation method for cubic Bézier curves `CubicBezierCurve.utils.evaluateT`.
|
|
33
|
+
* @modified 2025-04-18 Refactored method `CubicBezierCurve.getPointAt` to use `evaluateT`.
|
|
34
|
+
* @modified 2025-04-18 Fixed the `CubicBezierCurve.getBounds` method: now returning the real bounding box. Before it was an approximated one.
|
|
35
|
+
* @modified 2025-ß4-18 Added helper methods for bounding box calculation `CubucBezierCurve.util.cubicPolyMinMax` and `cubicPoly`.
|
|
36
|
+
* @version 2.9.0
|
|
27
37
|
*
|
|
28
38
|
* @file CubicBezierCurve
|
|
29
39
|
* @public
|
|
@@ -116,7 +126,7 @@ export class CubicBezierCurve {
|
|
|
116
126
|
* Translate the whole curve by the given {x,y} amount: moves all four points.
|
|
117
127
|
*
|
|
118
128
|
* @method translate
|
|
119
|
-
* @param {
|
|
129
|
+
* @param {XYCoords} amount - The amount to translate this curve by.
|
|
120
130
|
* @instance
|
|
121
131
|
* @memberof CubicBezierCurve
|
|
122
132
|
* @return {CubicBezierCurve} this (for chaining).
|
|
@@ -128,6 +138,18 @@ export class CubicBezierCurve {
|
|
|
128
138
|
this.endPoint.add(amount);
|
|
129
139
|
return this;
|
|
130
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Translate the whole curve by the given {x,y} amount: moves all four points.
|
|
143
|
+
*
|
|
144
|
+
* @method translate
|
|
145
|
+
* @param {XYCoords} amount - The amount to translate this curve by.
|
|
146
|
+
* @instance
|
|
147
|
+
* @memberof CubicBezierCurve
|
|
148
|
+
* @return {CubicBezierCurve} this (for chaining).
|
|
149
|
+
**/
|
|
150
|
+
move(amount) {
|
|
151
|
+
return this.translate(amount);
|
|
152
|
+
}
|
|
131
153
|
/**
|
|
132
154
|
* Reverse this curve, means swapping start- and end-point and swapping
|
|
133
155
|
* start-control- and end-control-point.
|
|
@@ -208,6 +230,9 @@ export class CubicBezierCurve {
|
|
|
208
230
|
*
|
|
209
231
|
* This function uses a recursive approach by cutting the curve into several linear segments.
|
|
210
232
|
*
|
|
233
|
+
* @method getClosestT
|
|
234
|
+
* @instance
|
|
235
|
+
* @memberof CubicBezierCurve
|
|
211
236
|
* @param {Vertex} p - The point to find the closest position ('t' on the curve).
|
|
212
237
|
* @return {number}
|
|
213
238
|
**/
|
|
@@ -257,27 +282,35 @@ export class CubicBezierCurve {
|
|
|
257
282
|
tNext: tStart + tDiff * (Math.min(stepCount, minIndex + 1) / stepCount)
|
|
258
283
|
};
|
|
259
284
|
}
|
|
285
|
+
//--- BEGIN --- Implement interface `IBounded`
|
|
260
286
|
/**
|
|
261
287
|
* Get the bounds of this bezier curve.
|
|
262
288
|
*
|
|
263
289
|
* The bounds are approximated by the underlying segment buffer; the more segment there are,
|
|
264
290
|
* the more accurate will be the returned bounds.
|
|
265
291
|
*
|
|
266
|
-
* @
|
|
292
|
+
* @method getClosestT
|
|
293
|
+
* @instance
|
|
294
|
+
* @memberof CubicBezierCurve
|
|
295
|
+
* @return {Bounds} The bounds of this ellipse.
|
|
267
296
|
**/
|
|
268
297
|
getBounds() {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
298
|
+
// Thanks to Richard "RM" for the Bézier bounds calculatin
|
|
299
|
+
// https://jsfiddle.net/SalixAlba/QQnvm/4/
|
|
300
|
+
const xMinMax = CubicBezierCurve.utils.cubicPolyMinMax(this.startPoint.x, this.startControlPoint.x, this.endControlPoint.x, this.endPoint.x);
|
|
301
|
+
const xl = xMinMax.min;
|
|
302
|
+
const xh = xMinMax.max;
|
|
303
|
+
const yMinMax = CubicBezierCurve.utils.cubicPolyMinMax(this.startPoint.y, this.startControlPoint.y, this.endControlPoint.y, this.endPoint.y);
|
|
304
|
+
const yl = yMinMax.min;
|
|
305
|
+
const yh = yMinMax.max;
|
|
306
|
+
return Bounds.computeFromVertices([
|
|
307
|
+
{ x: xl, y: yl },
|
|
308
|
+
{ x: xl, y: yh },
|
|
309
|
+
{ x: xh, y: yh },
|
|
310
|
+
{ x: xh, y: yl }
|
|
311
|
+
]);
|
|
280
312
|
}
|
|
313
|
+
//--- END --- Implement interface `IBounded`
|
|
281
314
|
/**
|
|
282
315
|
* Get the start point of the curve.<br>
|
|
283
316
|
* <br>
|
|
@@ -364,14 +397,19 @@ export class CubicBezierCurve {
|
|
|
364
397
|
**/
|
|
365
398
|
getPointAt(t) {
|
|
366
399
|
// Perform some powerful math magic
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
400
|
+
// TODO: cleanup
|
|
401
|
+
// const x: number =
|
|
402
|
+
// this.startPoint.x * Math.pow(1.0 - t, 3) +
|
|
403
|
+
// this.startControlPoint.x * 3 * t * Math.pow(1.0 - t, 2) +
|
|
404
|
+
// this.endControlPoint.x * 3 * Math.pow(t, 2) * (1.0 - t) +
|
|
405
|
+
// this.endPoint.x * Math.pow(t, 3);
|
|
406
|
+
// const y: number =
|
|
407
|
+
// this.startPoint.y * Math.pow(1.0 - t, 3) +
|
|
408
|
+
// this.startControlPoint.y * 3 * t * Math.pow(1.0 - t, 2) +
|
|
409
|
+
// this.endControlPoint.y * 3 * Math.pow(t, 2) * (1.0 - t) +
|
|
410
|
+
// this.endPoint.y * Math.pow(t, 3);
|
|
411
|
+
const x = CubicBezierCurve.utils.evaluateT(this.startPoint.x, this.startControlPoint.x, this.endControlPoint.x, this.endPoint.x, t);
|
|
412
|
+
const y = CubicBezierCurve.utils.evaluateT(this.startPoint.y, this.startControlPoint.y, this.endControlPoint.y, this.endPoint.y, t);
|
|
375
413
|
return new Vertex(x, y);
|
|
376
414
|
}
|
|
377
415
|
/**
|
|
@@ -512,17 +550,7 @@ export class CubicBezierCurve {
|
|
|
512
550
|
* @return {CubicBezierCurve} The sub curve as a new curve.
|
|
513
551
|
**/
|
|
514
552
|
getSubCurveAt(tStart, tEnd) {
|
|
515
|
-
//
|
|
516
|
-
// const endVec: Vector = new Vector(this.getPointAt(tEnd), this.getTangentAt(tEnd).inv());
|
|
517
|
-
// // Tangents are relative. Make absolute.
|
|
518
|
-
// startVec.b.add(startVec.a);
|
|
519
|
-
// endVec.b.add(endVec.a);
|
|
520
|
-
// // This 'splits' the curve at the given point at t.
|
|
521
|
-
// startVec.scale(0.33333333 * (tEnd - tStart));
|
|
522
|
-
// endVec.scale(0.33333333 * (tEnd - tStart));
|
|
523
|
-
// // Draw the bezier curve
|
|
524
|
-
// // pb.draw.cubicBezier( startVec.a, endVec.a, startVec.b, endVec.b, '#8800ff', 2 );
|
|
525
|
-
// return new CubicBezierCurve(startVec.a, endVec.a, startVec.b, endVec.b);
|
|
553
|
+
// This 'splits' the curve at the given point at t.
|
|
526
554
|
const subCurbePoints = CubicBezierCurve.utils.getSubCurvePointsAt(this, tStart, tEnd);
|
|
527
555
|
return new CubicBezierCurve(subCurbePoints[0], subCurbePoints[1], subCurbePoints[2], subCurbePoints[3]);
|
|
528
556
|
}
|
|
@@ -614,6 +642,69 @@ export class CubicBezierCurve {
|
|
|
614
642
|
return this.endControlPoint;
|
|
615
643
|
}
|
|
616
644
|
//---END PathSegment-------------------------
|
|
645
|
+
//--- BEGIN --- Implement interface `Intersectable`
|
|
646
|
+
/**
|
|
647
|
+
* Get all line intersections with this shape.
|
|
648
|
+
*
|
|
649
|
+
* This method returns all intersections (as vertices) with this shape. The returned array of vertices is in no specific order.
|
|
650
|
+
*
|
|
651
|
+
* @param {VertTuple} line - The line to find intersections with.
|
|
652
|
+
* @param {boolean} inVectorBoundsOnly - If set to true only intersecion points on the passed vector are returned (located strictly between start and end vertex).
|
|
653
|
+
* @returns {Array<Vertex>} - An array of all intersections with the shape outline.
|
|
654
|
+
*/
|
|
655
|
+
lineIntersections(line, inVectorBoundsOnly = false) {
|
|
656
|
+
const intersectionTs = this.lineIntersectionTs(line);
|
|
657
|
+
const intersectionPoints = intersectionTs.map((t) => {
|
|
658
|
+
return this.getPointAt(t);
|
|
659
|
+
});
|
|
660
|
+
if (inVectorBoundsOnly) {
|
|
661
|
+
// const maxDist = line.length();
|
|
662
|
+
return intersectionPoints.filter((vert) => line.hasPoint(vert, true));
|
|
663
|
+
}
|
|
664
|
+
else {
|
|
665
|
+
return intersectionPoints;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* Get all line intersections of this polygon and their tangents along the shape.
|
|
670
|
+
*
|
|
671
|
+
* This method returns all intersection tangents (as vectors) with this shape. The returned array of vectors is in no specific order.
|
|
672
|
+
*
|
|
673
|
+
* @param line
|
|
674
|
+
* @param lineIntersectionTangents
|
|
675
|
+
* @returns
|
|
676
|
+
*/
|
|
677
|
+
lineIntersectionTangents(line, inVectorBoundsOnly = false) {
|
|
678
|
+
const intersectionTs = this.lineIntersectionTs(line);
|
|
679
|
+
const intersectionTangents = intersectionTs.map((t) => {
|
|
680
|
+
const startPoint = this.getPointAt(t);
|
|
681
|
+
const endPoint = this.getTangentAt(t);
|
|
682
|
+
return new Vector(startPoint, endPoint.add(startPoint));
|
|
683
|
+
});
|
|
684
|
+
if (inVectorBoundsOnly) {
|
|
685
|
+
return intersectionTangents.filter((vec) => line.hasPoint(vec.a, true));
|
|
686
|
+
}
|
|
687
|
+
else {
|
|
688
|
+
return intersectionTangents;
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
//--- END --- Implement interface `Intersectable`
|
|
692
|
+
lineIntersectionTs(line) {
|
|
693
|
+
var A = line.b.y - line.a.y; // A=y2-y1
|
|
694
|
+
var B = line.a.x - line.b.x; // B=x1-x2
|
|
695
|
+
var C = line.a.x * (line.a.y - line.b.y) + line.a.y * (line.b.x - line.a.x); //C=x1*(y1-y2)+y1*(x2-x1)
|
|
696
|
+
// var bx = bezierCoeffs(px[0], px[1], px[2], px[3]);
|
|
697
|
+
// var by = bezierCoeffs(py[0], py[1], py[2], py[3]);
|
|
698
|
+
var bx = CubicBezierCurve.utils.bezierCoeffs(this.startPoint.x, this.startControlPoint.x, this.endControlPoint.x, this.endPoint.x);
|
|
699
|
+
var by = CubicBezierCurve.utils.bezierCoeffs(this.startPoint.y, this.startControlPoint.y, this.endControlPoint.y, this.endPoint.y);
|
|
700
|
+
const poly = Array(4);
|
|
701
|
+
poly[0] = A * bx[0] + B * by[0]; /*t^3*/
|
|
702
|
+
poly[1] = A * bx[1] + B * by[1]; /*t^2*/
|
|
703
|
+
poly[2] = A * bx[2] + B * by[2]; /*t*/
|
|
704
|
+
poly[3] = A * bx[3] + B * by[3] + C; /*1*/
|
|
705
|
+
var roots = CubicBezierCurve.utils.cubicRoots(poly);
|
|
706
|
+
return roots.filter((root) => root != -1);
|
|
707
|
+
}
|
|
617
708
|
/**
|
|
618
709
|
* Check if this and the specified curve are equal.<br>
|
|
619
710
|
* <br>
|
|
@@ -781,6 +872,71 @@ CubicBezierCurve.END_POINT = 3;
|
|
|
781
872
|
* Helper utils.
|
|
782
873
|
*/
|
|
783
874
|
CubicBezierCurve.utils = {
|
|
875
|
+
evaluateT: (p0, p1, p2, p3, t) => {
|
|
876
|
+
return p0 * Math.pow(1.0 - t, 3) +
|
|
877
|
+
p1 * 3 * t * Math.pow(1.0 - t, 2) +
|
|
878
|
+
p2 * 3 * Math.pow(t, 2) * (1.0 - t) +
|
|
879
|
+
p3 * Math.pow(t, 3);
|
|
880
|
+
},
|
|
881
|
+
cubicPolyMinMax: (p0, p1, p2, p3) => {
|
|
882
|
+
// var polyX = CubicBezierCurve.utils.cubicPoly2(
|
|
883
|
+
// p0, // P[0].X, // bezierCurve.startPoint.x,
|
|
884
|
+
// p1, // P[1].X, // bezierCurve.startControlPoint.x,
|
|
885
|
+
// p2, // P[2].X, // bezierCurve.endControlPoint.x,
|
|
886
|
+
// p3 // P[3].X // bezierCurve.endPoint.x
|
|
887
|
+
// );
|
|
888
|
+
// var a = polyX.a;
|
|
889
|
+
// var b = polyX.b;
|
|
890
|
+
// var c = polyX.c;
|
|
891
|
+
// var disc = polyX.b * polyX.b - 4 * polyX.a * polyX.c;
|
|
892
|
+
var polyX = CubicBezierCurve.utils.cubicPoly(p0, // P[0].X, // bezierCurve.startPoint.x,
|
|
893
|
+
p1, // P[1].X, // bezierCurve.startControlPoint.x,
|
|
894
|
+
p2, // P[2].X, // bezierCurve.endControlPoint.x,
|
|
895
|
+
p3 // P[3].X // bezierCurve.endPoint.x
|
|
896
|
+
);
|
|
897
|
+
var a = polyX[0]; // .a;
|
|
898
|
+
var b = polyX[1]; // .b;
|
|
899
|
+
var c = polyX[2]; // .c;
|
|
900
|
+
//alert("a "+a+" "+b+" "+c);
|
|
901
|
+
// var disc = b * b - 4 * a * c;
|
|
902
|
+
var disc = polyX[1] * polyX[1] - 4 * polyX[0] * polyX[2];
|
|
903
|
+
// var polyX = CubicBezierCurve.utils.bezierCoeffs(p3,p2,p1,p0);
|
|
904
|
+
// var a = polyX[0]; //polyX.a;
|
|
905
|
+
// var b = polyX[1]; // .b;
|
|
906
|
+
// var c = polyX[2]; //.c;
|
|
907
|
+
// var disc = polyX[1] * polyX[1] - 4 * polyX[0] * polyX[2];
|
|
908
|
+
// var xl = Math.min(bCurve.endPoint.x, bCurve.startPoint.x); // P[0].X;
|
|
909
|
+
// var xh = Math.max(bCurve.endPoint.x, bCurve.startPoint.x); // P[0].X;
|
|
910
|
+
var xl = Math.min(p3, p0); // P[0].X;
|
|
911
|
+
var xh = Math.max(p3, p0); // P[0].X;
|
|
912
|
+
// if (P[3].X < xl) xl = P[3].X;
|
|
913
|
+
// if (P[3].X > xh) xh = P[3].X;
|
|
914
|
+
if (disc >= 0) {
|
|
915
|
+
var t1 = (-b + Math.sqrt(disc)) / (2 * a);
|
|
916
|
+
// alert("t1 " + t1);
|
|
917
|
+
if (t1 > 0 && t1 < 1) {
|
|
918
|
+
// var x1 = evalBez(PX, t1);
|
|
919
|
+
// var x1 = bCurve.getPointAt(t1).x;
|
|
920
|
+
var x1 = CubicBezierCurve.utils.evaluateT(p0, p1, p2, p3, t1); // bCurve.getPointAt(t1).x;
|
|
921
|
+
if (x1 < xl)
|
|
922
|
+
xl = x1;
|
|
923
|
+
if (x1 > xh)
|
|
924
|
+
xh = x1;
|
|
925
|
+
}
|
|
926
|
+
var t2 = (-b - Math.sqrt(disc)) / (2 * a);
|
|
927
|
+
// alert("t2 " + t2);
|
|
928
|
+
if (t2 > 0 && t2 < 1) {
|
|
929
|
+
// var x2 = evalBez(PX, t2);
|
|
930
|
+
// var x2 = bCurve.getPointAt(t2).x;
|
|
931
|
+
var x2 = CubicBezierCurve.utils.evaluateT(p0, p1, p2, p3, t2); //
|
|
932
|
+
if (x2 < xl)
|
|
933
|
+
xl = x2;
|
|
934
|
+
if (x2 > xh)
|
|
935
|
+
xh = x2;
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
return { min: xl, max: xh };
|
|
939
|
+
},
|
|
784
940
|
/**
|
|
785
941
|
* Get the points of a sub curve at the given start end end offsets (values between 0.0 and 1.0).
|
|
786
942
|
*
|
|
@@ -804,6 +960,94 @@ CubicBezierCurve.utils = {
|
|
|
804
960
|
startVec.scale(0.33333333 * (tEnd - tStart));
|
|
805
961
|
endVec.scale(0.33333333 * (tEnd - tStart));
|
|
806
962
|
return [startVec.a, endVec.a, startVec.b, endVec.b];
|
|
963
|
+
},
|
|
964
|
+
/**
|
|
965
|
+
* Compute the cubic roots for the given cubic polynomial coefficients.
|
|
966
|
+
*
|
|
967
|
+
* Based on
|
|
968
|
+
* http://mysite.verizon.net/res148h4j/javascript/script_exact_cubic.html#the%20source%20code
|
|
969
|
+
* Inspired by
|
|
970
|
+
* https://www.particleincell.com/2013/cubic-line-intersection/
|
|
971
|
+
* Thanks to Stephan Schmitt and Particle-In-Cell!
|
|
972
|
+
*
|
|
973
|
+
* @param poly
|
|
974
|
+
* @returns
|
|
975
|
+
*/
|
|
976
|
+
cubicRoots: (poly) => {
|
|
977
|
+
const a = poly[0];
|
|
978
|
+
const b = poly[1];
|
|
979
|
+
const c = poly[2];
|
|
980
|
+
const d = poly[3];
|
|
981
|
+
const A = b / a;
|
|
982
|
+
const B = c / a;
|
|
983
|
+
const C = d / a;
|
|
984
|
+
var S, T, Im;
|
|
985
|
+
const Q = (3 * B - Math.pow(A, 2)) / 9;
|
|
986
|
+
const R = (9 * A * B - 27 * C - 2 * Math.pow(A, 3)) / 54;
|
|
987
|
+
const D = Math.pow(Q, 3) + Math.pow(R, 2); // polynomial discriminant
|
|
988
|
+
const ts = []; // Array();
|
|
989
|
+
if (D >= 0) {
|
|
990
|
+
// complex or duplicate roots
|
|
991
|
+
S = CubicBezierCurve.utils.sgn(R + Math.sqrt(D)) * Math.pow(Math.abs(R + Math.sqrt(D)), 1 / 3);
|
|
992
|
+
T = CubicBezierCurve.utils.sgn(R - Math.sqrt(D)) * Math.pow(Math.abs(R - Math.sqrt(D)), 1 / 3);
|
|
993
|
+
ts[0] = -A / 3 + (S + T); // real root
|
|
994
|
+
ts[1] = -A / 3 - (S + T) / 2; // real part of complex root
|
|
995
|
+
ts[2] = -A / 3 - (S + T) / 2; // real part of complex root
|
|
996
|
+
Im = Math.abs((Math.sqrt(3) * (S - T)) / 2); // complex part of root pair
|
|
997
|
+
// Mark complex roots to be discarded
|
|
998
|
+
if (Im != 0) {
|
|
999
|
+
ts[1] = -1;
|
|
1000
|
+
ts[2] = -1;
|
|
1001
|
+
}
|
|
1002
|
+
} // distinct real roots
|
|
1003
|
+
else {
|
|
1004
|
+
const th = Math.acos(R / Math.sqrt(-Math.pow(Q, 3)));
|
|
1005
|
+
ts[0] = 2 * Math.sqrt(-Q) * Math.cos(th / 3) - A / 3;
|
|
1006
|
+
ts[1] = 2 * Math.sqrt(-Q) * Math.cos((th + 2 * Math.PI) / 3) - A / 3;
|
|
1007
|
+
ts[2] = 2 * Math.sqrt(-Q) * Math.cos((th + 4 * Math.PI) / 3) - A / 3;
|
|
1008
|
+
Im = 0.0;
|
|
1009
|
+
}
|
|
1010
|
+
// Discard all t's out of spec and sort the rest
|
|
1011
|
+
return ts.filter((t) => t >= 0 && t <= 1.0).sort();
|
|
1012
|
+
},
|
|
1013
|
+
/**
|
|
1014
|
+
* Compute the Bézier coefficients from the given Bézier point coordinates.
|
|
1015
|
+
*
|
|
1016
|
+
* @param {number} p0 - The start point coordinate.
|
|
1017
|
+
* @param {number} p1 - The start control point coordinate.
|
|
1018
|
+
* @param {number} p2 - The end control point coordinate.
|
|
1019
|
+
* @param {number} p3 - The end point coordinate.
|
|
1020
|
+
* @returns {[number,number,number,number]}
|
|
1021
|
+
*/
|
|
1022
|
+
bezierCoeffs: (p0, p1, p2, p3) => {
|
|
1023
|
+
const coeffs = [NaN, NaN, NaN, NaN]; //Array(4);
|
|
1024
|
+
coeffs[0] = -p0 + 3 * p1 + -3 * p2 + p3;
|
|
1025
|
+
coeffs[1] = 3 * p0 - 6 * p1 + 3 * p2;
|
|
1026
|
+
coeffs[2] = -3 * p0 + 3 * p1;
|
|
1027
|
+
coeffs[3] = p0;
|
|
1028
|
+
return coeffs;
|
|
1029
|
+
},
|
|
1030
|
+
/**
|
|
1031
|
+
* Calculate the cubic polynomial coefficients used to find the bounding box.
|
|
1032
|
+
*
|
|
1033
|
+
* @param {number} p0 - The start point coordinate.
|
|
1034
|
+
* @param {number} p1 - The start control point coordinate.
|
|
1035
|
+
* @param {number} p2 - The end control point coordinate.
|
|
1036
|
+
* @param {number} p3 - The end point coordinate.
|
|
1037
|
+
* @returns {[number,number,number]}
|
|
1038
|
+
*/
|
|
1039
|
+
cubicPoly: (p0, p1, p2, p3) => {
|
|
1040
|
+
return [
|
|
1041
|
+
3 * p3 - 9 * p2 + 9 * p1 - 3 * p0,
|
|
1042
|
+
6 * p0 - 12 * p1 + 6 * p2,
|
|
1043
|
+
3 * p1 - 3 * p0
|
|
1044
|
+
];
|
|
1045
|
+
},
|
|
1046
|
+
/**
|
|
1047
|
+
* sign of number, but is division safe: no zero returned :)
|
|
1048
|
+
*/
|
|
1049
|
+
sgn(x) {
|
|
1050
|
+
return x < 0.0 ? -1 : 1;
|
|
807
1051
|
}
|
|
808
1052
|
};
|
|
809
1053
|
//# sourceMappingURL=CubicBezierCurve.js.map
|