plotboilerplate 1.29.0 → 1.31.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 +26 -13
- package/dist/index.esm.js +310 -57
- 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 +266 -36
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +1 -1
- package/src/cjs/Circle.d.ts +17 -1
- package/src/cjs/Circle.js +21 -1
- package/src/cjs/Circle.js.map +1 -1
- package/src/cjs/CubicBezierCurve.d.ts +34 -3
- package/src/cjs/CubicBezierCurve.js +79 -12
- package/src/cjs/CubicBezierCurve.js.map +1 -1
- package/src/cjs/Line.d.ts +46 -1
- package/src/cjs/Line.js +80 -1
- package/src/cjs/Line.js.map +1 -1
- package/src/cjs/Polygon.d.ts +18 -4
- package/src/cjs/Polygon.js +56 -18
- package/src/cjs/Polygon.js.map +1 -1
- package/src/cjs/VertTuple.d.ts +24 -2
- package/src/cjs/VertTuple.js +28 -2
- package/src/cjs/VertTuple.js.map +1 -1
- package/src/cjs/Vertex.d.ts +2 -2
- package/src/cjs/Vertex.js +2 -2
- package/src/cjs/utils/algorithms/delaunay2voronoi.d.ts +2 -1
- package/src/cjs/utils/algorithms/delaunay2voronoi.js +8 -10
- package/src/cjs/utils/algorithms/delaunay2voronoi.js.map +1 -1
- package/src/cjs/utils/datastructures/PointSet.d.ts +63 -0
- package/src/cjs/utils/datastructures/PointSet.js +126 -0
- package/src/cjs/utils/datastructures/PointSet.js.map +1 -0
- package/src/cjs/utils/datastructures/VoronoiCell.d.ts +19 -2
- package/src/cjs/utils/datastructures/VoronoiCell.js +39 -12
- package/src/cjs/utils/datastructures/VoronoiCell.js.map +1 -1
- package/src/cjs/utils/renderers/VoronoiRenderer.d.ts +99 -0
- package/src/cjs/utils/renderers/VoronoiRenderer.js +147 -0
- package/src/cjs/utils/renderers/VoronoiRenderer.js.map +1 -0
- package/src/esm/Circle.d.ts +17 -1
- package/src/esm/Circle.js +21 -1
- package/src/esm/Circle.js.map +1 -1
- package/src/esm/CubicBezierCurve.d.ts +34 -3
- package/src/esm/CubicBezierCurve.js +79 -12
- package/src/esm/CubicBezierCurve.js.map +1 -1
- package/src/esm/Line.d.ts +46 -1
- package/src/esm/Line.js +80 -1
- package/src/esm/Line.js.map +1 -1
- package/src/esm/Polygon.d.ts +18 -4
- package/src/esm/Polygon.js +56 -18
- package/src/esm/Polygon.js.map +1 -1
- package/src/esm/VertTuple.d.ts +24 -2
- package/src/esm/VertTuple.js +28 -2
- package/src/esm/VertTuple.js.map +1 -1
- package/src/esm/Vertex.d.ts +2 -2
- package/src/esm/Vertex.js +2 -2
- package/src/esm/utils/algorithms/delaunay2voronoi.d.ts +2 -1
- package/src/esm/utils/algorithms/delaunay2voronoi.js +8 -10
- package/src/esm/utils/algorithms/delaunay2voronoi.js.map +1 -1
- package/src/esm/utils/datastructures/PointSet.d.ts +63 -0
- package/src/esm/utils/datastructures/PointSet.js +115 -0
- package/src/esm/utils/datastructures/PointSet.js.map +1 -0
- package/src/esm/utils/datastructures/VoronoiCell.d.ts +19 -2
- package/src/esm/utils/datastructures/VoronoiCell.js +39 -12
- package/src/esm/utils/datastructures/VoronoiCell.js.map +1 -1
- package/src/esm/utils/renderers/VoronoiRenderer.d.ts +99 -0
- package/src/esm/utils/renderers/VoronoiRenderer.js +142 -0
- package/src/esm/utils/renderers/VoronoiRenderer.js.map +1 -0
- package/src/index-gl.js +1 -2
- package/src/ts/Circle.ts +23 -1
- package/src/ts/CubicBezierCurve.ts +133 -48
- package/src/ts/Line.ts +84 -1
- package/src/ts/Polygon.ts +58 -18
- package/src/ts/VertTuple.ts +30 -2
- package/src/ts/Vertex.ts +2 -2
- package/src/ts/utils/_AppContext.ts_ +22 -0
- package/src/ts/utils/algorithms/delaunay2voronoi.ts +81 -88
- package/src/ts/utils/datastructures/PointSet.ts +135 -0
- package/src/ts/utils/datastructures/VoronoiCell.ts +198 -169
- package/src/ts/utils/renderers/VoronoiRenderer.ts +200 -0
package/dist/plotboilerplate.js
CHANGED
|
@@ -1750,7 +1750,8 @@ exports.Bounds = Bounds;
|
|
|
1750
1750
|
* @modified 2026-07-08 Adding the `Circle.setRadius` method (for chaining).
|
|
1751
1751
|
* @mofified 2026-07-31 Adding the `radicalAxis(Circle)` method. Added the `Circle.circleUtils.createRadicalAxisHelperCircle` and `.circleDistance` helper methods.
|
|
1752
1752
|
* @modified 2026-08-03 Adding `Circle.tangentsFromPoint`.
|
|
1753
|
-
* @
|
|
1753
|
+
* @modified 2026-08-16 Adding the `Circle.sectorAngleByArcLength` method and the `Circle.circleUtils.sectorAngleByArcLength` helper method.
|
|
1754
|
+
* @version 1.8.0
|
|
1754
1755
|
**/
|
|
1755
1756
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1756
1757
|
exports.Circle = void 0;
|
|
@@ -2136,6 +2137,15 @@ var Circle = /** @class */ (function () {
|
|
|
2136
2137
|
}
|
|
2137
2138
|
return [new Vector_1.Vector(intersection.a, vert), new Vector_1.Vector(intersection.b, vert)];
|
|
2138
2139
|
};
|
|
2140
|
+
/**
|
|
2141
|
+
* Calculate inner sector angle for this circle and a given circle arc length.
|
|
2142
|
+
*
|
|
2143
|
+
* @param {number} sectorArcLength - The desired arc length (in units).
|
|
2144
|
+
* @returns The sector's inner angle (in radians).
|
|
2145
|
+
*/
|
|
2146
|
+
Circle.prototype.sectorAngleByArcLength = function (sectorArcLength) {
|
|
2147
|
+
return Circle.circleUtils.sectorAngleByArcLength(sectorArcLength, this.radius);
|
|
2148
|
+
};
|
|
2139
2149
|
/**
|
|
2140
2150
|
* Create a deep copy of this circle.
|
|
2141
2151
|
*
|
|
@@ -2213,6 +2223,16 @@ var Circle = /** @class */ (function () {
|
|
|
2213
2223
|
*/
|
|
2214
2224
|
circleDistance: function (circleA, circleB) {
|
|
2215
2225
|
return circleA.center.distance(circleB.center) - circleA.radius - circleB.radius;
|
|
2226
|
+
},
|
|
2227
|
+
/**
|
|
2228
|
+
* Calculate the inner sector angle for a given circle arc length and radius.
|
|
2229
|
+
*
|
|
2230
|
+
* @param {number} sectorArcLength - The desired arc length.
|
|
2231
|
+
* @param {number} circleRadius - The circle's radius.
|
|
2232
|
+
* @returns The sector angle in radians.
|
|
2233
|
+
*/
|
|
2234
|
+
sectorAngleByArcLength: function (sectorArcLength, circleRadius) {
|
|
2235
|
+
return sectorArcLength / circleRadius;
|
|
2216
2236
|
}
|
|
2217
2237
|
};
|
|
2218
2238
|
return Circle;
|
|
@@ -8278,12 +8298,16 @@ exports["default"] = PlotBoilerplate;
|
|
|
8278
8298
|
* @modified 2025-04-15 Changed param of `VertTuple.moveTo` method from `Vertex` to `XYCoords`.
|
|
8279
8299
|
* @modified 2025-04-15 Added method `VertTuple.move` method.
|
|
8280
8300
|
* @modified 2026-06-10 Adding helper function `VertTuple.utils.calcCircumcircle`.
|
|
8281
|
-
* @
|
|
8301
|
+
* @modified 2026-06-17 Adding method `VertTuple.asLine` for converting TertTuples to Line instances.
|
|
8302
|
+
* @modified 2026-09-21 Adding method `VertTuple.asVector` for converting TertTuples to Vector instances.
|
|
8303
|
+
* @version 1.7.0
|
|
8282
8304
|
*/
|
|
8283
8305
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
8284
8306
|
exports.VertTuple = void 0;
|
|
8285
8307
|
var Vertex_1 = __webpack_require__(787);
|
|
8286
8308
|
var UIDGenerator_1 = __webpack_require__(938);
|
|
8309
|
+
var Line_1 = __webpack_require__(939);
|
|
8310
|
+
var Vector_1 = __webpack_require__(30);
|
|
8287
8311
|
/**
|
|
8288
8312
|
* @classdesc An abstract base classes for vertex tuple constructs, like Lines or Vectors.
|
|
8289
8313
|
* @abstract
|
|
@@ -8566,7 +8590,7 @@ var VertTuple = /** @class */ (function () {
|
|
|
8566
8590
|
/**
|
|
8567
8591
|
* Create a deep clone of this instance.
|
|
8568
8592
|
*
|
|
8569
|
-
* @method
|
|
8593
|
+
* @method clone
|
|
8570
8594
|
* @return {T} A type safe clone if this instance.
|
|
8571
8595
|
* @instance
|
|
8572
8596
|
* @memberof VertTuple
|
|
@@ -8574,6 +8598,28 @@ var VertTuple = /** @class */ (function () {
|
|
|
8574
8598
|
VertTuple.prototype.clone = function () {
|
|
8575
8599
|
return this.factory(this.a.clone(), this.b.clone());
|
|
8576
8600
|
};
|
|
8601
|
+
/**
|
|
8602
|
+
* Converts this `VertTuple` to a `Line` (segment).
|
|
8603
|
+
*
|
|
8604
|
+
* @method asLine
|
|
8605
|
+
* @return {Line} This tuple as `Line` instance.
|
|
8606
|
+
* @instance
|
|
8607
|
+
* @memberof VertTuple
|
|
8608
|
+
**/
|
|
8609
|
+
VertTuple.prototype.asLine = function () {
|
|
8610
|
+
return new Line_1.Line(this.a, this.b);
|
|
8611
|
+
};
|
|
8612
|
+
/**
|
|
8613
|
+
* Converts this `VertTuple` to a `Vector` (arrow).
|
|
8614
|
+
*
|
|
8615
|
+
* @method asVector
|
|
8616
|
+
* @return {Line} This tuple as `Vector` instance.
|
|
8617
|
+
* @instance
|
|
8618
|
+
* @memberof VertTuple
|
|
8619
|
+
**/
|
|
8620
|
+
VertTuple.prototype.asVector = function () {
|
|
8621
|
+
return new Vector_1.Vector(this.a, this.b);
|
|
8622
|
+
};
|
|
8577
8623
|
/**
|
|
8578
8624
|
* Create a string representation of this line.
|
|
8579
8625
|
*
|
|
@@ -9144,7 +9190,9 @@ exports.PBText = PBText;
|
|
|
9144
9190
|
* @modified 2025-05-16 Class `Polygon` now implements `IBounded`.
|
|
9145
9191
|
* @modified 2025-05-20 Tweaking `Polygon.getInnerAngleAt` and `Polygo.isAngleAcute` to handle indices out of array bounds as well.
|
|
9146
9192
|
* @modified 2025-06-07 Adding `Polygon.closestLineIntersectionIndex` to determine line intersections plus detected edge index.
|
|
9147
|
-
* @
|
|
9193
|
+
* @modified 2026-09-16 Adding a `forceClockwise` parameter to the `Polygon.getCentroid()` method.
|
|
9194
|
+
* @modified 2026-09-21 Adding `Polygon.revert` method to change the winding order.
|
|
9195
|
+
* @version 1.17.0
|
|
9148
9196
|
*
|
|
9149
9197
|
* @file Polygon
|
|
9150
9198
|
* @public
|
|
@@ -9449,6 +9497,20 @@ var Polygon = /** @class */ (function () {
|
|
|
9449
9497
|
// return Polygon.utils.signedArea(this.vertices) < 0;
|
|
9450
9498
|
return Polygon.utils.isClockwise(this.vertices);
|
|
9451
9499
|
};
|
|
9500
|
+
/**
|
|
9501
|
+
* Revert the order of this polygon's vertices to change the winding order.
|
|
9502
|
+
* This operation is in-place.
|
|
9503
|
+
*
|
|
9504
|
+
* @method revert
|
|
9505
|
+
* @instance
|
|
9506
|
+
* @memberof Polygon
|
|
9507
|
+
* @return {Polygon} This for chaining.
|
|
9508
|
+
*/
|
|
9509
|
+
Polygon.prototype.revert = function () {
|
|
9510
|
+
// this.vertices.slice().reverse(); // Copy?
|
|
9511
|
+
this.vertices.reverse();
|
|
9512
|
+
return this;
|
|
9513
|
+
};
|
|
9452
9514
|
/**
|
|
9453
9515
|
* Get the perimeter of this polygon.
|
|
9454
9516
|
* The perimeter is the absolute length of the outline.
|
|
@@ -9530,35 +9592,37 @@ var Polygon = /** @class */ (function () {
|
|
|
9530
9592
|
};
|
|
9531
9593
|
/**
|
|
9532
9594
|
* Get centroid.
|
|
9533
|
-
* Centroids define the barycenter of any non self-intersecting convex polygon.
|
|
9595
|
+
* Centroids define the barycenter of any non self-intersecting convex clockwise polygon.
|
|
9534
9596
|
*
|
|
9535
|
-
* If the polygon is self intersecting or non
|
|
9597
|
+
* If the polygon is self intersecting or non convex or not clockwise then the barycenter is not well defined.
|
|
9536
9598
|
*
|
|
9537
9599
|
* https://mathworld.wolfram.com/PolygonCentroid.html
|
|
9538
9600
|
*
|
|
9539
9601
|
* @method getCentroid
|
|
9540
9602
|
* @instance
|
|
9603
|
+
* @param {boolean} forceClockwise - [optiona] If set to true then the centroid will be calculated for the clockwise polygon.
|
|
9541
9604
|
* @memberof Polygon
|
|
9542
9605
|
* @returns {Vertex|null}
|
|
9543
9606
|
*/
|
|
9544
|
-
Polygon.prototype.getCentroid = function () {
|
|
9607
|
+
Polygon.prototype.getCentroid = function (forceClockwise) {
|
|
9545
9608
|
if (this.vertices.length === 0) {
|
|
9546
9609
|
return null;
|
|
9547
9610
|
}
|
|
9548
|
-
|
|
9549
|
-
|
|
9550
|
-
for (var i = 0; i < n; i++) {
|
|
9551
|
-
|
|
9552
|
-
|
|
9553
|
-
|
|
9554
|
-
|
|
9555
|
-
|
|
9556
|
-
|
|
9557
|
-
}
|
|
9558
|
-
|
|
9559
|
-
|
|
9560
|
-
|
|
9561
|
-
return
|
|
9611
|
+
// const centroid: Vertex = new Vertex(0.0, 0.0);
|
|
9612
|
+
// const n = this.vertices.length;
|
|
9613
|
+
// for (var i = 0; i < n; i++) {
|
|
9614
|
+
// // center.add(this.vertices[i]);
|
|
9615
|
+
// const cur: Vertex = this.vertices[i];
|
|
9616
|
+
// const next: Vertex = this.vertices[(i + 1) % n];
|
|
9617
|
+
// var factor: number = cur.x * next.y - next.x * cur.y;
|
|
9618
|
+
// centroid.x += (cur.x + next.x) * factor;
|
|
9619
|
+
// centroid.y += (cur.y + next.y) * factor;
|
|
9620
|
+
// }
|
|
9621
|
+
// const area = this.area();
|
|
9622
|
+
// centroid.x *= 1 / (6 * area);
|
|
9623
|
+
// centroid.y *= 1 / (6 * area);
|
|
9624
|
+
// return centroid;
|
|
9625
|
+
return Polygon.utils.calculateCentroid(this.vertices, forceClockwise);
|
|
9562
9626
|
};
|
|
9563
9627
|
//--- BEGIN --- Implement interface `Intersectable`
|
|
9564
9628
|
/**
|
|
@@ -9989,6 +10053,26 @@ var Polygon = /** @class */ (function () {
|
|
|
9989
10053
|
isClockwise: function (vertices) {
|
|
9990
10054
|
return Polygon.utils.signedArea(vertices) < 0;
|
|
9991
10055
|
},
|
|
10056
|
+
calculateCentroid: function (vertices, forceClockwise) {
|
|
10057
|
+
var centroid = new Vertex_1.Vertex(0.0, 0.0);
|
|
10058
|
+
var n = vertices.length;
|
|
10059
|
+
if (forceClockwise && !Polygon.utils.isClockwise(vertices)) {
|
|
10060
|
+
return Polygon.utils.calculateCentroid(vertices.slice().reverse());
|
|
10061
|
+
}
|
|
10062
|
+
for (var i = 0; i < n; i++) {
|
|
10063
|
+
// center.add(this.vertices[i]);
|
|
10064
|
+
var cur = vertices[i];
|
|
10065
|
+
var next = vertices[(i + 1) % n];
|
|
10066
|
+
var factor = cur.x * next.y - next.x * cur.y;
|
|
10067
|
+
centroid.x += (cur.x + next.x) * factor;
|
|
10068
|
+
centroid.y += (cur.y + next.y) * factor;
|
|
10069
|
+
}
|
|
10070
|
+
// const area = this.area();
|
|
10071
|
+
var area = Polygon.utils.area(vertices);
|
|
10072
|
+
centroid.x *= 1 / (6 * area);
|
|
10073
|
+
centroid.y *= 1 / (6 * area);
|
|
10074
|
+
return centroid;
|
|
10075
|
+
},
|
|
9992
10076
|
/**
|
|
9993
10077
|
* Calulate the signed polyon area by interpreting the polygon as a matrix
|
|
9994
10078
|
* and calculating its determinant.
|
|
@@ -12248,7 +12332,7 @@ exports.Triangle = Triangle;
|
|
|
12248
12332
|
* @modified 2025-04-13 Adding the `Vertex.move(amount: XYCoords)` method (does the same as `add`, added by naming convention).
|
|
12249
12333
|
* @modified 2025-05-07 Class `Vertex` is now implementing interface `IBounded` (to meet convention).
|
|
12250
12334
|
* @modified 2026-06-10 Adding methods `Vertex.findClosestPoint` and `Vertex.findFarestPoint`.
|
|
12251
|
-
* @version 2.12.
|
|
12335
|
+
* @version 2.12.1
|
|
12252
12336
|
*
|
|
12253
12337
|
* @file Vertex
|
|
12254
12338
|
* @public
|
|
@@ -12726,7 +12810,7 @@ var Vertex = /** @class */ (function () {
|
|
|
12726
12810
|
* around given center.
|
|
12727
12811
|
*
|
|
12728
12812
|
* @method rotate
|
|
12729
|
-
* @param {number} angle - The angle to 'rotate' this vertex; 0.0 means no change.
|
|
12813
|
+
* @param {number} angle - The angle in radians to 'rotate' this vertex; 0.0 means no change.
|
|
12730
12814
|
* @param {XYCoords=} center - The center of rotation; default is (0,0).
|
|
12731
12815
|
* @return {Vertex} this
|
|
12732
12816
|
* @instance
|
|
@@ -14364,7 +14448,8 @@ exports.UIDGenerator = UIDGenerator;
|
|
|
14364
14448
|
* @modified 2023-09-25 Changed param type of `intersection()` from Line to VertTuple.
|
|
14365
14449
|
* @modified 2025-04-15 Class `Line` now implements interface `Intersectable`.
|
|
14366
14450
|
* @modified 2025-04-16 Class `Line` now implements interface `IBounded`.
|
|
14367
|
-
* @
|
|
14451
|
+
* @modified 2026-08-16 Adding methods `Line.trimStart` and `Line.trimEnd`. Adding methods `Line.trimStartAt` and `Line.trimEndAt`.
|
|
14452
|
+
* @version 2.5.0
|
|
14368
14453
|
*
|
|
14369
14454
|
* @file Line
|
|
14370
14455
|
* @public
|
|
@@ -14514,6 +14599,84 @@ var Line = /** @class */ (function (_super) {
|
|
|
14514
14599
|
return this;
|
|
14515
14600
|
};
|
|
14516
14601
|
//--- END Implement PathSegment ---
|
|
14602
|
+
/**
|
|
14603
|
+
* Trim this line segment from the start point by the given amount.
|
|
14604
|
+
* The amount must be positive and should be withing the segment's length. If the amount exceeds the segment's length
|
|
14605
|
+
* then the length of the resulting line will be zero (0.0).
|
|
14606
|
+
*
|
|
14607
|
+
* @method trimStart
|
|
14608
|
+
* @memberof Line
|
|
14609
|
+
* @param {number} amount - The positive amount to trim the line from the start point `a`.
|
|
14610
|
+
* @returns {Line} This for chaining, with updated point `a`.
|
|
14611
|
+
*/
|
|
14612
|
+
Line.prototype.trimStart = function (amount) {
|
|
14613
|
+
// Calculate the relative position `t` on this line.
|
|
14614
|
+
var t = amount / this.length();
|
|
14615
|
+
// `t` should be inside 0..1 – otherwise the amount was too large or negative.
|
|
14616
|
+
if (t < 0.0) {
|
|
14617
|
+
return this;
|
|
14618
|
+
}
|
|
14619
|
+
if (t > 1.0) {
|
|
14620
|
+
// Set the line to length zero (endpoint only)
|
|
14621
|
+
this.a = this.b.clone();
|
|
14622
|
+
return this;
|
|
14623
|
+
}
|
|
14624
|
+
this.a = this.vertAt(t);
|
|
14625
|
+
return this;
|
|
14626
|
+
};
|
|
14627
|
+
/**
|
|
14628
|
+
* Trim this line segment from the start point by the given relative amount.
|
|
14629
|
+
* The amount must be positive and should be within 0.0 and 1.0. If the amount exceeds the segment's length
|
|
14630
|
+
* then the length of the resulting line will be zero (0.0).
|
|
14631
|
+
*
|
|
14632
|
+
* @method trimStartAt
|
|
14633
|
+
* @memberof Line
|
|
14634
|
+
* @param {number} amount - The positive amount to trim the line from the start point `a`.
|
|
14635
|
+
* @returns {Line} This for chaining, with updated point `a`.
|
|
14636
|
+
*/
|
|
14637
|
+
Line.prototype.trimStartAt = function (relativeAmount) {
|
|
14638
|
+
// Calculate the relative position `t` on this line.
|
|
14639
|
+
return this.trimStart(relativeAmount * this.length());
|
|
14640
|
+
};
|
|
14641
|
+
/**
|
|
14642
|
+
* Trim this line segment from the end point by the given amount.
|
|
14643
|
+
* The amount must be positive and should be withing the segment's length. If the amount exceeds the segment's length
|
|
14644
|
+
* then the length of the resulting line will be zero (0.0).
|
|
14645
|
+
*
|
|
14646
|
+
* @method trimEnd
|
|
14647
|
+
* @memberof Line
|
|
14648
|
+
* @param {number} amount - The positive amount to trim the line from the end point `b`.
|
|
14649
|
+
* @returns {Line} This for chaining, with updated point `b`.
|
|
14650
|
+
*/
|
|
14651
|
+
Line.prototype.trimEnd = function (amount) {
|
|
14652
|
+
// Calculate the relative position `t` on this line.
|
|
14653
|
+
var t = 1.0 - amount / this.length();
|
|
14654
|
+
// `t` should be inside 0..1 – otherwise the amount was too large or negative.
|
|
14655
|
+
if (t < 0.0) {
|
|
14656
|
+
return this;
|
|
14657
|
+
}
|
|
14658
|
+
if (t > 1.0) {
|
|
14659
|
+
// Set the line to length zero (endpoint only)
|
|
14660
|
+
this.b = this.a.clone();
|
|
14661
|
+
return this;
|
|
14662
|
+
}
|
|
14663
|
+
this.b = this.vertAt(t);
|
|
14664
|
+
return this;
|
|
14665
|
+
};
|
|
14666
|
+
/**
|
|
14667
|
+
* Trim this line segment from the end point by the given relative amount.
|
|
14668
|
+
* The amount must be positive and should be within 0.0 and 1.0. If the amount exceeds the segment's length
|
|
14669
|
+
* then the length of the resulting line will be zero (0.0).
|
|
14670
|
+
*
|
|
14671
|
+
* @method trimEndAt
|
|
14672
|
+
* @memberof Line
|
|
14673
|
+
* @param {number} amount - The positive amount to trim the line from the start point `a`.
|
|
14674
|
+
* @returns {Line} This for chaining, with updated point `a`.
|
|
14675
|
+
*/
|
|
14676
|
+
Line.prototype.trimEndAt = function (relativeAmount) {
|
|
14677
|
+
// Calculate the relative position `t` on this line.
|
|
14678
|
+
return this.trimEnd(relativeAmount * this.length());
|
|
14679
|
+
};
|
|
14517
14680
|
//--- BEGIN --- Implement interface `Intersectable`
|
|
14518
14681
|
/**
|
|
14519
14682
|
* Get all line intersections with this polygon.
|
|
@@ -14604,8 +14767,9 @@ exports.Line = Line;
|
|
|
14604
14767
|
* @modified 2025-04-18 Added evaluation method for cubic Bézier curves `CubicBezierCurve.utils.evaluateT`.
|
|
14605
14768
|
* @modified 2025-04-18 Refactored method `CubicBezierCurve.getPointAt` to use `evaluateT`.
|
|
14606
14769
|
* @modified 2025-04-18 Fixed the `CubicBezierCurve.getBounds` method: now returning the real bounding box. Before it was an approximated one.
|
|
14607
|
-
* @modified 2025
|
|
14608
|
-
* @
|
|
14770
|
+
* @modified 2025-04-18 Added helper methods for bounding box calculation `CubucBezierCurve.util.cubicPolyMinMax` and `cubicPoly`.
|
|
14771
|
+
* @modified 2026-09-09 Adding methods `CubicBezierCurve.trimStartEnd` and `CubicBezierCurve.trimStartEndAt`.
|
|
14772
|
+
* @version 2.10.0
|
|
14609
14773
|
*
|
|
14610
14774
|
* @file CubicBezierCurve
|
|
14611
14775
|
* @public
|
|
@@ -15060,6 +15224,7 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
15060
15224
|
this.endControlPoint.set(subCurbePoints[3]);
|
|
15061
15225
|
this.updateArcLengths();
|
|
15062
15226
|
return this;
|
|
15227
|
+
// return this.trimStartEndAt(t, null);
|
|
15063
15228
|
};
|
|
15064
15229
|
/**
|
|
15065
15230
|
* Trim off the end of this curve. The position parameter `uValue` is the absolute position on the
|
|
@@ -15095,7 +15260,79 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
15095
15260
|
this.endControlPoint.set(subCurbePoints[3]);
|
|
15096
15261
|
this.updateArcLengths();
|
|
15097
15262
|
return this;
|
|
15263
|
+
// return this.trimStartEndAt(null, t);
|
|
15264
|
+
};
|
|
15265
|
+
/**
|
|
15266
|
+
* Trim off a start and end section of this curve. The position parameters `uStart` and `uEnd` are the absolute positions in [0..arcLength].
|
|
15267
|
+
* The remaining curve will be the one in the bounds `[uStart,uEnd]` (so `[0.0,uStart]` and `[uEnd,1.0]` are cut off).
|
|
15268
|
+
*
|
|
15269
|
+
* Parameters out of bounds (< 0.0 or > arcLength) are ignored.
|
|
15270
|
+
* If `uEnd` is smaller than `uStart` then a curve with length zero (0) at `uStart` is returned.
|
|
15271
|
+
*
|
|
15272
|
+
* @method trimStartEndAt
|
|
15273
|
+
* @instance
|
|
15274
|
+
* @memberof CubicBezierCurve
|
|
15275
|
+
* @param {number} tStart - The relative position parameter where to cut off the head curve.
|
|
15276
|
+
* @param {number} tEnd - The relative position parameter where to cut off the tail curve.
|
|
15277
|
+
* @returns {CubicBezierCurve} `this` for chanining.
|
|
15278
|
+
*/
|
|
15279
|
+
CubicBezierCurve.prototype.trimStartEnd = function (uStart, uEnd) {
|
|
15280
|
+
return this.trimStartEndAt(this.convertU2T(uStart), this.convertU2T(uEnd));
|
|
15281
|
+
};
|
|
15282
|
+
/**
|
|
15283
|
+
* Trim off a start and end section of this curve. The position parameters `tStart` and `tEnd` are the relative positions in [0..1].
|
|
15284
|
+
* The remaining curve will be the one in the bounds `[tStart,tEnd]` (so `[0.0,tStart]` and `[tEnd,1.0]` are cut off).
|
|
15285
|
+
*
|
|
15286
|
+
* Parameters out of bounds (< 0.0 or > 1.0) are ignored.
|
|
15287
|
+
* If `tEnd` is smaller than `tStart` then a curve with length zero (0) at `tStart` is returned.
|
|
15288
|
+
*
|
|
15289
|
+
* @method trimStartEndAt
|
|
15290
|
+
* @instance
|
|
15291
|
+
* @memberof CubicBezierCurve
|
|
15292
|
+
* @param {number} tStart - The relative position parameter where to cut off the head curve.
|
|
15293
|
+
* @param {number} tEnd - The relative position parameter where to cut off the tail curve.
|
|
15294
|
+
* @returns {CubicBezierCurve} `this` for chanining.
|
|
15295
|
+
*/
|
|
15296
|
+
CubicBezierCurve.prototype.trimStartEndAt = function (tStart, tEnd) {
|
|
15297
|
+
var cleanTrimStart = Math.min(Math.max(0.0, tStart), 1.0);
|
|
15298
|
+
var cleanTrimEnd = Math.min(Math.max(cleanTrimStart, tEnd), 1.0);
|
|
15299
|
+
this.trimStartAt(cleanTrimStart);
|
|
15300
|
+
var relativeTrimEnd = (cleanTrimEnd - cleanTrimStart) / (1.0 - cleanTrimStart);
|
|
15301
|
+
this.trimEndAt(relativeTrimEnd);
|
|
15302
|
+
return this;
|
|
15098
15303
|
};
|
|
15304
|
+
// __trimStartEndAt(tStart: number, tEnd: number): CubicBezierCurve {
|
|
15305
|
+
// var finalCurvePoints = [
|
|
15306
|
+
// this.startPoint.clone(),
|
|
15307
|
+
// this.endPoint.clone(),
|
|
15308
|
+
// this.startControlPoint.clone(),
|
|
15309
|
+
// this.endControlPoint.clone()
|
|
15310
|
+
// ];
|
|
15311
|
+
// if (typeof tStart === "number" && !Number.isNaN(tStart)) {
|
|
15312
|
+
// const subCurvePointsStart = CubicBezierCurve.utils.getSubCurvePointsAt(this, tStart, 1.0);
|
|
15313
|
+
// finalCurvePoints[0].set(subCurvePointsStart[0]);
|
|
15314
|
+
// finalCurvePoints[2].set(subCurvePointsStart[2]);
|
|
15315
|
+
// // this.startPoint.set(subCurvePointsStart[0]);
|
|
15316
|
+
// // this.startControlPoint.set(subCurvePointsStart[2]);
|
|
15317
|
+
// // this.endPoint.set(subCurvePointsStart[1]);
|
|
15318
|
+
// // this.endControlPoint.set(subCurvePointsStart[3]);
|
|
15319
|
+
// }
|
|
15320
|
+
// if (typeof tEnd === "number" && !Number.isNaN(tEnd)) {
|
|
15321
|
+
// const subCurvePointsEnd = CubicBezierCurve.utils.getSubCurvePointsAt(this, 0.0, tEnd);
|
|
15322
|
+
// // this.startPoint.set(subCurvePointsEnd[0]);
|
|
15323
|
+
// // this.startControlPoint.set(subCurvePointsEnd[2]);
|
|
15324
|
+
// // this.endPoint.set(subCurvePointsEnd[1]);
|
|
15325
|
+
// // this.endControlPoint.set(subCurvePointsEnd[3]);
|
|
15326
|
+
// finalCurvePoints[1].set(subCurvePointsEnd[1]);
|
|
15327
|
+
// finalCurvePoints[3].set(subCurvePointsEnd[3]);
|
|
15328
|
+
// }
|
|
15329
|
+
// this.startPoint.set(finalCurvePoints[0]);
|
|
15330
|
+
// this.endPoint.set(finalCurvePoints[1]);
|
|
15331
|
+
// this.startControlPoint.set(finalCurvePoints[2]);
|
|
15332
|
+
// this.endControlPoint.set(finalCurvePoints[3]);
|
|
15333
|
+
// this.updateArcLengths();
|
|
15334
|
+
// return this;
|
|
15335
|
+
// }
|
|
15099
15336
|
/**
|
|
15100
15337
|
* Get a sub curve at the given start end end positions (values on the curve's length, between 0 and curve.arcLength).
|
|
15101
15338
|
*
|
|
@@ -15450,10 +15687,7 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
15450
15687
|
*/
|
|
15451
15688
|
CubicBezierCurve.utils = {
|
|
15452
15689
|
evaluateT: function (p0, p1, p2, p3, t) {
|
|
15453
|
-
return p0 * Math.pow(1.0 - t, 3) +
|
|
15454
|
-
p1 * 3 * t * Math.pow(1.0 - t, 2) +
|
|
15455
|
-
p2 * 3 * Math.pow(t, 2) * (1.0 - t) +
|
|
15456
|
-
p3 * Math.pow(t, 3);
|
|
15690
|
+
return (p0 * Math.pow(1.0 - t, 3) + p1 * 3 * t * Math.pow(1.0 - t, 2) + p2 * 3 * Math.pow(t, 2) * (1.0 - t) + p3 * Math.pow(t, 3));
|
|
15457
15691
|
},
|
|
15458
15692
|
cubicPolyMinMax: function (p0, p1, p2, p3) {
|
|
15459
15693
|
// var polyX = CubicBezierCurve.utils.cubicPoly2(
|
|
@@ -15525,7 +15759,7 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
15525
15759
|
* @param {number} tEnd – The end offset if the desired cub curve (must be in [0..1]).
|
|
15526
15760
|
* @instance
|
|
15527
15761
|
* @memberof CubicBezierCurve
|
|
15528
|
-
* @return {
|
|
15762
|
+
* @return {[Vertex, Vertex, Vertex, Vertex]} The sub curve as curve vertices.
|
|
15529
15763
|
**/
|
|
15530
15764
|
getSubCurvePointsAt: function (curve, tStart, tEnd) {
|
|
15531
15765
|
var startVec = new Vector_1.Vector(curve.getPointAt(tStart), curve.getTangentAt(tStart));
|
|
@@ -15614,11 +15848,7 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
15614
15848
|
* @returns {[number,number,number]}
|
|
15615
15849
|
*/
|
|
15616
15850
|
cubicPoly: function (p0, p1, p2, p3) {
|
|
15617
|
-
return [
|
|
15618
|
-
3 * p3 - 9 * p2 + 9 * p1 - 3 * p0,
|
|
15619
|
-
6 * p0 - 12 * p1 + 6 * p2,
|
|
15620
|
-
3 * p1 - 3 * p0
|
|
15621
|
-
];
|
|
15851
|
+
return [3 * p3 - 9 * p2 + 9 * p1 - 3 * p0, 6 * p0 - 12 * p1 + 6 * p2, 3 * p1 - 3 * p0];
|
|
15622
15852
|
},
|
|
15623
15853
|
/**
|
|
15624
15854
|
* sign of number, but is division safe: no zero returned :)
|