plotboilerplate 1.20.1 → 1.21.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.
Files changed (141) hide show
  1. package/README.md +17 -1
  2. package/dist/index.esm.js +2065 -1397
  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 +1265 -584
  9. package/dist/plotboilerplate.min.js +1 -1
  10. package/package.json +2 -1
  11. package/src/cjs/BezierPath.d.ts +27 -49
  12. package/src/cjs/BezierPath.js +69 -237
  13. package/src/cjs/BezierPath.js.map +1 -1
  14. package/src/cjs/Bounds.d.ts +14 -1
  15. package/src/cjs/Bounds.js +21 -1
  16. package/src/cjs/Bounds.js.map +1 -1
  17. package/src/cjs/CubicBezierCurve.d.ts +70 -1
  18. package/src/cjs/CubicBezierCurve.js +130 -12
  19. package/src/cjs/CubicBezierCurve.js.map +1 -1
  20. package/src/cjs/Line.d.ts +2 -1
  21. package/src/cjs/Line.js +1 -0
  22. package/src/cjs/Line.js.map +1 -1
  23. package/src/cjs/PBText.d.ts +2 -1
  24. package/src/cjs/PBText.js +10 -9
  25. package/src/cjs/PBText.js.map +1 -1
  26. package/src/cjs/PlotBoilerplate.d.ts +10 -13
  27. package/src/cjs/PlotBoilerplate.js +136 -47
  28. package/src/cjs/PlotBoilerplate.js.map +1 -1
  29. package/src/cjs/Polygon.d.ts +35 -1
  30. package/src/cjs/Polygon.js +87 -1
  31. package/src/cjs/Polygon.js.map +1 -1
  32. package/src/cjs/Triangle.js +1 -0
  33. package/src/cjs/Triangle.js.map +1 -1
  34. package/src/cjs/VEllipse.js +1 -1
  35. package/src/cjs/VEllipse.js.map +1 -1
  36. package/src/cjs/Vector.d.ts +4 -4
  37. package/src/cjs/Vector.js +2 -2
  38. package/src/cjs/Vector.js.map +1 -1
  39. package/src/cjs/VertTuple.d.ts +2 -1
  40. package/src/cjs/VertTuple.js +4 -3
  41. package/src/cjs/VertTuple.js.map +1 -1
  42. package/src/cjs/Vertex.d.ts +14 -3
  43. package/src/cjs/Vertex.js +18 -3
  44. package/src/cjs/Vertex.js.map +1 -1
  45. package/src/cjs/draw.d.ts +159 -79
  46. package/src/cjs/draw.js +311 -139
  47. package/src/cjs/draw.js.map +1 -1
  48. package/src/cjs/drawgl.d.ts +93 -55
  49. package/src/cjs/drawgl.js +90 -34
  50. package/src/cjs/drawgl.js.map +1 -1
  51. package/src/cjs/drawutilssvg.d.ts +233 -58
  52. package/src/cjs/drawutilssvg.js +384 -95
  53. package/src/cjs/drawutilssvg.js.map +1 -1
  54. package/src/cjs/interfaces/DrawLib.d.ts +161 -82
  55. package/src/cjs/interfaces/DrawLib.js +7 -0
  56. package/src/cjs/interfaces/DrawLib.js.map +1 -1
  57. package/src/cjs/interfaces/core.d.ts +46 -32
  58. package/src/cjs/interfaces/core.js +2 -0
  59. package/src/cjs/interfaces/core.js.map +1 -1
  60. package/src/cjs/utils/creategui.js +16 -10
  61. package/src/cjs/utils/datastructures/Color.d.ts +3 -1
  62. package/src/cjs/utils/datastructures/Color.js +12 -1
  63. package/src/cjs/utils/datastructures/Color.js.map +1 -1
  64. package/src/cjs/utils/detectDarkMode.d.ts +10 -0
  65. package/src/cjs/utils/detectDarkMode.js +32 -0
  66. package/src/cjs/utils/detectDarkMode.js.map +1 -0
  67. package/src/cjs/utils/module.js +4 -2
  68. package/src/esm/BezierPath.d.ts +27 -49
  69. package/src/esm/BezierPath.js +69 -237
  70. package/src/esm/BezierPath.js.map +1 -1
  71. package/src/esm/Bounds.d.ts +14 -1
  72. package/src/esm/Bounds.js +19 -1
  73. package/src/esm/Bounds.js.map +1 -1
  74. package/src/esm/CubicBezierCurve.d.ts +70 -1
  75. package/src/esm/CubicBezierCurve.js +130 -12
  76. package/src/esm/CubicBezierCurve.js.map +1 -1
  77. package/src/esm/Line.d.ts +2 -1
  78. package/src/esm/Line.js +1 -0
  79. package/src/esm/Line.js.map +1 -1
  80. package/src/esm/PBText.d.ts +2 -1
  81. package/src/esm/PBText.js +10 -9
  82. package/src/esm/PBText.js.map +1 -1
  83. package/src/esm/PlotBoilerplate.d.ts +10 -13
  84. package/src/esm/PlotBoilerplate.js +136 -48
  85. package/src/esm/PlotBoilerplate.js.map +1 -1
  86. package/src/esm/Polygon.d.ts +35 -1
  87. package/src/esm/Polygon.js +85 -1
  88. package/src/esm/Polygon.js.map +1 -1
  89. package/src/esm/Triangle.js +1 -0
  90. package/src/esm/Triangle.js.map +1 -1
  91. package/src/esm/VEllipse.js +1 -1
  92. package/src/esm/VEllipse.js.map +1 -1
  93. package/src/esm/Vector.d.ts +4 -4
  94. package/src/esm/Vector.js +2 -2
  95. package/src/esm/Vector.js.map +1 -1
  96. package/src/esm/VertTuple.d.ts +2 -1
  97. package/src/esm/VertTuple.js +4 -3
  98. package/src/esm/VertTuple.js.map +1 -1
  99. package/src/esm/Vertex.d.ts +14 -3
  100. package/src/esm/Vertex.js +18 -3
  101. package/src/esm/Vertex.js.map +1 -1
  102. package/src/esm/draw.d.ts +159 -79
  103. package/src/esm/draw.js +307 -137
  104. package/src/esm/draw.js.map +1 -1
  105. package/src/esm/drawgl.d.ts +93 -55
  106. package/src/esm/drawgl.js +90 -34
  107. package/src/esm/drawgl.js.map +1 -1
  108. package/src/esm/drawutilssvg.d.ts +233 -58
  109. package/src/esm/drawutilssvg.js +379 -95
  110. package/src/esm/drawutilssvg.js.map +1 -1
  111. package/src/esm/interfaces/DrawLib.d.ts +161 -82
  112. package/src/esm/interfaces/DrawLib.js +7 -0
  113. package/src/esm/interfaces/DrawLib.js.map +1 -1
  114. package/src/esm/interfaces/core.d.ts +46 -32
  115. package/src/esm/interfaces/core.js +2 -0
  116. package/src/esm/interfaces/core.js.map +1 -1
  117. package/src/esm/utils/datastructures/Color.d.ts +3 -1
  118. package/src/esm/utils/datastructures/Color.js +12 -1
  119. package/src/esm/utils/datastructures/Color.js.map +1 -1
  120. package/src/esm/utils/detectDarkMode.d.ts +10 -0
  121. package/src/esm/utils/detectDarkMode.js +28 -0
  122. package/src/esm/utils/detectDarkMode.js.map +1 -0
  123. package/src/ts/BezierPath.ts +74 -244
  124. package/src/ts/Bounds.ts +25 -1
  125. package/src/ts/CubicBezierCurve.ts +139 -12
  126. package/src/ts/Line.ts +2 -1
  127. package/src/ts/PBText.ts +10 -9
  128. package/src/ts/PlotBoilerplate.ts +130 -50
  129. package/src/ts/Polygon.ts +91 -1
  130. package/src/ts/Triangle.ts +2 -1
  131. package/src/ts/VEllipse.ts +2 -2
  132. package/src/ts/Vector.ts +4 -4
  133. package/src/ts/VertTuple.ts +4 -3
  134. package/src/ts/Vertex.ts +20 -4
  135. package/src/ts/draw.ts +316 -119
  136. package/src/ts/drawgl.ts +141 -78
  137. package/src/ts/drawutilssvg.ts +562 -133
  138. package/src/ts/interfaces/DrawLib.ts +223 -86
  139. package/src/ts/interfaces/core.ts +47 -32
  140. package/src/ts/utils/datastructures/Color.ts +13 -1
  141. package/src/ts/utils/detectDarkMode.ts +30 -0
@@ -448,7 +448,9 @@ class AlloyFinger {
448
448
  * @modified 2022-01-31 Added `BezierPath.getEvenDistributionVertices(number)`.
449
449
  * @modified 2022-02-02 Added the `destroy` method.
450
450
  * @modified 2022-02-02 Cleared the `toSVGString` function (deprecated). Use `drawutilssvg` instead.
451
- * @version 2.5.0
451
+ * @modified 2023-10-06 Adding the `BezierPath.toPathPoints()` method.
452
+ * @modified 2023-10-07 Adding the `BezierPath.fromCurve(CubicBezierCurve)` static function.
453
+ * @version 2.6.0
452
454
  *
453
455
  * @file BezierPath
454
456
  * @public
@@ -485,7 +487,7 @@ var BezierPath = /** @class */ (function () {
485
487
  * @name BezierPath
486
488
  * @param {Vertex[]} pathPoints - An array of path vertices (no control points).
487
489
  **/
488
- function BezierPath(pathPoints) {
490
+ function BezierPath() {
489
491
  /**
490
492
  * Required to generate proper CSS classes and other class related IDs.
491
493
  **/
@@ -498,9 +500,11 @@ var BezierPath = /** @class */ (function () {
498
500
  this.END_CONTROL_POINT = 2;
499
501
  /** @constant {number} */
500
502
  this.END_POINT = 3;
503
+ // pathPoints: Array<Vertex> | undefined | null) {
501
504
  this.uid = UIDGenerator_1.UIDGenerator.next();
502
- if (!pathPoints)
503
- pathPoints = [];
505
+ // if (!pathPoints) {
506
+ // pathPoints = [];
507
+ // }
504
508
  this.totalArcLength = 0.0;
505
509
  // Set this flag to true if you want the first point and
506
510
  // last point of the path to be auto adjusted, too.
@@ -653,215 +657,6 @@ var BezierPath = /** @class */ (function () {
653
657
  BezierPath.prototype.getCurveAt = function (curveIndex) {
654
658
  return this.bezierCurves[curveIndex];
655
659
  };
656
- /**
657
- * Remove the end point of this path (which removes the last curve from this path).<br>
658
- * <br>
659
- * Please note that this function does never remove the first curve, thus the path
660
- * cannot be empty after this call.
661
- *
662
- * @method removeEndPoint
663
- * @instance
664
- * @memberof BezierPath
665
- * @return {boolean} Indicating if the last curve was removed.
666
- **/
667
- /*
668
- BezierPath.prototype.removeEndPoint = function() {
669
- if( this.bezierCurves.length <= 1 )
670
- return false;
671
-
672
- var newArray = [ this.bezierCurves.length-1 ];
673
- for( var i = 0; i < this.bezierCurves.length-1; i++ ) {
674
- newArray[i] = this.bezierCurves[i];
675
- }
676
-
677
- // Update arc length
678
- this.totalArcLength -= this.bezierCurves[ this.bezierCurves.length-1 ].getLength();
679
- this.bezierCurves = newArray;
680
- return true;
681
- }
682
- */
683
- /**
684
- * Remove the start point of this path (which removes the first curve from this path).<br>
685
- * <br>
686
- * Please note that this function does never remove the last curve, thus the path
687
- * cannot be empty after this call.<br>
688
- *
689
- * @method removeStartPoint
690
- * @instance
691
- * @memberof BezierPath
692
- * @return {boolean} Indicating if the first curve was removed.
693
- **/
694
- /*
695
- BezierPath.prototype.removeStartPoint = function() {
696
-
697
- if( this.bezierCurves.length <= 1 )
698
- return false;
699
-
700
- var newArray = [ this.bezierCurves.length-1 ];
701
- for( var i = 1; i < this.bezierCurves.length; i++ ) {
702
-
703
- newArray[i-1] = this.bezierCurves[i];
704
-
705
- }
706
-
707
- // Update arc length
708
- this.totalArcLength -= this.bezierCurves[ 0 ].getLength();
709
- this.bezierCurves = newArray;
710
-
711
- return true;
712
- }
713
- */
714
- /**
715
- * Removes a path point inside the path.
716
- *
717
- * This function joins the bezier curve at the given index with
718
- * its predecessor, which means that the start point at the given
719
- * curve index will be removed.
720
- *
721
- * @method joinAt
722
- * @param {number} curveIndex - The index of the curve to be joined with its predecessor.
723
- * @instance
724
- * @memberof BezierPath
725
- * @return {boolean} True if the passed index indicated an inner vertex and the two curves were joined.
726
- **/
727
- /*
728
- BezierPath.prototype.joinAt = function( curveIndex ) {
729
-
730
- if( curveIndex < 0 || curveIndex >= this.bezierCurves.length )
731
- return false;
732
-
733
- var leftCurve = this.bezierCurves[ curveIndex-1 ];
734
- var rightCurve = this.bezierCurves[ curveIndex ];
735
-
736
- // Make the length of the new handle double that long
737
- var leftControlPoint = leftCurve.getStartControlPoint().clone();
738
- leftControlPoint.sub( leftCurve.getStartPoint() );
739
- leftControlPoint.multiplyScalar( 2.0 );
740
- leftControlPoint.add( leftCurve.getStartPoint() );
741
-
742
- var rightControlPoint = rightCurve.getEndControlPoint().clone();
743
- rightControlPoint.sub( rightCurve.getEndPoint() );
744
- rightControlPoint.multiplyScalar( 2.0 );
745
- rightControlPoint.add( rightCurve.getEndPoint() );
746
-
747
- var newCurve = new IKRS.CubicBezierCurve( leftCurve.getStartPoint(),
748
- rightCurve.getEndPoint(),
749
- leftControlPoint,
750
- rightControlPoint
751
- );
752
- // Place into array
753
- var newArray = [ this.bezierCurves.length - 1 ];
754
-
755
- for( var i = 0; i < curveIndex-1; i++ )
756
- newArray[ i ] = this.bezierCurves[i];
757
-
758
- newArray[ curveIndex-1 ] = newCurve;
759
-
760
- // Shift trailing curves left
761
- for( var i = curveIndex; i+1 < this.bezierCurves.length; i++ )
762
- newArray[ i ] = this.bezierCurves[ i+1 ];
763
-
764
- this.bezierCurves = newArray;
765
- this.updateArcLengths();
766
-
767
- return true;
768
- }
769
- */
770
- /**
771
- * Add a new inner curve point to the path.<br>
772
- * <br>
773
- * This function splits the bezier curve at the given index and given
774
- * curve segment index.
775
- *
776
- * @method splitAt
777
- * @param {number} curveIndex - The index of the curve to split.
778
- * @param {nunber} segmentIndex - The index of the curve segment where the split should be performed.
779
- * @instance
780
- * @memberof BezierPath
781
- * @return {boolean} True if the passed indices were valid and the path was split.
782
- **/
783
- /*
784
- BezierPath.prototype.splitAt = function( curveIndex,
785
- segmentIndex
786
- ) {
787
- // Must be a valid curve index
788
- if( curveIndex < 0 || curveIndex >= this.bezierCurves.length )
789
- return false;
790
-
791
- var oldCurve = this.bezierCurves[ curveIndex ];
792
-
793
- // Segment must be an INNER point!
794
- // (the outer points are already bezier end/start points!)
795
- if( segmentIndex < 1 || segmentIndex-1 >= oldCurve.segmentCache.length )
796
- return false;
797
-
798
- // Make room for a new curve
799
- for( var c = this.bezierCurves.length; c > curveIndex; c-- ) {
800
- // Move one position to the right
801
- this.bezierCurves[ c ] = this.bezierCurves[ c-1 ];
802
- }
803
-
804
- // Accumulate segment lengths
805
- var u = 0;
806
- for( var i = 0; i < segmentIndex; i++ )
807
- u += oldCurve.segmentLengths[i];
808
- //var tangent = oldCurve.getTangentAt( u );
809
- var tangent = oldCurve.getTangent( u );
810
- tangent = tangent.multiplyScalar( 0.25 );
811
-
812
- var leftEndControlPoint = oldCurve.segmentCache[ segmentIndex ].clone();
813
- leftEndControlPoint.sub( tangent );
814
-
815
- var rightStartControlPoint = oldCurve.segmentCache[ segmentIndex ].clone();
816
- rightStartControlPoint.add( tangent );
817
-
818
- // Make the old existing handles a quarter that long
819
- var leftStartControlPoint = oldCurve.getStartControlPoint().clone();
820
- // move to (0,0)
821
- leftStartControlPoint.sub( oldCurve.getStartPoint() );
822
- leftStartControlPoint.multiplyScalar( 0.25 );
823
- leftStartControlPoint.add( oldCurve.getStartPoint() );
824
-
825
- var rightEndControlPoint = oldCurve.getEndControlPoint().clone();
826
- // move to (0,0)
827
- rightEndControlPoint.sub( oldCurve.getEndPoint() );
828
- rightEndControlPoint.multiplyScalar( 0.25 );
829
- rightEndControlPoint.add( oldCurve.getEndPoint() );
830
-
831
- var newLeft = new CubicBezierCurve( oldCurve.getStartPoint(), // old start point
832
- oldCurve.segmentCache[ segmentIndex ], // new end point
833
- leftStartControlPoint, // old start control point
834
- leftEndControlPoint // new end control point
835
- );
836
- var newRight = new CubicBezierCurve( oldCurve.segmentCache[ segmentIndex ], // new start point
837
- oldCurve.getEndPoint(), // old end point
838
- rightStartControlPoint, // new start control point
839
- rightEndControlPoint // old end control point
840
- );
841
-
842
- // Insert split curve(s) at free index
843
- this.bezierCurves[ curveIndex ] = newLeft;
844
- this.bezierCurves[ curveIndex + 1 ] = newRight;
845
-
846
- // Update total arc length, even if there is only a very little change!
847
- this.totalArcLength -= oldCurve.getLength();
848
- this.totalArcLength += newLeft.getLength();
849
- this.totalArcLength += newRight.getLength();
850
-
851
- return true;
852
- };
853
- */
854
- /*
855
- insertVertexAt( t:number ) : void {
856
- console.log('Inserting vertex at', t );
857
- // Find the curve index
858
- var u : number = 0;
859
- var curveIndex : number = -1;
860
- var localT : number = 0.0;
861
- for( var i = 0; curveIndex == -1 && i < this.bezierCurves.length; i++ ) {
862
-
863
- }
864
- }; */
865
660
  /**
866
661
  * Move the whole bezier path by the given (x,y)-amount.
867
662
  *
@@ -896,22 +691,6 @@ var BezierPath = /** @class */ (function () {
896
691
  * @return {BezierPath} this for chaining.
897
692
  **/
898
693
  BezierPath.prototype.scale = function (anchor, scaleFactor) {
899
- // var scaleFactors : XYCoords = { x : scaleFactor, y : scaleFactor };
900
- // for (var i = 0; i < this.bezierCurves.length; i++) {
901
- // var curve = this.bezierCurves[i];
902
- // curve.getStartPoint().scale(scaleFactor, anchor);
903
- // curve.getStartControlPoint().scale(scaleFactor, anchor);
904
- // curve.getEndControlPoint().scale(scaleFactor, anchor);
905
- // // Do NOT scale the end point here!
906
- // // Don't forget that the curves are connected and on curve's end point
907
- // // the the successor's start point (same instance)!
908
- // }
909
- // // Finally move the last end point (was not scaled yet)
910
- // if (this.bezierCurves.length > 0 && !this.adjustCircular) {
911
- // this.bezierCurves[this.bezierCurves.length - 1].getEndPoint().scale(scaleFactor, anchor);
912
- // }
913
- // this.updateArcLengths();
914
- // return this;
915
694
  return this.scaleXY({ x: scaleFactor, y: scaleFactor }, anchor);
916
695
  };
917
696
  /**
@@ -1407,7 +1186,7 @@ var BezierPath = /** @class */ (function () {
1407
1186
  * @return {BezierPath}
1408
1187
  **/
1409
1188
  BezierPath.prototype.clone = function () {
1410
- var path = new BezierPath(undefined);
1189
+ var path = new BezierPath(); // undefined);
1411
1190
  for (var i = 0; i < this.bezierCurves.length; i++) {
1412
1191
  path.bezierCurves.push(this.bezierCurves[i].clone());
1413
1192
  // Connect splines
@@ -1447,6 +1226,10 @@ var BezierPath = /** @class */ (function () {
1447
1226
  * This function should invalidate any installed listeners and invalidate this object.
1448
1227
  * After calling this function the object might not hold valid data any more and
1449
1228
  * should not be used.
1229
+ *
1230
+ * @method destroy
1231
+ * @instance
1232
+ * @memberof BezierPath
1450
1233
  */
1451
1234
  BezierPath.prototype.destroy = function () {
1452
1235
  for (var i = 0; i < this.bezierCurves.length; i++) {
@@ -1454,6 +1237,40 @@ var BezierPath = /** @class */ (function () {
1454
1237
  }
1455
1238
  this.isDestroyed = true;
1456
1239
  };
1240
+ /**
1241
+ * Convert this path to an array of path points that can be drawn by the default DrawLib
1242
+ * implementations.
1243
+ *
1244
+ * @method toPathPoints
1245
+ * @instance
1246
+ * @memberof BezierPath
1247
+ * @return {Array<XYCoords>}
1248
+ */
1249
+ BezierPath.prototype.toPathPoints = function () {
1250
+ if (this.bezierCurves.length === 0) {
1251
+ return [];
1252
+ }
1253
+ if (this.bezierCurves.length === 1) {
1254
+ return [
1255
+ this.bezierCurves[0].startPoint,
1256
+ this.bezierCurves[0].startControlPoint,
1257
+ this.bezierCurves[0].endControlPoint,
1258
+ this.bezierCurves[0].endPoint
1259
+ ];
1260
+ }
1261
+ var arr = [];
1262
+ arr.push(this.bezierCurves[0].startPoint);
1263
+ arr.push(this.bezierCurves[0].startControlPoint);
1264
+ for (var i = 1; i < this.bezierCurves.length; i++) {
1265
+ arr.push(this.bezierCurves[i - 1].endControlPoint);
1266
+ arr.push(this.bezierCurves[i - 1].endPoint);
1267
+ arr.push(this.bezierCurves[i].startPoint);
1268
+ arr.push(this.bezierCurves[i].startControlPoint);
1269
+ }
1270
+ arr.push(this.bezierCurves[0].endControlPoint);
1271
+ arr.push(this.bezierCurves[0].endPoint);
1272
+ return arr;
1273
+ };
1457
1274
  /**
1458
1275
  * Create a JSON string representation of this bézier curve.
1459
1276
  *
@@ -1494,6 +1311,20 @@ var BezierPath = /** @class */ (function () {
1494
1311
  var obj = JSON.parse(jsonString);
1495
1312
  return BezierPath.fromArray(obj);
1496
1313
  };
1314
+ /**
1315
+ * Construct a new path with a single curve. Adding more curves is always possible.
1316
+ *
1317
+ * @method fromCurve
1318
+ * @param {CubicBezierCurve} curve - The curve to construct a new path from.
1319
+ * @static
1320
+ * @memberof BezierPath
1321
+ * @return {BezierPath} The constructed bezier path instance.
1322
+ */
1323
+ BezierPath.fromCurve = function (curve) {
1324
+ var path = new BezierPath(); // []);
1325
+ path.addCurve(curve);
1326
+ return path;
1327
+ };
1497
1328
  /**
1498
1329
  * Create a BezierPath instance from the given array.
1499
1330
  *
@@ -1505,13 +1336,15 @@ var BezierPath = /** @class */ (function () {
1505
1336
  * @return {BezierPath} The bezier path instance retrieved from the array data.
1506
1337
  **/
1507
1338
  BezierPath.fromArray = function (obj) {
1508
- if (!Array.isArray(obj))
1339
+ if (!Array.isArray(obj)) {
1509
1340
  throw "[BezierPath.fromArray] Passed object must be an array.";
1341
+ }
1510
1342
  var arr = obj; // FORCE?
1511
- if (arr.length < 1)
1343
+ if (arr.length < 1) {
1512
1344
  throw "[BezierPath.fromArray] Passed array must contain at least one bezier curve (has " + arr.length + ").";
1345
+ }
1513
1346
  // Create an empty bezier path
1514
- var bPath = new BezierPath(undefined);
1347
+ var bPath = new BezierPath(); // undefined);
1515
1348
  var lastCurve = null;
1516
1349
  for (var i = 0; i < arr.length; i++) {
1517
1350
  // Convert object (or array?) to bezier curve
@@ -1621,9 +1454,8 @@ var BezierPath = /** @class */ (function () {
1621
1454
  */
1622
1455
  BezierPath.fromReducedList = function (pointArray, adjustCircular) {
1623
1456
  // Convert to object
1624
- var bezierPath = new BezierPath(null); // No points yet
1625
- // var firstStartPoint: Vertex;
1626
- var startPoint;
1457
+ var bezierPath = new BezierPath(); // null); // No points yet
1458
+ var startPoint = new Vertex_1.Vertex();
1627
1459
  var startControlPoint;
1628
1460
  var endControlPoint;
1629
1461
  var endPoint;
@@ -1645,7 +1477,7 @@ var BezierPath = /** @class */ (function () {
1645
1477
  startPoint = endPoint;
1646
1478
  i += 6;
1647
1479
  } while (i + 2 < pointArray.length);
1648
- bezierPath.adjustCircular = adjustCircular;
1480
+ bezierPath.adjustCircular = adjustCircular !== null && adjustCircular !== void 0 ? adjustCircular : false;
1649
1481
  if (adjustCircular) {
1650
1482
  bezierPath.bezierCurves[bezierPath.bezierCurves.length - 1].endPoint = bezierPath.bezierCurves[0].startPoint;
1651
1483
  }
@@ -1684,7 +1516,8 @@ exports.BezierPath = BezierPath;
1684
1516
  * @modified 2022-02-01 Added the `toString` function.
1685
1517
  * @modified 2022-10-09 Added the `fromDimension` function.
1686
1518
  * @modified 2022-11-28 Added the `clone` method.
1687
- * @version 1.6.0
1519
+ * @modified 2023-09-29 Added the `randomPoint` method.
1520
+ * @version 1.7.0
1688
1521
  **/
1689
1522
  Object.defineProperty(exports, "__esModule", ({ value: true }));
1690
1523
  exports.Bounds = void 0;
@@ -1734,6 +1567,25 @@ var Bounds = /** @class */ (function () {
1734
1567
  Bounds.prototype.getCenter = function () {
1735
1568
  return new Vertex_1.Vertex(this.min.x + (this.max.x - this.min.x) / 2.0, this.min.y + (this.max.y - this.min.y) / 2);
1736
1569
  };
1570
+ /**
1571
+ * Generate a random point inside this bounds object. Safe areas at the border to avoid
1572
+ * included.
1573
+ *
1574
+ * @method randomPoint
1575
+ * @instance
1576
+ * @memberof Bounds
1577
+ * @param {horizontalSafeArea} - (optional) The horizonal (left and right) safe area. No vertex will be created here. Can be used as percent in (0.0 ... 0.1) interval.
1578
+ * @param {verticalSafeArea} - (optional) The vertical (top and bottom) safe area. No vertex will be created here. Can be used as percent in (0.0 ... 0.1) interval
1579
+ * @returns {Vertex} A pseudo random point inside these bounds.
1580
+ */
1581
+ Bounds.prototype.randomPoint = function (horizontalSafeArea, verticalSafeArea) {
1582
+ if (horizontalSafeArea === void 0) { horizontalSafeArea = 0; }
1583
+ if (verticalSafeArea === void 0) { verticalSafeArea = 0; }
1584
+ // Check if the safe areas are meant as percent
1585
+ var absHorizontalSafeArea = horizontalSafeArea > 0 && horizontalSafeArea < 1 ? this.width * horizontalSafeArea : horizontalSafeArea;
1586
+ var absVerticalSafeArea = verticalSafeArea > 0 && verticalSafeArea < 1 ? this.height * verticalSafeArea : verticalSafeArea;
1587
+ return new Vertex_1.Vertex(this.min.x + absHorizontalSafeArea + Math.random() * (this.width - 2 * absHorizontalSafeArea), this.min.y + absVerticalSafeArea + Math.random() * (this.height - 2 * absVerticalSafeArea));
1588
+ };
1737
1589
  /**
1738
1590
  * Convert these bounds to a human readable form.
1739
1591
  *
@@ -2212,7 +2064,9 @@ exports.CircleSector = CircleSector;
2212
2064
  * @modified 2022-02-02 Added the `destroy` method.
2213
2065
  * @modified 2022-02-02 Cleared the `toSVGPathData` function (deprecated). Use `drawutilssvg` instead.
2214
2066
  * @modified 2022-10-17 The `CubicBezierCurve` class now implements the new `PathSegment` interface.
2215
- * @version 2.7.1
2067
+ * @modified 2023-09-30 Added the function `CubicbezierCurve.getSubCurve(number,number)` – similar to `getSubCurveAt(...)` but with absolute position parameters.
2068
+ * @modified 2023-10-07 Added the `trimEnd`, `trimEndAt`, `trimStart`, `trimStartAt` methods.
2069
+ * @version 2.8.0
2216
2070
  *
2217
2071
  * @file CubicBezierCurve
2218
2072
  * @public
@@ -2605,6 +2459,91 @@ var CubicBezierCurve = /** @class */ (function () {
2605
2459
  // Note: my implementation does NOT normalize tangent vectors!
2606
2460
  return new Vertex_1.Vertex(tX, tY);
2607
2461
  };
2462
+ /**
2463
+ * Trim off a start section of this curve. The position parameter `uValue` is the absolute position on the
2464
+ * curve in `[0...arcLength]`.
2465
+ * The remaining curve will be the one in the bounds `[uValue,1]` (so `[0.0,uValue]` is cut off).
2466
+ *
2467
+ * Note this function just converts the absolute parameter to a relative one and call `trimStartAt`.
2468
+ *
2469
+ * @method trimStart
2470
+ * @instance
2471
+ * @memberof CubicBezierCurve
2472
+ * @param {number} uValue - The absolute position parameter where to cut off the head curve.
2473
+ * @returns {CubicBezierCurve} `this` for chanining.
2474
+ */
2475
+ CubicBezierCurve.prototype.trimStart = function (uValue) {
2476
+ return this.trimStartAt(this.convertU2T(uValue));
2477
+ };
2478
+ /**
2479
+ * Trim off a start section of this curve. The position parameter `t` is the relative position in [0..1].
2480
+ * The remaining curve will be the one in the bounds `[uValue,1]` (so `[0.0,uValue]` is cut off).
2481
+ *
2482
+ * @method trimStartAt
2483
+ * @instance
2484
+ * @memberof CubicBezierCurve
2485
+ * @param {number} t - The relative position parameter where to cut off the head curve.
2486
+ * @returns {CubicBezierCurve} `this` for chanining.
2487
+ */
2488
+ CubicBezierCurve.prototype.trimStartAt = function (t) {
2489
+ var subCurbePoints = CubicBezierCurve.utils.getSubCurvePointsAt(this, t, 1.0);
2490
+ this.startPoint.set(subCurbePoints[0]);
2491
+ this.startControlPoint.set(subCurbePoints[2]);
2492
+ this.endPoint.set(subCurbePoints[1]);
2493
+ this.endControlPoint.set(subCurbePoints[3]);
2494
+ this.updateArcLengths();
2495
+ return this;
2496
+ };
2497
+ /**
2498
+ * Trim off the end of this curve. The position parameter `uValue` is the absolute position on the
2499
+ * curve in `[0...arcLength]`.
2500
+ * The remaining curve will be the one in the bounds `[0,uValue]` (so `[1.0-uValue,1.0]` is cut off).
2501
+ *
2502
+ * Note this function just converts the absolute parameter to a relative one and call `trimEndAt`.
2503
+ *
2504
+ * @method trimEnd
2505
+ * @instance
2506
+ * @memberof CubicBezierCurve
2507
+ * @param {number} uValue - The absolute position parameter where to cut off the tail curve.
2508
+ * @returns {CubicBezierCurve} `this` for chanining.
2509
+ */
2510
+ CubicBezierCurve.prototype.trimEnd = function (uValue) {
2511
+ return this.trimEndAt(this.convertU2T(uValue));
2512
+ };
2513
+ /**
2514
+ * Trim off the end of this curve. The position parameter `t` is the relative position in [0..1].
2515
+ * The remaining curve will be the one in the bounds `[0,t]` (so `[1.0-t,1.0]` is cut off).
2516
+ *
2517
+ * @method trimEndAt
2518
+ * @instance
2519
+ * @memberof CubicBezierCurve
2520
+ * @param {number} t - The relative position parameter where to cut off the tail curve.
2521
+ * @returns {CubicBezierCurve} `this` for chanining.
2522
+ */
2523
+ CubicBezierCurve.prototype.trimEndAt = function (t) {
2524
+ var subCurbePoints = CubicBezierCurve.utils.getSubCurvePointsAt(this, 0.0, t);
2525
+ this.startPoint.set(subCurbePoints[0]);
2526
+ this.startControlPoint.set(subCurbePoints[2]);
2527
+ this.endPoint.set(subCurbePoints[1]);
2528
+ this.endControlPoint.set(subCurbePoints[3]);
2529
+ this.updateArcLengths();
2530
+ return this;
2531
+ };
2532
+ /**
2533
+ * Get a sub curve at the given start end end positions (values on the curve's length, between 0 and curve.arcLength).
2534
+ *
2535
+ * tStart >= tEnd is allowed, you will get a reversed sub curve then.
2536
+ *
2537
+ * @method getSubCurve
2538
+ * @param {number} tStart – The start position of the desired sub curve (must be in [0..arcLength]).
2539
+ * @param {number} tEnd – The end position if the desired cub curve (must be in [0..arcLength]).
2540
+ * @instance
2541
+ * @memberof CubicBezierCurve
2542
+ * @return {CubicBezierCurve} The sub curve as a new curve.
2543
+ **/
2544
+ CubicBezierCurve.prototype.getSubCurve = function (uStart, uEnd) {
2545
+ return this.getSubCurveAt(this.convertU2T(uStart), this.convertU2T(uEnd));
2546
+ };
2608
2547
  /**
2609
2548
  * Get a sub curve at the given start end end offsets (values between 0.0 and 1.0).
2610
2549
  *
@@ -2618,17 +2557,19 @@ var CubicBezierCurve = /** @class */ (function () {
2618
2557
  * @return {CubicBezierCurve} The sub curve as a new curve.
2619
2558
  **/
2620
2559
  CubicBezierCurve.prototype.getSubCurveAt = function (tStart, tEnd) {
2621
- var startVec = new Vector_1.Vector(this.getPointAt(tStart), this.getTangentAt(tStart));
2622
- var endVec = new Vector_1.Vector(this.getPointAt(tEnd), this.getTangentAt(tEnd).inv());
2623
- // Tangents are relative. Make absolute.
2624
- startVec.b.add(startVec.a);
2625
- endVec.b.add(endVec.a);
2626
- // This 'splits' the curve at the given point at t.
2627
- startVec.scale(0.33333333 * (tEnd - tStart));
2628
- endVec.scale(0.33333333 * (tEnd - tStart));
2629
- // Draw the bezier curve
2630
- // pb.draw.cubicBezier( startVec.a, endVec.a, startVec.b, endVec.b, '#8800ff', 2 );
2631
- return new CubicBezierCurve(startVec.a, endVec.a, startVec.b, endVec.b);
2560
+ // const startVec: Vector = new Vector(this.getPointAt(tStart), this.getTangentAt(tStart));
2561
+ // const endVec: Vector = new Vector(this.getPointAt(tEnd), this.getTangentAt(tEnd).inv());
2562
+ // // Tangents are relative. Make absolute.
2563
+ // startVec.b.add(startVec.a);
2564
+ // endVec.b.add(endVec.a);
2565
+ // // This 'splits' the curve at the given point at t.
2566
+ // startVec.scale(0.33333333 * (tEnd - tStart));
2567
+ // endVec.scale(0.33333333 * (tEnd - tStart));
2568
+ // // Draw the bezier curve
2569
+ // // pb.draw.cubicBezier( startVec.a, endVec.a, startVec.b, endVec.b, '#8800ff', 2 );
2570
+ // return new CubicBezierCurve(startVec.a, endVec.a, startVec.b, endVec.b);
2571
+ var subCurbePoints = CubicBezierCurve.utils.getSubCurvePointsAt(this, tStart, tEnd);
2572
+ return new CubicBezierCurve(subCurbePoints[0], subCurbePoints[1], subCurbePoints[2], subCurbePoints[3]);
2632
2573
  };
2633
2574
  /**
2634
2575
  * Convert a relative curve position u to the absolute curve position t.
@@ -2880,6 +2821,35 @@ var CubicBezierCurve = /** @class */ (function () {
2880
2821
  CubicBezierCurve.END_CONTROL_POINT = 2;
2881
2822
  /** @constant {number} */
2882
2823
  CubicBezierCurve.END_POINT = 3;
2824
+ /**
2825
+ * Helper utils.
2826
+ */
2827
+ CubicBezierCurve.utils = {
2828
+ /**
2829
+ * Get the points of a sub curve at the given start end end offsets (values between 0.0 and 1.0).
2830
+ *
2831
+ * tStart >= tEnd is allowed, you will get a reversed sub curve then.
2832
+ *
2833
+ * @method getSubCurvePointsAt
2834
+ * @param {CubicBezierCurve} curve – The curve to get the sub curve points from.
2835
+ * @param {number} tStart – The start offset of the desired sub curve (must be in [0..1]).
2836
+ * @param {number} tEnd – The end offset if the desired cub curve (must be in [0..1]).
2837
+ * @instance
2838
+ * @memberof CubicBezierCurve
2839
+ * @return {CubicBezierCurve} The sub curve as a new curve.
2840
+ **/
2841
+ getSubCurvePointsAt: function (curve, tStart, tEnd) {
2842
+ var startVec = new Vector_1.Vector(curve.getPointAt(tStart), curve.getTangentAt(tStart));
2843
+ var endVec = new Vector_1.Vector(curve.getPointAt(tEnd), curve.getTangentAt(tEnd).inv());
2844
+ // Tangents are relative. Make absolute.
2845
+ startVec.b.add(startVec.a);
2846
+ endVec.b.add(endVec.a);
2847
+ // This 'splits' the curve at the given point at t.
2848
+ startVec.scale(0.33333333 * (tEnd - tStart));
2849
+ endVec.scale(0.33333333 * (tEnd - tStart));
2850
+ return [startVec.a, endVec.a, startVec.b, endVec.b];
2851
+ }
2852
+ };
2883
2853
  return CubicBezierCurve;
2884
2854
  }());
2885
2855
  exports.CubicBezierCurve = CubicBezierCurve;
@@ -3445,6 +3415,7 @@ exports.KeyHandler = KeyHandler;
3445
3415
  * @modified 2022-02-02 Added the `destroy` method.
3446
3416
  * @modified 2022-10-09 Changed the actual return value of the `intersection` function to null (was undefined before).
3447
3417
  * @modified 2022-10-17 Adding these methods from the `PathSegment` interface: getStartPoint, getEndPoint, revert.
3418
+ * @modified 2023-09-25 Changed param type of `intersection()` from Line to VertTuple.
3448
3419
  * @version 2.3.0
3449
3420
  *
3450
3421
  * @file Line
@@ -4086,7 +4057,8 @@ exports.PBImage = PBImage;
4086
4057
  * @author Ikaros Kappler
4087
4058
  * @date 2021-11-16
4088
4059
  * @modified 2022-02-02 Added the `destroy` method.
4089
- * @version 1.1.0
4060
+ * @modified 2023-09-25 Fixed a type error in the constructor. Nothing vital.
4061
+ * @version 1.1.1
4090
4062
  **/
4091
4063
  Object.defineProperty(exports, "__esModule", ({ value: true }));
4092
4064
  exports.PBText = void 0;
@@ -4121,14 +4093,14 @@ var PBText = /** @class */ (function () {
4121
4093
  this.uid = UIDGenerator_1.UIDGenerator.next();
4122
4094
  this.text = text;
4123
4095
  this.anchor = anchor !== null && anchor !== void 0 ? anchor : new Vertex_1.Vertex();
4124
- this.color = options.color;
4125
- this.fontFamily = options.fontFamily;
4126
- this.fontSize = options.fontSize;
4127
- this.fontStyle = options.fontStyle;
4128
- this.fontWeight = options.fontWeight;
4129
- this.lineHeight = options.lineHeight;
4130
- this.textAlign = options.textAlign;
4131
- this.rotation = options.rotation;
4096
+ this.color = options === null || options === void 0 ? void 0 : options.color;
4097
+ this.fontFamily = options === null || options === void 0 ? void 0 : options.fontFamily;
4098
+ this.fontSize = options === null || options === void 0 ? void 0 : options.fontSize;
4099
+ this.fontStyle = options === null || options === void 0 ? void 0 : options.fontStyle;
4100
+ this.fontWeight = options === null || options === void 0 ? void 0 : options.fontWeight;
4101
+ this.lineHeight = options === null || options === void 0 ? void 0 : options.lineHeight;
4102
+ this.textAlign = options === null || options === void 0 ? void 0 : options.textAlign;
4103
+ this.rotation = options === null || options === void 0 ? void 0 : options.rotation;
4132
4104
  }
4133
4105
  /**
4134
4106
  * This function should invalidate any installed listeners and invalidate this object.
@@ -4231,7 +4203,12 @@ var __webpack_unused_export__;
4231
4203
  * @modified 2022-10-25 Added the `origin` to the default draw config.
4232
4204
  * @modified 2022-11-06 Adding an XML declaration to the SVG export routine.
4233
4205
  * @modified 2022-11-23 Added the `drawRaster` (default=true) option to the config/drawconfig.
4234
- * @version 1.17.0
4206
+ * @modified 2023-02-04 Fixed a bug in the `drawDrawable` function; fill's current classname was not set.
4207
+ * @modified 2023-02-10 Fixing an issue of the `style.position` setting when `fitToParent=true` from `absolute` to `static` (default).
4208
+ * @modified 2023-02-10 Cleaning up most type errors in the main class (mostly null checks).
4209
+ * @modified 2023-02-10 Adding `enableZoom` and `enablePan` (both default true) to have the option to disable these functions.
4210
+ * @modified 2023-09-29 Adding proper dicionary key and value types to the params of `PlotBoilerplate.utils.safeMergeByKeys` (was `object` before).
4211
+ * @version 1.17.3
4235
4212
  *
4236
4213
  * @file PlotBoilerplate
4237
4214
  * @fileoverview The main class.
@@ -4343,6 +4320,8 @@ var PlotBoilerplate = /** @class */ (function () {
4343
4320
  * @param {boolean=} [config.enableTouch=true] - Indicates if the application should handle touch events for you.
4344
4321
  * @param {boolean=} [config.enableKeys=true] - Indicates if the application should handle key events for you.
4345
4322
  * @param {boolean=} [config.enableMouseWheel=true] - Indicates if the application should handle mouse wheel events for you.
4323
+ * @param {boolean=} [config.enablePan=true] - (default true) Set to false if you want to disable panning completely.
4324
+ * @param {boolean=} [config.enableZoom=true] - (default true) Set to false if you want to disable zooming completely.
4346
4325
  * @param {boolean=} [config.enableGL=false] - Indicates if the application should use the experimental WebGL features (not recommended).
4347
4326
  * @param {boolean=} [config.enableSVGExport=true] - Indicates if the SVG export should be enabled (default is true).
4348
4327
  * Note that changes from the postDraw hook might not be visible in the export.
@@ -4369,7 +4348,7 @@ var PlotBoilerplate = /** @class */ (function () {
4369
4348
  draggable: true,
4370
4349
  visible: true
4371
4350
  };
4372
- if (typeof config.canvas == "undefined") {
4351
+ if (typeof config.canvas === "undefined") {
4373
4352
  throw "No canvas specified.";
4374
4353
  }
4375
4354
  /**
@@ -4423,6 +4402,8 @@ var PlotBoilerplate = /** @class */ (function () {
4423
4402
  enableTouch: f.bool(config, "enableTouch", true),
4424
4403
  enableKeys: f.bool(config, "enableKeys", true),
4425
4404
  enableMouseWheel: f.bool(config, "enableMouseWheel", true),
4405
+ enableZoom: f.bool(config, "enableZoom", true),
4406
+ enablePan: f.bool(config, "enablePan", true),
4426
4407
  // Experimental (and unfinished)
4427
4408
  enableGL: f.bool(config, "enableGL", false)
4428
4409
  }; // END confog
@@ -4459,6 +4440,10 @@ var PlotBoilerplate = /** @class */ (function () {
4459
4440
  fill: true
4460
4441
  }
4461
4442
  },
4443
+ // bezierPath: {
4444
+ // color: "#0022a8",
4445
+ // lineWidth: 1
4446
+ // },
4462
4447
  polygon: {
4463
4448
  color: "#0022a8",
4464
4449
  lineWidth: 1
@@ -4518,7 +4503,10 @@ var PlotBoilerplate = /** @class */ (function () {
4518
4503
  // +-------------------------------
4519
4504
  this.grid = new Grid_1.Grid(new Vertex_1.Vertex(0, 0), new Vertex_1.Vertex(50, 50));
4520
4505
  this.canvasSize = { width: PlotBoilerplate.DEFAULT_CANVAS_WIDTH, height: PlotBoilerplate.DEFAULT_CANVAS_HEIGHT };
4521
- var canvasElement = typeof config.canvas == "string" ? document.querySelector(config.canvas) : config.canvas;
4506
+ var canvasElement = typeof config.canvas === "string" ? document.querySelector(config.canvas) : config.canvas;
4507
+ if (typeof canvasElement === "undefined") {
4508
+ throw "Cannot initialize PlotBoilerplate with a null canvas (element \"" + config.canvas + " not found).";
4509
+ }
4522
4510
  // Which renderer to use: Canvas2D, WebGL (experimental) or SVG?
4523
4511
  if (canvasElement.tagName.toLowerCase() === "canvas") {
4524
4512
  this.canvas = canvasElement;
@@ -5087,7 +5075,7 @@ var PlotBoilerplate = /** @class */ (function () {
5087
5075
  this.draw.setCurrentId(d.uid);
5088
5076
  this.fill.setCurrentId(d.uid);
5089
5077
  this.draw.setCurrentClassName(d.className);
5090
- this.draw.setCurrentClassName(d.className);
5078
+ this.fill.setCurrentClassName(d.className);
5091
5079
  this.drawDrawable(d, renderTime, draw, fill);
5092
5080
  }
5093
5081
  };
@@ -5108,7 +5096,13 @@ var PlotBoilerplate = /** @class */ (function () {
5108
5096
  **/
5109
5097
  PlotBoilerplate.prototype.drawDrawable = function (d, renderTime, draw, fill) {
5110
5098
  if (d instanceof BezierPath_1.BezierPath) {
5099
+ var curveIndex = 0;
5111
5100
  for (var c in d.bezierCurves) {
5101
+ // Restore these settings again in each loop (will be overwritten)
5102
+ this.draw.setCurrentId(d.uid + "-" + curveIndex);
5103
+ this.fill.setCurrentId(d.uid + "-" + curveIndex);
5104
+ this.draw.setCurrentClassName(d.className);
5105
+ this.fill.setCurrentClassName(d.className);
5112
5106
  draw.cubicBezier(d.bezierCurves[c].startPoint, d.bezierCurves[c].endPoint, d.bezierCurves[c].startControlPoint, d.bezierCurves[c].endControlPoint, this.drawConfig.bezier.color, this.drawConfig.bezier.lineWidth);
5113
5107
  if (this.drawConfig.drawBezierHandlePoints && this.drawConfig.drawHandlePoints) {
5114
5108
  if (d.bezierCurves[c].startPoint.attr.visible) {
@@ -5160,12 +5154,13 @@ var PlotBoilerplate = /** @class */ (function () {
5160
5154
  if (this.drawConfig.drawBezierHandleLines && this.drawConfig.drawHandleLines) {
5161
5155
  draw.setCurrentId(d.uid + "_l0");
5162
5156
  draw.setCurrentClassName(d.className + "-start-line");
5163
- draw.line(d.bezierCurves[c].startPoint, d.bezierCurves[c].startControlPoint, this.drawConfig.bezier.handleLine.color, this.drawConfig.bezier.handleLine.lineWidth);
5157
+ draw.handleLine(d.bezierCurves[c].startPoint, d.bezierCurves[c].startControlPoint);
5164
5158
  draw.setCurrentId(d.uid + "_l1");
5165
5159
  draw.setCurrentClassName(d.className + "-end-line");
5166
- draw.line(d.bezierCurves[c].endPoint, d.bezierCurves[c].endControlPoint, this.drawConfig.bezier.handleLine.color, this.drawConfig.bezier.handleLine.lineWidth);
5160
+ draw.handleLine(d.bezierCurves[c].endPoint, d.bezierCurves[c].endControlPoint);
5167
5161
  }
5168
- }
5162
+ curveIndex++;
5163
+ } // END for
5169
5164
  }
5170
5165
  else if (d instanceof Polygon_1.Polygon) {
5171
5166
  draw.polygon(d, this.drawConfig.polygon.color, this.drawConfig.polygon.lineWidth);
@@ -5185,11 +5180,11 @@ var PlotBoilerplate = /** @class */ (function () {
5185
5180
  draw.setCurrentId(d.uid + "_e0");
5186
5181
  draw.setCurrentClassName(d.className + "-v-line");
5187
5182
  // draw.line( d.center.clone().add(0,d.axis.y-d.center.y), d.axis, '#c8c8c8' );
5188
- draw.line(d.center.clone().add(0, d.signedRadiusV()).rotate(d.rotation, d.center), d.axis, "#c8c8c8");
5183
+ draw.handleLine(d.center.clone().add(0, d.signedRadiusV()).rotate(d.rotation, d.center), d.axis); // , "#c8c8c8");
5189
5184
  draw.setCurrentId(d.uid + "_e1");
5190
5185
  draw.setCurrentClassName(d.className + "-h-line");
5191
5186
  // draw.line( d.center.clone().add(d.axis.x-d.center.x,0), d.axis, '#c8c8c8' );
5192
- draw.line(d.center.clone().add(d.signedRadiusH(), 0).rotate(d.rotation, d.center), d.axis, "#c8c8c8");
5187
+ draw.handleLine(d.center.clone().add(d.signedRadiusH(), 0).rotate(d.rotation, d.center), d.axis); // , "#c8c8c8");
5193
5188
  }
5194
5189
  draw.setCurrentId(d.uid);
5195
5190
  draw.setCurrentClassName("" + d.className);
@@ -5276,10 +5271,10 @@ var PlotBoilerplate = /** @class */ (function () {
5276
5271
  else {
5277
5272
  console.error("Cannot draw object. Unknown class.");
5278
5273
  }
5279
- draw.setCurrentClassName(undefined);
5280
- draw.setCurrentId(undefined);
5281
- fill.setCurrentClassName(undefined);
5282
- fill.setCurrentId(undefined);
5274
+ draw.setCurrentClassName(null);
5275
+ draw.setCurrentId(null);
5276
+ fill.setCurrentClassName(null);
5277
+ fill.setCurrentId(null);
5283
5278
  };
5284
5279
  /**
5285
5280
  * Draw the select-polygon (if there is one).
@@ -5369,8 +5364,8 @@ var PlotBoilerplate = /** @class */ (function () {
5369
5364
  this.drawSelectPolygon(draw);
5370
5365
  // Clear IDs and classnames (postDraw hook might draw somthing and the do not want
5371
5366
  // to interfered with that).
5372
- draw.setCurrentId(undefined);
5373
- draw.setCurrentClassName(undefined);
5367
+ draw.setCurrentId(null);
5368
+ draw.setCurrentClassName(null);
5374
5369
  }; // END redraw
5375
5370
  /**
5376
5371
  * This function clears the canvas with the configured background color.<br>
@@ -5507,7 +5502,7 @@ var PlotBoilerplate = /** @class */ (function () {
5507
5502
  }
5508
5503
  else if (_self.config.fitToParent) {
5509
5504
  // Set editor size
5510
- _self.canvas.style.position = "absolute";
5505
+ _self.canvas.style.position = "static";
5511
5506
  var space = this.getAvailableContainerSpace();
5512
5507
  _self.canvas.style.width = ((_c = _self.config.canvasWidthFactor) !== null && _c !== void 0 ? _c : 1.0) * space.width + "px";
5513
5508
  _self.canvas.style.height = ((_d = _self.config.canvasHeightFactor) !== null && _d !== void 0 ? _d : 1.0) * space.height + "px";
@@ -5578,24 +5573,24 @@ var PlotBoilerplate = /** @class */ (function () {
5578
5573
  **/
5579
5574
  PlotBoilerplate.prototype.handleClick = function (e) {
5580
5575
  var _self = this;
5581
- var p = this.locatePointNear(_self.transformMousePosition(e.params.pos.x, e.params.pos.y), PlotBoilerplate.DEFAULT_CLICK_TOLERANCE / Math.min(_self.config.cssScaleX, _self.config.cssScaleY));
5582
- if (p) {
5583
- _self.vertices[p.vindex].listeners.fireClickEvent(e);
5576
+ var point = this.locatePointNear(_self.transformMousePosition(e.params.pos.x, e.params.pos.y), PlotBoilerplate.DEFAULT_CLICK_TOLERANCE / Math.min(_self.config.cssScaleX || 1.0, _self.config.cssScaleY || 1.0));
5577
+ if (point) {
5578
+ _self.vertices[point.vindex].listeners.fireClickEvent(e);
5584
5579
  if (this.keyHandler && this.keyHandler.isDown("shift")) {
5585
- if (p.typeName == "bpath") {
5586
- var vert = _self.paths[p.pindex].bezierCurves[p.cindex].getPointByID(p.pid);
5580
+ if (point.typeName == "bpath") {
5581
+ var vert = _self.paths[point.pindex].bezierCurves[point.cindex].getPointByID(point.pid);
5587
5582
  if (vert.attr.selectable)
5588
5583
  vert.attr.isSelected = !vert.attr.isSelected;
5589
5584
  }
5590
- else if (p.typeName == "vertex") {
5591
- var vert = _self.vertices[p.vindex];
5585
+ else if (point.typeName == "vertex") {
5586
+ var vert = _self.vertices[point.vindex];
5592
5587
  if (vert.attr.selectable)
5593
5588
  vert.attr.isSelected = !vert.attr.isSelected;
5594
5589
  }
5595
5590
  _self.redraw();
5596
5591
  }
5597
- else if (this.keyHandler.isDown("y")) {
5598
- _self.vertices[p.vindex].attr.bezierAutoAdjust = !_self.vertices[p.vindex].attr.bezierAutoAdjust;
5592
+ else if (this.keyHandler && this.keyHandler.isDown("y")) {
5593
+ _self.vertices[point.vindex].attr.bezierAutoAdjust = !_self.vertices[point.vindex].attr.bezierAutoAdjust;
5599
5594
  _self.redraw();
5600
5595
  }
5601
5596
  }
@@ -5662,11 +5657,11 @@ var PlotBoilerplate = /** @class */ (function () {
5662
5657
  var _self = this;
5663
5658
  if (e.button != 0)
5664
5659
  return; // Only react on left mouse or touch events
5665
- var p = _self.locatePointNear(_self.transformMousePosition(e.params.pos.x, e.params.pos.y), PlotBoilerplate.DEFAULT_CLICK_TOLERANCE / Math.min(_self.config.cssScaleX, _self.config.cssScaleY));
5666
- if (!p)
5660
+ var draggablePoint = _self.locatePointNear(_self.transformMousePosition(e.params.pos.x, e.params.pos.y), PlotBoilerplate.DEFAULT_CLICK_TOLERANCE / Math.min(_self.config.cssScaleX, _self.config.cssScaleY));
5661
+ if (!draggablePoint)
5667
5662
  return;
5668
5663
  // Drag all selected elements?
5669
- if (p.typeName == "vertex" && _self.vertices[p.vindex].attr.isSelected) {
5664
+ if (draggablePoint.typeName == "vertex" && _self.vertices[draggablePoint.vindex].attr.isSelected) {
5670
5665
  // Multi drag
5671
5666
  // for( var i in _self.vertices ) {
5672
5667
  for (var i = 0; i < _self.vertices.length; i++) {
@@ -5678,13 +5673,15 @@ var PlotBoilerplate = /** @class */ (function () {
5678
5673
  }
5679
5674
  else {
5680
5675
  // Single drag
5681
- if (!_self.vertices[p.vindex].attr.draggable)
5676
+ if (!_self.vertices[draggablePoint.vindex].attr.draggable)
5682
5677
  return;
5683
- _self.draggedElements.push(p);
5684
- if (p.typeName == "bpath")
5685
- _self.paths[p.pindex].bezierCurves[p.cindex].getPointByID(p.pid).listeners.fireDragStartEvent(e);
5686
- else if (p.typeName == "vertex")
5687
- _self.vertices[p.vindex].listeners.fireDragStartEvent(e);
5678
+ _self.draggedElements.push(draggablePoint);
5679
+ if (draggablePoint.typeName == "bpath")
5680
+ _self.paths[draggablePoint.pindex].bezierCurves[draggablePoint.cindex]
5681
+ .getPointByID(draggablePoint.pid)
5682
+ .listeners.fireDragStartEvent(e);
5683
+ else if (draggablePoint.typeName == "vertex")
5684
+ _self.vertices[draggablePoint.vindex].listeners.fireDragStartEvent(e);
5688
5685
  }
5689
5686
  _self.redraw();
5690
5687
  };
@@ -5711,7 +5708,10 @@ var PlotBoilerplate = /** @class */ (function () {
5711
5708
  // not this one. So this tab will never receive any [Ctrl-down] events
5712
5709
  // until next keypress; the implication is, that [Ctrl] would still
5713
5710
  // considered to be pressed which is not true.
5714
- if (this.keyHandler.isDown("alt") || this.keyHandler.isDown("spacebar")) {
5711
+ if (this.keyHandler && (this.keyHandler.isDown("alt") || this.keyHandler.isDown("spacebar"))) {
5712
+ if (!this.config.enablePan) {
5713
+ return;
5714
+ }
5715
5715
  _self.setOffset(_self.draw.offset.clone().add(e.params.dragAmount));
5716
5716
  _self.redraw();
5717
5717
  }
@@ -5780,6 +5780,9 @@ var PlotBoilerplate = /** @class */ (function () {
5780
5780
  * @return {void}
5781
5781
  **/
5782
5782
  PlotBoilerplate.prototype.mouseWheelHandler = function (e) {
5783
+ if (!this.config.enableZoom) {
5784
+ return;
5785
+ }
5783
5786
  var zoomStep = 1.25; // Make configurable?
5784
5787
  // CHANGED replaced _self by this
5785
5788
  var _self = this;
@@ -5845,6 +5848,7 @@ var PlotBoilerplate = /** @class */ (function () {
5845
5848
  this.setOffset({ x: newOffsetX, y: newOffsetY });
5846
5849
  };
5847
5850
  PlotBoilerplate.prototype.installInputListeners = function () {
5851
+ var _this = this;
5848
5852
  var _self = this;
5849
5853
  if (this.config.enableMouse) {
5850
5854
  // Install a mouse handler on the canvas.
@@ -5919,6 +5923,9 @@ var PlotBoilerplate = /** @class */ (function () {
5919
5923
  if (evt.touches.length == 1 && draggedElement) {
5920
5924
  evt.preventDefault();
5921
5925
  evt.stopPropagation();
5926
+ if (!touchDownPos || !touchMovePos) {
5927
+ return;
5928
+ }
5922
5929
  var rel = relPos_1({ x: evt.touches[0].clientX, y: evt.touches[0].clientY });
5923
5930
  var trans = _self.transformMousePosition(rel.x, rel.y);
5924
5931
  var diff = new Vertex_1.Vertex(_self.transformMousePosition(touchMovePos.x, touchMovePos.y)).difference(trans);
@@ -5943,6 +5950,9 @@ var PlotBoilerplate = /** @class */ (function () {
5943
5950
  touchMovePos = new Vertex_1.Vertex(rel);
5944
5951
  }
5945
5952
  else if (evt.touches.length == 2) {
5953
+ if (!_this.config.enablePan) {
5954
+ return;
5955
+ }
5946
5956
  // If at least two fingers touch and move, then change the draw offset (panning).
5947
5957
  evt.preventDefault();
5948
5958
  evt.stopPropagation();
@@ -5955,6 +5965,9 @@ var PlotBoilerplate = /** @class */ (function () {
5955
5965
  touchEnd: function (evt) {
5956
5966
  // Note: e.touches.length is 0 here
5957
5967
  if (draggedElement && draggedElement.typeName == "vertex") {
5968
+ if (!touchDownPos) {
5969
+ return;
5970
+ }
5958
5971
  var draggingVertex = _self.vertices[draggedElement.vindex];
5959
5972
  var fakeEvent = {
5960
5973
  isTouchEvent: true,
@@ -5987,9 +6000,17 @@ var PlotBoilerplate = /** @class */ (function () {
5987
6000
  multiTouchStartScale = null;
5988
6001
  },
5989
6002
  pinch: function (evt) {
6003
+ if (!_this.config.enableZoom) {
6004
+ return;
6005
+ }
6006
+ var touchItem0 = evt.touches.item(0);
6007
+ var touchItem1 = evt.touches.item(1);
6008
+ if (!evt.touches || !multiTouchStartScale || !touchItem0 || !touchItem1) {
6009
+ return;
6010
+ }
5990
6011
  // For pinching there must be at least two touch items
5991
- var fingerA = new Vertex_1.Vertex(evt.touches.item(0).clientX, evt.touches.item(0).clientY);
5992
- var fingerB = new Vertex_1.Vertex(evt.touches.item(1).clientX, evt.touches.item(1).clientY);
6012
+ var fingerA = new Vertex_1.Vertex(touchItem0.clientX, touchItem0.clientY);
6013
+ var fingerB = new Vertex_1.Vertex(touchItem1.clientX, touchItem1.clientY);
5993
6014
  var center = new Line_1.Line(fingerA, fingerB).vertAt(0.5);
5994
6015
  _self.setZoom(multiTouchStartScale.x * evt.zoom, multiTouchStartScale.y * evt.zoom, center);
5995
6016
  _self.redraw();
@@ -6102,22 +6123,35 @@ var PlotBoilerplate = /** @class */ (function () {
6102
6123
  **/
6103
6124
  safeMergeByKeys: function (base, extension) {
6104
6125
  for (var k in extension) {
6105
- if (!extension.hasOwnProperty(k))
6126
+ if (!extension.hasOwnProperty(k)) {
6106
6127
  continue;
6128
+ }
6107
6129
  if (base.hasOwnProperty(k)) {
6108
6130
  var typ = typeof base[k];
6131
+ var extVal = extension[k];
6109
6132
  try {
6110
- if (typ == "boolean")
6111
- base[k] = !!JSON.parse(extension[k]);
6112
- else if (typ == "number")
6113
- base[k] = JSON.parse(extension[k]) * 1;
6114
- else if (typ == "function" && typeof extension[k] == "function")
6133
+ if (typ == "boolean") {
6134
+ if (typeof extVal === "string")
6135
+ base[k] = Boolean(!!JSON.parse(extVal));
6136
+ else
6137
+ base[k] = extVal;
6138
+ }
6139
+ else if (typ == "number") {
6140
+ if (typeof extVal === "string")
6141
+ base[k] = Number(JSON.parse(extVal) * 1);
6142
+ else
6143
+ base[k] = extension[k];
6144
+ }
6145
+ else if (typ == "function" && typeof extVal == "function") {
6115
6146
  base[k] = extension[k];
6116
- else
6147
+ }
6148
+ else {
6149
+ // Probably a sting
6117
6150
  base[k] = extension[k];
6151
+ }
6118
6152
  }
6119
6153
  catch (e) {
6120
- console.error("error in key ", k, extension[k], e);
6154
+ console.error("error in key ", k, extVal, e);
6121
6155
  }
6122
6156
  }
6123
6157
  else {
@@ -6126,6 +6160,31 @@ var PlotBoilerplate = /** @class */ (function () {
6126
6160
  }
6127
6161
  return base;
6128
6162
  },
6163
+ /*
6164
+ __safeMergeByKeys: <KeyType extends string | number | symbol, ValueType extends boolean | number | string | Function>(
6165
+ base: Record<KeyType, ValueType>,
6166
+ extension: Record<KeyType, string>
6167
+ ): Record<KeyType, ValueType> => {
6168
+ for (var k in extension) {
6169
+ if (!extension.hasOwnProperty(k)) continue;
6170
+ if (base.hasOwnProperty(k)) {
6171
+ var typ = typeof base[k];
6172
+ try {
6173
+ if (typ == "boolean") base[k] = !!JSON.parse(extension[k]);
6174
+ else if (typ == "number") base[k] = JSON.parse(extension[k]) * 1;
6175
+ else if (typ == "function" && typeof extension[k] == "function") base[k] = extension[k];
6176
+ else base[k] = extension[k];
6177
+ } catch (e) {
6178
+ console.error("error in key ", k, extension[k], e);
6179
+ }
6180
+ } else {
6181
+ base[k] = extension[k];
6182
+ }
6183
+ }
6184
+ return base;
6185
+ },
6186
+ *()
6187
+
6129
6188
  /**
6130
6189
  * A helper function to scale elements (usually the canvas) using CSS.
6131
6190
  *
@@ -6138,8 +6197,10 @@ var PlotBoilerplate = /** @class */ (function () {
6138
6197
  **/
6139
6198
  setCSSscale: function (element, scaleX, scaleY) {
6140
6199
  element.style["transform-origin"] = "0 0";
6141
- if (scaleX == 1.0 && scaleY == 1.0)
6142
- element.style.transform = null;
6200
+ if (scaleX == 1.0 && scaleY == 1.0) {
6201
+ // element.style.transform = null;
6202
+ element.style.removeProperty("transform");
6203
+ }
6143
6204
  else
6144
6205
  element.style.transform = "scale(" + scaleX + "," + scaleY + ")";
6145
6206
  },
@@ -6307,7 +6368,10 @@ __webpack_unused_export__ = PlotBoilerplate;
6307
6368
  * @modified 2022-02-02 Added the `destroy` method.
6308
6369
  * @modified 2022-02-02 Cleared the `Polygon.toSVGString` function (deprecated). Use `drawutilssvg` instead.
6309
6370
  * @modified 2022-03-08 Added the `Polygon.clone()` function.
6310
- * @version 1.10.0
6371
+ * @modified 2023-09-25 Added the `Polygon.getInterpolationPolygon(number)` function.
6372
+ * @modified 2023-09-25 Added the `Polygon.lineIntersections(Line,boolean)` function.
6373
+ * @modified 2023-09-29 Added the `Polygon.closestLineIntersection(Line,boolean)` function.
6374
+ * @version 1.11.0
6311
6375
  *
6312
6376
  * @file Polygon
6313
6377
  * @public
@@ -6316,6 +6380,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
6316
6380
  exports.Polygon = void 0;
6317
6381
  var BezierPath_1 = __webpack_require__(126);
6318
6382
  var Bounds_1 = __webpack_require__(262);
6383
+ var Line_1 = __webpack_require__(831);
6319
6384
  var UIDGenerator_1 = __webpack_require__(197);
6320
6385
  var Vertex_1 = __webpack_require__(421);
6321
6386
  /**
@@ -6515,6 +6580,88 @@ var Polygon = /** @class */ (function () {
6515
6580
  }
6516
6581
  return this;
6517
6582
  };
6583
+ /**
6584
+ * Get all line intersections with this polygon.
6585
+ *
6586
+ * See demo `47-closest-vector-projection-on-polygon` for how it works.
6587
+ *
6588
+ * @param {VertTuple} line - The line to find intersections with.
6589
+ * @param {boolean} inVectorBoundsOnly - If set to true only intersecion points on the passed vector are returned (located strictly between start and end vertex).
6590
+ * @returns {Array<Vertex>} - An array of all intersections within the polygon bounds.
6591
+ */
6592
+ Polygon.prototype.lineIntersections = function (line, inVectorBoundsOnly) {
6593
+ if (inVectorBoundsOnly === void 0) { inVectorBoundsOnly = false; }
6594
+ // Find the intersections of all lines inside the edge bounds
6595
+ var intersectionPoints = [];
6596
+ for (var i = 0; i < this.vertices.length; i++) {
6597
+ var polyLine = new Line_1.Line(this.vertices[i], this.vertices[(i + 1) % this.vertices.length]);
6598
+ var intersection = polyLine.intersection(line);
6599
+ // true => only inside bounds
6600
+ // ignore last edge if open
6601
+ if ((!this.isOpen || i + 1 !== this.vertices.length) &&
6602
+ intersection !== null &&
6603
+ polyLine.hasPoint(intersection, true) &&
6604
+ (!inVectorBoundsOnly || line.hasPoint(intersection, inVectorBoundsOnly))) {
6605
+ intersectionPoints.push(intersection);
6606
+ }
6607
+ }
6608
+ return intersectionPoints;
6609
+ };
6610
+ /**
6611
+ * Get the closest line-polygon-intersection point (closest the line point A).
6612
+ *
6613
+ * See demo `47-closest-vector-projection-on-polygon` for how it works.
6614
+ *
6615
+ * @param {VertTuple} line - The line to find intersections with.
6616
+ * @param {boolean} inVectorBoundsOnly - If set to true only intersecion points on the passed vector are considered (located strictly between start and end vertex).
6617
+ * @returns {Array<Vertex>} - An array of all intersections within the polygon bounds.
6618
+ */
6619
+ Polygon.prototype.closestLineIntersection = function (line, inVectorBoundsOnly) {
6620
+ if (inVectorBoundsOnly === void 0) { inVectorBoundsOnly = false; }
6621
+ var allIntersections = this.lineIntersections(line, inVectorBoundsOnly);
6622
+ if (allIntersections.length <= 0) {
6623
+ // Empty polygon -> no intersections
6624
+ return null;
6625
+ }
6626
+ // Find the closest intersection
6627
+ var closestIntersection = new Vertex_1.Vertex(Number.MAX_VALUE, Number.MAX_VALUE);
6628
+ var curDist = Number.MAX_VALUE;
6629
+ for (var i in allIntersections) {
6630
+ var curVert = allIntersections[i];
6631
+ var dist = curVert.distance(line.a);
6632
+ if (dist < curDist) {
6633
+ // && line.hasPoint(curVert)) {
6634
+ curDist = dist;
6635
+ closestIntersection = curVert;
6636
+ }
6637
+ }
6638
+ return closestIntersection;
6639
+ };
6640
+ /**
6641
+ * Construct a new polygon from this polygon with more vertices on each edge. The
6642
+ * interpolation count determines the number of additional vertices on each edge.
6643
+ * An interpolation count of `0` will return a polygon that equals the source
6644
+ * polygon.
6645
+ *
6646
+ * @param {number} interpolationCount
6647
+ * @returns {Polygon} A polygon with `interpolationCount` more vertices (as as factor).
6648
+ */
6649
+ Polygon.prototype.getInterpolationPolygon = function (interpolationCount) {
6650
+ var verts = [];
6651
+ for (var i = 0; i < this.vertices.length; i++) {
6652
+ var curVert = this.vertices[i];
6653
+ var nextVert = this.vertices[(i + 1) % this.vertices.length];
6654
+ verts.push(curVert.clone());
6655
+ // Add interpolation points
6656
+ if (!this.isOpen || i + 1 !== this.vertices.length) {
6657
+ var lerpAmount = 1.0 / (interpolationCount + 1);
6658
+ for (var j = 1; j <= interpolationCount; j++) {
6659
+ verts.push(curVert.clone().lerp(nextVert, lerpAmount * j));
6660
+ }
6661
+ }
6662
+ }
6663
+ return new Polygon(verts, this.isOpen);
6664
+ };
6518
6665
  /**
6519
6666
  * Convert this polygon into a new polygon with n evenly distributed vertices.
6520
6667
  *
@@ -7090,6 +7237,7 @@ var Triangle = /** @class */ (function () {
7090
7237
  var lineC = new Line_1.Line(this.c, this.a);
7091
7238
  var bisector1 = geomutils_1.geomutils.nsectAngle(this.b, this.a, this.c, 2)[0]; // bisector of first angle (in b)
7092
7239
  var bisector2 = geomutils_1.geomutils.nsectAngle(this.c, this.b, this.a, 2)[0]; // bisector of second angle (in c)
7240
+ // Cast to non-null here because we know there _is_ an intersection
7093
7241
  var intersection = bisector1.intersection(bisector2);
7094
7242
  // Find the closest points on one of the polygon lines (all have same distance by construction)
7095
7243
  var circleIntersA = lineA.getClosestPoint(intersection);
@@ -7543,7 +7691,7 @@ var VEllipse = /** @class */ (function () {
7543
7691
  else {
7544
7692
  var startTangent = this.tangentAt(curAngle);
7545
7693
  var endTangent = this.tangentAt(nextAngle);
7546
- // Find intersection
7694
+ // Find intersection (ignore that the result might be null in some extreme cases)
7547
7695
  var intersection = startTangent.intersection(endTangent);
7548
7696
  // What if intersection is undefined?
7549
7697
  // --> This *can* not happen if segmentCount > 2 and height and width of the ellipse are not zero.
@@ -8088,8 +8236,8 @@ var Vector = /** @class */ (function (_super) {
8088
8236
  * Example:
8089
8237
  * buildArrowHead( new Vertex(0,0), new Vertex(50,100), 8, 1.0, 1.0 )
8090
8238
  *
8091
- * @param {Vertex} zA - The start vertex of the vector to calculate the arrow head for.
8092
- * @param {Vertex} zB - The end vertex of the vector.
8239
+ * @param {XYCoords} zA - The start vertex of the vector to calculate the arrow head for.
8240
+ * @param {XYCoords} zB - The end vertex of the vector.
8093
8241
  * @param {number} headlen - The length of the arrow head (along the vector direction. A good value is 12).
8094
8242
  * @param {number} scaleX - The horizontal scaling during draw.
8095
8243
  * @param {number} scaleY - the vertical scaling during draw.
@@ -8126,7 +8274,8 @@ exports.Vector = Vector;
8126
8274
  * @modified 2020-12-04 Added the `hasPoint(XYCoords)` function.
8127
8275
  * @modified 2021-01-20 Added UID.
8128
8276
  * @modified 2022-02-02 Added the `destroy` method.
8129
- * @version 1.2.0
8277
+ * @modified 2023-09-29 Fixed a calculation error in the VertTuple.hasPoint() function; distance measure was broken!
8278
+ * @version 1.2.1
8130
8279
  */
8131
8280
  Object.defineProperty(exports, "__esModule", ({ value: true }));
8132
8281
  exports.VertTuple = void 0;
@@ -8344,12 +8493,12 @@ var VertTuple = /** @class */ (function () {
8344
8493
  VertTuple.prototype.hasPoint = function (point, insideBoundsOnly) {
8345
8494
  var t = this.getClosestT(point);
8346
8495
  // Compare to pointDistance?
8496
+ var distance = Math.sqrt(VertTuple.vtutils.dist2(point, this.vertAt(t)));
8347
8497
  if (typeof insideBoundsOnly !== "undefined" && insideBoundsOnly) {
8348
- var distance = Math.sqrt(VertTuple.vtutils.dist2(point, this.vertAt(t)));
8349
8498
  return distance < Vertex_1.Vertex.EPSILON && t >= 0 && t <= 1;
8350
8499
  }
8351
8500
  else {
8352
- return t >= 0 && t <= 1;
8501
+ return distance < Vertex_1.Vertex.EPSILON; // t >= 0 && t <= 1;
8353
8502
  }
8354
8503
  };
8355
8504
  /**
@@ -8461,6 +8610,8 @@ exports.VertTuple = VertTuple;
8461
8610
  * @modified 2022-02-02 Added the `destroy` method.
8462
8611
  * @modified 2022-02-02 Cleared the `Vertex.toSVGString` function (deprecated). Use `drawutilssvg` instead.
8463
8612
  * @modified 2022-11-28 Added the `subXY`, `subX` and `subY` methods to the `Vertex` class.
8613
+ * @modified 2023-09-29 Downgraded types for the `Vertex.utils.buildArrowHead` function (replacing Vertex params by more generic XYCoords type).
8614
+ * @modified 2023-09-29 Added the `Vertex.abs()` method as it seems useful.
8464
8615
  * @version 2.8.0
8465
8616
  *
8466
8617
  * @file Vertex
@@ -8982,6 +9133,19 @@ var Vertex = /** @class */ (function () {
8982
9133
  this.y = -this.y;
8983
9134
  return this;
8984
9135
  };
9136
+ /**
9137
+ * Set both coordinates of this vertex to their absolute value (abs(x), abs(y)).
9138
+ *
9139
+ * @method abs
9140
+ * @return {Vertex} this
9141
+ * @instance
9142
+ * @memberof Vertex
9143
+ */
9144
+ Vertex.prototype.abs = function () {
9145
+ this.x = Math.abs(this.x);
9146
+ this.y = Math.abs(this.y);
9147
+ return this;
9148
+ };
8985
9149
  /**
8986
9150
  * Get a string representation of this vertex.
8987
9151
  *
@@ -9039,15 +9203,15 @@ var Vertex = /** @class */ (function () {
9039
9203
  * Example:
9040
9204
  * buildArrowHead( new Vertex(0,0), new Vertex(50,100), 8, 1.0, 1.0 )
9041
9205
  *
9042
- * @param {Vertex} zA - The start vertex of the vector to calculate the arrow head for.
9043
- * @param {Vertex} zB - The end vertex of the vector.
9206
+ * @param {XYCoords} zA - The start vertex of the vector to calculate the arrow head for.
9207
+ * @param {XYCoords} zB - The end vertex of the vector.
9044
9208
  * @param {number} headlen - The length of the arrow head (along the vector direction. A good value is 12).
9045
9209
  * @param {number} scaleX - The horizontal scaling during draw.
9046
9210
  * @param {number} scaleY - the vertical scaling during draw.
9047
9211
  **/
9048
9212
  // @DEPRECATED: use Vector.utils.buildArrowHead instead!!!
9049
9213
  buildArrowHead: function (zA, zB, headlen, scaleX, scaleY) {
9050
- // console.warn('This function is deprecated! Use Vector.utils.buildArrowHead instead!');
9214
+ console.warn("[DEPRECATION] Vertex.utils.buildArrowHead is deprecated. Please use Vector.utils.buildArrowHead instead.");
9051
9215
  var angle = Math.atan2((zB.y - zA.y) * scaleY, (zB.x - zA.x) * scaleX);
9052
9216
  var vertices = [];
9053
9217
  vertices.push(new Vertex(zB.x * scaleX - headlen * Math.cos(angle), zB.y * scaleY - headlen * Math.sin(angle)));
@@ -9467,13 +9631,23 @@ exports.VertexListeners = VertexListeners;
9467
9631
  * @modified 2022-08-23 Fixed a type issue in the `polyline` function.
9468
9632
  * @modified 2022-08-23 Fixed a type issue in the `setConfiguration` function.
9469
9633
  * @modified 2022-08-23 Fixed a type issue in the `path` function.
9470
- * @version 1.12.3
9634
+ * @modified 2023-02-10 The methods `setCurrentClassName` and `setCurrentId` also accept `null` now.
9635
+ * @modified 2023-09-29 Removed unused method stub for texturedPoly helper function (cleanup).
9636
+ * @modified 2023-09-29 Downgrading all `Vertex` param type to the more generic `XYCoords` type in these render functions: line, arrow, texturedPoly, cubicBezier, cubicBezierPath, handle, handleLine, dot, point, circle, circleArc, ellipse, grid, raster.
9637
+ * @modified 2023-09-29 Added the `headLength` parameter to the 'DrawLib.arrow()` function.
9638
+ * @modified 2023-09-29 Added the `arrowHead(...)` function to the 'DrawLib.arrow()` interface.
9639
+ * @modified 2023-09-29 Added the `cubicBezierArrow(...)` function to the 'DrawLib.arrow()` interface.
9640
+ * @modified 2023-09-29 Added the `lineDashes` attribute.
9641
+ * @modified 2023-09-30 Adding `strokeOptions` param to these draw function: line, arrow, cubicBezierArrow, cubicBezier, cubicBezierPath, circle, circleArc, ellipse, square, rect, polygon, polyline.
9642
+ * @modified 2023-10-07 Adding the optional `arrowHeadBasePositionBuffer` param to the arrowHead(...) method.
9643
+ * @version 1.13.0
9471
9644
  **/
9472
9645
  Object.defineProperty(exports, "__esModule", ({ value: true }));
9473
9646
  exports.drawutils = void 0;
9474
9647
  var CubicBezierCurve_1 = __webpack_require__(510);
9475
9648
  var Vertex_1 = __webpack_require__(421);
9476
9649
  var drawutilssvg_1 = __webpack_require__(829);
9650
+ var Vector_1 = __webpack_require__(73);
9477
9651
  // Todo: rename this class to Drawutils?
9478
9652
  /**
9479
9653
  * @classdesc A wrapper class for basic drawing operations.
@@ -9494,10 +9668,48 @@ var drawutils = /** @class */ (function () {
9494
9668
  **/
9495
9669
  function drawutils(context, fillShapes) {
9496
9670
  this.ctx = context;
9671
+ // this.lineDash = [];
9497
9672
  this.offset = new Vertex_1.Vertex(0, 0);
9498
9673
  this.scale = new Vertex_1.Vertex(1, 1);
9499
9674
  this.fillShapes = fillShapes;
9500
9675
  }
9676
+ /**
9677
+ * A private helper method to apply stroke options to the current
9678
+ * context.
9679
+ * @param {StrokeOptions=} strokeOptions -
9680
+ */
9681
+ drawutils.prototype.applyStrokeOpts = function (strokeOptions) {
9682
+ var _this = this;
9683
+ var _a, _b;
9684
+ this.ctx.setLineDash(((_a = strokeOptions === null || strokeOptions === void 0 ? void 0 : strokeOptions.dashArray) !== null && _a !== void 0 ? _a : []).map(function (dashArrayElem) {
9685
+ // Note assume scale.x === scale.y
9686
+ // Invariant scale makes funny stuff anyway.
9687
+ return dashArrayElem * _this.scale.x;
9688
+ }));
9689
+ this.ctx.lineDashOffset = ((_b = strokeOptions === null || strokeOptions === void 0 ? void 0 : strokeOptions.dashOffset) !== null && _b !== void 0 ? _b : 0) * this.scale.x;
9690
+ };
9691
+ // +---------------------------------------------------------------------------------
9692
+ // | This is the final helper function for drawing and filling stuff. It is not
9693
+ // | intended to be used from the outside.
9694
+ // |
9695
+ // | When in draw mode it draws the current shape.
9696
+ // | When in fill mode it fills the current shape.
9697
+ // |
9698
+ // | This function is usually only called internally.
9699
+ // |
9700
+ // | @param color A stroke/fill color to use.
9701
+ // +-------------------------------
9702
+ // TODO: convert this to a STATIC function.
9703
+ drawutils.prototype._fillOrDraw = function (color) {
9704
+ if (this.fillShapes) {
9705
+ this.ctx.fillStyle = color;
9706
+ this.ctx.fill();
9707
+ }
9708
+ else {
9709
+ this.ctx.strokeStyle = color;
9710
+ this.ctx.stroke();
9711
+ }
9712
+ };
9501
9713
  /**
9502
9714
  * Called before each draw cycle.
9503
9715
  * @param {UID=} uid - (optional) A UID identifying the currently drawn element(s).
@@ -9528,13 +9740,27 @@ var drawutils = /** @class */ (function () {
9528
9740
  drawutils.prototype.setConfiguration = function (configuration) {
9529
9741
  this.ctx.globalCompositeOperation = configuration.blendMode || "source-over";
9530
9742
  };
9743
+ // /**
9744
+ // * Set or clear the line-dash configuration. Pass `null` for un-dashed lines.
9745
+ // *
9746
+ // * See https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray
9747
+ // * and https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash
9748
+ // * for how line dashes work.
9749
+ // *
9750
+ // * @method
9751
+ // * @param {Array<number> lineDashes - The line-dash array configuration.
9752
+ // * @returns {void}
9753
+ // */
9754
+ // setLineDash(lineDash: Array<number>) {
9755
+ // this.lineDash = lineDash;
9756
+ // }
9531
9757
  /**
9532
9758
  * This method shouled be called each time the currently drawn `Drawable` changes.
9533
9759
  * It is used by some libraries for identifying elemente on re-renders.
9534
9760
  *
9535
9761
  * @name setCurrentId
9536
9762
  * @method
9537
- * @param {UID} uid - A UID identifying the currently drawn element(s).
9763
+ * @param {UID|null} uid - A UID identifying the currently drawn element(s).
9538
9764
  **/
9539
9765
  drawutils.prototype.setCurrentId = function (uid) {
9540
9766
  // NOOP
@@ -9545,7 +9771,7 @@ var drawutils = /** @class */ (function () {
9545
9771
  *
9546
9772
  * @name setCurrentClassName
9547
9773
  * @method
9548
- * @param {string} className - A class name for further custom use cases.
9774
+ * @param {string|null} className - A class name for further custom use cases.
9549
9775
  **/
9550
9776
  drawutils.prototype.setCurrentClassName = function (className) {
9551
9777
  // NOOP
@@ -9554,17 +9780,20 @@ var drawutils = /** @class */ (function () {
9554
9780
  * Draw the line between the given two points with the specified (CSS-) color.
9555
9781
  *
9556
9782
  * @method line
9557
- * @param {Vertex} zA - The start point of the line.
9558
- * @param {Vertex} zB - The end point of the line.
9783
+ * @param {XYCoords} zA - The start point of the line.
9784
+ * @param {XYCoords} zB - The end point of the line.
9559
9785
  * @param {string} color - Any valid CSS color string.
9560
9786
  * @param {number} lineWidth? - [optional] The line's width.
9787
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
9788
+ *
9561
9789
  * @return {void}
9562
9790
  * @instance
9563
9791
  * @memberof drawutils
9564
9792
  **/
9565
- drawutils.prototype.line = function (zA, zB, color, lineWidth) {
9793
+ drawutils.prototype.line = function (zA, zB, color, lineWidth, strokeOptions) {
9566
9794
  this.ctx.save();
9567
9795
  this.ctx.beginPath();
9796
+ this.applyStrokeOpts(strokeOptions);
9568
9797
  this.ctx.moveTo(this.offset.x + zA.x * this.scale.x, this.offset.y + zA.y * this.scale.y);
9569
9798
  this.ctx.lineTo(this.offset.x + zB.x * this.scale.x, this.offset.y + zB.y * this.scale.y);
9570
9799
  this.ctx.strokeStyle = color;
@@ -9576,22 +9805,76 @@ var drawutils = /** @class */ (function () {
9576
9805
  * Draw a line and an arrow at the end (zB) of the given line with the specified (CSS-) color.
9577
9806
  *
9578
9807
  * @method arrow
9579
- * @param {Vertex} zA - The start point of the arrow-line.
9580
- * @param {Vertex} zB - The end point of the arrow-line.
9808
+ * @param {XYCoords} zA - The start point of the arrow-line.
9809
+ * @param {XYCoords} zB - The end point of the arrow-line.
9581
9810
  * @param {string} color - Any valid CSS color string.
9582
9811
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
9812
+ * @param {headLength=8} headLength - (optional) The length of the arrow head (default is 8 units).
9813
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
9814
+ *
9583
9815
  * @return {void}
9584
9816
  * @instance
9585
9817
  * @memberof drawutils
9586
9818
  **/
9587
- drawutils.prototype.arrow = function (zA, zB, color, lineWidth) {
9588
- var headlen = 8; // length of head in pixels
9589
- // var vertices = PlotBoilerplate.utils.buildArrowHead( zA, zB, headlen, this.scale.x, this.scale.y );
9590
- // var vertices : Array<Vertex> = Vertex.utils.buildArrowHead( zA, zB, headlen, this.scale.x, this.scale.y );
9819
+ drawutils.prototype.arrow = function (zA, zB, color, lineWidth, headLength, strokeOptions) {
9820
+ if (headLength === void 0) { headLength = 8; }
9821
+ var arrowHeadBasePosition = new Vertex_1.Vertex(0, 0);
9822
+ this.arrowHead(zA, zB, color, lineWidth, headLength, undefined, arrowHeadBasePosition); // Will NOT use dash configuration
9823
+ this.line(zA, arrowHeadBasePosition, color, lineWidth, strokeOptions); // Will use dash configuration
9824
+ };
9825
+ /**
9826
+ * Draw a cubic Bézier curve and and an arrow at the end (endControlPoint) of the given line width the specified (CSS-) color and arrow size.
9827
+ *
9828
+ * @method cubicBezierArrow
9829
+ * @param {XYCoords} startPoint - The start point of the cubic Bézier curve
9830
+ * @param {XYCoords} endPoint - The end point the cubic Bézier curve.
9831
+ * @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
9832
+ * @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
9833
+ * @param {string} color - The CSS color to draw the curve with.
9834
+ * @param {number} lineWidth - (optional) The line width to use.
9835
+ * @param {headLength=8} headLength - (optional) The length of the arrow head (default is 8 units).
9836
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
9837
+ *
9838
+ * @return {void}
9839
+ * @instance
9840
+ * @memberof DrawLib
9841
+ */
9842
+ drawutils.prototype.cubicBezierArrow = function (startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, headLength, strokeOptions) {
9843
+ var arrowHeadBasePosition = new Vertex_1.Vertex(0, 0);
9844
+ // Will NOT use dash configuration
9845
+ this.arrowHead(endControlPoint, endPoint, color, lineWidth, headLength, undefined, arrowHeadBasePosition);
9846
+ var diff = arrowHeadBasePosition.difference(endPoint);
9847
+ // Will use dash configuration
9848
+ this.cubicBezier(startPoint, { x: endPoint.x - diff.x, y: endPoint.y - diff.y }, startControlPoint, { x: endControlPoint.x - diff.x, y: endControlPoint.y - diff.y }, color, lineWidth, strokeOptions);
9849
+ };
9850
+ /**
9851
+ * Draw just an arrow head a the end of an imaginary line (zB) of the given line width the specified (CSS-) color and size.
9852
+ *
9853
+ * @method arrow
9854
+ * @param {XYCoords} zA - The start point of the arrow-line.
9855
+ * @param {XYCoords} zB - The end point of the arrow-line.
9856
+ * @param {string} color - Any valid CSS color string.
9857
+ * @param {number=1} lineWidth - (optional) The line width to use; default is 1.
9858
+ * @param {number=8} headLength - (optional) The length of the arrow head (default is 8 pixels).
9859
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
9860
+ * @param {XYCoords=} arrowHeadBasePositionBuffer - (optional) If not null, then this position will contain the arrow head's start point (after execution). Some sort of OUT variable.
9861
+ *
9862
+ * @return {void}
9863
+ * @instance
9864
+ * @memberof DrawLib
9865
+ **/
9866
+ drawutils.prototype.arrowHead = function (zA, zB, color, lineWidth, headLength, strokeOptions, arrowHeadBasePositionBuffer) {
9867
+ // var headLength: number = 8; // length of head in pixels
9868
+ if (headLength === void 0) { headLength = 8; }
9591
9869
  this.ctx.save();
9592
9870
  this.ctx.beginPath();
9593
- var vertices = Vertex_1.Vertex.utils.buildArrowHead(zA, zB, headlen, this.scale.x, this.scale.y);
9594
- this.ctx.moveTo(this.offset.x + zA.x * this.scale.x, this.offset.y + zA.y * this.scale.y);
9871
+ this.applyStrokeOpts(strokeOptions);
9872
+ var vertices = Vector_1.Vector.utils.buildArrowHead(zA, zB, headLength, this.scale.x, this.scale.y);
9873
+ if (arrowHeadBasePositionBuffer) {
9874
+ arrowHeadBasePositionBuffer.x = vertices[0].x / this.scale.x;
9875
+ arrowHeadBasePositionBuffer.y = vertices[0].y / this.scale.y;
9876
+ }
9877
+ this.ctx.moveTo(this.offset.x + vertices[0].x, this.offset.y + vertices[0].y);
9595
9878
  for (var i = 0; i < vertices.length; i++) {
9596
9879
  this.ctx.lineTo(this.offset.x + vertices[i].x, this.offset.y + vertices[i].y);
9597
9880
  }
@@ -9607,8 +9890,8 @@ var drawutils = /** @class */ (function () {
9607
9890
  *
9608
9891
  * @method image
9609
9892
  * @param {Image} image - The image object to draw.
9610
- * @param {Vertex} position - The position to draw the the upper left corner at.
9611
- * @param {Vertex} size - The x/y-size to draw the image with.
9893
+ * @param {XYCoords} position - The position to draw the the upper left corner at.
9894
+ * @param {XYCoords} size - The x/y-size to draw the image with.
9612
9895
  * @param {number=0.0} alpha - (optional, default=0.0) The transparency (1.0=opaque, 0.0=transparent).
9613
9896
  * @return {void}
9614
9897
  * @instance
@@ -9638,7 +9921,7 @@ var drawutils = /** @class */ (function () {
9638
9921
  * @param {Image} textureImage - The image object to draw.
9639
9922
  * @param {Bounds} textureSize - The texture size to use; these are the original bounds to map the polygon vertices to.
9640
9923
  * @param {Polygon} polygon - The polygon to use as clip path.
9641
- * @param {Vertex} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
9924
+ * @param {XYCoords} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
9642
9925
  * @param {number} rotation - The rotation to use for the polygon (and for the texture).
9643
9926
  * @param {XYCoords={x:0,y:0}} rotationCenter - (optional) The rotational center; default is center of bounding box.
9644
9927
  * @return {void}
@@ -9647,10 +9930,9 @@ var drawutils = /** @class */ (function () {
9647
9930
  **/
9648
9931
  drawutils.prototype.texturedPoly = function (textureImage, textureSize, polygon, polygonPosition, rotation) {
9649
9932
  var basePolygonBounds = polygon.getBounds();
9650
- var targetCenterDifference = polygonPosition.clone().difference(basePolygonBounds.getCenter());
9651
- // var rotationalOffset = rotationCenter ? polygonPosition.difference(rotationCenter) : { x: 0, y: 0 };
9652
- // var rotationalOffset = { x: 0, y: 0 };
9653
- var tileCenter = basePolygonBounds.getCenter().sub(targetCenterDifference);
9933
+ // var targetCenterDifference = polygonPosition.clone().difference(basePolygonBounds.getCenter());
9934
+ var targetCenterDifference = new Vertex_1.Vertex(polygonPosition.x, polygonPosition.y).difference(basePolygonBounds.getCenter());
9935
+ // var tileCenter = basePolygonBounds.getCenter().sub(targetCenterDifference);
9654
9936
  // Get the position offset of the polygon
9655
9937
  var targetTextureSize = new Vertex_1.Vertex(textureSize.width, textureSize.height);
9656
9938
  // var targetTextureOffset = new Vertex(-textureSize.width / 2, -textureSize.height / 2).sub(targetCenterDifference);
@@ -9673,53 +9955,83 @@ var drawutils = /** @class */ (function () {
9673
9955
  );
9674
9956
  this.ctx.restore();
9675
9957
  };
9676
- drawutils.prototype._texturedPoly = function (textureImage, textureSize, polygon, polygonPosition, rotation, rotationCenter) {
9677
- if (rotationCenter === void 0) { rotationCenter = { x: 0, y: 0 }; }
9678
- var basePolygonBounds = polygon.getBounds();
9679
- var targetCenterDifference = polygonPosition.clone().difference(basePolygonBounds.getCenter());
9680
- var rotationalOffset = rotationCenter ? polygonPosition.difference(rotationCenter) : { x: 0, y: 0 };
9681
- // var rotationalOffset = { x: 0, y: 0 };
9682
- var tileCenter = basePolygonBounds.getCenter().sub(targetCenterDifference);
9683
- // Get the position offset of the polygon
9684
- var targetTextureSize = new Vertex_1.Vertex(textureSize.width, textureSize.height);
9685
- var targetTextureOffset = new Vertex_1.Vertex(-textureSize.width / 2, -textureSize.height / 2).sub(targetCenterDifference);
9686
- this.ctx.save();
9687
- // this.ctx.translate(
9688
- // this.offset.x + (tileCenter.x - rotationalOffset.x * 0 + targetTextureOffset.x * 0.0) * this.scale.x,
9689
- // this.offset.y + (tileCenter.y - rotationalOffset.y * 0 + targetTextureOffset.y * 0.0) * this.scale.y
9690
- // );
9691
- this.ctx.translate(this.offset.x + (tileCenter.x - rotationalOffset.x * 0 + targetTextureOffset.x * 0.0) * this.scale.x, this.offset.y + (tileCenter.y - rotationalOffset.y * 0 + targetTextureOffset.y * 0.0) * this.scale.y);
9692
- this.ctx.rotate(rotation);
9693
- drawutils.helpers.clipPoly(this.ctx, {
9694
- x: (-targetCenterDifference.x * 1 - tileCenter.x - rotationalOffset.x) * this.scale.x,
9695
- y: (-targetCenterDifference.y * 1 - tileCenter.y - rotationalOffset.y) * this.scale.y
9696
- }, this.scale, polygon.vertices);
9697
- this.ctx.drawImage(textureImage, 0, 0, textureImage.naturalWidth - 1, // There is this horrible Safari bug (fixed in newer versions)
9958
+ /*
9959
+ _texturedPoly(
9960
+ textureImage: HTMLImageElement,
9961
+ textureSize: Bounds,
9962
+ polygon: Polygon,
9963
+ polygonPosition: XYCoords,
9964
+ rotation: number,
9965
+ rotationCenter: XYCoords = { x: 0, y: 0 }
9966
+ ): void {
9967
+ var basePolygonBounds = polygon.getBounds();
9968
+ var targetCenterDifference = polygonPosition.clone().difference(basePolygonBounds.getCenter());
9969
+ var rotationalOffset = rotationCenter ? polygonPosition.difference(rotationCenter) : { x: 0, y: 0 };
9970
+ // var rotationalOffset = { x: 0, y: 0 };
9971
+ var tileCenter = basePolygonBounds.getCenter().sub(targetCenterDifference);
9972
+
9973
+ // Get the position offset of the polygon
9974
+ var targetTextureSize = new Vertex(textureSize.width, textureSize.height);
9975
+ var targetTextureOffset = new Vertex(-textureSize.width / 2, -textureSize.height / 2).sub(targetCenterDifference);
9976
+
9977
+ this.ctx.save();
9978
+
9979
+ // this.ctx.translate(
9980
+ // this.offset.x + (tileCenter.x - rotationalOffset.x * 0 + targetTextureOffset.x * 0.0) * this.scale.x,
9981
+ // this.offset.y + (tileCenter.y - rotationalOffset.y * 0 + targetTextureOffset.y * 0.0) * this.scale.y
9982
+ // );
9983
+ this.ctx.translate(
9984
+ this.offset.x + (tileCenter.x - rotationalOffset.x * 0 + targetTextureOffset.x * 0.0) * this.scale.x,
9985
+ this.offset.y + (tileCenter.y - rotationalOffset.y * 0 + targetTextureOffset.y * 0.0) * this.scale.y
9986
+ );
9987
+ this.ctx.rotate(rotation);
9988
+
9989
+ drawutils.helpers.clipPoly(
9990
+ this.ctx,
9991
+ {
9992
+ x: (-targetCenterDifference.x * 1 - tileCenter.x - rotationalOffset.x) * this.scale.x,
9993
+ y: (-targetCenterDifference.y * 1 - tileCenter.y - rotationalOffset.y) * this.scale.y
9994
+ },
9995
+ this.scale,
9996
+ polygon.vertices
9997
+ );
9998
+ this.ctx.drawImage(
9999
+ textureImage,
10000
+ 0,
10001
+ 0,
10002
+ textureImage.naturalWidth - 1, // There is this horrible Safari bug (fixed in newer versions)
9698
10003
  textureImage.naturalHeight - 1, // To avoid errors substract 1 here.
9699
- (-polygonPosition.x + targetTextureOffset.x * 1 - rotationalOffset.x * 1) * this.scale.x, (-polygonPosition.y + targetTextureOffset.y * 1 - rotationalOffset.y * 1) * this.scale.y, targetTextureSize.x * this.scale.x, targetTextureSize.y * this.scale.y);
9700
- // const scaledTextureSize = new Bounds(
9701
- // new Vertex(
9702
- // -polygonPosition.x + targetTextureOffset.x - rotationalOffset.x,
9703
- // -polygonPosition.y + targetTextureOffset.y - rotationalOffset.y
9704
- // ).scaleXY(this.scale, rotationCenter),
9705
- // new Vertex(
9706
- // -polygonPosition.x + targetTextureOffset.x - rotationalOffset.x + targetTextureSize.x,
9707
- // -polygonPosition.y + targetTextureOffset.y - rotationalOffset.y + targetTextureSize.y
9708
- // ).scaleXY(this.scale, rotationCenter)
9709
- // );
9710
- // this.ctx.drawImage(
9711
- // textureImage,
9712
- // 0,
9713
- // 0,
9714
- // textureImage.naturalWidth - 1, // There is this horrible Safari bug (fixed in newer versions)
9715
- // textureImage.naturalHeight - 1, // To avoid errors substract 1 here.
9716
- // scaledTextureSize.min.x,
9717
- // scaledTextureSize.min.y,
9718
- // scaledTextureSize.width,
9719
- // scaledTextureSize.height
9720
- // );
9721
- this.ctx.restore();
9722
- };
10004
+ (-polygonPosition.x + targetTextureOffset.x * 1 - rotationalOffset.x * 1) * this.scale.x,
10005
+ (-polygonPosition.y + targetTextureOffset.y * 1 - rotationalOffset.y * 1) * this.scale.y,
10006
+ targetTextureSize.x * this.scale.x,
10007
+ targetTextureSize.y * this.scale.y
10008
+ );
10009
+
10010
+ // const scaledTextureSize = new Bounds(
10011
+ // new Vertex(
10012
+ // -polygonPosition.x + targetTextureOffset.x - rotationalOffset.x,
10013
+ // -polygonPosition.y + targetTextureOffset.y - rotationalOffset.y
10014
+ // ).scaleXY(this.scale, rotationCenter),
10015
+ // new Vertex(
10016
+ // -polygonPosition.x + targetTextureOffset.x - rotationalOffset.x + targetTextureSize.x,
10017
+ // -polygonPosition.y + targetTextureOffset.y - rotationalOffset.y + targetTextureSize.y
10018
+ // ).scaleXY(this.scale, rotationCenter)
10019
+ // );
10020
+ // this.ctx.drawImage(
10021
+ // textureImage,
10022
+ // 0,
10023
+ // 0,
10024
+ // textureImage.naturalWidth - 1, // There is this horrible Safari bug (fixed in newer versions)
10025
+ // textureImage.naturalHeight - 1, // To avoid errors substract 1 here.
10026
+ // scaledTextureSize.min.x,
10027
+ // scaledTextureSize.min.y,
10028
+ // scaledTextureSize.width,
10029
+ // scaledTextureSize.height
10030
+ // );
10031
+
10032
+ this.ctx.restore();
10033
+ }
10034
+ */
9723
10035
  /**
9724
10036
  * Draw a rectangle.
9725
10037
  *
@@ -9728,10 +10040,16 @@ var drawutils = /** @class */ (function () {
9728
10040
  * @param {number} height - The height of the rectangle.
9729
10041
  * @param {string} color - The color to use.
9730
10042
  * @param {number=1} lineWidth - (optional) The line with to use (default is 1).
10043
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
10044
+ *
10045
+ * @return {void}
10046
+ * @instance
10047
+ * @memberof drawutils
9731
10048
  **/
9732
- drawutils.prototype.rect = function (position, width, height, color, lineWidth) {
10049
+ drawutils.prototype.rect = function (position, width, height, color, lineWidth, strokeOptions) {
9733
10050
  this.ctx.save();
9734
10051
  this.ctx.beginPath();
10052
+ this.applyStrokeOpts(strokeOptions);
9735
10053
  this.ctx.moveTo(this.offset.x + position.x * this.scale.x, this.offset.y + position.y * this.scale.y);
9736
10054
  this.ctx.lineTo(this.offset.x + (position.x + width) * this.scale.x, this.offset.y + position.y * this.scale.y);
9737
10055
  this.ctx.lineTo(this.offset.x + (position.x + width) * this.scale.x, this.offset.y + (position.y + height) * this.scale.y);
@@ -9742,43 +10060,23 @@ var drawutils = /** @class */ (function () {
9742
10060
  this._fillOrDraw(color);
9743
10061
  this.ctx.restore();
9744
10062
  };
9745
- // +---------------------------------------------------------------------------------
9746
- // | This is the final helper function for drawing and filling stuff. It is not
9747
- // | intended to be used from the outside.
9748
- // |
9749
- // | When in draw mode it draws the current shape.
9750
- // | When in fill mode it fills the current shape.
9751
- // |
9752
- // | This function is usually only called internally.
9753
- // |
9754
- // | @param color A stroke/fill color to use.
9755
- // +-------------------------------
9756
- // TODO: convert this to a STATIC function.
9757
- drawutils.prototype._fillOrDraw = function (color) {
9758
- if (this.fillShapes) {
9759
- this.ctx.fillStyle = color;
9760
- this.ctx.fill();
9761
- }
9762
- else {
9763
- this.ctx.strokeStyle = color;
9764
- this.ctx.stroke();
9765
- }
9766
- };
9767
10063
  /**
9768
10064
  * Draw the given (cubic) bézier curve.
9769
10065
  *
9770
10066
  * @method cubicBezier
9771
- * @param {Vertex} startPoint - The start point of the cubic Bézier curve
9772
- * @param {Vertex} endPoint - The end point the cubic Bézier curve.
9773
- * @param {Vertex} startControlPoint - The start control point the cubic Bézier curve.
9774
- * @param {Vertex} endControlPoint - The end control point the cubic Bézier curve.
10067
+ * @param {XYCoords} startPoint - The start point of the cubic Bézier curve
10068
+ * @param {XYCoords} endPoint - The end point the cubic Bézier curve.
10069
+ * @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
10070
+ * @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
9775
10071
  * @param {string} color - The CSS color to draw the curve with.
9776
10072
  * @param {number} lineWidth - (optional) The line width to use.
10073
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
10074
+ *
9777
10075
  * @return {void}
9778
10076
  * @instance
9779
10077
  * @memberof drawutils
9780
10078
  */
9781
- drawutils.prototype.cubicBezier = function (startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth) {
10079
+ drawutils.prototype.cubicBezier = function (startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, strokeOptions) {
9782
10080
  if (startPoint instanceof CubicBezierCurve_1.CubicBezierCurve) {
9783
10081
  this.cubicBezier(startPoint.startPoint, startPoint.endPoint, startPoint.startControlPoint, startPoint.endControlPoint, color, lineWidth);
9784
10082
  return;
@@ -9786,6 +10084,7 @@ var drawutils = /** @class */ (function () {
9786
10084
  // Draw curve
9787
10085
  this.ctx.save();
9788
10086
  this.ctx.beginPath();
10087
+ this.applyStrokeOpts(strokeOptions);
9789
10088
  this.ctx.moveTo(this.offset.x + startPoint.x * this.scale.x, this.offset.y + startPoint.y * this.scale.y);
9790
10089
  this.ctx.bezierCurveTo(this.offset.x + startControlPoint.x * this.scale.x, this.offset.y + startControlPoint.y * this.scale.y, this.offset.x + endControlPoint.x * this.scale.x, this.offset.y + endControlPoint.y * this.scale.y, this.offset.x + endPoint.x * this.scale.x, this.offset.y + endPoint.y * this.scale.y);
9791
10090
  //this.ctx.closePath();
@@ -9797,19 +10096,22 @@ var drawutils = /** @class */ (function () {
9797
10096
  * Draw the given (quadratic) bézier curve.
9798
10097
  *
9799
10098
  * @method quadraticBezier
9800
- * @param {Vertex} startPoint - The start point of the cubic Bézier curve
9801
- * @param {Vertex} controlPoint - The control point the cubic Bézier curve.
9802
- * @param {Vertex} endPoint - The end control point the cubic Bézier curve.
10099
+ * @param {XYCoords} startPoint - The start point of the cubic Bézier curve
10100
+ * @param {XYCoords} controlPoint - The control point the cubic Bézier curve.
10101
+ * @param {XYCoords} endPoint - The end control point the cubic Bézier curve.
9803
10102
  * @param {string} color - The CSS color to draw the curve with.
9804
10103
  * @param {number|string} lineWidth - (optional) The line width to use.
10104
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
10105
+ *
9805
10106
  * @return {void}
9806
10107
  * @instance
9807
10108
  * @memberof drawutils
9808
10109
  */
9809
- drawutils.prototype.quadraticBezier = function (startPoint, controlPoint, endPoint, color, lineWidth) {
10110
+ drawutils.prototype.quadraticBezier = function (startPoint, controlPoint, endPoint, color, lineWidth, strokeOptions) {
9810
10111
  // Draw curve
9811
10112
  this.ctx.save();
9812
10113
  this.ctx.beginPath();
10114
+ this.applyStrokeOpts(strokeOptions);
9813
10115
  this.ctx.moveTo(this.offset.x + startPoint.x * this.scale.x, this.offset.y + startPoint.y * this.scale.y);
9814
10116
  this.ctx.quadraticCurveTo(this.offset.x + controlPoint.x * this.scale.x, this.offset.y + controlPoint.y * this.scale.y, this.offset.x + endPoint.x * this.scale.x, this.offset.y + endPoint.y * this.scale.y);
9815
10117
  this.ctx.lineWidth = lineWidth || 2;
@@ -9824,22 +10126,26 @@ var drawutils = /** @class */ (function () {
9824
10126
  * <pre> [ point1, point1_startControl, point2_endControl, point2, point2_startControl, point3_endControl, point3, ... pointN_endControl, pointN ]</pre>
9825
10127
  *
9826
10128
  * @method cubicBezierPath
9827
- * @param {Vertex[]} path - The cubic bezier path as described above.
10129
+ * @param {XYCoords[]} path - The cubic bezier path as described above.
9828
10130
  * @param {string} color - The CSS colot to draw the path with.
9829
10131
  * @param {number=1} lineWidth - (optional) The line width to use.
10132
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
10133
+ *
9830
10134
  * @return {void}
9831
10135
  * @instance
9832
10136
  * @memberof drawutils
9833
10137
  */
9834
- drawutils.prototype.cubicBezierPath = function (path, color, lineWidth) {
9835
- if (!path || path.length == 0)
10138
+ drawutils.prototype.cubicBezierPath = function (path, color, lineWidth, strokeOptions) {
10139
+ if (!path || path.length == 0) {
9836
10140
  return;
10141
+ }
9837
10142
  // Draw curve
9838
10143
  this.ctx.save();
9839
10144
  this.ctx.beginPath();
9840
10145
  var endPoint;
9841
10146
  var startControlPoint;
9842
10147
  var endControlPoint;
10148
+ this.applyStrokeOpts(strokeOptions);
9843
10149
  this.ctx.moveTo(this.offset.x + path[0].x * this.scale.x, this.offset.y + path[0].y * this.scale.y);
9844
10150
  for (var i = 1; i < path.length; i += 3) {
9845
10151
  startControlPoint = path[i];
@@ -9858,8 +10164,8 @@ var drawutils = /** @class */ (function () {
9858
10164
  * The colors for this are fixed and cannot be specified.
9859
10165
  *
9860
10166
  * @method handle
9861
- * @param {Vertex} startPoint - The start of the handle.
9862
- * @param {Vertex} endPoint - The end point of the handle.
10167
+ * @param {XYCoords} startPoint - The start of the handle.
10168
+ * @param {XYCoords} endPoint - The end point of the handle.
9863
10169
  * @return {void}
9864
10170
  * @instance
9865
10171
  * @memberof drawutils
@@ -9874,21 +10180,21 @@ var drawutils = /** @class */ (function () {
9874
10180
  * Draw a handle line (with a light grey).
9875
10181
  *
9876
10182
  * @method handleLine
9877
- * @param {Vertex} startPoint - The start point to draw the handle at.
9878
- * @param {Vertex} endPoint - The end point to draw the handle at.
10183
+ * @param {XYCoords} startPoint - The start point to draw the handle at.
10184
+ * @param {XYCoords} endPoint - The end point to draw the handle at.
9879
10185
  * @return {void}
9880
10186
  * @instance
9881
10187
  * @memberof drawutils
9882
10188
  */
9883
10189
  drawutils.prototype.handleLine = function (startPoint, endPoint) {
9884
10190
  // Draw handle lines
9885
- this.line(startPoint, endPoint, "rgb(192,192,192)");
10191
+ this.line(startPoint, endPoint, "rgba(128,128,128, 0.5)", undefined);
9886
10192
  };
9887
10193
  /**
9888
10194
  * Draw a 1x1 dot with the specified (CSS-) color.
9889
10195
  *
9890
10196
  * @method dot
9891
- * @param {Vertex} p - The position to draw the dot at.
10197
+ * @param {XYCoords} p - The position to draw the dot at.
9892
10198
  * @param {string} color - The CSS color to draw the dot with.
9893
10199
  * @return {void}
9894
10200
  * @instance
@@ -9897,6 +10203,7 @@ var drawutils = /** @class */ (function () {
9897
10203
  drawutils.prototype.dot = function (p, color) {
9898
10204
  this.ctx.save();
9899
10205
  this.ctx.beginPath();
10206
+ this.ctx.setLineDash([]); // Clear line-dash settings
9900
10207
  this.ctx.moveTo(Math.round(this.offset.x + this.scale.x * p.x), Math.round(this.offset.y + this.scale.y * p.y));
9901
10208
  this.ctx.lineTo(Math.round(this.offset.x + this.scale.x * p.x + 1), Math.round(this.offset.y + this.scale.y * p.y + 1));
9902
10209
  this.ctx.closePath();
@@ -9908,7 +10215,7 @@ var drawutils = /** @class */ (function () {
9908
10215
  * Draw the given point with the specified (CSS-) color and radius 3.
9909
10216
  *
9910
10217
  * @method point
9911
- * @param {Vertex} p - The position to draw the point at.
10218
+ * @param {XYCoords} p - The position to draw the point at.
9912
10219
  * @param {string} color - The CSS color to draw the point with.
9913
10220
  * @return {void}
9914
10221
  * @instance
@@ -9916,6 +10223,7 @@ var drawutils = /** @class */ (function () {
9916
10223
  */
9917
10224
  drawutils.prototype.point = function (p, color) {
9918
10225
  var radius = 3;
10226
+ this.ctx.setLineDash([]); // Clear line-dash settings
9919
10227
  this.ctx.beginPath();
9920
10228
  this.ctx.arc(this.offset.x + p.x * this.scale.x, this.offset.y + p.y * this.scale.y, radius, 0, 2 * Math.PI, false);
9921
10229
  this.ctx.closePath();
@@ -9928,15 +10236,18 @@ var drawutils = /** @class */ (function () {
9928
10236
  * Note that if the x- and y- scales are different the result will be an ellipse rather than a circle.
9929
10237
  *
9930
10238
  * @method circle
9931
- * @param {Vertex} center - The center of the circle.
10239
+ * @param {XYCoords} center - The center of the circle.
9932
10240
  * @param {number} radius - The radius of the circle.
9933
10241
  * @param {string} color - The CSS color to draw the circle with.
9934
10242
  * @param {number} lineWidth - The line width (optional, default=1).
10243
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
10244
+ *
9935
10245
  * @return {void}
9936
10246
  * @instance
9937
10247
  * @memberof drawutils
9938
10248
  */
9939
- drawutils.prototype.circle = function (center, radius, color, lineWidth) {
10249
+ drawutils.prototype.circle = function (center, radius, color, lineWidth, strokeOptions) {
10250
+ this.applyStrokeOpts(strokeOptions);
9940
10251
  this.ctx.beginPath();
9941
10252
  this.ctx.ellipse(this.offset.x + center.x * this.scale.x, this.offset.y + center.y * this.scale.y, radius * this.scale.x, radius * this.scale.y, 0.0, 0.0, Math.PI * 2);
9942
10253
  this.ctx.closePath();
@@ -9944,24 +10255,28 @@ var drawutils = /** @class */ (function () {
9944
10255
  this._fillOrDraw(color);
9945
10256
  };
9946
10257
  /**
9947
- * Draw a circular arc (section of a circle) with the given CSS color.
9948
- *
9949
- * @method circleArc
9950
- * @param {Vertex} center - The center of the circle.
9951
- * @param {number} radius - The radius of the circle.
9952
- * @param {number} startAngle - The angle to start at.
9953
- * @param {number} endAngle - The angle to end at.
9954
- * @param {string=#000000} color - The CSS color to draw the circle with.
9955
- * @param {number=1} lineWidth - The line width to use
9956
- // * @param {boolean=false} options.asSegment - If `true` then no beginPath and no draw will be applied (as part of larger path).
9957
- * @return {void}
9958
- * @instance
9959
- * @memberof drawutils
9960
- */
10258
+ * Draw a circular arc (section of a circle) with the given CSS color.
10259
+ *
10260
+ * @method circleArc
10261
+ * @param {XYCoords} center - The center of the circle.
10262
+ * @param {number} radius - The radius of the circle.
10263
+ * @param {number} startAngle - The angle to start at.
10264
+ * @param {number} endAngle - The angle to end at.
10265
+ * @param {string=#000000} color - The CSS color to draw the circle with.
10266
+ * @param {number=1} lineWidth - The line width to use
10267
+ * @param {boolean=false} options.asSegment - If `true` then no beginPath and no draw will be applied (as part of larger path).
10268
+ * @param {number=} options.dashOffset - (optional) `See StrokeOptions`.
10269
+ * @param {number=[]} options.dashArray - (optional) `See StrokeOptions`.
10270
+ *
10271
+ * @return {void}
10272
+ * @instance
10273
+ * @memberof drawutils
10274
+ */
9961
10275
  drawutils.prototype.circleArc = function (center, radius, startAngle, endAngle, color, lineWidth, options) {
9962
10276
  if (!options || !options.asSegment) {
9963
10277
  this.ctx.beginPath();
9964
10278
  }
10279
+ this.applyStrokeOpts(options);
9965
10280
  this.ctx.ellipse(this.offset.x + center.x * this.scale.x, this.offset.y + center.y * this.scale.y, radius * this.scale.x, radius * this.scale.y, 0.0, startAngle, endAngle, false);
9966
10281
  if (!options || !options.asSegment) {
9967
10282
  // this.ctx.closePath();
@@ -9973,20 +10288,23 @@ var drawutils = /** @class */ (function () {
9973
10288
  * Draw an ellipse with the specified (CSS-) color and thw two radii.
9974
10289
  *
9975
10290
  * @method ellipse
9976
- * @param {Vertex} center - The center of the ellipse.
10291
+ * @param {XYCoords} center - The center of the ellipse.
9977
10292
  * @param {number} radiusX - The radius of the ellipse.
9978
10293
  * @param {number} radiusY - The radius of the ellipse.
9979
10294
  * @param {string} color - The CSS color to draw the ellipse with.
9980
10295
  * @param {number} lineWidth=1 - An optional line width param (default is 1).
9981
10296
  * @param {number=} rotation - (optional, default=0) The rotation of the ellipse.
10297
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
10298
+ *
9982
10299
  * @return {void}
9983
10300
  * @instance
9984
10301
  * @memberof drawutils
9985
10302
  */
9986
- drawutils.prototype.ellipse = function (center, radiusX, radiusY, color, lineWidth, rotation) {
10303
+ drawutils.prototype.ellipse = function (center, radiusX, radiusY, color, lineWidth, rotation, strokeOptions) {
9987
10304
  if (typeof rotation === "undefined") {
9988
10305
  rotation = 0.0;
9989
10306
  }
10307
+ this.applyStrokeOpts(strokeOptions);
9990
10308
  this.ctx.beginPath();
9991
10309
  this.ctx.ellipse(this.offset.x + center.x * this.scale.x, this.offset.y + center.y * this.scale.y, radiusX * this.scale.x, radiusY * this.scale.y, rotation, 0.0, Math.PI * 2);
9992
10310
  this.ctx.closePath();
@@ -10003,11 +10321,14 @@ var drawutils = /** @class */ (function () {
10003
10321
  * @param {number} size - The size of the square.
10004
10322
  * @param {string} color - The CSS color to draw the square with.
10005
10323
  * @param {number} lineWidth - The line with to use (optional, default is 1).
10324
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
10325
+ *
10006
10326
  * @return {void}
10007
10327
  * @instance
10008
10328
  * @memberof drawutils
10009
10329
  */
10010
- drawutils.prototype.square = function (center, size, color, lineWidth) {
10330
+ drawutils.prototype.square = function (center, size, color, lineWidth, strokeOptions) {
10331
+ this.applyStrokeOpts(strokeOptions);
10011
10332
  this.ctx.beginPath();
10012
10333
  this.ctx.rect(this.offset.x + (center.x - size / 2.0) * this.scale.x, this.offset.y + (center.y - size / 2.0) * this.scale.y, size * this.scale.x, size * this.scale.y);
10013
10334
  this.ctx.closePath();
@@ -10018,7 +10339,7 @@ var drawutils = /** @class */ (function () {
10018
10339
  * Draw a grid of horizontal and vertical lines with the given (CSS-) color.
10019
10340
  *
10020
10341
  * @method grid
10021
- * @param {Vertex} center - The center of the grid.
10342
+ * @param {XYCoords} center - The center of the grid.
10022
10343
  * @param {number} width - The total width of the grid (width/2 each to the left and to the right).
10023
10344
  * @param {number} height - The total height of the grid (height/2 each to the top and to the bottom).
10024
10345
  * @param {number} sizeX - The horizontal grid size.
@@ -10029,6 +10350,7 @@ var drawutils = /** @class */ (function () {
10029
10350
  * @memberof drawutils
10030
10351
  */
10031
10352
  drawutils.prototype.grid = function (center, width, height, sizeX, sizeY, color) {
10353
+ this.ctx.setLineDash([]); // Clear line-dash settings
10032
10354
  this.ctx.beginPath();
10033
10355
  var yMin = -Math.ceil((height * 0.5) / sizeY) * sizeY;
10034
10356
  var yMax = height / 2;
@@ -10053,7 +10375,7 @@ var drawutils = /** @class */ (function () {
10053
10375
  * This works analogue to the grid() function
10054
10376
  *
10055
10377
  * @method raster
10056
- * @param {Vertex} center - The center of the raster.
10378
+ * @param {XYCoords} center - The center of the raster.
10057
10379
  * @param {number} width - The total width of the raster (width/2 each to the left and to the right).
10058
10380
  * @param {number} height - The total height of the raster (height/2 each to the top and to the bottom).
10059
10381
  * @param {number} sizeX - The horizontal raster size.
@@ -10065,6 +10387,7 @@ var drawutils = /** @class */ (function () {
10065
10387
  */
10066
10388
  drawutils.prototype.raster = function (center, width, height, sizeX, sizeY, color) {
10067
10389
  this.ctx.save();
10390
+ this.ctx.setLineDash([]); // Clear line-dash settings
10068
10391
  this.ctx.beginPath();
10069
10392
  for (var x = -Math.ceil((width * 0.5) / sizeX) * sizeX; x < width / 2; x += sizeX) {
10070
10393
  for (var y = -Math.ceil((height * 0.5) / sizeY) * sizeY; y < height / 2; y += sizeY) {
@@ -10089,14 +10412,15 @@ var drawutils = /** @class */ (function () {
10089
10412
  * as even shaped diamonds.
10090
10413
  *
10091
10414
  * @method diamondHandle
10092
- * @param {Vertex} center - The center of the diamond.
10093
- * @param {Vertex} size - The x/y-size of the diamond.
10415
+ * @param {XYCoords} center - The center of the diamond.
10416
+ * @param {number} size - The x/y-size of the diamond.
10094
10417
  * @param {string} color - The CSS color to draw the diamond with.
10095
10418
  * @return {void}
10096
10419
  * @instance
10097
10420
  * @memberof drawutils
10098
10421
  */
10099
10422
  drawutils.prototype.diamondHandle = function (center, size, color) {
10423
+ this.ctx.setLineDash([]); // Clear line-dash settings
10100
10424
  this.ctx.beginPath();
10101
10425
  this.ctx.moveTo(this.offset.x + center.x * this.scale.x - size / 2.0, this.offset.y + center.y * this.scale.y);
10102
10426
  this.ctx.lineTo(this.offset.x + center.x * this.scale.x, this.offset.y + center.y * this.scale.y - size / 2.0);
@@ -10114,14 +10438,15 @@ var drawutils = /** @class */ (function () {
10114
10438
  * as even shaped squares.
10115
10439
  *
10116
10440
  * @method squareHandle
10117
- * @param {Vertex} center - The center of the square.
10118
- * @param {Vertex} size - The x/y-size of the square.
10441
+ * @param {XYCoords} center - The center of the square.
10442
+ * @param {number} size - The x/y-size of the square.
10119
10443
  * @param {string} color - The CSS color to draw the square with.
10120
10444
  * @return {void}
10121
10445
  * @instance
10122
10446
  * @memberof drawutils
10123
10447
  */
10124
10448
  drawutils.prototype.squareHandle = function (center, size, color) {
10449
+ this.ctx.setLineDash([]); // Clear line-dash settings
10125
10450
  this.ctx.beginPath();
10126
10451
  this.ctx.rect(this.offset.x + center.x * this.scale.x - size / 2.0, this.offset.y + center.y * this.scale.y - size / 2.0, size, size);
10127
10452
  this.ctx.closePath();
@@ -10136,7 +10461,7 @@ var drawutils = /** @class */ (function () {
10136
10461
  * as even shaped circles.
10137
10462
  *
10138
10463
  * @method circleHandle
10139
- * @param {Vertex} center - The center of the circle.
10464
+ * @param {XYCoords} center - The center of the circle.
10140
10465
  * @param {number} radius - The radius of the circle.
10141
10466
  * @param {string} color - The CSS color to draw the circle with.
10142
10467
  * @return {void}
@@ -10145,6 +10470,7 @@ var drawutils = /** @class */ (function () {
10145
10470
  */
10146
10471
  drawutils.prototype.circleHandle = function (center, radius, color) {
10147
10472
  radius = radius || 3;
10473
+ this.ctx.setLineDash([]); // Clear line-dash settings
10148
10474
  this.ctx.beginPath();
10149
10475
  this.ctx.arc(this.offset.x + center.x * this.scale.x, this.offset.y + center.y * this.scale.y, radius, 0, 2 * Math.PI, false);
10150
10476
  this.ctx.closePath();
@@ -10167,6 +10493,7 @@ var drawutils = /** @class */ (function () {
10167
10493
  */
10168
10494
  drawutils.prototype.crosshair = function (center, radius, color, lineWidth) {
10169
10495
  this.ctx.save();
10496
+ this.ctx.setLineDash([]); // Clear line-dash settings
10170
10497
  this.ctx.beginPath();
10171
10498
  this.ctx.moveTo(this.offset.x + center.x * this.scale.x - radius, this.offset.y + center.y * this.scale.y);
10172
10499
  this.ctx.lineTo(this.offset.x + center.x * this.scale.x + radius, this.offset.y + center.y * this.scale.y);
@@ -10194,6 +10521,7 @@ var drawutils = /** @class */ (function () {
10194
10521
  */
10195
10522
  drawutils.prototype.cross = function (center, radius, color, lineWidth) {
10196
10523
  this.ctx.save();
10524
+ this.ctx.setLineDash([]); // Clear line-dash settings
10197
10525
  this.ctx.beginPath();
10198
10526
  this.ctx.moveTo(this.offset.x + center.x * this.scale.x - radius, this.offset.y + center.y * this.scale.y - radius);
10199
10527
  this.ctx.lineTo(this.offset.x + center.x * this.scale.x + radius, this.offset.y + center.y * this.scale.y + radius);
@@ -10212,30 +10540,35 @@ var drawutils = /** @class */ (function () {
10212
10540
  * @param {Polygon} polygon - The polygon to draw.
10213
10541
  * @param {string} color - The CSS color to draw the polygon with.
10214
10542
  * @param {string} lineWidth - The line width to use.
10543
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
10544
+ *
10215
10545
  * @return {void}
10216
10546
  * @instance
10217
10547
  * @memberof drawutils
10218
10548
  */
10219
- drawutils.prototype.polygon = function (polygon, color, lineWidth) {
10220
- this.polyline(polygon.vertices, polygon.isOpen, color, lineWidth);
10549
+ drawutils.prototype.polygon = function (polygon, color, lineWidth, strokeOptions) {
10550
+ this.polyline(polygon.vertices, polygon.isOpen, color, lineWidth, strokeOptions);
10221
10551
  };
10222
10552
  /**
10223
10553
  * Draw a polygon line (alternative function to the polygon).
10224
10554
  *
10225
10555
  * @method polyline
10226
- * @param {Vertex[]} vertices - The polygon vertices to draw.
10556
+ * @param {XYCoords[]} vertices - The polygon vertices to draw.
10227
10557
  * @param {boolan} isOpen - If true the polyline will not be closed at its end.
10228
10558
  * @param {string} color - The CSS color to draw the polygon with.
10229
10559
  * @param {number} lineWidth - The line width (default is 1.0);
10560
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
10561
+ *
10230
10562
  * @return {void}
10231
10563
  * @instance
10232
10564
  * @memberof drawutils
10233
10565
  */
10234
- drawutils.prototype.polyline = function (vertices, isOpen, color, lineWidth) {
10566
+ drawutils.prototype.polyline = function (vertices, isOpen, color, lineWidth, strokeOptions) {
10235
10567
  if (vertices.length <= 1) {
10236
10568
  return;
10237
10569
  }
10238
10570
  this.ctx.save();
10571
+ this.applyStrokeOpts(strokeOptions);
10239
10572
  this.ctx.beginPath();
10240
10573
  this.ctx.lineWidth = (lineWidth || 1.0) * this.scale.x;
10241
10574
  this.ctx.moveTo(this.offset.x + vertices[0].x * this.scale.x, this.offset.y + vertices[0].y * this.scale.y);
@@ -10347,6 +10680,8 @@ var drawutils = /** @class */ (function () {
10347
10680
  * @param {string=null} color - (optional) The color to draw this path with (default is null).
10348
10681
  * @param {number=1} lineWidth - (optional) the line width to use (default is 1).
10349
10682
  * @param {boolean=false} options.inplace - (optional) If set to true then path transforamtions (scale and translate) will be done in-place in the array. This can boost the performance.
10683
+ * @param {number=} options.dashOffset - (optional) `See StrokeOptions`.
10684
+ * @param {number=[]} options.dashArray - (optional) `See StrokeOptions`.
10350
10685
  * @instance
10351
10686
  * @memberof drawutils
10352
10687
  * @return {R} An instance representing the drawn path.
@@ -10358,6 +10693,7 @@ var drawutils = /** @class */ (function () {
10358
10693
  this.ctx.strokeStyle = color;
10359
10694
  }
10360
10695
  this.ctx.lineWidth = lineWidth || 1;
10696
+ this.applyStrokeOpts(options);
10361
10697
  if (this.fillShapes) {
10362
10698
  if (color) {
10363
10699
  this.ctx.fillStyle = color;
@@ -10422,7 +10758,13 @@ exports.drawutils = drawutils;
10422
10758
  * @modified 2022-02-03 Added the `cross(...)` function.
10423
10759
  * @modified 2022-03-27 Added the `texturedPoly` function.
10424
10760
  * @modified 2022-07-26 Adding `alpha` to the `image(...)` function.
10425
- * @version 0.0.8
10761
+ * @modified 2023-02-10 The methods `setCurrentClassName` and `setCurrentId` also accept `null` now.
10762
+ * @modified 2023-09-29 Downgrading all `Vertex` param type to the more generic `XYCoords` type in these render functions: line, arrow, texturedPoly, cubicBezier, cubicBezierPath, handle, handleLine, dot, point, circle, circleArc, ellipse, grid, raster.
10763
+ * @modified 2023-09-29 Added the `headLength` parameter to the 'DrawLib.arrow()` function.
10764
+ * @modified 2023-09-29 Added the `arrowHead(...)` function to the 'DrawLib.arrow()` interface.
10765
+ * @modified 2023-09-29 Added the `cubicBezierArrow(...)` function to the 'DrawLib.arrow()` interface.
10766
+ * @modified 2023-09-29 Added the `lineDashes` attribute.
10767
+ * @version 0.0.10
10426
10768
  **/
10427
10769
  Object.defineProperty(exports, "__esModule", ({ value: true }));
10428
10770
  exports.drawutilsgl = void 0;
@@ -10443,7 +10785,7 @@ var drawutilsgl = /** @class */ (function () {
10443
10785
  *
10444
10786
  * @constructor
10445
10787
  * @name drawutils
10446
- * @param {WebGLRenderingContext} context - The drawing context.
10788
+ * @param {WebGLRenderingContext|null} context - The drawing context.
10447
10789
  * @param {boolean} fillShaped - Indicates if the constructed drawutils should fill all drawn shapes (if possible).
10448
10790
  **/
10449
10791
  function drawutilsgl(context, fillShapes) {
@@ -10519,13 +10861,27 @@ var drawutilsgl = /** @class */ (function () {
10519
10861
  drawutilsgl.prototype.setConfiguration = function (configuration) {
10520
10862
  // TODO
10521
10863
  };
10864
+ // /**
10865
+ // * Set or clear the line-dash configuration. Pass `null` for un-dashed lines.
10866
+ // *
10867
+ // * See https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray
10868
+ // * and https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash
10869
+ // * for how line dashes work.
10870
+ // *
10871
+ // * @method
10872
+ // * @param {Array<number> lineDashes - The line-dash array configuration.
10873
+ // * @returns {void}
10874
+ // */
10875
+ // setLineDash(lineDashes: Array<number>) {
10876
+ // // TODO
10877
+ // }
10522
10878
  /**
10523
10879
  * This method shouled be called each time the currently drawn `Drawable` changes.
10524
10880
  * It is used by some libraries for identifying elemente on re-renders.
10525
10881
  *
10526
10882
  * @name setCurrentId
10527
10883
  * @method
10528
- * @param {UID} uid - A UID identifying the currently drawn element(s).es.
10884
+ * @param {UID|null} uid - A UID identifying the currently drawn element(s).es.
10529
10885
  **/
10530
10886
  drawutilsgl.prototype.setCurrentId = function (uid) {
10531
10887
  // NOOP
@@ -10537,7 +10893,7 @@ var drawutilsgl = /** @class */ (function () {
10537
10893
  *
10538
10894
  * @name setCurrentClassName
10539
10895
  * @method
10540
- * @param {string} className - A class name for further custom use cases.
10896
+ * @param {string|null} className - A class name for further custom use cases.
10541
10897
  **/
10542
10898
  drawutilsgl.prototype.setCurrentClassName = function (className) {
10543
10899
  // NOOP
@@ -10546,8 +10902,8 @@ var drawutilsgl = /** @class */ (function () {
10546
10902
  * Draw the line between the given two points with the specified (CSS-) color.
10547
10903
  *
10548
10904
  * @method line
10549
- * @param {Vertex} zA - The start point of the line.
10550
- * @param {Vertex} zB - The end point of the line.
10905
+ * @param {XYCoords} zA - The start point of the line.
10906
+ * @param {XYCoords} zB - The end point of the line.
10551
10907
  * @param {string} color - Any valid CSS color string.
10552
10908
  * @return {void}
10553
10909
  * @instance
@@ -10596,9 +10952,10 @@ var drawutilsgl = /** @class */ (function () {
10596
10952
  * Draw a line and an arrow at the end (zB) of the given line with the specified (CSS-) color.
10597
10953
  *
10598
10954
  * @method arrow
10599
- * @param {Vertex} zA - The start point of the arrow-line.
10600
- * @param {Vertex} zB - The end point of the arrow-line.
10955
+ * @param {XYCoords} zA - The start point of the arrow-line.
10956
+ * @param {XYCoords} zB - The end point of the arrow-line.
10601
10957
  * @param {string} color - Any valid CSS color string.
10958
+ * @param {headLength=8} headLength - (optional) The length of the arrow head (default is 8 units).
10602
10959
  * @return {void}
10603
10960
  * @instance
10604
10961
  * @memberof drawutils
@@ -10606,6 +10963,41 @@ var drawutilsgl = /** @class */ (function () {
10606
10963
  drawutilsgl.prototype.arrow = function (zA, zB, color) {
10607
10964
  // NOT YET IMPLEMENTED
10608
10965
  };
10966
+ /**
10967
+ * Draw a cubic Bézier curve and and an arrow at the end (endControlPoint) of the given line width the specified (CSS-) color and arrow size.
10968
+ *
10969
+ * @method cubicBezierArrow
10970
+ * @param {XYCoords} startPoint - The start point of the cubic Bézier curve
10971
+ * @param {XYCoords} endPoint - The end point the cubic Bézier curve.
10972
+ * @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
10973
+ * @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
10974
+ * @param {string} color - The CSS color to draw the curve with.
10975
+ * @param {number} lineWidth - (optional) The line width to use.
10976
+ * @param {headLength=8} headLength - (optional) The length of the arrow head (default is 8 units).
10977
+ *
10978
+ * @return {void}
10979
+ * @instance
10980
+ * @memberof DrawLib
10981
+ */
10982
+ drawutilsgl.prototype.cubicBezierArrow = function (startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, headLength) {
10983
+ // NOT YET IMPLEMENTED
10984
+ };
10985
+ /**
10986
+ * Draw just an arrow head a the end of an imaginary line (zB) of the given line width the specified (CSS-) color and size.
10987
+ *
10988
+ * @method arrow
10989
+ * @param {XYCoords} zA - The start point of the arrow-line.
10990
+ * @param {XYCoords} zB - The end point of the arrow-line.
10991
+ * @param {string} color - Any valid CSS color string.
10992
+ * @param {number=1} lineWidth - (optional) The line width to use; default is 1.
10993
+ * @param {number=8} headLength - (optional) The length of the arrow head (default is 8 pixels).
10994
+ * @return {void}
10995
+ * @instance
10996
+ * @memberof DrawLib
10997
+ **/
10998
+ drawutilsgl.prototype.arrowHead = function (zA, zB, color, lineWidth, headLength) {
10999
+ // NOT YET IMPLEMENTED
11000
+ };
10609
11001
  /**
10610
11002
  * Draw an image at the given position with the given size.<br>
10611
11003
  * <br>
@@ -10613,8 +11005,8 @@ var drawutilsgl = /** @class */ (function () {
10613
11005
  *
10614
11006
  * @method image
10615
11007
  * @param {Image} image - The image object to draw.
10616
- * @param {Vertex} position - The position to draw the the upper left corner at.
10617
- * @param {Vertex} size - The x/y-size to draw the image with.
11008
+ * @param {XYCoords} position - The position to draw the the upper left corner at.
11009
+ * @param {XYCoords} size - The x/y-size to draw the image with.
10618
11010
  * @param {number=0.0} alpha - (optional, default=0.0) The transparency (0.0=opaque, 1.0=transparent).
10619
11011
  * @return {void}
10620
11012
  * @instance
@@ -10633,7 +11025,7 @@ var drawutilsgl = /** @class */ (function () {
10633
11025
  * @param {Image} textureImage - The image object to draw.
10634
11026
  * @param {Bounds} textureSize - The texture size to use; these are the original bounds to map the polygon vertices to.
10635
11027
  * @param {Polygon} polygon - The polygon to use as clip path.
10636
- * @param {Vertex} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
11028
+ * @param {XYCoords} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
10637
11029
  * @param {number} rotation - The rotation to use for the polygon (and for the texture).
10638
11030
  * @return {void}
10639
11031
  * @instance
@@ -10660,10 +11052,10 @@ var drawutilsgl = /** @class */ (function () {
10660
11052
  * Draw the given (cubic) bézier curve.
10661
11053
  *
10662
11054
  * @method cubicBezier
10663
- * @param {Vertex} startPoint - The start point of the cubic Bézier curve
10664
- * @param {Vertex} endPoint - The end point the cubic Bézier curve.
10665
- * @param {Vertex} startControlPoint - The start control point the cubic Bézier curve.
10666
- * @param {Vertex} endControlPoint - The end control point the cubic Bézier curve.
11055
+ * @param {XYCoords} startPoint - The start point of the cubic Bézier curve
11056
+ * @param {XYCoords} endPoint - The end point the cubic Bézier curve.
11057
+ * @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
11058
+ * @param {VertXYCoordsex} endControlPoint - The end control point the cubic Bézier curve.
10667
11059
  * @param {string} color - The CSS color to draw the curve with.
10668
11060
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
10669
11061
  * @return {void}
@@ -10681,7 +11073,7 @@ var drawutilsgl = /** @class */ (function () {
10681
11073
  * <pre> [ point1, point1_startControl, point2_endControl, point2, point2_startControl, point3_endControl, point3, ... pointN_endControl, pointN ]</pre>
10682
11074
  *
10683
11075
  * @method cubicBezierPath
10684
- * @param {Vertex[]} path - The cubic bezier path as described above.
11076
+ * @param {XYCoords[]} path - The cubic bezier path as described above.
10685
11077
  * @param {string} color - The CSS colot to draw the path with.
10686
11078
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
10687
11079
  * @return {void}
@@ -10697,8 +11089,8 @@ var drawutilsgl = /** @class */ (function () {
10697
11089
  * The colors for this are fixed and cannot be specified.
10698
11090
  *
10699
11091
  * @method handle
10700
- * @param {Vertex} startPoint - The start of the handle.
10701
- * @param {Vertex} endPoint - The end point of the handle.
11092
+ * @param {XYCoords} startPoint - The start of the handle.
11093
+ * @param {XYCoords} endPoint - The end point of the handle.
10702
11094
  * @return {void}
10703
11095
  * @instance
10704
11096
  * @memberof drawutils
@@ -10710,8 +11102,8 @@ var drawutilsgl = /** @class */ (function () {
10710
11102
  * Draw a handle line (with a light grey).
10711
11103
  *
10712
11104
  * @method handleLine
10713
- * @param {Vertex} startPoint - The start point to draw the handle at.
10714
- * @param {Vertex} endPoint - The end point to draw the handle at.
11105
+ * @param {XYCoords} startPoint - The start point to draw the handle at.
11106
+ * @param {XYCoords} endPoint - The end point to draw the handle at.
10715
11107
  * @return {void}
10716
11108
  * @instance
10717
11109
  * @memberof drawutils
@@ -10723,7 +11115,7 @@ var drawutilsgl = /** @class */ (function () {
10723
11115
  * Draw a 1x1 dot with the specified (CSS-) color.
10724
11116
  *
10725
11117
  * @method dot
10726
- * @param {Vertex} p - The position to draw the dot at.
11118
+ * @param {XYCoords} p - The position to draw the dot at.
10727
11119
  * @param {string} color - The CSS color to draw the dot with.
10728
11120
  * @return {void}
10729
11121
  * @instance
@@ -10736,7 +11128,7 @@ var drawutilsgl = /** @class */ (function () {
10736
11128
  * Draw the given point with the specified (CSS-) color and radius 3.
10737
11129
  *
10738
11130
  * @method point
10739
- * @param {Vertex} p - The position to draw the point at.
11131
+ * @param {XYCoords} p - The position to draw the point at.
10740
11132
  * @param {string} color - The CSS color to draw the point with.
10741
11133
  * @return {void}
10742
11134
  * @instance
@@ -10751,7 +11143,7 @@ var drawutilsgl = /** @class */ (function () {
10751
11143
  * Note that if the x- and y- scales are different the result will be an ellipse rather than a circle.
10752
11144
  *
10753
11145
  * @method circle
10754
- * @param {Vertex} center - The center of the circle.
11146
+ * @param {XYCoords} center - The center of the circle.
10755
11147
  * @param {number} radius - The radius of the circle.
10756
11148
  * @param {string} color - The CSS color to draw the circle with.
10757
11149
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
@@ -10766,7 +11158,7 @@ var drawutilsgl = /** @class */ (function () {
10766
11158
  * Draw a circular arc (section of a circle) with the given CSS color.
10767
11159
  *
10768
11160
  * @method circleArc
10769
- * @param {Vertex} center - The center of the circle.
11161
+ * @param {XYCoords} center - The center of the circle.
10770
11162
  * @param {number} radius - The radius of the circle.
10771
11163
  * @param {number} startAngle - The angle to start at.
10772
11164
  * @param {number} endAngle - The angle to end at.
@@ -10782,7 +11174,7 @@ var drawutilsgl = /** @class */ (function () {
10782
11174
  * Draw an ellipse with the specified (CSS-) color and thw two radii.
10783
11175
  *
10784
11176
  * @method ellipse
10785
- * @param {Vertex} center - The center of the ellipse.
11177
+ * @param {XYCoords} center - The center of the ellipse.
10786
11178
  * @param {number} radiusX - The radius of the ellipse.
10787
11179
  * @param {number} radiusY - The radius of the ellipse.
10788
11180
  * @param {string} color - The CSS color to draw the ellipse with.
@@ -10802,7 +11194,7 @@ var drawutilsgl = /** @class */ (function () {
10802
11194
  *
10803
11195
  * @method square
10804
11196
  * @param {XYCords} center - The center of the square.
10805
- * @param {Vertex} size - The size of the square.
11197
+ * @param {number} size - The size of the square.
10806
11198
  * @param {string} color - The CSS color to draw the square with.
10807
11199
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
10808
11200
  * @return {void}
@@ -10828,7 +11220,7 @@ var drawutilsgl = /** @class */ (function () {
10828
11220
  * Draw a grid of horizontal and vertical lines with the given (CSS-) color.
10829
11221
  *
10830
11222
  * @method grid
10831
- * @param {Vertex} center - The center of the grid.
11223
+ * @param {XYCoords} center - The center of the grid.
10832
11224
  * @param {number} width - The total width of the grid (width/2 each to the left and to the right).
10833
11225
  * @param {number} height - The total height of the grid (height/2 each to the top and to the bottom).
10834
11226
  * @param {number} sizeX - The horizontal grid size.
@@ -10847,7 +11239,7 @@ var drawutilsgl = /** @class */ (function () {
10847
11239
  * This works analogue to the grid() function
10848
11240
  *
10849
11241
  * @method raster
10850
- * @param {Vertex} center - The center of the raster.
11242
+ * @param {XYCoords} center - The center of the raster.
10851
11243
  * @param {number} width - The total width of the raster (width/2 each to the left and to the right).
10852
11244
  * @param {number} height - The total height of the raster (height/2 each to the top and to the bottom).
10853
11245
  * @param {number} sizeX - The horizontal raster size.
@@ -10868,8 +11260,8 @@ var drawutilsgl = /** @class */ (function () {
10868
11260
  * as even shaped diamonds.
10869
11261
  *
10870
11262
  * @method diamondHandle
10871
- * @param {Vertex} center - The center of the diamond.
10872
- * @param {Vertex} size - The x/y-size of the diamond.
11263
+ * @param {XYCoords} center - The center of the diamond.
11264
+ * @param {number} size - The x/y-size of the diamond.
10873
11265
  * @param {string} color - The CSS color to draw the diamond with.
10874
11266
  * @return {void}
10875
11267
  * @instance
@@ -10886,8 +11278,8 @@ var drawutilsgl = /** @class */ (function () {
10886
11278
  * as even shaped squares.
10887
11279
  *
10888
11280
  * @method squareHandle
10889
- * @param {Vertex} center - The center of the square.
10890
- * @param {Vertex} size - The x/y-size of the square.
11281
+ * @param {XYCoords} center - The center of the square.
11282
+ * @param {number} size - The x/y-size of the square.
10891
11283
  * @param {string} color - The CSS color to draw the square with.
10892
11284
  * @return {void}
10893
11285
  * @instance
@@ -10904,7 +11296,7 @@ var drawutilsgl = /** @class */ (function () {
10904
11296
  * as even shaped circles.
10905
11297
  *
10906
11298
  * @method circleHandle
10907
- * @param {Vertex} center - The center of the circle.
11299
+ * @param {XYCoords} center - The center of the circle.
10908
11300
  * @param {number} radius - The radius of the circle.
10909
11301
  * @param {string} color - The CSS color to draw the circle with.
10910
11302
  * @return {void}
@@ -11000,7 +11392,7 @@ var drawutilsgl = /** @class */ (function () {
11000
11392
  * Draw a polygon line (alternative function to the polygon).
11001
11393
  *
11002
11394
  * @method polyline
11003
- * @param {Vertex[]} vertices - The polygon vertices to draw.
11395
+ * @param {XYCoords[]} vertices - The polygon vertices to draw.
11004
11396
  * @param {boolan} isOpen - If true the polyline will not be closed at its end.
11005
11397
  * @param {string} color - The CSS color to draw the polygon with.
11006
11398
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
@@ -11190,7 +11582,17 @@ var GLU = /** @class */ (function () {
11190
11582
  * @modified 2022-03-26 Added the `texturedPoly` function to draw textures polygons.
11191
11583
  * @modified 2022-07-26 Adding `alpha` to the `image(...)` function.
11192
11584
  * @modified 2022-11-10 Tweaking some type issues.
11193
- * @version 1.6.2
11585
+ * @modified 2023-02-04 Fixed a typo in the CSS classname for cubic Bézier paths: cubicBezier (was cubierBezier).
11586
+ * @modified 2023-02-10 The methods `setCurrentClassName` and `setCurrentId` also accept `null` now.
11587
+ * @modified 2023-09-29 Added initialization checks for null parameters.
11588
+ * @modified 2023-09-29 Added a missing implementation to the `drawurilssvg.do(XYCoords,string)` function. Didn't draw anything.
11589
+ * @modified 2023-09-29 Downgrading all `Vertex` param type to the more generic `XYCoords` type in these render functions: line, arrow, texturedPoly, cubicBezier, cubicBezierPath, handle, handleLine, dot, point, circle, circleArc, ellipse, grid, raster.
11590
+ * @modified 2023-09-29 Added the `headLength` parameter to the 'DrawLib.arrow()` function.
11591
+ * @modified 2023-09-29 Added the `arrowHead(...)` function to the 'DrawLib.arrow()` interface.
11592
+ * @modified 2023-09-29 Added the `cubicBezierArrow(...)` function to the 'DrawLib.arrow()` interface.
11593
+ * @modified 2023-10-04 Adding `strokeOptions` param to these draw function: line, arrow, cubicBezierArrow, cubicBezier, cubicBezierPath, circle, circleArc, ellipse, square, rect, polygon, polyline.
11594
+ *
11595
+ * @version 1.6.7
11194
11596
  **/
11195
11597
  Object.defineProperty(exports, "__esModule", ({ value: true }));
11196
11598
  exports.drawutilssvg = void 0;
@@ -11198,6 +11600,7 @@ var CircleSector_1 = __webpack_require__(946);
11198
11600
  var CubicBezierCurve_1 = __webpack_require__(510);
11199
11601
  var Vertex_1 = __webpack_require__(421);
11200
11602
  var UIDGenerator_1 = __webpack_require__(197);
11603
+ var Vector_1 = __webpack_require__(73);
11201
11604
  var RAD_TO_DEG = 180 / Math.PI;
11202
11605
  /**
11203
11606
  * @classdesc A helper class for basic SVG drawing operations. This class should
@@ -11228,11 +11631,14 @@ var drawutilssvg = /** @class */ (function () {
11228
11631
  this.offset = new Vertex_1.Vertex(0, 0).set(offset);
11229
11632
  this.scale = new Vertex_1.Vertex(1, 1).set(scale);
11230
11633
  this.fillShapes = fillShapes;
11231
- this.isSecondary = isSecondary;
11634
+ this.isSecondary = Boolean(isSecondary);
11232
11635
  this.drawlibConfiguration = {};
11233
11636
  this.cache = new Map();
11234
11637
  this.setSize(canvasSize);
11235
11638
  if (isSecondary) {
11639
+ if (!gNode || !bufferGNode || !nodeDefs || !bufferNodeDefs) {
11640
+ throw "Cannot create secondary svg draw lib with undefinde gNode|bufferGNode|nodeDefs|bufferNodeDefs.";
11641
+ }
11236
11642
  this.gNode = gNode;
11237
11643
  this.bufferGNode = bufferGNode;
11238
11644
  this.nodeDefs = nodeDefs;
@@ -11258,6 +11664,8 @@ var drawutilssvg = /** @class */ (function () {
11258
11664
  // Which default styles to add? -> All from the DrawConfig.
11259
11665
  // Compare with DrawConfig interface
11260
11666
  var keys = {
11667
+ // "bezier": "CubicBezierCurve", // TODO: is this correct?
11668
+ "bezierPath": "BezierPath",
11261
11669
  "polygon": "Polygon",
11262
11670
  "triangle": "Triangle",
11263
11671
  "ellipse": "Ellipse",
@@ -11323,6 +11731,9 @@ var drawutilssvg = /** @class */ (function () {
11323
11731
  * @param {string} nodeName - The expected node name.
11324
11732
  */
11325
11733
  drawutilssvg.prototype.findElement = function (key, nodeName) {
11734
+ if (!key) {
11735
+ return null;
11736
+ }
11326
11737
  var node = this.cache.get(key);
11327
11738
  if (node && node.nodeName.toUpperCase() === nodeName.toUpperCase()) {
11328
11739
  this.cache.delete(key);
@@ -11368,6 +11779,9 @@ var drawutilssvg = /** @class */ (function () {
11368
11779
  if (this.drawlibConfiguration.blendMode) {
11369
11780
  node.style["mix-blend-mode"] = this.drawlibConfiguration.blendMode;
11370
11781
  }
11782
+ // if (this.lineDashEnabled && this.lineDash && this.lineDash.length > 0 && drawutilssvg.nodeSupportsLineDash(nodeName)) {
11783
+ // node.setAttribute("stroke-dasharray", this.lineDash.join(" "));
11784
+ // }
11371
11785
  return node;
11372
11786
  };
11373
11787
  /**
@@ -11390,23 +11804,58 @@ var drawutilssvg = /** @class */ (function () {
11390
11804
  * @param {number=1} lineWidth - (optional) A line width to use for drawing (default is 1).
11391
11805
  * @return {SVGElement} The node itself (for chaining).
11392
11806
  */
11393
- drawutilssvg.prototype._bindFillDraw = function (node, className, color, lineWidth) {
11807
+ drawutilssvg.prototype._bindFillDraw = function (node, className, color, lineWidth, strokeOptions) {
11808
+ this._configureNode(node, className, this.fillShapes, color, lineWidth, strokeOptions);
11809
+ return this._bindNode(node, undefined);
11810
+ };
11811
+ /**
11812
+ * Bind this given node to a parent. If no parent is passed then the global
11813
+ * node buffer will be used.
11814
+ *
11815
+ * @method _bindNode
11816
+ * @private
11817
+ * @instance
11818
+ * @memberof drawutilssvg
11819
+ * @param {SVGElement} node - The SVG node to bind.
11820
+ * @param {SVGElement=} bindingParent - (optional) You may pass node other than the glober buffer node.
11821
+ * @returns {SVGElement} The passed node itself.
11822
+ */
11823
+ drawutilssvg.prototype._bindNode = function (node, bindingParent) {
11824
+ if (!node.parentNode) {
11825
+ // Attach to DOM only if not already attached
11826
+ (bindingParent !== null && bindingParent !== void 0 ? bindingParent : this.bufferGNode).appendChild(node);
11827
+ }
11828
+ return node;
11829
+ };
11830
+ /**
11831
+ * Add custom CSS class names and the globally defined CSS classname to the
11832
+ * given node.
11833
+ *
11834
+ * @method addCSSClasses
11835
+ * @private
11836
+ * @instance
11837
+ * @memberof drawutilssvg
11838
+ * @param {SVGElement} node - The SVG node to bind.
11839
+ * @param {string} className - The additional custom classname to add.
11840
+ * @returns {void}
11841
+ */
11842
+ drawutilssvg.prototype._addCSSClasses = function (node, className) {
11394
11843
  if (this.curClassName) {
11395
11844
  node.setAttribute("class", className + " " + this.curClassName);
11396
11845
  }
11397
11846
  else {
11398
11847
  node.setAttribute("class", className);
11399
11848
  }
11400
- node.setAttribute("fill", this.fillShapes ? color : "none");
11401
- node.setAttribute("stroke", this.fillShapes ? "none" : color);
11849
+ };
11850
+ drawutilssvg.prototype._configureNode = function (node, className, fillMode, color, lineWidth, strokeOptions) {
11851
+ this._addCSSClasses(node, className);
11852
+ node.setAttribute("fill", fillMode && color ? color : "none");
11853
+ node.setAttribute("stroke", fillMode ? "none" : color || "none");
11402
11854
  node.setAttribute("stroke-width", "" + (lineWidth || 1));
11403
11855
  if (this.curId) {
11404
11856
  node.setAttribute("id", "" + this.curId); // Maybe React-style 'key' would be better?
11405
11857
  }
11406
- if (!node.parentNode) {
11407
- // Attach to DOM only if not already attached
11408
- this.bufferGNode.appendChild(node);
11409
- }
11858
+ this.applyStrokeOpts(node, strokeOptions);
11410
11859
  return node;
11411
11860
  };
11412
11861
  /**
@@ -11428,7 +11877,7 @@ var drawutilssvg = /** @class */ (function () {
11428
11877
  * that under the hood the same gl context and gl program will be used.
11429
11878
  */
11430
11879
  drawutilssvg.prototype.copyInstance = function (fillShapes) {
11431
- var copy = new drawutilssvg(this.svgNode, this.offset, this.scale, this.canvasSize, fillShapes, null, // no DrawConfig
11880
+ var copy = new drawutilssvg(this.svgNode, this.offset, this.scale, this.canvasSize, fillShapes, null, // no DrawConfig – this will work as long as `isSecondary===true`
11432
11881
  true, // isSecondary
11433
11882
  this.gNode, this.bufferGNode, this.nodeDefs, this.bufferedNodeDefs);
11434
11883
  return copy;
@@ -11443,13 +11892,27 @@ var drawutilssvg = /** @class */ (function () {
11443
11892
  drawutilssvg.prototype.setConfiguration = function (configuration) {
11444
11893
  this.drawlibConfiguration = configuration;
11445
11894
  };
11895
+ // /**
11896
+ // * Set or clear the line-dash configuration. Pass `null` for un-dashed lines.
11897
+ // *
11898
+ // * See https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray
11899
+ // * and https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash
11900
+ // * for how line dashes work.
11901
+ // *
11902
+ // * @method
11903
+ // * @param {Array<number> lineDashes - The line-dash array configuration.
11904
+ // * @returns {void}
11905
+ // */
11906
+ // setLineDash(lineDashes: Array<number>) {
11907
+ // this.lineDash = lineDashes;
11908
+ // }
11446
11909
  /**
11447
11910
  * This method shouled be called each time the currently drawn `Drawable` changes.
11448
11911
  * It is used by some libraries for identifying elemente on re-renders.
11449
11912
  *
11450
11913
  * @name setCurrentId
11451
11914
  * @method
11452
- * @param {UID} uid - A UID identifying the currently drawn element(s).
11915
+ * @param {UID|null} uid - A UID identifying the currently drawn element(s).
11453
11916
  * @instance
11454
11917
  * @memberof drawutilssvg
11455
11918
  **/
@@ -11462,7 +11925,7 @@ var drawutilssvg = /** @class */ (function () {
11462
11925
  *
11463
11926
  * @name setCurrentClassName
11464
11927
  * @method
11465
- * @param {string} className - A class name for further custom use cases.
11928
+ * @param {string|null} className - A class name for further custom use cases.
11466
11929
  * @instance
11467
11930
  * @memberof drawutilssvg
11468
11931
  **/
@@ -11517,6 +11980,27 @@ var drawutilssvg = /** @class */ (function () {
11517
11980
  this.nodeDefs = this.bufferedNodeDefs;
11518
11981
  this.bufferedNodeDefs = tmpDefsNode;
11519
11982
  };
11983
+ /**
11984
+ * A private helper method to apply stroke options to the current
11985
+ * context.
11986
+ * @param {StrokeOptions=} strokeOptions -
11987
+ */
11988
+ drawutilssvg.prototype.applyStrokeOpts = function (node, strokeOptions) {
11989
+ var _this = this;
11990
+ if (strokeOptions &&
11991
+ strokeOptions.dashArray &&
11992
+ strokeOptions.dashArray.length > 0 &&
11993
+ drawutilssvg.nodeSupportsLineDash(node.tagName)) {
11994
+ node.setAttribute("stroke-dasharray", strokeOptions.dashArray
11995
+ .map(function (dashArayElem) {
11996
+ return dashArayElem * _this.scale.x;
11997
+ })
11998
+ .join(" "));
11999
+ if (strokeOptions.dashOffset) {
12000
+ node.setAttribute("stroke-dashoffset", "" + strokeOptions.dashOffset * this.scale.x);
12001
+ }
12002
+ }
12003
+ };
11520
12004
  drawutilssvg.prototype._x = function (x) {
11521
12005
  return this.offset.x + this.scale.x * x;
11522
12006
  };
@@ -11527,47 +12011,104 @@ var drawutilssvg = /** @class */ (function () {
11527
12011
  * Draw the line between the given two points with the specified (CSS-) color.
11528
12012
  *
11529
12013
  * @method line
11530
- * @param {Vertex} zA - The start point of the line.
11531
- * @param {Vertex} zB - The end point of the line.
12014
+ * @param {XYCoords} zA - The start point of the line.
12015
+ * @param {XYCoords} zB - The end point of the line.
11532
12016
  * @param {string} color - Any valid CSS color string.
11533
12017
  * @param {number=1} lineWidth? - [optional] The line's width.
12018
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
12019
+ *
11534
12020
  * @return {void}
11535
12021
  * @instance
11536
12022
  * @memberof drawutilssvg
11537
12023
  **/
11538
- drawutilssvg.prototype.line = function (zA, zB, color, lineWidth) {
11539
- var line = this.makeNode("line");
11540
- line.setAttribute("x1", "" + this._x(zA.x));
11541
- line.setAttribute("y1", "" + this._y(zA.y));
11542
- line.setAttribute("x2", "" + this._x(zB.x));
11543
- line.setAttribute("y2", "" + this._y(zB.y));
11544
- return this._bindFillDraw(line, "line", color, lineWidth || 1);
12024
+ drawutilssvg.prototype.line = function (zA, zB, color, lineWidth, strokeOptions) {
12025
+ // const line: SVGElement = this.makeNode("line");
12026
+ // this.applyStrokeOpts(line, strokeOptions);
12027
+ // line.setAttribute("x1", `${this._x(zA.x)}`);
12028
+ // line.setAttribute("y1", `${this._y(zA.y)}`);
12029
+ // line.setAttribute("x2", `${this._x(zB.x)}`);
12030
+ // line.setAttribute("y2", `${this._y(zB.y)}`);
12031
+ var line = this.makeLineNode(zA, zB, color, lineWidth, strokeOptions);
12032
+ return this._bindFillDraw(line, "line", color, lineWidth || 1, strokeOptions);
11545
12033
  };
11546
12034
  /**
11547
12035
  * Draw a line and an arrow at the end (zB) of the given line with the specified (CSS-) color.
11548
12036
  *
11549
12037
  * @method arrow
11550
- * @param {Vertex} zA - The start point of the arrow-line.
11551
- * @param {Vertex} zB - The end point of the arrow-line.
12038
+ * @param {XYCoords} zA - The start point of the arrow-line.
12039
+ * @param {XYCoords} zB - The end point of the arrow-line.
11552
12040
  * @param {string} color - Any valid CSS color string.
11553
12041
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
12042
+ * @param {headLength=8} headLength - (optional) The length of the arrow head (default is 8 units).
12043
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
12044
+ *
11554
12045
  * @return {void}
11555
12046
  * @instance
11556
12047
  * @memberof drawutilssvg
11557
12048
  **/
11558
- drawutilssvg.prototype.arrow = function (zA, zB, color, lineWidth) {
11559
- var node = this.makeNode("path");
11560
- var headlen = 8; // length of head in pixels
11561
- var vertices = Vertex_1.Vertex.utils.buildArrowHead(zA, zB, headlen, this.scale.x, this.scale.y);
11562
- var d = ["M", this._x(zA.x), this._y(zA.y)];
11563
- for (var i = 0; i <= vertices.length; i++) {
11564
- d.push("L");
11565
- // Note: only use offset here (the vertices are already scaled)
11566
- d.push(this.offset.x + vertices[i % vertices.length].x);
11567
- d.push(this.offset.y + vertices[i % vertices.length].y);
11568
- }
11569
- node.setAttribute("d", d.join(" "));
11570
- return this._bindFillDraw(node, "arrow", color, lineWidth || 1);
12049
+ drawutilssvg.prototype.arrow = function (zA, zB, color, lineWidth, headLength, strokeOptions) {
12050
+ if (headLength === void 0) { headLength = 8; }
12051
+ var group = this.makeNode("g");
12052
+ var arrowHeadBasePosition = { x: 0, y: 0 };
12053
+ // Just create the child nodes, don't bind them to the root node.
12054
+ var arrowHead = this.makeArrowHeadNode(zA, zB, color, lineWidth, headLength, undefined, arrowHeadBasePosition);
12055
+ var line = this.makeLineNode(zA, arrowHeadBasePosition, color, lineWidth, strokeOptions);
12056
+ group.appendChild(line);
12057
+ group.appendChild(arrowHead);
12058
+ this._addCSSClasses(group, "linear-arrow");
12059
+ this._bindNode(group, undefined);
12060
+ return group;
12061
+ };
12062
+ /**
12063
+ * Draw a cubic Bézier curve and and an arrow at the end (endControlPoint) of the given line width the specified (CSS-) color and arrow size.
12064
+ *
12065
+ * @method cubicBezierArrow
12066
+ * @param {XYCoords} startPoint - The start point of the cubic Bézier curve
12067
+ * @param {XYCoords} endPoint - The end point the cubic Bézier curve.
12068
+ * @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
12069
+ * @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
12070
+ * @param {string} color - The CSS color to draw the curve with.
12071
+ * @param {number} lineWidth - (optional) The line width to use.
12072
+ * @param {headLength=8} headLength - (optional) The length of the arrow head (default is 8 units).
12073
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
12074
+ *
12075
+ * @return {void}
12076
+ * @instance
12077
+ * @memberof DrawLib
12078
+ */
12079
+ drawutilssvg.prototype.cubicBezierArrow = function (startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, headLength, strokeOptions) {
12080
+ if (headLength === void 0) { headLength = 8; }
12081
+ var group = this.makeNode("g");
12082
+ // Just create the child nodes, don't bind them to the root node.
12083
+ var arrowHeadBasePosition = new Vertex_1.Vertex(0, 0);
12084
+ var arrowHead = this.makeArrowHeadNode(endControlPoint, endPoint, color, lineWidth, headLength, undefined, arrowHeadBasePosition);
12085
+ var diff = arrowHeadBasePosition.difference(endPoint);
12086
+ var bezier = this.makeCubicBezierNode(startPoint, { x: endPoint.x - diff.x, y: endPoint.y - diff.y }, startControlPoint, { x: endControlPoint.x - diff.x, y: endControlPoint.y - diff.y }, color, lineWidth, strokeOptions);
12087
+ group.appendChild(bezier);
12088
+ group.appendChild(arrowHead);
12089
+ this._addCSSClasses(group, "cubicbezier-arrow");
12090
+ this._bindNode(group, undefined);
12091
+ return group;
12092
+ };
12093
+ /**
12094
+ * Draw just an arrow head a the end of an imaginary line (zB) of the given line width the specified (CSS-) color and size.
12095
+ *
12096
+ * @method arrow
12097
+ * @param {XYCoords} zA - The start point of the arrow-line.
12098
+ * @param {XYCoords} zB - The end point of the arrow-line.
12099
+ * @param {string} color - Any valid CSS color string.
12100
+ * @param {number=1} lineWidth - (optional) The line width to use; default is 1.
12101
+ * @param {number=8} headLength - (optional) The length of the arrow head (default is 8 pixels).
12102
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
12103
+ *
12104
+ * @return {void}
12105
+ * @instance
12106
+ * @memberof DrawLib
12107
+ **/
12108
+ drawutilssvg.prototype.arrowHead = function (zA, zB, color, lineWidth, headLength, strokeOptions) {
12109
+ if (headLength === void 0) { headLength = 8; }
12110
+ var node = this.makeArrowHeadNode(zA, zB, color, lineWidth, headLength, strokeOptions);
12111
+ return this._bindFillDraw(node, "arrowhead", color, lineWidth || 1, strokeOptions);
11571
12112
  };
11572
12113
  /**
11573
12114
  * Draw an image at the given position with the given size.<br>
@@ -11576,8 +12117,8 @@ var drawutilssvg = /** @class */ (function () {
11576
12117
  *
11577
12118
  * @method image
11578
12119
  * @param {Image} image - The image object to draw.
11579
- * @param {Vertex} position - The position to draw the the upper left corner at.
11580
- * @param {Vertex} size - The x/y-size to draw the image with.
12120
+ * @param {XYCoords} position - The position to draw the the upper left corner at.
12121
+ * @param {XYCoords} size - The x/y-size to draw the image with.
11581
12122
  * @param {number=0.0} alpha - (optional, default=0.0) The transparency (1.0=opaque, 0.0=transparent).
11582
12123
  * @return {void}
11583
12124
  * @instance
@@ -11622,16 +12163,16 @@ var drawutilssvg = /** @class */ (function () {
11622
12163
  * @param {Image} textureImage - The image object to draw.
11623
12164
  * @param {Bounds} textureSize - The texture size to use; these are the original bounds to map the polygon vertices to.
11624
12165
  * @param {Polygon} polygon - The polygon to use as clip path.
11625
- * @param {Vertex} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
12166
+ * @param {XYCoords} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
11626
12167
  * @param {number} rotation - The rotation to use for the polygon (and for the texture).
11627
12168
  * @return {void}
11628
12169
  * @instance
11629
12170
  * @memberof drawutilssvg
11630
12171
  **/
11631
12172
  drawutilssvg.prototype.texturedPoly = function (textureImage, textureSize, polygon, polygonPosition, rotation) {
11632
- var basePolygonBounds = polygon.getBounds();
12173
+ // const basePolygonBounds: Bounds = polygon.getBounds();
11633
12174
  var rotatedScalingOrigin = new Vertex_1.Vertex(textureSize.min).clone().rotate(rotation, polygonPosition);
11634
- var rotationCenter = polygonPosition.clone().add(rotatedScalingOrigin.difference(textureSize.min).inv());
12175
+ // const rotationCenter = polygonPosition.clone().add(rotatedScalingOrigin.difference(textureSize.min).inv());
11635
12176
  // Create something like this
11636
12177
  // ...
11637
12178
  // <defs>
@@ -11686,36 +12227,21 @@ var drawutilssvg = /** @class */ (function () {
11686
12227
  * Draw the given (cubic) bézier curve.
11687
12228
  *
11688
12229
  * @method cubicBezier
11689
- * @param {Vertex} startPoint - The start point of the cubic Bézier curve
11690
- * @param {Vertex} endPoint - The end point the cubic Bézier curve.
11691
- * @param {Vertex} startControlPoint - The start control point the cubic Bézier curve.
11692
- * @param {Vertex} endControlPoint - The end control point the cubic Bézier curve.
12230
+ * @param {XYCoords} startPoint - The start point of the cubic Bézier curve
12231
+ * @param {XYCoords} endPoint - The end point the cubic Bézier curve.
12232
+ * @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
12233
+ * @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
11693
12234
  * @param {string} color - The CSS color to draw the curve with.
11694
12235
  * @param {number} lineWidth - (optional) The line width to use.
12236
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
12237
+ *
11695
12238
  * @return {void}
11696
12239
  * @instance
11697
12240
  * @memberof drawutilssvg
11698
12241
  */
11699
- drawutilssvg.prototype.cubicBezier = function (startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth) {
11700
- if (startPoint instanceof CubicBezierCurve_1.CubicBezierCurve) {
11701
- return this.cubicBezier(startPoint.startPoint, startPoint.endPoint, startPoint.startControlPoint, startPoint.endControlPoint, color, lineWidth);
11702
- }
11703
- var node = this.makeNode("path");
11704
- // Draw curve
11705
- var d = [
11706
- "M",
11707
- this._x(startPoint.x),
11708
- this._y(startPoint.y),
11709
- "C",
11710
- this._x(startControlPoint.x),
11711
- this._y(startControlPoint.y),
11712
- this._x(endControlPoint.x),
11713
- this._y(endControlPoint.y),
11714
- this._x(endPoint.x),
11715
- this._y(endPoint.y)
11716
- ];
11717
- node.setAttribute("d", d.join(" "));
11718
- return this._bindFillDraw(node, "cubierBezier", color, lineWidth);
12242
+ drawutilssvg.prototype.cubicBezier = function (startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, strokeOptions) {
12243
+ var node = this.makeCubicBezierNode(startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, strokeOptions);
12244
+ return this._bindNode(node, undefined);
11719
12245
  };
11720
12246
  /**
11721
12247
  * Draw the given (cubic) Bézier path.
@@ -11725,17 +12251,21 @@ var drawutilssvg = /** @class */ (function () {
11725
12251
  * <pre> [ point1, point1_startControl, point2_endControl, point2, point2_startControl, point3_endControl, point3, ... pointN_endControl, pointN ]</pre>
11726
12252
  *
11727
12253
  * @method cubicBezierPath
11728
- * @param {Vertex[]} path - The cubic bezier path as described above.
12254
+ * @param {XYCoords[]} path - The cubic bezier path as described above.
11729
12255
  * @param {string} color - The CSS colot to draw the path with.
11730
12256
  * @param {number=1} lineWidth - (optional) The line width to use.
12257
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
12258
+ *
11731
12259
  * @return {void}
11732
12260
  * @instance
11733
12261
  * @memberof drawutilssvg
11734
12262
  */
11735
- drawutilssvg.prototype.cubicBezierPath = function (path, color, lineWidth) {
12263
+ drawutilssvg.prototype.cubicBezierPath = function (path, color, lineWidth, strokeOptions) {
11736
12264
  var node = this.makeNode("path");
11737
- if (!path || path.length == 0)
12265
+ this.applyStrokeOpts(node, strokeOptions);
12266
+ if (!path || path.length == 0) {
11738
12267
  return node;
12268
+ }
11739
12269
  // Draw curve
11740
12270
  var d = ["M", this._x(path[0].x), this._y(path[0].y)];
11741
12271
  // Draw curve path
@@ -11772,20 +12302,20 @@ var drawutilssvg = /** @class */ (function () {
11772
12302
  * Draw a handle line (with a light grey).
11773
12303
  *
11774
12304
  * @method handleLine
11775
- * @param {Vertex} startPoint - The start point to draw the handle at.
11776
- * @param {Vertex} endPoint - The end point to draw the handle at.
12305
+ * @param {XYCoords} startPoint - The start point to draw the handle at.
12306
+ * @param {XYCoords} endPoint - The end point to draw the handle at.
11777
12307
  * @return {void}
11778
12308
  * @instance
11779
12309
  * @memberof drawutilssvg
11780
12310
  */
11781
12311
  drawutilssvg.prototype.handleLine = function (startPoint, endPoint) {
11782
- this.line(startPoint, endPoint, "rgb(192,192,192)");
12312
+ this.line(startPoint, endPoint, "rgb(128,128,128,0.5)");
11783
12313
  };
11784
12314
  /**
11785
12315
  * Draw a 1x1 dot with the specified (CSS-) color.
11786
12316
  *
11787
12317
  * @method dot
11788
- * @param {Vertex} p - The position to draw the dot at.
12318
+ * @param {XYCoords} p - The position to draw the dot at.
11789
12319
  * @param {string} color - The CSS color to draw the dot with.
11790
12320
  * @return {void}
11791
12321
  * @instance
@@ -11793,13 +12323,17 @@ var drawutilssvg = /** @class */ (function () {
11793
12323
  */
11794
12324
  drawutilssvg.prototype.dot = function (p, color) {
11795
12325
  var node = this.makeNode("line");
12326
+ node.setAttribute("x1", "" + this._x(p.x));
12327
+ node.setAttribute("y1", "" + this._y(p.y));
12328
+ node.setAttribute("x2", "" + this._x(p.x));
12329
+ node.setAttribute("y2", "" + this._y(p.y));
11796
12330
  return this._bindFillDraw(node, "dot", color, 1);
11797
12331
  };
11798
12332
  /**
11799
12333
  * Draw the given point with the specified (CSS-) color and radius 3.
11800
12334
  *
11801
12335
  * @method point
11802
- * @param {Vertex} p - The position to draw the point at.
12336
+ * @param {XYCoords} p - The position to draw the point at.
11803
12337
  * @param {string} color - The CSS color to draw the point with.
11804
12338
  * @return {void}
11805
12339
  * @instance
@@ -11819,17 +12353,20 @@ var drawutilssvg = /** @class */ (function () {
11819
12353
  * Note that if the x- and y- scales are different the result will be an ellipse rather than a circle.
11820
12354
  *
11821
12355
  * @method circle
11822
- * @param {Vertex} center - The center of the circle.
12356
+ * @param {XYCoords} center - The center of the circle.
11823
12357
  * @param {number} radius - The radius of the circle.
11824
12358
  * @param {string} color - The CSS color to draw the circle with.
11825
12359
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
12360
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
12361
+ *
11826
12362
  * @return {void}
11827
12363
  * @instance
11828
12364
  * @memberof drawutilssvg
11829
12365
  */
11830
- drawutilssvg.prototype.circle = function (center, radius, color, lineWidth) {
12366
+ drawutilssvg.prototype.circle = function (center, radius, color, lineWidth, strokeOptions) {
11831
12367
  // Todo: draw ellipse when scalex!=scaley
11832
12368
  var node = this.makeNode("circle");
12369
+ this.applyStrokeOpts(node, strokeOptions);
11833
12370
  node.setAttribute("cx", "" + this._x(center.x));
11834
12371
  node.setAttribute("cy", "" + this._y(center.y));
11835
12372
  node.setAttribute("r", "" + radius * this.scale.x); // y?
@@ -11839,17 +12376,20 @@ var drawutilssvg = /** @class */ (function () {
11839
12376
  * Draw a circular arc (section of a circle) with the given CSS color.
11840
12377
  *
11841
12378
  * @method circleArc
11842
- * @param {Vertex} center - The center of the circle.
12379
+ * @param {XYCoords} center - The center of the circle.
11843
12380
  * @param {number} radius - The radius of the circle.
11844
12381
  * @param {number} startAngle - The angle to start at.
11845
12382
  * @param {number} endAngle - The angle to end at.
11846
12383
  * @param {string} color - The CSS color to draw the circle with.
12384
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
12385
+ *
11847
12386
  * @return {void}
11848
12387
  * @instance
11849
12388
  * @memberof drawutilssvg
11850
12389
  */
11851
- drawutilssvg.prototype.circleArc = function (center, radius, startAngle, endAngle, color, lineWidth) {
12390
+ drawutilssvg.prototype.circleArc = function (center, radius, startAngle, endAngle, color, lineWidth, strokeOptions) {
11852
12391
  var node = this.makeNode("path");
12392
+ this.applyStrokeOpts(node, strokeOptions);
11853
12393
  var arcData = CircleSector_1.CircleSector.circleSectorUtils.describeSVGArc(this._x(center.x), this._y(center.y), radius * this.scale.x, // y?
11854
12394
  startAngle, endAngle);
11855
12395
  node.setAttribute("d", arcData.join(" "));
@@ -11859,21 +12399,24 @@ var drawutilssvg = /** @class */ (function () {
11859
12399
  * Draw an ellipse with the specified (CSS-) color and thw two radii.
11860
12400
  *
11861
12401
  * @method ellipse
11862
- * @param {Vertex} center - The center of the ellipse.
12402
+ * @param {XYCoords} center - The center of the ellipse.
11863
12403
  * @param {number} radiusX - The radius of the ellipse.
11864
12404
  * @param {number} radiusY - The radius of the ellipse.
11865
12405
  * @param {string} color - The CSS color to draw the ellipse with.
11866
12406
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
11867
12407
  * @param {number=} rotation - (optional, default=0) The rotation of the ellipse.
12408
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
12409
+ *
11868
12410
  * @return {void}
11869
12411
  * @instance
11870
12412
  * @memberof drawutilssvg
11871
12413
  */
11872
- drawutilssvg.prototype.ellipse = function (center, radiusX, radiusY, color, lineWidth, rotation) {
12414
+ drawutilssvg.prototype.ellipse = function (center, radiusX, radiusY, color, lineWidth, rotation, strokeOptions) {
11873
12415
  if (typeof rotation === "undefined") {
11874
12416
  rotation = 0.0;
11875
12417
  }
11876
12418
  var node = this.makeNode("ellipse");
12419
+ this.applyStrokeOpts(node, strokeOptions);
11877
12420
  node.setAttribute("cx", "" + this._x(center.x));
11878
12421
  node.setAttribute("cy", "" + this._y(center.y));
11879
12422
  node.setAttribute("rx", "" + radiusX * this.scale.x);
@@ -11889,15 +12432,18 @@ var drawutilssvg = /** @class */ (function () {
11889
12432
  *
11890
12433
  * @method square
11891
12434
  * @param {XYCoords} center - The center of the square.
11892
- * @param {Vertex} size - The size of the square.
12435
+ * @param {number} size - The size of the square.
11893
12436
  * @param {string} color - The CSS color to draw the square with.
11894
12437
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
11895
- * @return {void}
12438
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
12439
+ *
12440
+ * @return {SVGElement}
11896
12441
  * @instance
11897
12442
  * @memberof drawutilssvg
11898
12443
  */
11899
- drawutilssvg.prototype.square = function (center, size, color, lineWidth) {
12444
+ drawutilssvg.prototype.square = function (center, size, color, lineWidth, strokeOptions) {
11900
12445
  var node = this.makeNode("rectangle");
12446
+ this.applyStrokeOpts(node, strokeOptions);
11901
12447
  node.setAttribute("x", "" + this._x(center.x - size / 2.0));
11902
12448
  node.setAttribute("y", "" + this._y(center.y - size / 2.0));
11903
12449
  node.setAttribute("width", "" + size * this.scale.x);
@@ -11912,9 +12458,15 @@ var drawutilssvg = /** @class */ (function () {
11912
12458
  * @param {number} height - The height of the rectangle.
11913
12459
  * @param {string} color - The color to use.
11914
12460
  * @param {number=1} lineWidth - (optional) The line with to use (default is 1).
12461
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
12462
+ *
12463
+ * @return {SVGElement}
12464
+ * @instance
12465
+ * @memberof drawutilssvg
11915
12466
  **/
11916
- drawutilssvg.prototype.rect = function (position, width, height, color, lineWidth) {
12467
+ drawutilssvg.prototype.rect = function (position, width, height, color, lineWidth, strokeOptions) {
11917
12468
  var node = this.makeNode("rect");
12469
+ this.applyStrokeOpts(node, strokeOptions);
11918
12470
  node.setAttribute("x", "" + this._x(position.x));
11919
12471
  node.setAttribute("y", "" + this._y(position.y));
11920
12472
  node.setAttribute("width", "" + width * this.scale.x);
@@ -11925,7 +12477,7 @@ var drawutilssvg = /** @class */ (function () {
11925
12477
  * Draw a grid of horizontal and vertical lines with the given (CSS-) color.
11926
12478
  *
11927
12479
  * @method grid
11928
- * @param {Vertex} center - The center of the grid.
12480
+ * @param {XYCoords} center - The center of the grid.
11929
12481
  * @param {number} width - The total width of the grid (width/2 each to the left and to the right).
11930
12482
  * @param {number} height - The total height of the grid (height/2 each to the top and to the bottom).
11931
12483
  * @param {number} sizeX - The horizontal grid size.
@@ -11959,7 +12511,7 @@ var drawutilssvg = /** @class */ (function () {
11959
12511
  * This works analogue to the grid() function
11960
12512
  *
11961
12513
  * @method raster
11962
- * @param {Vertex} center - The center of the raster.
12514
+ * @param {XYCoords} center - The center of the raster.
11963
12515
  * @param {number} width - The total width of the raster (width/2 each to the left and to the right).
11964
12516
  * @param {number} height - The total height of the raster (height/2 each to the top and to the bottom).
11965
12517
  * @param {number} sizeX - The horizontal raster size.
@@ -11992,8 +12544,8 @@ var drawutilssvg = /** @class */ (function () {
11992
12544
  * as even shaped diamonds.
11993
12545
  *
11994
12546
  * @method diamondHandle
11995
- * @param {Vertex} center - The center of the diamond.
11996
- * @param {Vertex} size - The x/y-size of the diamond.
12547
+ * @param {XYCoords} center - The center of the diamond.
12548
+ * @param {number} size - The x/y-size of the diamond.
11997
12549
  * @param {string} color - The CSS color to draw the diamond with.
11998
12550
  * @return {void}
11999
12551
  * @instance
@@ -12027,8 +12579,8 @@ var drawutilssvg = /** @class */ (function () {
12027
12579
  * as even shaped squares.
12028
12580
  *
12029
12581
  * @method squareHandle
12030
- * @param {Vertex} center - The center of the square.
12031
- * @param {Vertex} size - The x/y-size of the square.
12582
+ * @param {XYCoords} center - The center of the square.
12583
+ * @param {XYCoords} size - The x/y-size of the square.
12032
12584
  * @param {string} color - The CSS color to draw the square with.
12033
12585
  * @return {void}
12034
12586
  * @instance
@@ -12050,7 +12602,7 @@ var drawutilssvg = /** @class */ (function () {
12050
12602
  * as even shaped circles.
12051
12603
  *
12052
12604
  * @method circleHandle
12053
- * @param {Vertex} center - The center of the circle.
12605
+ * @param {XYCoords} center - The center of the circle.
12054
12606
  * @param {number} radius - The radius of the circle.
12055
12607
  * @param {string} color - The CSS color to draw the circle with.
12056
12608
  * @return {void}
@@ -12149,18 +12701,22 @@ var drawutilssvg = /** @class */ (function () {
12149
12701
  * Draw a polygon line (alternative function to the polygon).
12150
12702
  *
12151
12703
  * @method polyline
12152
- * @param {Vertex[]} vertices - The polygon vertices to draw.
12704
+ * @param {XYCoords[]} vertices - The polygon vertices to draw.
12153
12705
  * @param {boolan} isOpen - If true the polyline will not be closed at its end.
12154
12706
  * @param {string} color - The CSS color to draw the polygon with.
12155
12707
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
12708
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
12709
+ *
12156
12710
  * @return {void}
12157
12711
  * @instance
12158
12712
  * @memberof drawutilssvg
12159
12713
  */
12160
- drawutilssvg.prototype.polyline = function (vertices, isOpen, color, lineWidth) {
12714
+ drawutilssvg.prototype.polyline = function (vertices, isOpen, color, lineWidth, strokeOptions) {
12161
12715
  var node = this.makeNode("path");
12162
- if (vertices.length == 0)
12716
+ this.applyStrokeOpts(node, strokeOptions);
12717
+ if (vertices.length == 0) {
12163
12718
  return node;
12719
+ }
12164
12720
  // Draw curve
12165
12721
  var d = ["M", this._x(vertices[0].x), this._y(vertices[0].y)];
12166
12722
  var n = vertices.length;
@@ -12263,12 +12819,16 @@ var drawutilssvg = /** @class */ (function () {
12263
12819
  * @param {string=null} color - (optional) The color to draw this path with (default is null).
12264
12820
  * @param {number=1} lineWidth - (optional) the line width to use (default is 1).
12265
12821
  * @param {boolean=false} options.inplace - (optional) If set to true then path transforamtions (scale and translate) will be done in-place in the array. This can boost the performance.
12822
+ * @param {number=} options.dashOffset - (optional) `See StrokeOptions`.
12823
+ * @param {number=[]} options.dashArray - (optional) `See StrokeOptions`.
12824
+ *
12266
12825
  * @instance
12267
12826
  * @memberof drawutils
12268
12827
  * @return {R} An instance representing the drawn path.
12269
12828
  */
12270
12829
  drawutilssvg.prototype.path = function (pathData, color, lineWidth, options) {
12271
12830
  var node = this.makeNode("path");
12831
+ this.applyStrokeOpts(node, options);
12272
12832
  // Transform the path: in-place (fast) or copy (slower)
12273
12833
  var d = options && options.inplace ? pathData : drawutilssvg.copyPathData(pathData);
12274
12834
  drawutilssvg.transformPathData(d, this.offset, this.scale);
@@ -12294,7 +12854,7 @@ var drawutilssvg = /** @class */ (function () {
12294
12854
  }
12295
12855
  // Add a covering rect with the given background color
12296
12856
  this.curId = "background";
12297
- this.curClassName = undefined;
12857
+ this.curClassName = null; // undefined;
12298
12858
  var node = this.makeNode("rect");
12299
12859
  // For some strange reason SVG rotation transforms use degrees instead of radians
12300
12860
  // Note that the background does not scale with the zoom level (always covers full element)
@@ -12306,7 +12866,7 @@ var drawutilssvg = /** @class */ (function () {
12306
12866
  this._bindFillDraw(node, this.curId, null, null);
12307
12867
  node.setAttribute("fill", typeof color === "undefined" ? "none" : color);
12308
12868
  // Clear the current ID again
12309
- this.curId = undefined;
12869
+ this.curId = null; // undefined;
12310
12870
  };
12311
12871
  /**
12312
12872
  * A private helper function to clear all SVG nodes from the &gt;g> node.
@@ -12511,6 +13071,127 @@ var drawutilssvg = /** @class */ (function () {
12511
13071
  }
12512
13072
  } // END while
12513
13073
  }; // END transformPathData
13074
+ drawutilssvg.nodeSupportsLineDash = function (nodeName) {
13075
+ return ["line", "path", "circle", "ellipse", "rectangle", "rect"].includes(nodeName);
13076
+ };
13077
+ /**
13078
+ * Creates a basic <line> node with start and end coordinates. The created node will not
13079
+ * be bound to any root node.
13080
+ *
13081
+ * @private
13082
+ * @method makeLineNode
13083
+ * @param {XYCoords} zA - The line's start position.
13084
+ * @param {XYCoords} zB - The line's start position.
13085
+ * @param {string} color - The CSS color to draw the point with.
13086
+ * @param {number=1} lineWidth - (optional) The line width to use.
13087
+ * @param {StrokeOptions=} strokeOptions - (optional) Additional stroke options to use.
13088
+ * @param {string=} classNameOverride - (optional) If nothing is passed the default classname 'path' will be used.
13089
+ * @return {SVGLineElement}
13090
+ * @instance
13091
+ * @memberof drawutilssvg
13092
+ */
13093
+ drawutilssvg.prototype.makeLineNode = function (zA, zB, color, lineWidth, strokeOptions, classNameOverride) {
13094
+ var line = this.makeNode("line");
13095
+ line.setAttribute("x1", "" + this._x(zA.x));
13096
+ line.setAttribute("y1", "" + this._y(zA.y));
13097
+ line.setAttribute("x2", "" + this._x(zB.x));
13098
+ line.setAttribute("y2", "" + this._y(zB.y));
13099
+ this._configureNode(line, classNameOverride !== null && classNameOverride !== void 0 ? classNameOverride : "line", this.fillShapes, color, lineWidth || 1, strokeOptions);
13100
+ return line;
13101
+ };
13102
+ /**
13103
+ * Creates a basic <path> node with given path string data. The created node will not
13104
+ * be bound to any root node.
13105
+ *
13106
+ * @private
13107
+ * @method makePathNode
13108
+ * @param {string} pathString - The path data (must be a valid path data string).
13109
+ * @param {string} color - The CSS color to draw the point with.
13110
+ * @param {number=1} lineWidth - (optional) The line width to use.
13111
+ * @param {StrokeOptions=} strokeOptions - (optional) Additional stroke options to use.
13112
+ * @param {string=} classNameOverride - (optional) If nothing is passed the default classname 'path' will be used.
13113
+ * @return {SVGPathElement}
13114
+ * @instance
13115
+ * @memberof drawutilssvg
13116
+ */
13117
+ drawutilssvg.prototype.makePathNode = function (pathString, color, lineWidth, strokeOptions, classNameOverride) {
13118
+ var path = this.makeNode("path");
13119
+ path.setAttribute("d", pathString);
13120
+ this._configureNode(path, classNameOverride !== null && classNameOverride !== void 0 ? classNameOverride : "path", this.fillShapes, color, lineWidth || 1, strokeOptions);
13121
+ return path;
13122
+ };
13123
+ /**
13124
+ * Creates a basic arrow head node (<path> node) at the end of the given line coordinates. The created node will not
13125
+ * be bound to any root node.
13126
+ *
13127
+ * @private
13128
+ * @method makeArrowHeadNode
13129
+ * @param {string} pathString - The path data (must be a valid path data string).
13130
+ * @param {string} color - The CSS color to draw the point with.
13131
+ * @param {number=1} lineWidth - (optional) The line width to use.
13132
+ * @param {number=8} headLength - (optional) The length of the arrow head; if none is specified then the head will be 8 absolute units long.
13133
+ * @param {StrokeOptions=} strokeOptions - (optional) Additional stroke options to use.
13134
+ * @param {XYCoords=} arrowHeadBasePositionBuffer - (optional) If not null, then this position will contain the arrow head's start point (after execution). Some sort of OUT variable.
13135
+ * @return {SVGPathElement}
13136
+ * @instance
13137
+ * @memberof drawutilssvg
13138
+ */
13139
+ drawutilssvg.prototype.makeArrowHeadNode = function (zA, zB, color, lineWidth, headLength, strokeOptions, arrowHeadBasePositionBuffer) {
13140
+ if (headLength === void 0) { headLength = 8; }
13141
+ var vertices = Vector_1.Vector.utils.buildArrowHead(zA, zB, headLength, this.scale.x, this.scale.y);
13142
+ var d = ["M", this.offset.x + vertices[0].x, this.offset.y + vertices[0].y];
13143
+ if (arrowHeadBasePositionBuffer) {
13144
+ arrowHeadBasePositionBuffer.x = vertices[0].x / this.scale.x;
13145
+ arrowHeadBasePositionBuffer.y = vertices[0].y / this.scale.y;
13146
+ }
13147
+ for (var i = 1; i <= vertices.length; i++) {
13148
+ d.push("L");
13149
+ // Note: only use offset here (the vertices are already scaled)
13150
+ d.push(this.offset.x + vertices[i % vertices.length].x);
13151
+ d.push(this.offset.y + vertices[i % vertices.length].y);
13152
+ }
13153
+ var node = this.makePathNode(d.join(" "), color, lineWidth, strokeOptions, "arrowhead");
13154
+ return node;
13155
+ };
13156
+ /**
13157
+ * Creates a basic cubic Bézier path node (<path> node) with the given cubic Bézier data. The created node will not
13158
+ * be bound to any root node.
13159
+ *
13160
+ * @private
13161
+ * @method makeCubicBezierNode
13162
+ * @param {XYCoords} startPoint - The start point of the cubic Bézier curve
13163
+ * @param {XYCoords} endPoint - The end point the cubic Bézier curve.
13164
+ * @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
13165
+ * @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
13166
+ * @param {string} color - The CSS color to draw the point with.
13167
+ * @param {number=1} lineWidth - (optional) The line width to use.
13168
+ * @param {StrokeOptions=} strokeOptions - (optional) Additional stroke options to use.
13169
+ * @param {string=} classNameOverride - (optional) If nothing is passed the default classname 'path' will be used.
13170
+ * @param {XYCoords=} arrowHeadBasePositionBuffer - (optional) If not null, then this position will contain the arrow head's start point (after execution). Some sort of OUT variable.
13171
+ * @return {SVGPathElement}
13172
+ * @instance
13173
+ * @memberof drawutilssvg
13174
+ */
13175
+ drawutilssvg.prototype.makeCubicBezierNode = function (startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, strokeOptions) {
13176
+ if (startPoint instanceof CubicBezierCurve_1.CubicBezierCurve) {
13177
+ return this.cubicBezier(startPoint.startPoint, startPoint.endPoint, startPoint.startControlPoint, startPoint.endControlPoint, color, lineWidth);
13178
+ }
13179
+ // Draw curve
13180
+ var d = [
13181
+ "M",
13182
+ this._x(startPoint.x),
13183
+ this._y(startPoint.y),
13184
+ "C",
13185
+ this._x(startControlPoint.x),
13186
+ this._y(startControlPoint.y),
13187
+ this._x(endControlPoint.x),
13188
+ this._y(endControlPoint.y),
13189
+ this._x(endPoint.x),
13190
+ this._y(endPoint.y)
13191
+ ];
13192
+ var node = this.makePathNode(d.join(" "), color, lineWidth, strokeOptions, "cubicBezier");
13193
+ return node;
13194
+ };
12514
13195
  drawutilssvg.HEAD_XML = [
12515
13196
  '<?xml version="1.0" encoding="UTF-8" standalone="no"?>',
12516
13197
  '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" ',