plotboilerplate 1.23.2 → 1.23.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +7052 -6754
- 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 +329 -27
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +4 -2
- package/src/cjs/PlotBoilerplate.d.ts +4 -2
- package/src/cjs/PlotBoilerplate.js +7 -3
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/Polygon.d.ts +107 -4
- package/src/cjs/Polygon.js +215 -9
- package/src/cjs/Polygon.js.map +1 -1
- package/src/cjs/Triangle.d.ts +23 -3
- package/src/cjs/Triangle.js +15 -2
- package/src/cjs/Triangle.js.map +1 -1
- package/src/cjs/VertTuple.d.ts +12 -7
- package/src/cjs/VertTuple.js +14 -9
- package/src/cjs/VertTuple.js.map +1 -1
- package/src/cjs/Vertex.d.ts +2 -1
- package/src/cjs/Vertex.js +5 -2
- package/src/cjs/Vertex.js.map +1 -1
- package/src/cjs/draw.d.ts +1 -0
- package/src/cjs/draw.js +2 -1
- package/src/cjs/draw.js.map +1 -1
- package/src/cjs/drawutilssvg.js +24 -0
- package/src/cjs/drawutilssvg.js.map +1 -1
- package/src/cjs/geomutils.d.ts +32 -1
- package/src/cjs/geomutils.js +47 -1
- package/src/cjs/geomutils.js.map +1 -1
- package/src/cjs/utils/algorithms/PolygonInset.d.ts +184 -0
- package/src/cjs/utils/algorithms/PolygonInset.js +431 -0
- package/src/cjs/utils/algorithms/PolygonInset.js.map +1 -0
- package/src/cjs/utils/algorithms/clearDuplicateVertices.d.ts +5 -4
- package/src/cjs/utils/algorithms/clearDuplicateVertices.js +6 -3
- package/src/cjs/utils/algorithms/clearDuplicateVertices.js.map +1 -1
- package/src/cjs/utils/algorithms/findPolygonSelfIntersections.d.ts +2 -1
- package/src/cjs/utils/algorithms/findPolygonSelfIntersections.js +3 -3
- package/src/cjs/utils/algorithms/findPolygonSelfIntersections.js.map +1 -1
- package/src/cjs/utils/algorithms/splitPolygonToNonIntersecting.d.ts +3 -2
- package/src/cjs/utils/algorithms/splitPolygonToNonIntersecting.js +11 -9
- package/src/cjs/utils/algorithms/splitPolygonToNonIntersecting.js.map +1 -1
- package/src/cjs/utils/detectDarkMode.js.map +1 -1
- package/src/cjs/utils/dom/guiSizeToggler.d.ts +2 -1
- package/src/cjs/utils/dom/guiSizeToggler.js +5 -3
- package/src/cjs/utils/dom/guiSizeToggler.js.map +1 -1
- package/src/esm/PlotBoilerplate.d.ts +4 -2
- package/src/esm/PlotBoilerplate.js +7 -3
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/Polygon.d.ts +107 -4
- package/src/esm/Polygon.js +214 -9
- package/src/esm/Polygon.js.map +1 -1
- package/src/esm/Triangle.d.ts +23 -3
- package/src/esm/Triangle.js +15 -2
- package/src/esm/Triangle.js.map +1 -1
- package/src/esm/VertTuple.d.ts +12 -7
- package/src/esm/VertTuple.js +14 -9
- package/src/esm/VertTuple.js.map +1 -1
- package/src/esm/Vertex.d.ts +2 -1
- package/src/esm/Vertex.js +5 -2
- package/src/esm/Vertex.js.map +1 -1
- package/src/esm/draw.d.ts +1 -0
- package/src/esm/draw.js +2 -1
- package/src/esm/draw.js.map +1 -1
- package/src/esm/drawutilssvg.js +24 -0
- package/src/esm/drawutilssvg.js.map +1 -1
- package/src/esm/geomutils.d.ts +32 -1
- package/src/esm/geomutils.js +47 -1
- package/src/esm/geomutils.js.map +1 -1
- package/src/esm/utils/algorithms/PolygonInset.d.ts +184 -0
- package/src/esm/utils/algorithms/PolygonInset.js +424 -0
- package/src/esm/utils/algorithms/PolygonInset.js.map +1 -0
- package/src/esm/utils/algorithms/clearDuplicateVertices.d.ts +5 -4
- package/src/esm/utils/algorithms/clearDuplicateVertices.js +6 -3
- package/src/esm/utils/algorithms/clearDuplicateVertices.js.map +1 -1
- package/src/esm/utils/algorithms/findPolygonSelfIntersections.d.ts +2 -1
- package/src/esm/utils/algorithms/findPolygonSelfIntersections.js +3 -3
- package/src/esm/utils/algorithms/findPolygonSelfIntersections.js.map +1 -1
- package/src/esm/utils/algorithms/splitPolygonToNonIntersecting.d.ts +3 -2
- package/src/esm/utils/algorithms/splitPolygonToNonIntersecting.js +11 -9
- package/src/esm/utils/algorithms/splitPolygonToNonIntersecting.js.map +1 -1
- package/src/esm/utils/detectDarkMode.js.map +1 -1
- package/src/esm/utils/dom/guiSizeToggler.d.ts +2 -1
- package/src/esm/utils/dom/guiSizeToggler.js +4 -2
- package/src/esm/utils/dom/guiSizeToggler.js.map +1 -1
- package/src/ts/PlotBoilerplate.ts +7 -3
- package/src/ts/Polygon.ts +230 -9
- package/src/ts/Triangle.ts +18 -4
- package/src/ts/VertTuple.ts +15 -10
- package/src/ts/Vertex.ts +5 -2
- package/src/ts/draw.ts +2 -1
- package/src/ts/drawutilssvg.ts +29 -0
- package/src/ts/geomutils.ts +49 -1
- package/src/ts/utils/algorithms/PolygonInset.ts +529 -0
- package/src/ts/utils/algorithms/clearDuplicateVertices.ts +11 -8
- package/src/ts/utils/algorithms/findPolygonSelfIntersections.ts +25 -26
- package/src/ts/utils/algorithms/splitPolygonToNonIntersecting.ts +92 -99
- package/src/ts/utils/detectDarkMode.ts +1 -3
- package/src/ts/utils/dom/guiSizeToggler.ts +4 -2
package/dist/plotboilerplate.js
CHANGED
|
@@ -4333,8 +4333,9 @@ exports.PBText = PBText;
|
|
|
4333
4333
|
* @modified 2023-09-29 Adding proper dicionary key and value types to the params of `PlotBoilerplate.utils.safeMergeByKeys` (was `object` before).
|
|
4334
4334
|
* @modified 2024-07-08 Adding `PlotBoilerplate.getGUI()` to retrieve the GUI instance.
|
|
4335
4335
|
* @modified 2024-08-25 Extending main class `PlotBoilerplate` optional param `isBackdropFiltersEnabled`.
|
|
4336
|
+
* @modified 2024-12-02 Adding the `triggerRedraw` to the `removeAll` method.
|
|
4336
4337
|
*
|
|
4337
|
-
* @version 1.
|
|
4338
|
+
* @version 1.20.0
|
|
4338
4339
|
*
|
|
4339
4340
|
* @file PlotBoilerplate
|
|
4340
4341
|
* @fileoverview The main class.
|
|
@@ -5094,16 +5095,19 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
5094
5095
|
*
|
|
5095
5096
|
* @method removeAll
|
|
5096
5097
|
* @param {boolean=false} keepVertices
|
|
5098
|
+
* @param {boolean=true} triggerRedraw - By default this method triggers the redraw routine; passing `false` will suppress redrawing.
|
|
5097
5099
|
* @instance
|
|
5098
5100
|
* @memberof PlotBoilerplate
|
|
5099
5101
|
* @return {void}
|
|
5100
5102
|
*/
|
|
5101
|
-
PlotBoilerplate.prototype.removeAll = function (keepVertices) {
|
|
5103
|
+
PlotBoilerplate.prototype.removeAll = function (keepVertices, triggerRedraw) {
|
|
5102
5104
|
this.drawables = [];
|
|
5103
5105
|
if (!Boolean(keepVertices)) {
|
|
5104
5106
|
this.vertices = [];
|
|
5105
5107
|
}
|
|
5106
|
-
|
|
5108
|
+
if (triggerRedraw || typeof triggerRedraw === "undefined") {
|
|
5109
|
+
this.redraw();
|
|
5110
|
+
}
|
|
5107
5111
|
};
|
|
5108
5112
|
/**
|
|
5109
5113
|
* Find the vertex near the given position.
|
|
@@ -6526,7 +6530,11 @@ exports["default"] = PlotBoilerplate;
|
|
|
6526
6530
|
* @modified 2023-09-25 Added the `Polygon.lineIntersections(Line,boolean)` function.
|
|
6527
6531
|
* @modified 2023-09-29 Added the `Polygon.closestLineIntersection(Line,boolean)` function.
|
|
6528
6532
|
* @modified 2023-11-24 Added the `Polygon.containsPolygon(Polygon)' function.
|
|
6529
|
-
* @
|
|
6533
|
+
* @modified 2024-10-12 Added the `getEdgeAt` method.
|
|
6534
|
+
* @modified 2024-10-30 Added the `getEdges` method.
|
|
6535
|
+
* @modified 2024-12-02 Added the `elimitateColinearEdges` method.
|
|
6536
|
+
* @modified 2025-02-12 Added the `containsVerts` method to test multiple vertices for containment.
|
|
6537
|
+
* @version 1.14.0
|
|
6530
6538
|
*
|
|
6531
6539
|
* @file Polygon
|
|
6532
6540
|
* @public
|
|
@@ -6536,8 +6544,10 @@ exports.Polygon = void 0;
|
|
|
6536
6544
|
var BezierPath_1 = __webpack_require__(733);
|
|
6537
6545
|
var Bounds_1 = __webpack_require__(76);
|
|
6538
6546
|
var Line_1 = __webpack_require__(939);
|
|
6547
|
+
var Triangle_1 = __webpack_require__(737);
|
|
6539
6548
|
var UIDGenerator_1 = __webpack_require__(938);
|
|
6540
6549
|
var Vertex_1 = __webpack_require__(787);
|
|
6550
|
+
var geomutils_1 = __webpack_require__(328);
|
|
6541
6551
|
/**
|
|
6542
6552
|
* @classdesc A polygon class. Any polygon consists of an array of vertices; polygons can be open or closed.
|
|
6543
6553
|
*
|
|
@@ -6564,15 +6574,16 @@ var Polygon = /** @class */ (function () {
|
|
|
6564
6574
|
**/
|
|
6565
6575
|
this.className = "Polygon";
|
|
6566
6576
|
this.uid = UIDGenerator_1.UIDGenerator.next();
|
|
6567
|
-
if (typeof vertices == "undefined")
|
|
6577
|
+
if (typeof vertices == "undefined") {
|
|
6568
6578
|
vertices = [];
|
|
6579
|
+
}
|
|
6569
6580
|
this.vertices = vertices;
|
|
6570
6581
|
this.isOpen = isOpen || false;
|
|
6571
6582
|
}
|
|
6572
6583
|
/**
|
|
6573
6584
|
* Add a vertex to the end of the `vertices` array.
|
|
6574
6585
|
*
|
|
6575
|
-
* @method
|
|
6586
|
+
* @method addVertex
|
|
6576
6587
|
* @param {Vertex} vert - The vertex to add.
|
|
6577
6588
|
* @instance
|
|
6578
6589
|
* @memberof Polygon
|
|
@@ -6580,6 +6591,108 @@ var Polygon = /** @class */ (function () {
|
|
|
6580
6591
|
Polygon.prototype.addVertex = function (vert) {
|
|
6581
6592
|
this.vertices.push(vert);
|
|
6582
6593
|
};
|
|
6594
|
+
/**
|
|
6595
|
+
* Add a vertex at a particular position of the `vertices` array.
|
|
6596
|
+
*
|
|
6597
|
+
* @method addVertexAt
|
|
6598
|
+
* @param {Vertex} vert - The vertex to add.
|
|
6599
|
+
* @param {number} index - The position to add the vertex at. Will be handled modulo.
|
|
6600
|
+
* @instance
|
|
6601
|
+
* @memberof Polygon
|
|
6602
|
+
**/
|
|
6603
|
+
Polygon.prototype.addVertexAt = function (vert, index) {
|
|
6604
|
+
// var moduloIndex = index % (this.vertices.length + 1);
|
|
6605
|
+
this.vertices.splice(index, 0, vert);
|
|
6606
|
+
};
|
|
6607
|
+
/**
|
|
6608
|
+
* Get a new instance of the line at the given start index. The returned line will consist
|
|
6609
|
+
* of the vertex at `vertIndex` and `vertIndex+1` (will be handled modulo).
|
|
6610
|
+
*
|
|
6611
|
+
* @method getEdgeAt
|
|
6612
|
+
* @param {number} vertIndex - The vertex index of the line to start.
|
|
6613
|
+
* @instance
|
|
6614
|
+
* @memberof Polygon
|
|
6615
|
+
* @return {Line}
|
|
6616
|
+
**/
|
|
6617
|
+
Polygon.prototype.getEdgeAt = function (vertIndex) {
|
|
6618
|
+
return new Line_1.Line(this.getVertexAt(vertIndex), this.getVertexAt(vertIndex + 1));
|
|
6619
|
+
};
|
|
6620
|
+
/**
|
|
6621
|
+
* Converts this polygon into a sequence of lines. Please note that each time
|
|
6622
|
+
* this method is called new lines are created. The underlying line vertices are no clones
|
|
6623
|
+
* (instances).
|
|
6624
|
+
*
|
|
6625
|
+
* @method getEdges
|
|
6626
|
+
* @instance
|
|
6627
|
+
* @memberof Polygon
|
|
6628
|
+
* @return {Array<Line>}
|
|
6629
|
+
*/
|
|
6630
|
+
Polygon.prototype.getEdges = function () {
|
|
6631
|
+
var lines = [];
|
|
6632
|
+
for (var i = 0; i + 1 < this.vertices.length; i++) {
|
|
6633
|
+
// var line = this.getLineAt(i).clone();
|
|
6634
|
+
lines.push(this.getEdgeAt(i));
|
|
6635
|
+
}
|
|
6636
|
+
if (!this.isOpen && this.vertices.length > 0) {
|
|
6637
|
+
lines.push(this.getEdgeAt(this.vertices.length - 1));
|
|
6638
|
+
}
|
|
6639
|
+
return lines;
|
|
6640
|
+
};
|
|
6641
|
+
/**
|
|
6642
|
+
* Checks if the angle at the given polygon vertex (index) is acute. Please not that this is
|
|
6643
|
+
* only working for clockwise polygons. If this polygon is not clockwise please use the
|
|
6644
|
+
* `isClockwise` method and reverse polygon vertices if needed.
|
|
6645
|
+
*
|
|
6646
|
+
* @method isAngleAcute
|
|
6647
|
+
* @instance
|
|
6648
|
+
* @memberof Polygon
|
|
6649
|
+
* @param {number} vertIndex - The index of the polygon vertex to check.
|
|
6650
|
+
* @returns {boolean} `true` is angle is acute, `false` is obtuse.
|
|
6651
|
+
*/
|
|
6652
|
+
Polygon.prototype.getInnerAngleAt = function (vertIndex) {
|
|
6653
|
+
var p2 = this.vertices[vertIndex];
|
|
6654
|
+
var p1 = this.vertices[(vertIndex + this.vertices.length - 1) % this.vertices.length].clone();
|
|
6655
|
+
var p3 = this.vertices[(vertIndex + 1) % this.vertices.length].clone();
|
|
6656
|
+
// See
|
|
6657
|
+
// https://math.stackexchange.com/questions/149959/how-to-find-the-interior-angle-of-an-irregular-pentagon-or-polygon
|
|
6658
|
+
// π−arccos((P2−P1)⋅(P3−P2)|P2−P1||P3−P2|)
|
|
6659
|
+
// Check if triangle is acute (will be used later)
|
|
6660
|
+
// Acute angles and obtuse angles need to be handled differently.
|
|
6661
|
+
var isAcute = this.isAngleAcute(vertIndex);
|
|
6662
|
+
// Differences
|
|
6663
|
+
var zero = new Vertex_1.Vertex(0, 0);
|
|
6664
|
+
var p2mp1 = new Vertex_1.Vertex(p2.x - p1.x, p2.y - p1.y);
|
|
6665
|
+
var p3mp2 = new Vertex_1.Vertex(p3.x - p2.x, p3.y - p2.y);
|
|
6666
|
+
var p2mp1_len = zero.distance(p2mp1);
|
|
6667
|
+
var p3mp2_len = zero.distance(p3mp2);
|
|
6668
|
+
// Dot products
|
|
6669
|
+
var dotProduct = geomutils_1.geomutils.dotProduct(p2mp1, p3mp2);
|
|
6670
|
+
var lengthProduct = p2mp1_len * p3mp2_len;
|
|
6671
|
+
if (isAcute) {
|
|
6672
|
+
return Math.PI - Math.acos(dotProduct / lengthProduct);
|
|
6673
|
+
}
|
|
6674
|
+
else {
|
|
6675
|
+
return Math.PI + Math.acos(dotProduct / lengthProduct);
|
|
6676
|
+
}
|
|
6677
|
+
};
|
|
6678
|
+
/**
|
|
6679
|
+
* Checks if the angle at the given polygon vertex (index) is acute.
|
|
6680
|
+
*
|
|
6681
|
+
* @method isAngleAcute
|
|
6682
|
+
* @instance
|
|
6683
|
+
* @memberof Polygon
|
|
6684
|
+
* @param {number} vertIndex - The index of the polygon vertex to check.
|
|
6685
|
+
* @returns {boolean} `true` is angle is acute, `false` is obtuse.
|
|
6686
|
+
*/
|
|
6687
|
+
Polygon.prototype.isAngleAcute = function (vertIndex) {
|
|
6688
|
+
var A = this.vertices[(vertIndex + this.vertices.length - 1) % this.vertices.length].clone();
|
|
6689
|
+
var B = this.vertices[vertIndex];
|
|
6690
|
+
var C = this.vertices[(vertIndex + 1) % this.vertices.length].clone();
|
|
6691
|
+
// Find local winding number for triangle A B C
|
|
6692
|
+
var windingNumber = Triangle_1.Triangle.utils.determinant(A, B, C);
|
|
6693
|
+
// console.log("vertIndex", vertIndex, "windingNumber", windingNumber);
|
|
6694
|
+
return windingNumber < 0;
|
|
6695
|
+
};
|
|
6583
6696
|
/**
|
|
6584
6697
|
* Get the polygon vertex at the given position (index).
|
|
6585
6698
|
*
|
|
@@ -6590,17 +6703,19 @@ var Polygon = /** @class */ (function () {
|
|
|
6590
6703
|
* - getVertexAt( vertices.length + k ) == getVertexAt( k )
|
|
6591
6704
|
* - getVertexAt( -k ) == getVertexAt( vertices.length -k )
|
|
6592
6705
|
*
|
|
6593
|
-
* @
|
|
6706
|
+
* @method getVertexAt
|
|
6594
6707
|
* @param {number} index - The index of the desired vertex.
|
|
6595
6708
|
* @instance
|
|
6596
6709
|
* @memberof Polygon
|
|
6597
6710
|
* @return {Vertex} At the given index.
|
|
6598
6711
|
**/
|
|
6599
6712
|
Polygon.prototype.getVertexAt = function (index) {
|
|
6600
|
-
if (index < 0)
|
|
6713
|
+
if (index < 0) {
|
|
6601
6714
|
return this.vertices[this.vertices.length - (Math.abs(index) % this.vertices.length)];
|
|
6602
|
-
|
|
6715
|
+
}
|
|
6716
|
+
else {
|
|
6603
6717
|
return this.vertices[index % this.vertices.length];
|
|
6718
|
+
}
|
|
6604
6719
|
};
|
|
6605
6720
|
/**
|
|
6606
6721
|
* Move the polygon's vertices by the given amount.
|
|
@@ -6624,7 +6739,7 @@ var Polygon = /** @class */ (function () {
|
|
|
6624
6739
|
* https://stackoverflow.com/questions/22521982/check-if-point-inside-a-polygon
|
|
6625
6740
|
*
|
|
6626
6741
|
* @method containsVert
|
|
6627
|
-
* @param {XYCoords} vert - The vertex to check.
|
|
6742
|
+
* @param {XYCoords} vert - The vertex to check.
|
|
6628
6743
|
* @return {boolean} True if the passed vertex is inside this polygon. The polygon is considered closed.
|
|
6629
6744
|
* @instance
|
|
6630
6745
|
* @memberof Polygon
|
|
@@ -6642,6 +6757,21 @@ var Polygon = /** @class */ (function () {
|
|
|
6642
6757
|
}
|
|
6643
6758
|
return inside;
|
|
6644
6759
|
};
|
|
6760
|
+
/**
|
|
6761
|
+
* Check if all given vertices are inside this polygon.<br>
|
|
6762
|
+
* <br>
|
|
6763
|
+
* This method just uses the `Polygon.containsVert` method.
|
|
6764
|
+
*
|
|
6765
|
+
* @method containsVerts
|
|
6766
|
+
* @param {XYCoords[]} verts - The vertices to check.
|
|
6767
|
+
* @return {boolean} True if all passed vertices are inside this polygon. The polygon is considered closed.
|
|
6768
|
+
* @instance
|
|
6769
|
+
* @memberof Polygon
|
|
6770
|
+
**/
|
|
6771
|
+
Polygon.prototype.containsVerts = function (verts) {
|
|
6772
|
+
var _this = this;
|
|
6773
|
+
return verts.every(function (vert) { return _this.containsVert(vert); });
|
|
6774
|
+
};
|
|
6645
6775
|
/**
|
|
6646
6776
|
* Check if the passed polygon is completly contained inside this polygon.
|
|
6647
6777
|
*
|
|
@@ -6704,7 +6834,8 @@ var Polygon = /** @class */ (function () {
|
|
|
6704
6834
|
* @return {boolean}
|
|
6705
6835
|
*/
|
|
6706
6836
|
Polygon.prototype.isClockwise = function () {
|
|
6707
|
-
return Polygon.utils.signedArea(this.vertices) < 0;
|
|
6837
|
+
// return Polygon.utils.signedArea(this.vertices) < 0;
|
|
6838
|
+
return Polygon.utils.isClockwise(this.vertices);
|
|
6708
6839
|
};
|
|
6709
6840
|
/**
|
|
6710
6841
|
* Get the perimeter of this polygon.
|
|
@@ -6763,6 +6894,28 @@ var Polygon = /** @class */ (function () {
|
|
|
6763
6894
|
}
|
|
6764
6895
|
return this;
|
|
6765
6896
|
};
|
|
6897
|
+
/**
|
|
6898
|
+
* Get the mean `center` of this polygon by calculating the mean value of all vertices.
|
|
6899
|
+
*
|
|
6900
|
+
* Mean: (v[0] + v[1] + ... v[n-1]) / n
|
|
6901
|
+
*
|
|
6902
|
+
* @method getMeanCenter
|
|
6903
|
+
* @instance
|
|
6904
|
+
* @memberof Polygon
|
|
6905
|
+
* @return {Vertex|null} `null` is no vertices are available.
|
|
6906
|
+
*/
|
|
6907
|
+
Polygon.prototype.getMeanCenter = function () {
|
|
6908
|
+
if (this.vertices.length === 0) {
|
|
6909
|
+
return null;
|
|
6910
|
+
}
|
|
6911
|
+
var center = this.vertices[0].clone();
|
|
6912
|
+
for (var i = 1; i < this.vertices.length; i++) {
|
|
6913
|
+
center.add(this.vertices[i]);
|
|
6914
|
+
}
|
|
6915
|
+
center.x /= this.vertices.length;
|
|
6916
|
+
center.y /= this.vertices.length;
|
|
6917
|
+
return center;
|
|
6918
|
+
};
|
|
6766
6919
|
/**
|
|
6767
6920
|
* Get all line intersections with this polygon.
|
|
6768
6921
|
*
|
|
@@ -6905,11 +7058,64 @@ var Polygon = /** @class */ (function () {
|
|
|
6905
7058
|
/**
|
|
6906
7059
|
* Create a deep copy of this polygon.
|
|
6907
7060
|
*
|
|
7061
|
+
* @method clone
|
|
7062
|
+
* @instance
|
|
7063
|
+
* @memberof Polygon
|
|
6908
7064
|
* @return {Polygon} The cloned polygon.
|
|
6909
7065
|
*/
|
|
6910
7066
|
Polygon.prototype.clone = function () {
|
|
6911
7067
|
return new Polygon(this.vertices.map(function (vert) { return vert.clone(); }), this.isOpen);
|
|
6912
7068
|
};
|
|
7069
|
+
/**
|
|
7070
|
+
* Create a new polygon without colinear adjacent edges. This method does not midify the current polygon
|
|
7071
|
+
* but creates a new one.
|
|
7072
|
+
*
|
|
7073
|
+
* Please note that this method does NOT create deep clones of the vertices. Use Polygon.clone() if you need to.
|
|
7074
|
+
*
|
|
7075
|
+
* Please also note that the `tolerance` may become really large here, as the denominator of two closely
|
|
7076
|
+
* parallel lines is usually pretty large. See the demo `57-eliminate-colinear-polygon-edges` to get
|
|
7077
|
+
* an impression of how denominators work.
|
|
7078
|
+
*
|
|
7079
|
+
* @method elimitateColinearEdges
|
|
7080
|
+
* @instance
|
|
7081
|
+
* @memberof Polygon
|
|
7082
|
+
* @param {number?} tolerance - (default is 1.0) The epsilon to detect co-linear edges.
|
|
7083
|
+
* @return {Polygon} A new polygon without co-linear adjacent edges – respective the given epsilon.
|
|
7084
|
+
*/
|
|
7085
|
+
Polygon.prototype.elimitateColinearEdges = function (tolerance) {
|
|
7086
|
+
var eps = typeof tolerance === "undefined" ? 1.0 : tolerance;
|
|
7087
|
+
var verts = this.vertices.slice(); // Creates a shallow copy
|
|
7088
|
+
var i = 0;
|
|
7089
|
+
var lineA = new Line_1.Line(new Vertex_1.Vertex(), new Vertex_1.Vertex());
|
|
7090
|
+
var lineB = new Line_1.Line(new Vertex_1.Vertex(), new Vertex_1.Vertex());
|
|
7091
|
+
while (i + 1 < verts.length && verts.length > 2) {
|
|
7092
|
+
var vertA = verts[i];
|
|
7093
|
+
var vertB = verts[(i + 1) % verts.length];
|
|
7094
|
+
lineA.a = vertA;
|
|
7095
|
+
lineA.b = vertB;
|
|
7096
|
+
lineB.a = vertB;
|
|
7097
|
+
var areColinear = false;
|
|
7098
|
+
var j = i + 2;
|
|
7099
|
+
do {
|
|
7100
|
+
var vertC = verts[j % verts.length];
|
|
7101
|
+
lineB.b = vertC;
|
|
7102
|
+
areColinear = lineA.colinear(lineB, eps);
|
|
7103
|
+
// console.log("are colinear?", i, i + 1, j, areColinear);
|
|
7104
|
+
if (areColinear) {
|
|
7105
|
+
j++;
|
|
7106
|
+
}
|
|
7107
|
+
} while (areColinear);
|
|
7108
|
+
// Now j points to the first vertex that's NOT colinear to the current lineA
|
|
7109
|
+
// -> delete all vertices in between
|
|
7110
|
+
if (j - i > 2) {
|
|
7111
|
+
// Means: there have been 'colinear vertices' in between
|
|
7112
|
+
// console.log("Splice", "i", i, "j", j, i + 1, j - i - 1);
|
|
7113
|
+
verts.splice(i + 1, j - i - 2);
|
|
7114
|
+
}
|
|
7115
|
+
i++;
|
|
7116
|
+
}
|
|
7117
|
+
return new Polygon(verts, this.isOpen);
|
|
7118
|
+
};
|
|
6913
7119
|
/**
|
|
6914
7120
|
* Convert this polygon to a sequence of quadratic Bézier curves.<br>
|
|
6915
7121
|
* <br>
|
|
@@ -7009,8 +7215,9 @@ var Polygon = /** @class */ (function () {
|
|
|
7009
7215
|
**/
|
|
7010
7216
|
Polygon.prototype.toCubicBezierSVGString = function (threshold) {
|
|
7011
7217
|
var qdata = this.toCubicBezierData(threshold);
|
|
7012
|
-
if (qdata.length == 0)
|
|
7218
|
+
if (qdata.length == 0) {
|
|
7013
7219
|
return "";
|
|
7220
|
+
}
|
|
7014
7221
|
var buffer = ["M " + qdata[0].x + " " + qdata[0].y];
|
|
7015
7222
|
for (var i = 1; i < qdata.length; i += 3) {
|
|
7016
7223
|
buffer.push("C " +
|
|
@@ -7080,6 +7287,9 @@ var Polygon = /** @class */ (function () {
|
|
|
7080
7287
|
}
|
|
7081
7288
|
return Math.abs(total);
|
|
7082
7289
|
},
|
|
7290
|
+
isClockwise: function (vertices) {
|
|
7291
|
+
return Polygon.utils.signedArea(vertices) < 0;
|
|
7292
|
+
},
|
|
7083
7293
|
/**
|
|
7084
7294
|
* Calulate the signed polyon area by interpreting the polygon as a matrix
|
|
7085
7295
|
* and calculating its determinant.
|
|
@@ -7131,7 +7341,9 @@ exports.Polygon = Polygon;
|
|
|
7131
7341
|
* @modified 2021-01-22 Always updating circumcircle when retieving it.
|
|
7132
7342
|
* @modified 2022-02-02 Added the `destroy` method.
|
|
7133
7343
|
* @modified 2022-02-02 Cleared the `Triangle.toSVGString` function (deprecated). Use `drawutilssvg` instead.
|
|
7134
|
-
* @
|
|
7344
|
+
* @modified 2024-11-22 Added static utility function Triangle.utils.determinant; adapted method `determinant`.
|
|
7345
|
+
* @modified 2024-11-22 Changing visibility of `Triangle.utils` from `private` to `public`.
|
|
7346
|
+
* @version 2.8.0
|
|
7135
7347
|
*
|
|
7136
7348
|
* @file Triangle
|
|
7137
7349
|
* @fileoverview A simple triangle class: three vertices.
|
|
@@ -7393,7 +7605,8 @@ var Triangle = /** @class */ (function () {
|
|
|
7393
7605
|
*/
|
|
7394
7606
|
Triangle.prototype.determinant = function () {
|
|
7395
7607
|
// (b.y - a.y)*(c.x - b.x) - (c.y - b.y)*(b.x - a.x);
|
|
7396
|
-
return (this.b.y - this.a.y) * (this.c.x - this.b.x) - (this.c.y - this.b.y) * (this.b.x - this.a.x);
|
|
7608
|
+
// return (this.b.y - this.a.y) * (this.c.x - this.b.x) - (this.c.y - this.b.y) * (this.b.x - this.a.x);
|
|
7609
|
+
return Triangle.utils.determinant(this.a, this.b, this.c);
|
|
7397
7610
|
};
|
|
7398
7611
|
/**
|
|
7399
7612
|
* Checks if the passed vertex (p) is inside this triangle.
|
|
@@ -7506,6 +7719,16 @@ var Triangle = /** @class */ (function () {
|
|
|
7506
7719
|
var s = (1 / (2 * area)) * (p0y * p2x - p0x * p2y + (p2y - p0y) * px + (p0x - p2x) * py);
|
|
7507
7720
|
var t = (1 / (2 * area)) * (p0x * p1y - p0y * p1x + (p0y - p1y) * px + (p1x - p0x) * py);
|
|
7508
7721
|
return s > 0 && t > 0 && 1 - s - t > 0;
|
|
7722
|
+
},
|
|
7723
|
+
/**
|
|
7724
|
+
* Calculate the determinant of the three vertices a, b and c (in this order).
|
|
7725
|
+
* @param {XYCords} a - The first vertex.
|
|
7726
|
+
* @param {XYCords} b - The first vertex.
|
|
7727
|
+
* @param {XYCords} c - The first vertex.
|
|
7728
|
+
* @returns {nmber}
|
|
7729
|
+
*/
|
|
7730
|
+
determinant: function (a, b, c) {
|
|
7731
|
+
return (b.y - a.y) * (c.x - b.x) - (c.y - b.y) * (b.x - a.x);
|
|
7509
7732
|
}
|
|
7510
7733
|
};
|
|
7511
7734
|
return Triangle;
|
|
@@ -8460,7 +8683,10 @@ exports.Vector = Vector;
|
|
|
8460
8683
|
* @modified 2021-01-20 Added UID.
|
|
8461
8684
|
* @modified 2022-02-02 Added the `destroy` method.
|
|
8462
8685
|
* @modified 2023-09-29 Fixed a calculation error in the VertTuple.hasPoint() function; distance measure was broken!
|
|
8463
|
-
* @
|
|
8686
|
+
* @modified 2024-09-10 Chaging the first param of `pointDistance` from `Vertex` to less strict type `XYCoords`. This should not break anything.
|
|
8687
|
+
* @modified 2024-09-10 Adding the optional `epsilon` param to the `hasPoint` method.
|
|
8688
|
+
* @modified 2024-12-02 Added the `epsilon` param to the `colinear` method. Default is 1.0e-6.
|
|
8689
|
+
* @version 1.3.0
|
|
8464
8690
|
*/
|
|
8465
8691
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
8466
8692
|
exports.VertTuple = void 0;
|
|
@@ -8635,12 +8861,13 @@ var VertTuple = /** @class */ (function () {
|
|
|
8635
8861
|
*
|
|
8636
8862
|
* @method colinear
|
|
8637
8863
|
* @param {VertTuple} line
|
|
8864
|
+
* @param {epsilon?=1.0e-6} epsilon - The epsilon to use (default is 1.0e-6).
|
|
8638
8865
|
* @instance
|
|
8639
8866
|
* @memberof VertTuple
|
|
8640
8867
|
* @return true if both lines are co-linear.
|
|
8641
8868
|
*/
|
|
8642
|
-
VertTuple.prototype.colinear = function (line) {
|
|
8643
|
-
return Math.abs(this.denominator(line)) < Vertex_1.Vertex.EPSILON;
|
|
8869
|
+
VertTuple.prototype.colinear = function (line, epsilon) {
|
|
8870
|
+
return Math.abs(this.denominator(line)) < (typeof epsilon === "undefined" ? Vertex_1.Vertex.EPSILON : epsilon);
|
|
8644
8871
|
};
|
|
8645
8872
|
/**
|
|
8646
8873
|
* Get the closest position T from this line to the specified point.
|
|
@@ -8669,21 +8896,22 @@ var VertTuple = /** @class */ (function () {
|
|
|
8669
8896
|
* that point is located between point `a` and `b`.
|
|
8670
8897
|
*
|
|
8671
8898
|
* @method hasPoint
|
|
8672
|
-
* @param {Vertex} point The point to check.
|
|
8673
|
-
* @param {boolean=} insideBoundsOnly If set to to true (default=false) the point must be between start and end point of the line.
|
|
8899
|
+
* @param {Vertex} point - The point to check.
|
|
8900
|
+
* @param {boolean=} insideBoundsOnly - [optional] If set to to true (default=false) the point must be between start and end point of the line.
|
|
8901
|
+
* @param {number=Vertex.EPSILON} epsilon - [optional] A tolerance.
|
|
8674
8902
|
* @return {boolean} True if the given point is on this line.
|
|
8675
8903
|
* @instance
|
|
8676
8904
|
* @memberof VertTuple
|
|
8677
8905
|
*/
|
|
8678
|
-
VertTuple.prototype.hasPoint = function (point, insideBoundsOnly) {
|
|
8906
|
+
VertTuple.prototype.hasPoint = function (point, insideBoundsOnly, epsilon) {
|
|
8679
8907
|
var t = this.getClosestT(point);
|
|
8680
8908
|
// Compare to pointDistance?
|
|
8681
8909
|
var distance = Math.sqrt(VertTuple.vtutils.dist2(point, this.vertAt(t)));
|
|
8682
8910
|
if (typeof insideBoundsOnly !== "undefined" && insideBoundsOnly) {
|
|
8683
|
-
return distance < Vertex_1.Vertex.EPSILON && t >= 0 && t <= 1;
|
|
8911
|
+
return distance < (epsilon !== null && epsilon !== void 0 ? epsilon : Vertex_1.Vertex.EPSILON) && t >= 0 && t <= 1;
|
|
8684
8912
|
}
|
|
8685
8913
|
else {
|
|
8686
|
-
return distance < Vertex_1.Vertex.EPSILON; // t >= 0 && t <= 1;
|
|
8914
|
+
return distance < (epsilon !== null && epsilon !== void 0 ? epsilon : Vertex_1.Vertex.EPSILON); // t >= 0 && t <= 1;
|
|
8687
8915
|
}
|
|
8688
8916
|
};
|
|
8689
8917
|
/**
|
|
@@ -8703,7 +8931,7 @@ var VertTuple = /** @class */ (function () {
|
|
|
8703
8931
|
* The the minimal distance between this line and the specified point.
|
|
8704
8932
|
*
|
|
8705
8933
|
* @method pointDistance
|
|
8706
|
-
* @param {
|
|
8934
|
+
* @param {XYCoords} p The point (vertex) to measre the distance to.
|
|
8707
8935
|
* @return {number} The absolute minimal distance.
|
|
8708
8936
|
* @instance
|
|
8709
8937
|
* @memberof VertTuple
|
|
@@ -8798,7 +9026,8 @@ exports.VertTuple = VertTuple;
|
|
|
8798
9026
|
* @modified 2023-09-29 Downgraded types for the `Vertex.utils.buildArrowHead` function (replacing Vertex params by more generic XYCoords type).
|
|
8799
9027
|
* @modified 2023-09-29 Added the `Vertex.abs()` method as it seems useful.
|
|
8800
9028
|
* @modified 2024-03-08 Added the optional `precision` param to the `toString` method.
|
|
8801
|
-
* @
|
|
9029
|
+
* @modified 2024-12-17 Outsourced the euclidean distance calculation of `Vertex.distance` to `geomutils.dist4`.
|
|
9030
|
+
* @version 2.9.1
|
|
8802
9031
|
*
|
|
8803
9032
|
* @file Vertex
|
|
8804
9033
|
* @public
|
|
@@ -8808,6 +9037,7 @@ exports.Vertex = void 0;
|
|
|
8808
9037
|
var VertexAttr_1 = __webpack_require__(476);
|
|
8809
9038
|
var UIDGenerator_1 = __webpack_require__(938);
|
|
8810
9039
|
var VertexListeners_1 = __webpack_require__(934);
|
|
9040
|
+
var geomutils_1 = __webpack_require__(328);
|
|
8811
9041
|
/**
|
|
8812
9042
|
* @classdesc A vertex is a pair of two numbers.<br>
|
|
8813
9043
|
* <br>
|
|
@@ -9151,7 +9381,8 @@ var Vertex = /** @class */ (function () {
|
|
|
9151
9381
|
* @memberof Vertex
|
|
9152
9382
|
**/
|
|
9153
9383
|
Vertex.prototype.distance = function (vert) {
|
|
9154
|
-
return Math.sqrt(Math.pow(vert.x - this.x, 2) + Math.pow(vert.y - this.y, 2));
|
|
9384
|
+
// return Math.sqrt(Math.pow(vert.x - this.x, 2) + Math.pow(vert.y - this.y, 2));
|
|
9385
|
+
return geomutils_1.geomutils.dist4(this.x, this.y, vert.x, vert.y);
|
|
9155
9386
|
};
|
|
9156
9387
|
/**
|
|
9157
9388
|
* Get the angle of this point (relative to (0,0) or to the given other origin point).
|
|
@@ -9832,6 +10063,7 @@ exports.VertexListeners = VertexListeners;
|
|
|
9832
10063
|
* @modified 2023-09-29 Added the `lineDashes` attribute.
|
|
9833
10064
|
* @modified 2023-09-30 Adding `strokeOptions` param to these draw function: line, arrow, cubicBezierArrow, cubicBezier, cubicBezierPath, circle, circleArc, ellipse, square, rect, polygon, polyline.
|
|
9834
10065
|
* @modified 2023-10-07 Adding the optional `arrowHeadBasePositionBuffer` param to the arrowHead(...) method.
|
|
10066
|
+
* @modified 2024-09-13 Remoed the scaling of `lineWidth` in the `polygon` and `polyline` methods. This makes no sense here and doesn't match up with the behavior of other line functions.
|
|
9835
10067
|
* @version 1.13.0
|
|
9836
10068
|
**/
|
|
9837
10069
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
@@ -10762,7 +10994,7 @@ var drawutils = /** @class */ (function () {
|
|
|
10762
10994
|
this.ctx.save();
|
|
10763
10995
|
this.applyStrokeOpts(strokeOptions);
|
|
10764
10996
|
this.ctx.beginPath();
|
|
10765
|
-
this.ctx.lineWidth =
|
|
10997
|
+
this.ctx.lineWidth = lineWidth || 1.0;
|
|
10766
10998
|
this.ctx.moveTo(this.offset.x + vertices[0].x * this.scale.x, this.offset.y + vertices[0].y * this.scale.y);
|
|
10767
10999
|
for (var i = 0; i < vertices.length; i++) {
|
|
10768
11000
|
this.ctx.lineTo(this.offset.x + vertices[i].x * this.scale.x, this.offset.y + vertices[i].y * this.scale.y);
|
|
@@ -12690,6 +12922,30 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
12690
12922
|
* @memberof drawutilssvg
|
|
12691
12923
|
*/
|
|
12692
12924
|
drawutilssvg.prototype.grid = function (center, width, height, sizeX, sizeY, color) {
|
|
12925
|
+
// console.log("grid");
|
|
12926
|
+
// const node: SVGElement = this.makeNode("pattern");
|
|
12927
|
+
// var patternId = "pattern_id_" + Math.floor(Math.random() * 65365);
|
|
12928
|
+
// node.setAttribute("id", patternId);
|
|
12929
|
+
// node.setAttribute("viewBox", `0,0,${sizeX},${sizeY}`);
|
|
12930
|
+
// node.setAttribute("width", `${sizeX}`);
|
|
12931
|
+
// node.setAttribute("height", `${sizeX}`);
|
|
12932
|
+
// var pattern: SVGElement = this.makeNode("path");
|
|
12933
|
+
// const d: SVGPathParams = [];
|
|
12934
|
+
// d.push("M", sizeX / 2.0, 0);
|
|
12935
|
+
// d.push("L", sizeX / 2.0, sizeY);
|
|
12936
|
+
// d.push("M", 0, sizeY / 2.0);
|
|
12937
|
+
// d.push("L", sizeX, sizeY / 2.0);
|
|
12938
|
+
// node.setAttribute("d", d.join(" "));
|
|
12939
|
+
// this.bufferedNodeDefs.append(pattern);
|
|
12940
|
+
// const fillNode: SVGElement = this.makeNode("rect");
|
|
12941
|
+
// // For some strange reason SVG rotation transforms use degrees instead of radians
|
|
12942
|
+
// // Note that the background does not scale with the zoom level (always covers full element)
|
|
12943
|
+
// fillNode.setAttribute("x", "0");
|
|
12944
|
+
// fillNode.setAttribute("y", "0");
|
|
12945
|
+
// fillNode.setAttribute("width", `${this.canvasSize.width}`);
|
|
12946
|
+
// fillNode.setAttribute("height", `${this.canvasSize.height}`);
|
|
12947
|
+
// fillNode.setAttribute("fill", `url(#${patternId})`);
|
|
12948
|
+
// return this._bindFillDraw(fillNode, "grid", "red", 1);
|
|
12693
12949
|
var node = this.makeNode("path");
|
|
12694
12950
|
var d = [];
|
|
12695
12951
|
var yMin = -Math.ceil((height * 0.5) / sizeY) * sizeY;
|
|
@@ -13415,7 +13671,10 @@ exports.drawutilssvg = drawutilssvg;
|
|
|
13415
13671
|
* @author Ikaros Kappler
|
|
13416
13672
|
* @date 2019-02-03
|
|
13417
13673
|
* @modified 2021-03-01 Added `wrapMax` function.
|
|
13418
|
-
* @
|
|
13674
|
+
* @modified 2024-11-15 Adding helper function `geomutils.mapAngleTo2PI(number)` for mapping any value into the interval [0,2*PI).
|
|
13675
|
+
* @modified 2024-11-22 Adding helper function `geomutils.dotProduct(number)` for calculating the dot product of two vertices (as vectors).
|
|
13676
|
+
*
|
|
13677
|
+
* @version 1.2.0
|
|
13419
13678
|
**/
|
|
13420
13679
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
13421
13680
|
exports.geomutils = void 0;
|
|
@@ -13427,6 +13686,49 @@ var Triangle_1 = __webpack_require__(737);
|
|
|
13427
13686
|
* @global
|
|
13428
13687
|
**/
|
|
13429
13688
|
exports.geomutils = {
|
|
13689
|
+
/**
|
|
13690
|
+
* Map any angle (any numeric value) to [0, Math.PI).
|
|
13691
|
+
*
|
|
13692
|
+
* @param {number} angle - The numeric value to map.
|
|
13693
|
+
* @return {number} The mapped angle inside [0,PI*2].
|
|
13694
|
+
**/
|
|
13695
|
+
mapAngleTo2PI: function (angle) {
|
|
13696
|
+
// Source: https://forums.codeguru.com/showthread.php?384172-get-angle-into-range-0-2*pi
|
|
13697
|
+
var new_angle = Math.asin(Math.sin(angle));
|
|
13698
|
+
if (Math.cos(angle) < 0) {
|
|
13699
|
+
return Math.PI - new_angle;
|
|
13700
|
+
}
|
|
13701
|
+
else if (new_angle < 0) {
|
|
13702
|
+
return new_angle + 2 * Math.PI;
|
|
13703
|
+
}
|
|
13704
|
+
else {
|
|
13705
|
+
return new_angle;
|
|
13706
|
+
}
|
|
13707
|
+
},
|
|
13708
|
+
/**
|
|
13709
|
+
* Calculate the euclidean distance between two points given by four coordinates (two coordinates each).
|
|
13710
|
+
*
|
|
13711
|
+
* @param {number} x1
|
|
13712
|
+
* @param {number} y1
|
|
13713
|
+
* @param {number} x2
|
|
13714
|
+
* @param {number} y2
|
|
13715
|
+
* @returns {number}
|
|
13716
|
+
*/
|
|
13717
|
+
dist4: function (x1, y1, x2, y2) {
|
|
13718
|
+
return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y1 - y2, 2));
|
|
13719
|
+
},
|
|
13720
|
+
/**
|
|
13721
|
+
* Map any angle (any numeric value) to [0, Math.PI).
|
|
13722
|
+
*
|
|
13723
|
+
* A × B := (A.x * B.x) + (A.y * B.y)
|
|
13724
|
+
*
|
|
13725
|
+
* @param {XYCoords} vertA - The first vertex.
|
|
13726
|
+
* @param {XYCoords} vertB - The second vertex.
|
|
13727
|
+
* @return {number} The dot product of the two vertices.
|
|
13728
|
+
**/
|
|
13729
|
+
dotProduct: function (vertA, vertB) {
|
|
13730
|
+
return vertA.x * vertB.x + vertA.y * vertB.y;
|
|
13731
|
+
},
|
|
13430
13732
|
/**
|
|
13431
13733
|
* Compute the n-section of the angle – described as a triangle (A,B,C) – in point A.
|
|
13432
13734
|
*
|