plotboilerplate 1.23.1 → 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.
Files changed (136) hide show
  1. package/README.md +1 -1
  2. package/dist/index.esm.js +7055 -6751
  3. package/dist/index.esm.js.map +1 -1
  4. package/dist/index.esm.min.js +1 -1
  5. package/dist/index.esm.min.js.map +1 -1
  6. package/dist/plotboilerplate.browser.min.js +1 -1
  7. package/dist/plotboilerplate.browser.min.js.map +1 -1
  8. package/dist/plotboilerplate.js +342 -34
  9. package/dist/plotboilerplate.min.js +1 -1
  10. package/package.json +4 -2
  11. package/src/cjs/PlotBoilerplate.d.ts +5 -2
  12. package/src/cjs/PlotBoilerplate.js +10 -4
  13. package/src/cjs/PlotBoilerplate.js.map +1 -1
  14. package/src/cjs/Polygon.d.ts +107 -4
  15. package/src/cjs/Polygon.js +215 -9
  16. package/src/cjs/Polygon.js.map +1 -1
  17. package/src/cjs/Triangle.d.ts +23 -3
  18. package/src/cjs/Triangle.js +15 -2
  19. package/src/cjs/Triangle.js.map +1 -1
  20. package/src/cjs/VertTuple.d.ts +12 -7
  21. package/src/cjs/VertTuple.js +14 -9
  22. package/src/cjs/VertTuple.js.map +1 -1
  23. package/src/cjs/Vertex.d.ts +2 -1
  24. package/src/cjs/Vertex.js +5 -2
  25. package/src/cjs/Vertex.js.map +1 -1
  26. package/src/cjs/draw.d.ts +1 -0
  27. package/src/cjs/draw.js +2 -1
  28. package/src/cjs/draw.js.map +1 -1
  29. package/src/cjs/drawutilssvg.d.ts +6 -1
  30. package/src/cjs/drawutilssvg.js +34 -6
  31. package/src/cjs/drawutilssvg.js.map +1 -1
  32. package/src/cjs/geomutils.d.ts +32 -1
  33. package/src/cjs/geomutils.js +47 -1
  34. package/src/cjs/geomutils.js.map +1 -1
  35. package/src/cjs/interfaces/core.d.ts +4 -2
  36. package/src/cjs/interfaces/core.js +1 -0
  37. package/src/cjs/interfaces/core.js.map +1 -1
  38. package/src/cjs/interfaces/externals.d.ts +30 -0
  39. package/src/cjs/utils/InitializationObserver.js +7 -0
  40. package/src/cjs/utils/InitializationObserver.js.map +1 -1
  41. package/src/cjs/utils/Params.d.ts +5 -3
  42. package/src/cjs/utils/Params.js +7 -3
  43. package/src/cjs/utils/Params.js.map +1 -1
  44. package/src/cjs/utils/algorithms/PolygonInset.d.ts +184 -0
  45. package/src/cjs/utils/algorithms/PolygonInset.js +431 -0
  46. package/src/cjs/utils/algorithms/PolygonInset.js.map +1 -0
  47. package/src/cjs/utils/algorithms/clearDuplicateVertices.d.ts +5 -4
  48. package/src/cjs/utils/algorithms/clearDuplicateVertices.js +6 -3
  49. package/src/cjs/utils/algorithms/clearDuplicateVertices.js.map +1 -1
  50. package/src/cjs/utils/algorithms/findPolygonSelfIntersections.d.ts +2 -1
  51. package/src/cjs/utils/algorithms/findPolygonSelfIntersections.js +3 -3
  52. package/src/cjs/utils/algorithms/findPolygonSelfIntersections.js.map +1 -1
  53. package/src/cjs/utils/algorithms/splitPolygonToNonIntersecting.d.ts +3 -2
  54. package/src/cjs/utils/algorithms/splitPolygonToNonIntersecting.js +11 -9
  55. package/src/cjs/utils/algorithms/splitPolygonToNonIntersecting.js.map +1 -1
  56. package/src/cjs/utils/creategui.js +69 -1
  57. package/src/cjs/utils/detectDarkMode.js.map +1 -1
  58. package/src/cjs/utils/dom/guiSizeToggler.d.ts +2 -1
  59. package/src/cjs/utils/dom/guiSizeToggler.js +5 -3
  60. package/src/cjs/utils/dom/guiSizeToggler.js.map +1 -1
  61. package/src/cjs/utils/gup.d.ts +1 -0
  62. package/src/cjs/utils/gup.js +3 -1
  63. package/src/cjs/utils/gup.js.map +1 -1
  64. package/src/esm/PlotBoilerplate.d.ts +5 -2
  65. package/src/esm/PlotBoilerplate.js +10 -4
  66. package/src/esm/PlotBoilerplate.js.map +1 -1
  67. package/src/esm/Polygon.d.ts +107 -4
  68. package/src/esm/Polygon.js +214 -9
  69. package/src/esm/Polygon.js.map +1 -1
  70. package/src/esm/Triangle.d.ts +23 -3
  71. package/src/esm/Triangle.js +15 -2
  72. package/src/esm/Triangle.js.map +1 -1
  73. package/src/esm/VertTuple.d.ts +12 -7
  74. package/src/esm/VertTuple.js +14 -9
  75. package/src/esm/VertTuple.js.map +1 -1
  76. package/src/esm/Vertex.d.ts +2 -1
  77. package/src/esm/Vertex.js +5 -2
  78. package/src/esm/Vertex.js.map +1 -1
  79. package/src/esm/draw.d.ts +1 -0
  80. package/src/esm/draw.js +2 -1
  81. package/src/esm/draw.js.map +1 -1
  82. package/src/esm/drawutilssvg.d.ts +6 -1
  83. package/src/esm/drawutilssvg.js +34 -6
  84. package/src/esm/drawutilssvg.js.map +1 -1
  85. package/src/esm/geomutils.d.ts +32 -1
  86. package/src/esm/geomutils.js +47 -1
  87. package/src/esm/geomutils.js.map +1 -1
  88. package/src/esm/interfaces/core.d.ts +4 -2
  89. package/src/esm/interfaces/core.js +1 -0
  90. package/src/esm/interfaces/core.js.map +1 -1
  91. package/src/esm/interfaces/externals.d.ts +30 -0
  92. package/src/esm/utils/InitializationObserver.js +7 -0
  93. package/src/esm/utils/InitializationObserver.js.map +1 -1
  94. package/src/esm/utils/Params.d.ts +5 -3
  95. package/src/esm/utils/Params.js +7 -3
  96. package/src/esm/utils/Params.js.map +1 -1
  97. package/src/esm/utils/algorithms/PolygonInset.d.ts +184 -0
  98. package/src/esm/utils/algorithms/PolygonInset.js +424 -0
  99. package/src/esm/utils/algorithms/PolygonInset.js.map +1 -0
  100. package/src/esm/utils/algorithms/clearDuplicateVertices.d.ts +5 -4
  101. package/src/esm/utils/algorithms/clearDuplicateVertices.js +6 -3
  102. package/src/esm/utils/algorithms/clearDuplicateVertices.js.map +1 -1
  103. package/src/esm/utils/algorithms/findPolygonSelfIntersections.d.ts +2 -1
  104. package/src/esm/utils/algorithms/findPolygonSelfIntersections.js +3 -3
  105. package/src/esm/utils/algorithms/findPolygonSelfIntersections.js.map +1 -1
  106. package/src/esm/utils/algorithms/splitPolygonToNonIntersecting.d.ts +3 -2
  107. package/src/esm/utils/algorithms/splitPolygonToNonIntersecting.js +11 -9
  108. package/src/esm/utils/algorithms/splitPolygonToNonIntersecting.js.map +1 -1
  109. package/src/esm/utils/detectDarkMode.js.map +1 -1
  110. package/src/esm/utils/dom/guiSizeToggler.d.ts +2 -1
  111. package/src/esm/utils/dom/guiSizeToggler.js +4 -2
  112. package/src/esm/utils/dom/guiSizeToggler.js.map +1 -1
  113. package/src/esm/utils/gup.d.ts +1 -0
  114. package/src/esm/utils/gup.js +3 -1
  115. package/src/esm/utils/gup.js.map +1 -1
  116. package/src/index-gl.js +3 -1
  117. package/src/index.js +2 -1
  118. package/src/ts/PlotBoilerplate.ts +11 -4
  119. package/src/ts/Polygon.ts +230 -9
  120. package/src/ts/Triangle.ts +18 -4
  121. package/src/ts/VertTuple.ts +15 -10
  122. package/src/ts/Vertex.ts +5 -2
  123. package/src/ts/draw.ts +2 -1
  124. package/src/ts/drawutilssvg.ts +46 -6
  125. package/src/ts/geomutils.ts +49 -1
  126. package/src/ts/interfaces/core.ts +5 -2
  127. package/src/ts/interfaces/externals.ts +34 -0
  128. package/src/ts/utils/InitializationObserver.ts +7 -0
  129. package/src/ts/utils/Params.ts +8 -3
  130. package/src/ts/utils/algorithms/PolygonInset.ts +529 -0
  131. package/src/ts/utils/algorithms/clearDuplicateVertices.ts +11 -8
  132. package/src/ts/utils/algorithms/findPolygonSelfIntersections.ts +25 -26
  133. package/src/ts/utils/algorithms/splitPolygonToNonIntersecting.ts +92 -99
  134. package/src/ts/utils/detectDarkMode.ts +1 -3
  135. package/src/ts/utils/dom/guiSizeToggler.ts +4 -2
  136. package/src/ts/utils/gup.ts +3 -1
@@ -4332,8 +4332,10 @@ exports.PBText = PBText;
4332
4332
  * @modified 2023-02-10 Adding `enableZoom` and `enablePan` (both default true) to have the option to disable these functions.
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
+ * @modified 2024-08-25 Extending main class `PlotBoilerplate` optional param `isBackdropFiltersEnabled`.
4336
+ * @modified 2024-12-02 Adding the `triggerRedraw` to the `removeAll` method.
4335
4337
  *
4336
- * @version 1.18.0
4338
+ * @version 1.20.0
4337
4339
  *
4338
4340
  * @file PlotBoilerplate
4339
4341
  * @fileoverview The main class.
@@ -4538,7 +4540,8 @@ var PlotBoilerplate = /** @class */ (function () {
4538
4540
  enableZoom: f.bool(config, "enableZoom", true), // default=true
4539
4541
  enablePan: f.bool(config, "enablePan", true), // default=true
4540
4542
  // Experimental (and unfinished)
4541
- enableGL: f.bool(config, "enableGL", false)
4543
+ enableGL: f.bool(config, "enableGL", false),
4544
+ isBackdropFiltersEnabled: f.bool(config, "isBackdropFiltersEnabled", true)
4542
4545
  }; // END confog
4543
4546
  /**
4544
4547
  * Configuration for drawing things.
@@ -5092,16 +5095,19 @@ var PlotBoilerplate = /** @class */ (function () {
5092
5095
  *
5093
5096
  * @method removeAll
5094
5097
  * @param {boolean=false} keepVertices
5098
+ * @param {boolean=true} triggerRedraw - By default this method triggers the redraw routine; passing `false` will suppress redrawing.
5095
5099
  * @instance
5096
5100
  * @memberof PlotBoilerplate
5097
5101
  * @return {void}
5098
5102
  */
5099
- PlotBoilerplate.prototype.removeAll = function (keepVertices) {
5103
+ PlotBoilerplate.prototype.removeAll = function (keepVertices, triggerRedraw) {
5100
5104
  this.drawables = [];
5101
5105
  if (!Boolean(keepVertices)) {
5102
5106
  this.vertices = [];
5103
5107
  }
5104
- this.redraw();
5108
+ if (triggerRedraw || typeof triggerRedraw === "undefined") {
5109
+ this.redraw();
5110
+ }
5105
5111
  };
5106
5112
  /**
5107
5113
  * Find the vertex near the given position.
@@ -6524,7 +6530,11 @@ exports["default"] = PlotBoilerplate;
6524
6530
  * @modified 2023-09-25 Added the `Polygon.lineIntersections(Line,boolean)` function.
6525
6531
  * @modified 2023-09-29 Added the `Polygon.closestLineIntersection(Line,boolean)` function.
6526
6532
  * @modified 2023-11-24 Added the `Polygon.containsPolygon(Polygon)' function.
6527
- * @version 1.12.0
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
6528
6538
  *
6529
6539
  * @file Polygon
6530
6540
  * @public
@@ -6534,8 +6544,10 @@ exports.Polygon = void 0;
6534
6544
  var BezierPath_1 = __webpack_require__(733);
6535
6545
  var Bounds_1 = __webpack_require__(76);
6536
6546
  var Line_1 = __webpack_require__(939);
6547
+ var Triangle_1 = __webpack_require__(737);
6537
6548
  var UIDGenerator_1 = __webpack_require__(938);
6538
6549
  var Vertex_1 = __webpack_require__(787);
6550
+ var geomutils_1 = __webpack_require__(328);
6539
6551
  /**
6540
6552
  * @classdesc A polygon class. Any polygon consists of an array of vertices; polygons can be open or closed.
6541
6553
  *
@@ -6562,15 +6574,16 @@ var Polygon = /** @class */ (function () {
6562
6574
  **/
6563
6575
  this.className = "Polygon";
6564
6576
  this.uid = UIDGenerator_1.UIDGenerator.next();
6565
- if (typeof vertices == "undefined")
6577
+ if (typeof vertices == "undefined") {
6566
6578
  vertices = [];
6579
+ }
6567
6580
  this.vertices = vertices;
6568
6581
  this.isOpen = isOpen || false;
6569
6582
  }
6570
6583
  /**
6571
6584
  * Add a vertex to the end of the `vertices` array.
6572
6585
  *
6573
- * @method addVert
6586
+ * @method addVertex
6574
6587
  * @param {Vertex} vert - The vertex to add.
6575
6588
  * @instance
6576
6589
  * @memberof Polygon
@@ -6578,6 +6591,108 @@ var Polygon = /** @class */ (function () {
6578
6591
  Polygon.prototype.addVertex = function (vert) {
6579
6592
  this.vertices.push(vert);
6580
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
+ };
6581
6696
  /**
6582
6697
  * Get the polygon vertex at the given position (index).
6583
6698
  *
@@ -6588,17 +6703,19 @@ var Polygon = /** @class */ (function () {
6588
6703
  * - getVertexAt( vertices.length + k ) == getVertexAt( k )
6589
6704
  * - getVertexAt( -k ) == getVertexAt( vertices.length -k )
6590
6705
  *
6591
- * @metho getVertexAt
6706
+ * @method getVertexAt
6592
6707
  * @param {number} index - The index of the desired vertex.
6593
6708
  * @instance
6594
6709
  * @memberof Polygon
6595
6710
  * @return {Vertex} At the given index.
6596
6711
  **/
6597
6712
  Polygon.prototype.getVertexAt = function (index) {
6598
- if (index < 0)
6713
+ if (index < 0) {
6599
6714
  return this.vertices[this.vertices.length - (Math.abs(index) % this.vertices.length)];
6600
- else
6715
+ }
6716
+ else {
6601
6717
  return this.vertices[index % this.vertices.length];
6718
+ }
6602
6719
  };
6603
6720
  /**
6604
6721
  * Move the polygon's vertices by the given amount.
@@ -6622,7 +6739,7 @@ var Polygon = /** @class */ (function () {
6622
6739
  * https://stackoverflow.com/questions/22521982/check-if-point-inside-a-polygon
6623
6740
  *
6624
6741
  * @method containsVert
6625
- * @param {XYCoords} vert - The vertex to check. The new x-component.
6742
+ * @param {XYCoords} vert - The vertex to check.
6626
6743
  * @return {boolean} True if the passed vertex is inside this polygon. The polygon is considered closed.
6627
6744
  * @instance
6628
6745
  * @memberof Polygon
@@ -6640,6 +6757,21 @@ var Polygon = /** @class */ (function () {
6640
6757
  }
6641
6758
  return inside;
6642
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
+ };
6643
6775
  /**
6644
6776
  * Check if the passed polygon is completly contained inside this polygon.
6645
6777
  *
@@ -6702,7 +6834,8 @@ var Polygon = /** @class */ (function () {
6702
6834
  * @return {boolean}
6703
6835
  */
6704
6836
  Polygon.prototype.isClockwise = function () {
6705
- return Polygon.utils.signedArea(this.vertices) < 0;
6837
+ // return Polygon.utils.signedArea(this.vertices) < 0;
6838
+ return Polygon.utils.isClockwise(this.vertices);
6706
6839
  };
6707
6840
  /**
6708
6841
  * Get the perimeter of this polygon.
@@ -6761,6 +6894,28 @@ var Polygon = /** @class */ (function () {
6761
6894
  }
6762
6895
  return this;
6763
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
+ };
6764
6919
  /**
6765
6920
  * Get all line intersections with this polygon.
6766
6921
  *
@@ -6903,11 +7058,64 @@ var Polygon = /** @class */ (function () {
6903
7058
  /**
6904
7059
  * Create a deep copy of this polygon.
6905
7060
  *
7061
+ * @method clone
7062
+ * @instance
7063
+ * @memberof Polygon
6906
7064
  * @return {Polygon} The cloned polygon.
6907
7065
  */
6908
7066
  Polygon.prototype.clone = function () {
6909
7067
  return new Polygon(this.vertices.map(function (vert) { return vert.clone(); }), this.isOpen);
6910
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
+ };
6911
7119
  /**
6912
7120
  * Convert this polygon to a sequence of quadratic Bézier curves.<br>
6913
7121
  * <br>
@@ -7007,8 +7215,9 @@ var Polygon = /** @class */ (function () {
7007
7215
  **/
7008
7216
  Polygon.prototype.toCubicBezierSVGString = function (threshold) {
7009
7217
  var qdata = this.toCubicBezierData(threshold);
7010
- if (qdata.length == 0)
7218
+ if (qdata.length == 0) {
7011
7219
  return "";
7220
+ }
7012
7221
  var buffer = ["M " + qdata[0].x + " " + qdata[0].y];
7013
7222
  for (var i = 1; i < qdata.length; i += 3) {
7014
7223
  buffer.push("C " +
@@ -7078,6 +7287,9 @@ var Polygon = /** @class */ (function () {
7078
7287
  }
7079
7288
  return Math.abs(total);
7080
7289
  },
7290
+ isClockwise: function (vertices) {
7291
+ return Polygon.utils.signedArea(vertices) < 0;
7292
+ },
7081
7293
  /**
7082
7294
  * Calulate the signed polyon area by interpreting the polygon as a matrix
7083
7295
  * and calculating its determinant.
@@ -7129,7 +7341,9 @@ exports.Polygon = Polygon;
7129
7341
  * @modified 2021-01-22 Always updating circumcircle when retieving it.
7130
7342
  * @modified 2022-02-02 Added the `destroy` method.
7131
7343
  * @modified 2022-02-02 Cleared the `Triangle.toSVGString` function (deprecated). Use `drawutilssvg` instead.
7132
- * @version 2.6.0
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
7133
7347
  *
7134
7348
  * @file Triangle
7135
7349
  * @fileoverview A simple triangle class: three vertices.
@@ -7391,7 +7605,8 @@ var Triangle = /** @class */ (function () {
7391
7605
  */
7392
7606
  Triangle.prototype.determinant = function () {
7393
7607
  // (b.y - a.y)*(c.x - b.x) - (c.y - b.y)*(b.x - a.x);
7394
- 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);
7395
7610
  };
7396
7611
  /**
7397
7612
  * Checks if the passed vertex (p) is inside this triangle.
@@ -7504,6 +7719,16 @@ var Triangle = /** @class */ (function () {
7504
7719
  var s = (1 / (2 * area)) * (p0y * p2x - p0x * p2y + (p2y - p0y) * px + (p0x - p2x) * py);
7505
7720
  var t = (1 / (2 * area)) * (p0x * p1y - p0y * p1x + (p0y - p1y) * px + (p1x - p0x) * py);
7506
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);
7507
7732
  }
7508
7733
  };
7509
7734
  return Triangle;
@@ -8458,7 +8683,10 @@ exports.Vector = Vector;
8458
8683
  * @modified 2021-01-20 Added UID.
8459
8684
  * @modified 2022-02-02 Added the `destroy` method.
8460
8685
  * @modified 2023-09-29 Fixed a calculation error in the VertTuple.hasPoint() function; distance measure was broken!
8461
- * @version 1.2.1
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
8462
8690
  */
8463
8691
  Object.defineProperty(exports, "__esModule", ({ value: true }));
8464
8692
  exports.VertTuple = void 0;
@@ -8633,12 +8861,13 @@ var VertTuple = /** @class */ (function () {
8633
8861
  *
8634
8862
  * @method colinear
8635
8863
  * @param {VertTuple} line
8864
+ * @param {epsilon?=1.0e-6} epsilon - The epsilon to use (default is 1.0e-6).
8636
8865
  * @instance
8637
8866
  * @memberof VertTuple
8638
8867
  * @return true if both lines are co-linear.
8639
8868
  */
8640
- VertTuple.prototype.colinear = function (line) {
8641
- 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);
8642
8871
  };
8643
8872
  /**
8644
8873
  * Get the closest position T from this line to the specified point.
@@ -8667,21 +8896,22 @@ var VertTuple = /** @class */ (function () {
8667
8896
  * that point is located between point `a` and `b`.
8668
8897
  *
8669
8898
  * @method hasPoint
8670
- * @param {Vertex} point The point to check.
8671
- * @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.
8672
8902
  * @return {boolean} True if the given point is on this line.
8673
8903
  * @instance
8674
8904
  * @memberof VertTuple
8675
8905
  */
8676
- VertTuple.prototype.hasPoint = function (point, insideBoundsOnly) {
8906
+ VertTuple.prototype.hasPoint = function (point, insideBoundsOnly, epsilon) {
8677
8907
  var t = this.getClosestT(point);
8678
8908
  // Compare to pointDistance?
8679
8909
  var distance = Math.sqrt(VertTuple.vtutils.dist2(point, this.vertAt(t)));
8680
8910
  if (typeof insideBoundsOnly !== "undefined" && insideBoundsOnly) {
8681
- 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;
8682
8912
  }
8683
8913
  else {
8684
- 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;
8685
8915
  }
8686
8916
  };
8687
8917
  /**
@@ -8701,7 +8931,7 @@ var VertTuple = /** @class */ (function () {
8701
8931
  * The the minimal distance between this line and the specified point.
8702
8932
  *
8703
8933
  * @method pointDistance
8704
- * @param {Vertex} p The point (vertex) to measre the distance to.
8934
+ * @param {XYCoords} p The point (vertex) to measre the distance to.
8705
8935
  * @return {number} The absolute minimal distance.
8706
8936
  * @instance
8707
8937
  * @memberof VertTuple
@@ -8796,7 +9026,8 @@ exports.VertTuple = VertTuple;
8796
9026
  * @modified 2023-09-29 Downgraded types for the `Vertex.utils.buildArrowHead` function (replacing Vertex params by more generic XYCoords type).
8797
9027
  * @modified 2023-09-29 Added the `Vertex.abs()` method as it seems useful.
8798
9028
  * @modified 2024-03-08 Added the optional `precision` param to the `toString` method.
8799
- * @version 2.9.0
9029
+ * @modified 2024-12-17 Outsourced the euclidean distance calculation of `Vertex.distance` to `geomutils.dist4`.
9030
+ * @version 2.9.1
8800
9031
  *
8801
9032
  * @file Vertex
8802
9033
  * @public
@@ -8806,6 +9037,7 @@ exports.Vertex = void 0;
8806
9037
  var VertexAttr_1 = __webpack_require__(476);
8807
9038
  var UIDGenerator_1 = __webpack_require__(938);
8808
9039
  var VertexListeners_1 = __webpack_require__(934);
9040
+ var geomutils_1 = __webpack_require__(328);
8809
9041
  /**
8810
9042
  * @classdesc A vertex is a pair of two numbers.<br>
8811
9043
  * <br>
@@ -9149,7 +9381,8 @@ var Vertex = /** @class */ (function () {
9149
9381
  * @memberof Vertex
9150
9382
  **/
9151
9383
  Vertex.prototype.distance = function (vert) {
9152
- 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);
9153
9386
  };
9154
9387
  /**
9155
9388
  * Get the angle of this point (relative to (0,0) or to the given other origin point).
@@ -9830,6 +10063,7 @@ exports.VertexListeners = VertexListeners;
9830
10063
  * @modified 2023-09-29 Added the `lineDashes` attribute.
9831
10064
  * @modified 2023-09-30 Adding `strokeOptions` param to these draw function: line, arrow, cubicBezierArrow, cubicBezier, cubicBezierPath, circle, circleArc, ellipse, square, rect, polygon, polyline.
9832
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.
9833
10067
  * @version 1.13.0
9834
10068
  **/
9835
10069
  Object.defineProperty(exports, "__esModule", ({ value: true }));
@@ -10760,7 +10994,7 @@ var drawutils = /** @class */ (function () {
10760
10994
  this.ctx.save();
10761
10995
  this.applyStrokeOpts(strokeOptions);
10762
10996
  this.ctx.beginPath();
10763
- this.ctx.lineWidth = (lineWidth || 1.0) * this.scale.x;
10997
+ this.ctx.lineWidth = lineWidth || 1.0;
10764
10998
  this.ctx.moveTo(this.offset.x + vertices[0].x * this.scale.x, this.offset.y + vertices[0].y * this.scale.y);
10765
10999
  for (var i = 0; i < vertices.length; i++) {
10766
11000
  this.ctx.lineTo(this.offset.x + vertices[i].x * this.scale.x, this.offset.y + vertices[i].y * this.scale.y);
@@ -11783,7 +12017,8 @@ var GLU = /** @class */ (function () {
11783
12017
  * @modified 2023-10-04 Adding `strokeOptions` param to these draw function: line, arrow, cubicBezierArrow, cubicBezier, cubicBezierPath, circle, circleArc, ellipse, square, rect, polygon, polyline.
11784
12018
  * @modified 2024-01-30 Fixing an issue with immutable style sets; changes to the global draw config did not reflect here (do now).
11785
12019
  * @modified 2024-03-10 Fixing some types for Typescript 5 compatibility.
11786
- * @version 1.6.9
12020
+ * @modified 2024-07-24 Caching custom style defs in a private buffer variable.
12021
+ * @version 1.6.10
11787
12022
  **/
11788
12023
  Object.defineProperty(exports, "__esModule", ({ value: true }));
11789
12024
  exports.drawutilssvg = void 0;
@@ -11898,6 +12133,13 @@ var drawutilssvg = /** @class */ (function () {
11898
12133
  console.warn("Warning: your draw config is missing the key '".concat(k, "' which is required."));
11899
12134
  }
11900
12135
  }
12136
+ if (this.customStyleDefs) {
12137
+ rules.push("\n/* Custom styles */\n");
12138
+ this.customStyleDefs.forEach(function (value, key) {
12139
+ rules.push(key + " { " + value + " }");
12140
+ });
12141
+ // this.nodeStyle.innerHTML += "\n/* Custom styles */\n" + rules.join("\n");
12142
+ }
11901
12143
  this.nodeStyle.innerHTML = rules.join("\n");
11902
12144
  };
11903
12145
  /**
@@ -11921,11 +12163,7 @@ var drawutilssvg = /** @class */ (function () {
11921
12163
  * @param {Map<string,string>} defs
11922
12164
  */
11923
12165
  drawutilssvg.prototype.addCustomStyleDefs = function (defs) {
11924
- var buffer = [];
11925
- defs.forEach(function (value, key) {
11926
- buffer.push(key + " { " + value + " }");
11927
- });
11928
- this.nodeStyle.innerHTML += "\n/* Custom styles */\n" + buffer.join("\n");
12166
+ this.customStyleDefs = defs;
11929
12167
  };
11930
12168
  /**
11931
12169
  * Retieve an old (cached) element.
@@ -12684,6 +12922,30 @@ var drawutilssvg = /** @class */ (function () {
12684
12922
  * @memberof drawutilssvg
12685
12923
  */
12686
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);
12687
12949
  var node = this.makeNode("path");
12688
12950
  var d = [];
12689
12951
  var yMin = -Math.ceil((height * 0.5) / sizeY) * sizeY;
@@ -13409,7 +13671,10 @@ exports.drawutilssvg = drawutilssvg;
13409
13671
  * @author Ikaros Kappler
13410
13672
  * @date 2019-02-03
13411
13673
  * @modified 2021-03-01 Added `wrapMax` function.
13412
- * @version 1.1.0
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
13413
13678
  **/
13414
13679
  Object.defineProperty(exports, "__esModule", ({ value: true }));
13415
13680
  exports.geomutils = void 0;
@@ -13421,6 +13686,49 @@ var Triangle_1 = __webpack_require__(737);
13421
13686
  * @global
13422
13687
  **/
13423
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
+ },
13424
13732
  /**
13425
13733
  * Compute the n-section of the angle – described as a triangle (A,B,C) – in point A.
13426
13734
  *