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
package/src/ts/CircleSector.ts
CHANGED
|
@@ -8,14 +8,22 @@
|
|
|
8
8
|
* @modified 2024-03-08 Added the `containsAngle` method.
|
|
9
9
|
* @modified 2024-03-09 Added the `circleSectorIntersection` method to find coherent sector intersections..
|
|
10
10
|
* @modified 2024-03-09 Added the `angleAt` method to determine any angle at some ratio.
|
|
11
|
+
* @modified 2025-04-02 Adding the `CircleSector.lineIntersections` and `CircleSector.lineIntersectionTangents` and implementing `Intersectable`.
|
|
12
|
+
* @modified 2025-04-09 Adding the `CircleSector.move()` method.
|
|
13
|
+
* @modified 2025-04-19 Tweaking the `CircleSector.containsAngle` method: all values (input angle, start- and end- angle) are wrapped into [0,2*PI) now.
|
|
14
|
+
* @modified 2025-04-19 Class `CircleSector` implements interface `Bounded` now (method `getBounds` added).
|
|
11
15
|
* @version 1.2.0
|
|
12
16
|
**/
|
|
13
17
|
|
|
18
|
+
import { Bounds } from "./Bounds";
|
|
14
19
|
import { Circle } from "./Circle";
|
|
15
20
|
import { Line } from "./Line";
|
|
16
21
|
import { UIDGenerator } from "./UIDGenerator";
|
|
22
|
+
import { Vector } from "./Vector";
|
|
23
|
+
import { VertTuple } from "./VertTuple";
|
|
17
24
|
import { Vertex } from "./Vertex";
|
|
18
|
-
import {
|
|
25
|
+
import { geomutils } from "./geomutils";
|
|
26
|
+
import { IBounded, Intersectable, SVGPathParams, SVGSerializable, UID, XYCoords } from "./interfaces";
|
|
19
27
|
|
|
20
28
|
/**
|
|
21
29
|
* @classdesc A simple circle sector: circle, start- and end-angle.
|
|
@@ -26,7 +34,7 @@ import { PathSegment, SVGPathParams, SVGSerializable, UID, XYCoords } from "./in
|
|
|
26
34
|
* @requires UIDGenerator
|
|
27
35
|
* @requires XYCoords
|
|
28
36
|
**/
|
|
29
|
-
export class CircleSector implements SVGSerializable {
|
|
37
|
+
export class CircleSector implements IBounded, Intersectable, SVGSerializable {
|
|
30
38
|
/**
|
|
31
39
|
* Required to generate proper CSS classes and other class related IDs.
|
|
32
40
|
**/
|
|
@@ -87,6 +95,52 @@ export class CircleSector implements SVGSerializable {
|
|
|
87
95
|
this.endAngle = endAngle;
|
|
88
96
|
}
|
|
89
97
|
|
|
98
|
+
//--- BEGIN --- Implement interface `IBounded`
|
|
99
|
+
/**
|
|
100
|
+
* Get the bounds of this ellipse.
|
|
101
|
+
*
|
|
102
|
+
* The bounds are approximated by the underlying segment buffer; the more segment there are,
|
|
103
|
+
* the more accurate will be the returned bounds.
|
|
104
|
+
*
|
|
105
|
+
* @method getBounds
|
|
106
|
+
* @instance
|
|
107
|
+
* @memberof VEllipse
|
|
108
|
+
* @return {Bounds} The bounds of this curve.
|
|
109
|
+
**/
|
|
110
|
+
getBounds(): Bounds {
|
|
111
|
+
const _self = this;
|
|
112
|
+
const circleBounds : Bounds = this.circle.getBounds();
|
|
113
|
+
// Calculage angles from east, west, north and south box points and check if they are inside
|
|
114
|
+
const candidates : Array<Vertex> = [
|
|
115
|
+
circleBounds.getNorthPoint(),
|
|
116
|
+
circleBounds.getSouthPoint(),
|
|
117
|
+
circleBounds.getWestPoint(),
|
|
118
|
+
circleBounds.getEastPoint()
|
|
119
|
+
].filter( (point : Vertex) => {
|
|
120
|
+
// Check for each candidate points if they are contained in this sector. Drop if not.
|
|
121
|
+
const angle : number = new Line(_self.circle.center, point).angle();
|
|
122
|
+
return _self.containsAngle(angle);
|
|
123
|
+
});
|
|
124
|
+
// Compute bounds and inlcude start end end point (they are definitely part of the bounds)
|
|
125
|
+
return Bounds.computeFromVertices(candidates.concat([this.getStartPoint(), this.getEndPoint()]));
|
|
126
|
+
}
|
|
127
|
+
//--- BEGIN --- Implement interface `IBounded`
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Move the circle sector by the given amount.
|
|
132
|
+
*
|
|
133
|
+
* @method move
|
|
134
|
+
* @param {XYCoords} amount - The amount to move.
|
|
135
|
+
* @instance
|
|
136
|
+
* @memberof CircleSector
|
|
137
|
+
* @return {CircleSector} this for chaining
|
|
138
|
+
**/
|
|
139
|
+
move(amount: XYCoords): CircleSector {
|
|
140
|
+
this.circle.move(amount);
|
|
141
|
+
return this;
|
|
142
|
+
}
|
|
143
|
+
|
|
90
144
|
/**
|
|
91
145
|
* Checks wether the given angle (must be inside 0 and PI*2) is contained inside this sector.
|
|
92
146
|
*
|
|
@@ -97,11 +151,21 @@ export class CircleSector implements SVGSerializable {
|
|
|
97
151
|
* @return {boolean} True if (and only if) this sector contains the given angle.
|
|
98
152
|
*/
|
|
99
153
|
containsAngle(angle: number) {
|
|
100
|
-
|
|
101
|
-
|
|
154
|
+
var wrappedAngle = geomutils.mapAngleTo2PI(angle);
|
|
155
|
+
var wrappedStart = geomutils.mapAngleTo2PI(this.startAngle);
|
|
156
|
+
var wrappedEnd = geomutils.mapAngleTo2PI(this.endAngle);
|
|
157
|
+
// TODO: cleanup
|
|
158
|
+
// if (this.startAngle <= this.endAngle) {
|
|
159
|
+
// return angle >= this.startAngle && angle < this.endAngle;
|
|
160
|
+
// } else {
|
|
161
|
+
// // startAngle > endAngle
|
|
162
|
+
// return angle >= this.startAngle || angle < this.endAngle;
|
|
163
|
+
// }
|
|
164
|
+
if (wrappedStart <= wrappedEnd) {
|
|
165
|
+
return wrappedAngle >= wrappedStart && wrappedAngle < wrappedEnd;
|
|
102
166
|
} else {
|
|
103
167
|
// startAngle > endAngle
|
|
104
|
-
return
|
|
168
|
+
return wrappedAngle >= wrappedStart || wrappedAngle < wrappedEnd;
|
|
105
169
|
}
|
|
106
170
|
}
|
|
107
171
|
|
|
@@ -206,6 +270,52 @@ export class CircleSector implements SVGSerializable {
|
|
|
206
270
|
return resultSector;
|
|
207
271
|
}
|
|
208
272
|
|
|
273
|
+
//--- BEGIN --- Implement interface `Intersectable`
|
|
274
|
+
/**
|
|
275
|
+
* Get the line intersections as vectors with this ellipse.
|
|
276
|
+
*
|
|
277
|
+
* @method lineIntersections
|
|
278
|
+
* @instance
|
|
279
|
+
* @param {VertTuple<Vector> ray - The line/ray to intersect this ellipse with.
|
|
280
|
+
* @param {boolean} inVectorBoundsOnly - (default=false) Set to true if only intersections within the vector bounds are of interest.
|
|
281
|
+
* @returns
|
|
282
|
+
*/
|
|
283
|
+
lineIntersections(ray: VertTuple<Vector>, inVectorBoundsOnly: boolean = false): Array<Vertex> {
|
|
284
|
+
// First get all line intersections from underlying ellipse.
|
|
285
|
+
const ellipseIntersections: Array<Vertex> = this.circle.lineIntersections(ray, inVectorBoundsOnly);
|
|
286
|
+
// Drop all intersection points that are not contained in the circle sectors bounds.
|
|
287
|
+
const tmpLine = new Line(this.circle.center, new Vertex());
|
|
288
|
+
return ellipseIntersections.filter((intersectionPoint: Vertex) => {
|
|
289
|
+
tmpLine.b.set(intersectionPoint);
|
|
290
|
+
const lineAngle = tmpLine.angle();
|
|
291
|
+
return this.containsAngle(geomutils.wrapMinMax(lineAngle, 0, Math.PI * 2));
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Get all line intersections of this polygon and their tangents along the shape.
|
|
297
|
+
*
|
|
298
|
+
* This method returns all intersection tangents (as vectors) with this shape. The returned array of vectors is in no specific order.
|
|
299
|
+
*
|
|
300
|
+
* @param line
|
|
301
|
+
* @param lineIntersectionTangents
|
|
302
|
+
* @returns
|
|
303
|
+
*/
|
|
304
|
+
lineIntersectionTangents(line: VertTuple<any>, inVectorBoundsOnly: boolean = false): Array<Vector> {
|
|
305
|
+
// Find the intersections of all lines plus their tangents inside the circle bounds
|
|
306
|
+
const interSectionPoints: Array<Vertex> = this.lineIntersections(line, inVectorBoundsOnly);
|
|
307
|
+
return interSectionPoints.map((vert: Vertex) => {
|
|
308
|
+
// Calculate angle
|
|
309
|
+
const lineFromCenter = new Line(this.circle.center, vert);
|
|
310
|
+
const angle: number = lineFromCenter.angle();
|
|
311
|
+
// console.log("angle", (angle / Math.PI) * 180.0);
|
|
312
|
+
// const angle = Math.random() * Math.PI * 2; // TODO
|
|
313
|
+
// Calculate tangent at angle
|
|
314
|
+
return this.circle.tangentAt(angle);
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
//--- END --- Implement interface `Intersectable`
|
|
318
|
+
|
|
209
319
|
/**
|
|
210
320
|
* This function should invalidate any installed listeners and invalidate this object.
|
|
211
321
|
* After calling this function the object might not hold valid data any more and
|
|
@@ -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
|
|
@@ -33,7 +43,8 @@ import { Bounds } from "./Bounds";
|
|
|
33
43
|
import { UIDGenerator } from "./UIDGenerator";
|
|
34
44
|
import { Vertex } from "./Vertex";
|
|
35
45
|
import { Vector } from "./Vector";
|
|
36
|
-
import { XYCoords, UID, PathSegment } from "./interfaces";
|
|
46
|
+
import { XYCoords, UID, PathSegment, Intersectable, IBounded } from "./interfaces";
|
|
47
|
+
import { VertTuple } from "./VertTuple";
|
|
37
48
|
|
|
38
49
|
/**
|
|
39
50
|
* @classdesc A refactored cubic bezier curve class.
|
|
@@ -45,7 +56,7 @@ import { XYCoords, UID, PathSegment } from "./interfaces";
|
|
|
45
56
|
* @requires UID
|
|
46
57
|
* @requires UIDGenerator
|
|
47
58
|
*/
|
|
48
|
-
export class CubicBezierCurve implements PathSegment {
|
|
59
|
+
export class CubicBezierCurve implements IBounded, Intersectable, PathSegment {
|
|
49
60
|
/** @constant {number} */
|
|
50
61
|
static readonly START_POINT: number = 0;
|
|
51
62
|
/** @constant {number} */
|
|
@@ -200,12 +211,12 @@ export class CubicBezierCurve implements PathSegment {
|
|
|
200
211
|
* Translate the whole curve by the given {x,y} amount: moves all four points.
|
|
201
212
|
*
|
|
202
213
|
* @method translate
|
|
203
|
-
* @param {
|
|
214
|
+
* @param {XYCoords} amount - The amount to translate this curve by.
|
|
204
215
|
* @instance
|
|
205
216
|
* @memberof CubicBezierCurve
|
|
206
217
|
* @return {CubicBezierCurve} this (for chaining).
|
|
207
218
|
**/
|
|
208
|
-
translate(amount:
|
|
219
|
+
translate(amount: XYCoords): CubicBezierCurve {
|
|
209
220
|
this.startPoint.add(amount);
|
|
210
221
|
this.startControlPoint.add(amount);
|
|
211
222
|
this.endControlPoint.add(amount);
|
|
@@ -213,6 +224,19 @@ export class CubicBezierCurve implements PathSegment {
|
|
|
213
224
|
return this;
|
|
214
225
|
}
|
|
215
226
|
|
|
227
|
+
/**
|
|
228
|
+
* Translate the whole curve by the given {x,y} amount: moves all four points.
|
|
229
|
+
*
|
|
230
|
+
* @method translate
|
|
231
|
+
* @param {XYCoords} amount - The amount to translate this curve by.
|
|
232
|
+
* @instance
|
|
233
|
+
* @memberof CubicBezierCurve
|
|
234
|
+
* @return {CubicBezierCurve} this (for chaining).
|
|
235
|
+
**/
|
|
236
|
+
move(amount: XYCoords): CubicBezierCurve {
|
|
237
|
+
return this.translate(amount);
|
|
238
|
+
}
|
|
239
|
+
|
|
216
240
|
/**
|
|
217
241
|
* Reverse this curve, means swapping start- and end-point and swapping
|
|
218
242
|
* start-control- and end-control-point.
|
|
@@ -301,6 +325,9 @@ export class CubicBezierCurve implements PathSegment {
|
|
|
301
325
|
*
|
|
302
326
|
* This function uses a recursive approach by cutting the curve into several linear segments.
|
|
303
327
|
*
|
|
328
|
+
* @method getClosestT
|
|
329
|
+
* @instance
|
|
330
|
+
* @memberof CubicBezierCurve
|
|
304
331
|
* @param {Vertex} p - The point to find the closest position ('t' on the curve).
|
|
305
332
|
* @return {number}
|
|
306
333
|
**/
|
|
@@ -358,27 +385,48 @@ export class CubicBezierCurve implements PathSegment {
|
|
|
358
385
|
};
|
|
359
386
|
}
|
|
360
387
|
|
|
388
|
+
//--- BEGIN --- Implement interface `IBounded`
|
|
361
389
|
/**
|
|
362
390
|
* Get the bounds of this bezier curve.
|
|
363
391
|
*
|
|
364
392
|
* The bounds are approximated by the underlying segment buffer; the more segment there are,
|
|
365
393
|
* the more accurate will be the returned bounds.
|
|
366
394
|
*
|
|
367
|
-
* @
|
|
395
|
+
* @method getClosestT
|
|
396
|
+
* @instance
|
|
397
|
+
* @memberof CubicBezierCurve
|
|
398
|
+
* @return {Bounds} The bounds of this ellipse.
|
|
368
399
|
**/
|
|
369
400
|
getBounds(): Bounds {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
401
|
+
// Thanks to Richard "RM" for the Bézier bounds calculatin
|
|
402
|
+
// https://jsfiddle.net/SalixAlba/QQnvm/4/
|
|
403
|
+
|
|
404
|
+
const xMinMax = CubicBezierCurve.utils.cubicPolyMinMax(
|
|
405
|
+
this.startPoint.x,
|
|
406
|
+
this.startControlPoint.x,
|
|
407
|
+
this.endControlPoint.x,
|
|
408
|
+
this.endPoint.x
|
|
409
|
+
);
|
|
410
|
+
const xl = xMinMax.min;
|
|
411
|
+
const xh = xMinMax.max;
|
|
412
|
+
|
|
413
|
+
const yMinMax = CubicBezierCurve.utils.cubicPolyMinMax(
|
|
414
|
+
this.startPoint.y,
|
|
415
|
+
this.startControlPoint.y,
|
|
416
|
+
this.endControlPoint.y,
|
|
417
|
+
this.endPoint.y
|
|
418
|
+
);
|
|
419
|
+
const yl = yMinMax.min;
|
|
420
|
+
const yh = yMinMax.max;
|
|
421
|
+
|
|
422
|
+
return Bounds.computeFromVertices([
|
|
423
|
+
{ x: xl, y: yl },
|
|
424
|
+
{ x: xl, y: yh },
|
|
425
|
+
{ x: xh, y: yh },
|
|
426
|
+
{ x: xh, y: yl }
|
|
427
|
+
]);
|
|
381
428
|
}
|
|
429
|
+
//--- END --- Implement interface `IBounded`
|
|
382
430
|
|
|
383
431
|
/**
|
|
384
432
|
* Get the start point of the curve.<br>
|
|
@@ -467,16 +515,19 @@ export class CubicBezierCurve implements PathSegment {
|
|
|
467
515
|
**/
|
|
468
516
|
getPointAt(t: number): Vertex {
|
|
469
517
|
// Perform some powerful math magic
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
518
|
+
// TODO: cleanup
|
|
519
|
+
// const x: number =
|
|
520
|
+
// this.startPoint.x * Math.pow(1.0 - t, 3) +
|
|
521
|
+
// this.startControlPoint.x * 3 * t * Math.pow(1.0 - t, 2) +
|
|
522
|
+
// this.endControlPoint.x * 3 * Math.pow(t, 2) * (1.0 - t) +
|
|
523
|
+
// this.endPoint.x * Math.pow(t, 3);
|
|
524
|
+
// const y: number =
|
|
525
|
+
// this.startPoint.y * Math.pow(1.0 - t, 3) +
|
|
526
|
+
// this.startControlPoint.y * 3 * t * Math.pow(1.0 - t, 2) +
|
|
527
|
+
// this.endControlPoint.y * 3 * Math.pow(t, 2) * (1.0 - t) +
|
|
528
|
+
// this.endPoint.y * Math.pow(t, 3);
|
|
529
|
+
const x: number = CubicBezierCurve.utils.evaluateT(this.startPoint.x, this.startControlPoint.x, this.endControlPoint.x, this.endPoint.x, t);
|
|
530
|
+
const y: number = CubicBezierCurve.utils.evaluateT(this.startPoint.y, this.startControlPoint.y, this.endControlPoint.y, this.endPoint.y, t);
|
|
480
531
|
return new Vertex(x, y);
|
|
481
532
|
}
|
|
482
533
|
|
|
@@ -628,20 +679,7 @@ export class CubicBezierCurve implements PathSegment {
|
|
|
628
679
|
* @return {CubicBezierCurve} The sub curve as a new curve.
|
|
629
680
|
**/
|
|
630
681
|
getSubCurveAt(tStart: number, tEnd: number): CubicBezierCurve {
|
|
631
|
-
//
|
|
632
|
-
// const endVec: Vector = new Vector(this.getPointAt(tEnd), this.getTangentAt(tEnd).inv());
|
|
633
|
-
|
|
634
|
-
// // Tangents are relative. Make absolute.
|
|
635
|
-
// startVec.b.add(startVec.a);
|
|
636
|
-
// endVec.b.add(endVec.a);
|
|
637
|
-
|
|
638
|
-
// // This 'splits' the curve at the given point at t.
|
|
639
|
-
// startVec.scale(0.33333333 * (tEnd - tStart));
|
|
640
|
-
// endVec.scale(0.33333333 * (tEnd - tStart));
|
|
641
|
-
|
|
642
|
-
// // Draw the bezier curve
|
|
643
|
-
// // pb.draw.cubicBezier( startVec.a, endVec.a, startVec.b, endVec.b, '#8800ff', 2 );
|
|
644
|
-
// return new CubicBezierCurve(startVec.a, endVec.a, startVec.b, endVec.b);
|
|
682
|
+
// This 'splits' the curve at the given point at t.
|
|
645
683
|
const subCurbePoints = CubicBezierCurve.utils.getSubCurvePointsAt(this, tStart, tEnd);
|
|
646
684
|
return new CubicBezierCurve(subCurbePoints[0], subCurbePoints[1], subCurbePoints[2], subCurbePoints[3]);
|
|
647
685
|
}
|
|
@@ -746,6 +784,83 @@ export class CubicBezierCurve implements PathSegment {
|
|
|
746
784
|
}
|
|
747
785
|
//---END PathSegment-------------------------
|
|
748
786
|
|
|
787
|
+
//--- BEGIN --- Implement interface `Intersectable`
|
|
788
|
+
/**
|
|
789
|
+
* Get all line intersections with this shape.
|
|
790
|
+
*
|
|
791
|
+
* This method returns all intersections (as vertices) with this shape. The returned array of vertices is in no specific order.
|
|
792
|
+
*
|
|
793
|
+
* @param {VertTuple} line - The line to find intersections with.
|
|
794
|
+
* @param {boolean} inVectorBoundsOnly - If set to true only intersecion points on the passed vector are returned (located strictly between start and end vertex).
|
|
795
|
+
* @returns {Array<Vertex>} - An array of all intersections with the shape outline.
|
|
796
|
+
*/
|
|
797
|
+
lineIntersections(line: VertTuple<any>, inVectorBoundsOnly: boolean = false): Array<Vertex> {
|
|
798
|
+
const intersectionTs: number[] = this.lineIntersectionTs(line);
|
|
799
|
+
const intersectionPoints: Vertex[] = intersectionTs.map((t: number) => {
|
|
800
|
+
return this.getPointAt(t);
|
|
801
|
+
});
|
|
802
|
+
if (inVectorBoundsOnly) {
|
|
803
|
+
// const maxDist = line.length();
|
|
804
|
+
return intersectionPoints.filter((vert: Vertex) => line.hasPoint(vert, true));
|
|
805
|
+
} else {
|
|
806
|
+
return intersectionPoints;
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
/**
|
|
811
|
+
* Get all line intersections of this polygon and their tangents along the shape.
|
|
812
|
+
*
|
|
813
|
+
* This method returns all intersection tangents (as vectors) with this shape. The returned array of vectors is in no specific order.
|
|
814
|
+
*
|
|
815
|
+
* @param line
|
|
816
|
+
* @param lineIntersectionTangents
|
|
817
|
+
* @returns
|
|
818
|
+
*/
|
|
819
|
+
lineIntersectionTangents(line: VertTuple<any>, inVectorBoundsOnly: boolean = false): Array<Vector> {
|
|
820
|
+
const intersectionTs: number[] = this.lineIntersectionTs(line);
|
|
821
|
+
const intersectionTangents: Array<Vector> = intersectionTs.map((t: number) => {
|
|
822
|
+
const startPoint = this.getPointAt(t);
|
|
823
|
+
const endPoint = this.getTangentAt(t);
|
|
824
|
+
return new Vector(startPoint, endPoint.add(startPoint));
|
|
825
|
+
});
|
|
826
|
+
if (inVectorBoundsOnly) {
|
|
827
|
+
return intersectionTangents.filter((vec: Vector) => line.hasPoint(vec.a, true));
|
|
828
|
+
} else {
|
|
829
|
+
return intersectionTangents;
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
//--- END --- Implement interface `Intersectable`
|
|
833
|
+
|
|
834
|
+
lineIntersectionTs(line: VertTuple<any>): Array<number> {
|
|
835
|
+
var A = line.b.y - line.a.y; // A=y2-y1
|
|
836
|
+
var B = line.a.x - line.b.x; // B=x1-x2
|
|
837
|
+
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)
|
|
838
|
+
|
|
839
|
+
// var bx = bezierCoeffs(px[0], px[1], px[2], px[3]);
|
|
840
|
+
// var by = bezierCoeffs(py[0], py[1], py[2], py[3]);
|
|
841
|
+
var bx = CubicBezierCurve.utils.bezierCoeffs(
|
|
842
|
+
this.startPoint.x,
|
|
843
|
+
this.startControlPoint.x,
|
|
844
|
+
this.endControlPoint.x,
|
|
845
|
+
this.endPoint.x
|
|
846
|
+
);
|
|
847
|
+
var by = CubicBezierCurve.utils.bezierCoeffs(
|
|
848
|
+
this.startPoint.y,
|
|
849
|
+
this.startControlPoint.y,
|
|
850
|
+
this.endControlPoint.y,
|
|
851
|
+
this.endPoint.y
|
|
852
|
+
);
|
|
853
|
+
|
|
854
|
+
const poly: number[] = Array<number>(4);
|
|
855
|
+
poly[0] = A * bx[0] + B * by[0]; /*t^3*/
|
|
856
|
+
poly[1] = A * bx[1] + B * by[1]; /*t^2*/
|
|
857
|
+
poly[2] = A * bx[2] + B * by[2]; /*t*/
|
|
858
|
+
poly[3] = A * bx[3] + B * by[3] + C; /*1*/
|
|
859
|
+
|
|
860
|
+
var roots = CubicBezierCurve.utils.cubicRoots(poly);
|
|
861
|
+
return roots.filter((root: number) => root != -1);
|
|
862
|
+
}
|
|
863
|
+
|
|
749
864
|
/**
|
|
750
865
|
* Check if this and the specified curve are equal.<br>
|
|
751
866
|
* <br>
|
|
@@ -911,7 +1026,80 @@ export class CubicBezierCurve implements PathSegment {
|
|
|
911
1026
|
/**
|
|
912
1027
|
* Helper utils.
|
|
913
1028
|
*/
|
|
914
|
-
|
|
1029
|
+
public static utils = {
|
|
1030
|
+
|
|
1031
|
+
evaluateT: (p0:number, p1:number, p2:number, p3:number, t:number) : number => {
|
|
1032
|
+
return p0 * Math.pow(1.0 - t, 3) +
|
|
1033
|
+
p1 * 3 * t * Math.pow(1.0 - t, 2) +
|
|
1034
|
+
p2 * 3 * Math.pow(t, 2) * (1.0 - t) +
|
|
1035
|
+
p3 * Math.pow(t, 3);
|
|
1036
|
+
},
|
|
1037
|
+
|
|
1038
|
+
cubicPolyMinMax: (p0:number, p1:number, p2:number, p3:number) : { min: number, max: number }=> {
|
|
1039
|
+
// var polyX = CubicBezierCurve.utils.cubicPoly2(
|
|
1040
|
+
// p0, // P[0].X, // bezierCurve.startPoint.x,
|
|
1041
|
+
// p1, // P[1].X, // bezierCurve.startControlPoint.x,
|
|
1042
|
+
// p2, // P[2].X, // bezierCurve.endControlPoint.x,
|
|
1043
|
+
// p3 // P[3].X // bezierCurve.endPoint.x
|
|
1044
|
+
// );
|
|
1045
|
+
|
|
1046
|
+
// var a = polyX.a;
|
|
1047
|
+
// var b = polyX.b;
|
|
1048
|
+
// var c = polyX.c;
|
|
1049
|
+
// var disc = polyX.b * polyX.b - 4 * polyX.a * polyX.c;
|
|
1050
|
+
|
|
1051
|
+
|
|
1052
|
+
var polyX = CubicBezierCurve.utils.cubicPoly(
|
|
1053
|
+
p0, // P[0].X, // bezierCurve.startPoint.x,
|
|
1054
|
+
p1, // P[1].X, // bezierCurve.startControlPoint.x,
|
|
1055
|
+
p2, // P[2].X, // bezierCurve.endControlPoint.x,
|
|
1056
|
+
p3 // P[3].X // bezierCurve.endPoint.x
|
|
1057
|
+
);
|
|
1058
|
+
var a = polyX[0]; // .a;
|
|
1059
|
+
var b = polyX[1]; // .b;
|
|
1060
|
+
var c = polyX[2]; // .c;
|
|
1061
|
+
//alert("a "+a+" "+b+" "+c);
|
|
1062
|
+
// var disc = b * b - 4 * a * c;
|
|
1063
|
+
var disc = polyX[1] * polyX[1] - 4 * polyX[0] * polyX[2];
|
|
1064
|
+
|
|
1065
|
+
|
|
1066
|
+
// var polyX = CubicBezierCurve.utils.bezierCoeffs(p3,p2,p1,p0);
|
|
1067
|
+
// var a = polyX[0]; //polyX.a;
|
|
1068
|
+
// var b = polyX[1]; // .b;
|
|
1069
|
+
// var c = polyX[2]; //.c;
|
|
1070
|
+
// var disc = polyX[1] * polyX[1] - 4 * polyX[0] * polyX[2];
|
|
1071
|
+
|
|
1072
|
+
// var xl = Math.min(bCurve.endPoint.x, bCurve.startPoint.x); // P[0].X;
|
|
1073
|
+
// var xh = Math.max(bCurve.endPoint.x, bCurve.startPoint.x); // P[0].X;
|
|
1074
|
+
var xl = Math.min(p3, p0); // P[0].X;
|
|
1075
|
+
var xh = Math.max(p3, p0); // P[0].X;
|
|
1076
|
+
// if (P[3].X < xl) xl = P[3].X;
|
|
1077
|
+
// if (P[3].X > xh) xh = P[3].X;
|
|
1078
|
+
if (disc >= 0) {
|
|
1079
|
+
var t1 = (-b + Math.sqrt(disc)) / (2 * a);
|
|
1080
|
+
// alert("t1 " + t1);
|
|
1081
|
+
if (t1 > 0 && t1 < 1) {
|
|
1082
|
+
// var x1 = evalBez(PX, t1);
|
|
1083
|
+
// var x1 = bCurve.getPointAt(t1).x;
|
|
1084
|
+
var x1 = CubicBezierCurve.utils.evaluateT(p0, p1, p2, p3, t1); // bCurve.getPointAt(t1).x;
|
|
1085
|
+
|
|
1086
|
+
if (x1 < xl) xl = x1;
|
|
1087
|
+
if (x1 > xh) xh = x1;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
var t2 = (-b - Math.sqrt(disc)) / (2 * a);
|
|
1091
|
+
// alert("t2 " + t2);
|
|
1092
|
+
if (t2 > 0 && t2 < 1) {
|
|
1093
|
+
// var x2 = evalBez(PX, t2);
|
|
1094
|
+
// var x2 = bCurve.getPointAt(t2).x;
|
|
1095
|
+
var x2 = CubicBezierCurve.utils.evaluateT(p0, p1, p2, p3, t2); //
|
|
1096
|
+
if (x2 < xl) xl = x2;
|
|
1097
|
+
if (x2 > xh) xh = x2;
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
return { min: xl, max: xh };
|
|
1101
|
+
},
|
|
1102
|
+
|
|
915
1103
|
/**
|
|
916
1104
|
* Get the points of a sub curve at the given start end end offsets (values between 0.0 and 1.0).
|
|
917
1105
|
*
|
|
@@ -938,6 +1126,108 @@ export class CubicBezierCurve implements PathSegment {
|
|
|
938
1126
|
endVec.scale(0.33333333 * (tEnd - tStart));
|
|
939
1127
|
|
|
940
1128
|
return [startVec.a, endVec.a, startVec.b, endVec.b];
|
|
1129
|
+
},
|
|
1130
|
+
|
|
1131
|
+
/**
|
|
1132
|
+
* Compute the cubic roots for the given cubic polynomial coefficients.
|
|
1133
|
+
*
|
|
1134
|
+
* Based on
|
|
1135
|
+
* http://mysite.verizon.net/res148h4j/javascript/script_exact_cubic.html#the%20source%20code
|
|
1136
|
+
* Inspired by
|
|
1137
|
+
* https://www.particleincell.com/2013/cubic-line-intersection/
|
|
1138
|
+
* Thanks to Stephan Schmitt and Particle-In-Cell!
|
|
1139
|
+
*
|
|
1140
|
+
* @param poly
|
|
1141
|
+
* @returns
|
|
1142
|
+
*/
|
|
1143
|
+
cubicRoots: (poly: number[]): number[] => {
|
|
1144
|
+
const a: number = poly[0];
|
|
1145
|
+
const b: number = poly[1];
|
|
1146
|
+
const c: number = poly[2];
|
|
1147
|
+
const d: number = poly[3];
|
|
1148
|
+
|
|
1149
|
+
const A: number = b / a;
|
|
1150
|
+
const B: number = c / a;
|
|
1151
|
+
const C: number = d / a;
|
|
1152
|
+
|
|
1153
|
+
var S: number, T: number, Im: number;
|
|
1154
|
+
|
|
1155
|
+
const Q: number = (3 * B - Math.pow(A, 2)) / 9;
|
|
1156
|
+
const R: number = (9 * A * B - 27 * C - 2 * Math.pow(A, 3)) / 54;
|
|
1157
|
+
const D: number = Math.pow(Q, 3) + Math.pow(R, 2); // polynomial discriminant
|
|
1158
|
+
|
|
1159
|
+
const ts: Array<number> = []; // Array();
|
|
1160
|
+
|
|
1161
|
+
if (D >= 0) {
|
|
1162
|
+
// complex or duplicate roots
|
|
1163
|
+
S = CubicBezierCurve.utils.sgn(R + Math.sqrt(D)) * Math.pow(Math.abs(R + Math.sqrt(D)), 1 / 3);
|
|
1164
|
+
T = CubicBezierCurve.utils.sgn(R - Math.sqrt(D)) * Math.pow(Math.abs(R - Math.sqrt(D)), 1 / 3);
|
|
1165
|
+
|
|
1166
|
+
ts[0] = -A / 3 + (S + T); // real root
|
|
1167
|
+
ts[1] = -A / 3 - (S + T) / 2; // real part of complex root
|
|
1168
|
+
ts[2] = -A / 3 - (S + T) / 2; // real part of complex root
|
|
1169
|
+
Im = Math.abs((Math.sqrt(3) * (S - T)) / 2); // complex part of root pair
|
|
1170
|
+
|
|
1171
|
+
// Mark complex roots to be discarded
|
|
1172
|
+
if (Im != 0) {
|
|
1173
|
+
ts[1] = -1;
|
|
1174
|
+
ts[2] = -1;
|
|
1175
|
+
}
|
|
1176
|
+
} // distinct real roots
|
|
1177
|
+
else {
|
|
1178
|
+
const th: number = Math.acos(R / Math.sqrt(-Math.pow(Q, 3)));
|
|
1179
|
+
|
|
1180
|
+
ts[0] = 2 * Math.sqrt(-Q) * Math.cos(th / 3) - A / 3;
|
|
1181
|
+
ts[1] = 2 * Math.sqrt(-Q) * Math.cos((th + 2 * Math.PI) / 3) - A / 3;
|
|
1182
|
+
ts[2] = 2 * Math.sqrt(-Q) * Math.cos((th + 4 * Math.PI) / 3) - A / 3;
|
|
1183
|
+
Im = 0.0;
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
// Discard all t's out of spec and sort the rest
|
|
1187
|
+
return ts.filter((t: number) => t >= 0 && t <= 1.0).sort();
|
|
1188
|
+
},
|
|
1189
|
+
|
|
1190
|
+
/**
|
|
1191
|
+
* Compute the Bézier coefficients from the given Bézier point coordinates.
|
|
1192
|
+
*
|
|
1193
|
+
* @param {number} p0 - The start point coordinate.
|
|
1194
|
+
* @param {number} p1 - The start control point coordinate.
|
|
1195
|
+
* @param {number} p2 - The end control point coordinate.
|
|
1196
|
+
* @param {number} p3 - The end point coordinate.
|
|
1197
|
+
* @returns {[number,number,number,number]}
|
|
1198
|
+
*/
|
|
1199
|
+
bezierCoeffs: (p0: number, p1: number, p2: number, p3: number): [number,number,number,number] => {
|
|
1200
|
+
const coeffs : [number,number,number,number] = [NaN,NaN,NaN,NaN]; //Array(4);
|
|
1201
|
+
coeffs[0] = -p0 + 3 * p1 + -3 * p2 + p3;
|
|
1202
|
+
coeffs[1] = 3 * p0 - 6 * p1 + 3 * p2;
|
|
1203
|
+
coeffs[2] = -3 * p0 + 3 * p1;
|
|
1204
|
+
coeffs[3] = p0;
|
|
1205
|
+
return coeffs;
|
|
1206
|
+
},
|
|
1207
|
+
|
|
1208
|
+
/**
|
|
1209
|
+
* Calculate the cubic polynomial coefficients used to find the bounding box.
|
|
1210
|
+
*
|
|
1211
|
+
* @param {number} p0 - The start point coordinate.
|
|
1212
|
+
* @param {number} p1 - The start control point coordinate.
|
|
1213
|
+
* @param {number} p2 - The end control point coordinate.
|
|
1214
|
+
* @param {number} p3 - The end point coordinate.
|
|
1215
|
+
* @returns {[number,number,number]}
|
|
1216
|
+
*/
|
|
1217
|
+
cubicPoly: (p0:number, p1:number, p2:number, p3:number) : [number,number,number] => {
|
|
1218
|
+
return [
|
|
1219
|
+
3 * p3 - 9 * p2 + 9 * p1 - 3 * p0,
|
|
1220
|
+
6 * p0 - 12 * p1 + 6 * p2,
|
|
1221
|
+
3 * p1 - 3 * p0
|
|
1222
|
+
]
|
|
1223
|
+
},
|
|
1224
|
+
|
|
1225
|
+
|
|
1226
|
+
/**
|
|
1227
|
+
* sign of number, but is division safe: no zero returned :)
|
|
1228
|
+
*/
|
|
1229
|
+
sgn(x: number): number {
|
|
1230
|
+
return x < 0.0 ? -1 : 1;
|
|
941
1231
|
}
|
|
942
1232
|
};
|
|
943
1233
|
}
|