plotboilerplate 1.20.2 → 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 (127) hide show
  1. package/dist/index.esm.js +1985 -1368
  2. package/dist/index.esm.js.map +1 -1
  3. package/dist/index.esm.min.js +1 -1
  4. package/dist/index.esm.min.js.map +1 -1
  5. package/dist/plotboilerplate.browser.min.js +1 -1
  6. package/dist/plotboilerplate.browser.min.js.map +1 -1
  7. package/dist/plotboilerplate.js +1170 -541
  8. package/dist/plotboilerplate.min.js +1 -1
  9. package/package.json +1 -1
  10. package/src/cjs/BezierPath.d.ts +27 -49
  11. package/src/cjs/BezierPath.js +67 -234
  12. package/src/cjs/BezierPath.js.map +1 -1
  13. package/src/cjs/Bounds.d.ts +14 -1
  14. package/src/cjs/Bounds.js +21 -1
  15. package/src/cjs/Bounds.js.map +1 -1
  16. package/src/cjs/CubicBezierCurve.d.ts +70 -1
  17. package/src/cjs/CubicBezierCurve.js +130 -12
  18. package/src/cjs/CubicBezierCurve.js.map +1 -1
  19. package/src/cjs/Line.d.ts +2 -1
  20. package/src/cjs/Line.js +1 -0
  21. package/src/cjs/Line.js.map +1 -1
  22. package/src/cjs/PBText.d.ts +2 -1
  23. package/src/cjs/PBText.js +10 -9
  24. package/src/cjs/PBText.js.map +1 -1
  25. package/src/cjs/PlotBoilerplate.d.ts +4 -13
  26. package/src/cjs/PlotBoilerplate.js +61 -15
  27. package/src/cjs/PlotBoilerplate.js.map +1 -1
  28. package/src/cjs/Polygon.d.ts +35 -1
  29. package/src/cjs/Polygon.js +87 -1
  30. package/src/cjs/Polygon.js.map +1 -1
  31. package/src/cjs/VEllipse.js +1 -1
  32. package/src/cjs/VEllipse.js.map +1 -1
  33. package/src/cjs/Vector.d.ts +4 -4
  34. package/src/cjs/Vector.js +2 -2
  35. package/src/cjs/Vector.js.map +1 -1
  36. package/src/cjs/VertTuple.d.ts +2 -1
  37. package/src/cjs/VertTuple.js +4 -3
  38. package/src/cjs/VertTuple.js.map +1 -1
  39. package/src/cjs/Vertex.d.ts +14 -3
  40. package/src/cjs/Vertex.js +18 -3
  41. package/src/cjs/Vertex.js.map +1 -1
  42. package/src/cjs/draw.d.ts +154 -75
  43. package/src/cjs/draw.js +308 -137
  44. package/src/cjs/draw.js.map +1 -1
  45. package/src/cjs/drawgl.d.ts +87 -50
  46. package/src/cjs/drawgl.js +86 -31
  47. package/src/cjs/drawgl.js.map +1 -1
  48. package/src/cjs/drawutilssvg.d.ts +226 -53
  49. package/src/cjs/drawutilssvg.js +374 -92
  50. package/src/cjs/drawutilssvg.js.map +1 -1
  51. package/src/cjs/interfaces/DrawLib.d.ts +157 -79
  52. package/src/cjs/interfaces/DrawLib.js +6 -0
  53. package/src/cjs/interfaces/DrawLib.js.map +1 -1
  54. package/src/cjs/interfaces/core.d.ts +13 -2
  55. package/src/cjs/interfaces/core.js +1 -0
  56. package/src/cjs/interfaces/core.js.map +1 -1
  57. package/src/cjs/utils/creategui.js +16 -10
  58. package/src/cjs/utils/detectDarkMode.d.ts +10 -0
  59. package/src/cjs/utils/detectDarkMode.js +32 -0
  60. package/src/cjs/utils/detectDarkMode.js.map +1 -0
  61. package/src/esm/BezierPath.d.ts +27 -49
  62. package/src/esm/BezierPath.js +67 -234
  63. package/src/esm/BezierPath.js.map +1 -1
  64. package/src/esm/Bounds.d.ts +14 -1
  65. package/src/esm/Bounds.js +19 -1
  66. package/src/esm/Bounds.js.map +1 -1
  67. package/src/esm/CubicBezierCurve.d.ts +70 -1
  68. package/src/esm/CubicBezierCurve.js +130 -12
  69. package/src/esm/CubicBezierCurve.js.map +1 -1
  70. package/src/esm/Line.d.ts +2 -1
  71. package/src/esm/Line.js +1 -0
  72. package/src/esm/Line.js.map +1 -1
  73. package/src/esm/PBText.d.ts +2 -1
  74. package/src/esm/PBText.js +10 -9
  75. package/src/esm/PBText.js.map +1 -1
  76. package/src/esm/PlotBoilerplate.d.ts +4 -13
  77. package/src/esm/PlotBoilerplate.js +62 -16
  78. package/src/esm/PlotBoilerplate.js.map +1 -1
  79. package/src/esm/Polygon.d.ts +35 -1
  80. package/src/esm/Polygon.js +85 -1
  81. package/src/esm/Polygon.js.map +1 -1
  82. package/src/esm/VEllipse.js +1 -1
  83. package/src/esm/VEllipse.js.map +1 -1
  84. package/src/esm/Vector.d.ts +4 -4
  85. package/src/esm/Vector.js +2 -2
  86. package/src/esm/Vector.js.map +1 -1
  87. package/src/esm/VertTuple.d.ts +2 -1
  88. package/src/esm/VertTuple.js +4 -3
  89. package/src/esm/VertTuple.js.map +1 -1
  90. package/src/esm/Vertex.d.ts +14 -3
  91. package/src/esm/Vertex.js +18 -3
  92. package/src/esm/Vertex.js.map +1 -1
  93. package/src/esm/draw.d.ts +154 -75
  94. package/src/esm/draw.js +304 -135
  95. package/src/esm/draw.js.map +1 -1
  96. package/src/esm/drawgl.d.ts +87 -50
  97. package/src/esm/drawgl.js +86 -31
  98. package/src/esm/drawgl.js.map +1 -1
  99. package/src/esm/drawutilssvg.d.ts +226 -53
  100. package/src/esm/drawutilssvg.js +369 -92
  101. package/src/esm/drawutilssvg.js.map +1 -1
  102. package/src/esm/interfaces/DrawLib.d.ts +157 -79
  103. package/src/esm/interfaces/DrawLib.js +6 -0
  104. package/src/esm/interfaces/DrawLib.js.map +1 -1
  105. package/src/esm/interfaces/core.d.ts +13 -2
  106. package/src/esm/interfaces/core.js +1 -0
  107. package/src/esm/interfaces/core.js.map +1 -1
  108. package/src/esm/utils/detectDarkMode.d.ts +10 -0
  109. package/src/esm/utils/detectDarkMode.js +28 -0
  110. package/src/esm/utils/detectDarkMode.js.map +1 -0
  111. package/src/ts/BezierPath.ts +72 -241
  112. package/src/ts/Bounds.ts +25 -1
  113. package/src/ts/CubicBezierCurve.ts +139 -12
  114. package/src/ts/Line.ts +2 -1
  115. package/src/ts/PBText.ts +10 -9
  116. package/src/ts/PlotBoilerplate.ts +56 -19
  117. package/src/ts/Polygon.ts +91 -1
  118. package/src/ts/VEllipse.ts +2 -2
  119. package/src/ts/Vector.ts +4 -4
  120. package/src/ts/VertTuple.ts +4 -3
  121. package/src/ts/Vertex.ts +20 -4
  122. package/src/ts/draw.ts +311 -115
  123. package/src/ts/drawgl.ts +133 -71
  124. package/src/ts/drawutilssvg.ts +543 -121
  125. package/src/ts/interfaces/DrawLib.ts +219 -83
  126. package/src/ts/interfaces/core.ts +14 -2
  127. 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,7 +1454,7 @@ 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
1457
+ var bezierPath = new BezierPath(); // null); // No points yet
1625
1458
  var startPoint = new Vertex_1.Vertex();
1626
1459
  var startControlPoint;
1627
1460
  var endControlPoint;
@@ -1683,7 +1516,8 @@ exports.BezierPath = BezierPath;
1683
1516
  * @modified 2022-02-01 Added the `toString` function.
1684
1517
  * @modified 2022-10-09 Added the `fromDimension` function.
1685
1518
  * @modified 2022-11-28 Added the `clone` method.
1686
- * @version 1.6.0
1519
+ * @modified 2023-09-29 Added the `randomPoint` method.
1520
+ * @version 1.7.0
1687
1521
  **/
1688
1522
  Object.defineProperty(exports, "__esModule", ({ value: true }));
1689
1523
  exports.Bounds = void 0;
@@ -1733,6 +1567,25 @@ var Bounds = /** @class */ (function () {
1733
1567
  Bounds.prototype.getCenter = function () {
1734
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);
1735
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
+ };
1736
1589
  /**
1737
1590
  * Convert these bounds to a human readable form.
1738
1591
  *
@@ -2211,7 +2064,9 @@ exports.CircleSector = CircleSector;
2211
2064
  * @modified 2022-02-02 Added the `destroy` method.
2212
2065
  * @modified 2022-02-02 Cleared the `toSVGPathData` function (deprecated). Use `drawutilssvg` instead.
2213
2066
  * @modified 2022-10-17 The `CubicBezierCurve` class now implements the new `PathSegment` interface.
2214
- * @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
2215
2070
  *
2216
2071
  * @file CubicBezierCurve
2217
2072
  * @public
@@ -2604,6 +2459,91 @@ var CubicBezierCurve = /** @class */ (function () {
2604
2459
  // Note: my implementation does NOT normalize tangent vectors!
2605
2460
  return new Vertex_1.Vertex(tX, tY);
2606
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
+ };
2607
2547
  /**
2608
2548
  * Get a sub curve at the given start end end offsets (values between 0.0 and 1.0).
2609
2549
  *
@@ -2617,17 +2557,19 @@ var CubicBezierCurve = /** @class */ (function () {
2617
2557
  * @return {CubicBezierCurve} The sub curve as a new curve.
2618
2558
  **/
2619
2559
  CubicBezierCurve.prototype.getSubCurveAt = function (tStart, tEnd) {
2620
- var startVec = new Vector_1.Vector(this.getPointAt(tStart), this.getTangentAt(tStart));
2621
- var endVec = new Vector_1.Vector(this.getPointAt(tEnd), this.getTangentAt(tEnd).inv());
2622
- // Tangents are relative. Make absolute.
2623
- startVec.b.add(startVec.a);
2624
- endVec.b.add(endVec.a);
2625
- // This 'splits' the curve at the given point at t.
2626
- startVec.scale(0.33333333 * (tEnd - tStart));
2627
- endVec.scale(0.33333333 * (tEnd - tStart));
2628
- // Draw the bezier curve
2629
- // pb.draw.cubicBezier( startVec.a, endVec.a, startVec.b, endVec.b, '#8800ff', 2 );
2630
- 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]);
2631
2573
  };
2632
2574
  /**
2633
2575
  * Convert a relative curve position u to the absolute curve position t.
@@ -2879,6 +2821,35 @@ var CubicBezierCurve = /** @class */ (function () {
2879
2821
  CubicBezierCurve.END_CONTROL_POINT = 2;
2880
2822
  /** @constant {number} */
2881
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
+ };
2882
2853
  return CubicBezierCurve;
2883
2854
  }());
2884
2855
  exports.CubicBezierCurve = CubicBezierCurve;
@@ -3444,6 +3415,7 @@ exports.KeyHandler = KeyHandler;
3444
3415
  * @modified 2022-02-02 Added the `destroy` method.
3445
3416
  * @modified 2022-10-09 Changed the actual return value of the `intersection` function to null (was undefined before).
3446
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.
3447
3419
  * @version 2.3.0
3448
3420
  *
3449
3421
  * @file Line
@@ -4085,7 +4057,8 @@ exports.PBImage = PBImage;
4085
4057
  * @author Ikaros Kappler
4086
4058
  * @date 2021-11-16
4087
4059
  * @modified 2022-02-02 Added the `destroy` method.
4088
- * @version 1.1.0
4060
+ * @modified 2023-09-25 Fixed a type error in the constructor. Nothing vital.
4061
+ * @version 1.1.1
4089
4062
  **/
4090
4063
  Object.defineProperty(exports, "__esModule", ({ value: true }));
4091
4064
  exports.PBText = void 0;
@@ -4120,14 +4093,14 @@ var PBText = /** @class */ (function () {
4120
4093
  this.uid = UIDGenerator_1.UIDGenerator.next();
4121
4094
  this.text = text;
4122
4095
  this.anchor = anchor !== null && anchor !== void 0 ? anchor : new Vertex_1.Vertex();
4123
- this.color = options.color;
4124
- this.fontFamily = options.fontFamily;
4125
- this.fontSize = options.fontSize;
4126
- this.fontStyle = options.fontStyle;
4127
- this.fontWeight = options.fontWeight;
4128
- this.lineHeight = options.lineHeight;
4129
- this.textAlign = options.textAlign;
4130
- 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;
4131
4104
  }
4132
4105
  /**
4133
4106
  * This function should invalidate any installed listeners and invalidate this object.
@@ -4234,7 +4207,8 @@ var __webpack_unused_export__;
4234
4207
  * @modified 2023-02-10 Fixing an issue of the `style.position` setting when `fitToParent=true` from `absolute` to `static` (default).
4235
4208
  * @modified 2023-02-10 Cleaning up most type errors in the main class (mostly null checks).
4236
4209
  * @modified 2023-02-10 Adding `enableZoom` and `enablePan` (both default true) to have the option to disable these functions.
4237
- * @version 1.17.2
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
4238
4212
  *
4239
4213
  * @file PlotBoilerplate
4240
4214
  * @fileoverview The main class.
@@ -4374,7 +4348,7 @@ var PlotBoilerplate = /** @class */ (function () {
4374
4348
  draggable: true,
4375
4349
  visible: true
4376
4350
  };
4377
- if (typeof config.canvas == "undefined") {
4351
+ if (typeof config.canvas === "undefined") {
4378
4352
  throw "No canvas specified.";
4379
4353
  }
4380
4354
  /**
@@ -4466,6 +4440,10 @@ var PlotBoilerplate = /** @class */ (function () {
4466
4440
  fill: true
4467
4441
  }
4468
4442
  },
4443
+ // bezierPath: {
4444
+ // color: "#0022a8",
4445
+ // lineWidth: 1
4446
+ // },
4469
4447
  polygon: {
4470
4448
  color: "#0022a8",
4471
4449
  lineWidth: 1
@@ -4525,7 +4503,10 @@ var PlotBoilerplate = /** @class */ (function () {
4525
4503
  // +-------------------------------
4526
4504
  this.grid = new Grid_1.Grid(new Vertex_1.Vertex(0, 0), new Vertex_1.Vertex(50, 50));
4527
4505
  this.canvasSize = { width: PlotBoilerplate.DEFAULT_CANVAS_WIDTH, height: PlotBoilerplate.DEFAULT_CANVAS_HEIGHT };
4528
- 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
+ }
4529
4510
  // Which renderer to use: Canvas2D, WebGL (experimental) or SVG?
4530
4511
  if (canvasElement.tagName.toLowerCase() === "canvas") {
4531
4512
  this.canvas = canvasElement;
@@ -5173,10 +5154,10 @@ var PlotBoilerplate = /** @class */ (function () {
5173
5154
  if (this.drawConfig.drawBezierHandleLines && this.drawConfig.drawHandleLines) {
5174
5155
  draw.setCurrentId(d.uid + "_l0");
5175
5156
  draw.setCurrentClassName(d.className + "-start-line");
5176
- 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);
5177
5158
  draw.setCurrentId(d.uid + "_l1");
5178
5159
  draw.setCurrentClassName(d.className + "-end-line");
5179
- 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);
5180
5161
  }
5181
5162
  curveIndex++;
5182
5163
  } // END for
@@ -5199,11 +5180,11 @@ var PlotBoilerplate = /** @class */ (function () {
5199
5180
  draw.setCurrentId(d.uid + "_e0");
5200
5181
  draw.setCurrentClassName(d.className + "-v-line");
5201
5182
  // draw.line( d.center.clone().add(0,d.axis.y-d.center.y), d.axis, '#c8c8c8' );
5202
- 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");
5203
5184
  draw.setCurrentId(d.uid + "_e1");
5204
5185
  draw.setCurrentClassName(d.className + "-h-line");
5205
5186
  // draw.line( d.center.clone().add(d.axis.x-d.center.x,0), d.axis, '#c8c8c8' );
5206
- 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");
5207
5188
  }
5208
5189
  draw.setCurrentId(d.uid);
5209
5190
  draw.setCurrentClassName("" + d.className);
@@ -6142,22 +6123,35 @@ var PlotBoilerplate = /** @class */ (function () {
6142
6123
  **/
6143
6124
  safeMergeByKeys: function (base, extension) {
6144
6125
  for (var k in extension) {
6145
- if (!extension.hasOwnProperty(k))
6126
+ if (!extension.hasOwnProperty(k)) {
6146
6127
  continue;
6128
+ }
6147
6129
  if (base.hasOwnProperty(k)) {
6148
6130
  var typ = typeof base[k];
6131
+ var extVal = extension[k];
6149
6132
  try {
6150
- if (typ == "boolean")
6151
- base[k] = !!JSON.parse(extension[k]);
6152
- else if (typ == "number")
6153
- base[k] = JSON.parse(extension[k]) * 1;
6154
- 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") {
6155
6146
  base[k] = extension[k];
6156
- else
6147
+ }
6148
+ else {
6149
+ // Probably a sting
6157
6150
  base[k] = extension[k];
6151
+ }
6158
6152
  }
6159
6153
  catch (e) {
6160
- console.error("error in key ", k, extension[k], e);
6154
+ console.error("error in key ", k, extVal, e);
6161
6155
  }
6162
6156
  }
6163
6157
  else {
@@ -6166,6 +6160,31 @@ var PlotBoilerplate = /** @class */ (function () {
6166
6160
  }
6167
6161
  return base;
6168
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
+
6169
6188
  /**
6170
6189
  * A helper function to scale elements (usually the canvas) using CSS.
6171
6190
  *
@@ -6349,7 +6368,10 @@ __webpack_unused_export__ = PlotBoilerplate;
6349
6368
  * @modified 2022-02-02 Added the `destroy` method.
6350
6369
  * @modified 2022-02-02 Cleared the `Polygon.toSVGString` function (deprecated). Use `drawutilssvg` instead.
6351
6370
  * @modified 2022-03-08 Added the `Polygon.clone()` function.
6352
- * @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
6353
6375
  *
6354
6376
  * @file Polygon
6355
6377
  * @public
@@ -6358,6 +6380,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
6358
6380
  exports.Polygon = void 0;
6359
6381
  var BezierPath_1 = __webpack_require__(126);
6360
6382
  var Bounds_1 = __webpack_require__(262);
6383
+ var Line_1 = __webpack_require__(831);
6361
6384
  var UIDGenerator_1 = __webpack_require__(197);
6362
6385
  var Vertex_1 = __webpack_require__(421);
6363
6386
  /**
@@ -6557,6 +6580,88 @@ var Polygon = /** @class */ (function () {
6557
6580
  }
6558
6581
  return this;
6559
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
+ };
6560
6665
  /**
6561
6666
  * Convert this polygon into a new polygon with n evenly distributed vertices.
6562
6667
  *
@@ -7586,7 +7691,7 @@ var VEllipse = /** @class */ (function () {
7586
7691
  else {
7587
7692
  var startTangent = this.tangentAt(curAngle);
7588
7693
  var endTangent = this.tangentAt(nextAngle);
7589
- // Find intersection
7694
+ // Find intersection (ignore that the result might be null in some extreme cases)
7590
7695
  var intersection = startTangent.intersection(endTangent);
7591
7696
  // What if intersection is undefined?
7592
7697
  // --> This *can* not happen if segmentCount > 2 and height and width of the ellipse are not zero.
@@ -8131,8 +8236,8 @@ var Vector = /** @class */ (function (_super) {
8131
8236
  * Example:
8132
8237
  * buildArrowHead( new Vertex(0,0), new Vertex(50,100), 8, 1.0, 1.0 )
8133
8238
  *
8134
- * @param {Vertex} zA - The start vertex of the vector to calculate the arrow head for.
8135
- * @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.
8136
8241
  * @param {number} headlen - The length of the arrow head (along the vector direction. A good value is 12).
8137
8242
  * @param {number} scaleX - The horizontal scaling during draw.
8138
8243
  * @param {number} scaleY - the vertical scaling during draw.
@@ -8169,7 +8274,8 @@ exports.Vector = Vector;
8169
8274
  * @modified 2020-12-04 Added the `hasPoint(XYCoords)` function.
8170
8275
  * @modified 2021-01-20 Added UID.
8171
8276
  * @modified 2022-02-02 Added the `destroy` method.
8172
- * @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
8173
8279
  */
8174
8280
  Object.defineProperty(exports, "__esModule", ({ value: true }));
8175
8281
  exports.VertTuple = void 0;
@@ -8387,12 +8493,12 @@ var VertTuple = /** @class */ (function () {
8387
8493
  VertTuple.prototype.hasPoint = function (point, insideBoundsOnly) {
8388
8494
  var t = this.getClosestT(point);
8389
8495
  // Compare to pointDistance?
8496
+ var distance = Math.sqrt(VertTuple.vtutils.dist2(point, this.vertAt(t)));
8390
8497
  if (typeof insideBoundsOnly !== "undefined" && insideBoundsOnly) {
8391
- var distance = Math.sqrt(VertTuple.vtutils.dist2(point, this.vertAt(t)));
8392
8498
  return distance < Vertex_1.Vertex.EPSILON && t >= 0 && t <= 1;
8393
8499
  }
8394
8500
  else {
8395
- return t >= 0 && t <= 1;
8501
+ return distance < Vertex_1.Vertex.EPSILON; // t >= 0 && t <= 1;
8396
8502
  }
8397
8503
  };
8398
8504
  /**
@@ -8504,6 +8610,8 @@ exports.VertTuple = VertTuple;
8504
8610
  * @modified 2022-02-02 Added the `destroy` method.
8505
8611
  * @modified 2022-02-02 Cleared the `Vertex.toSVGString` function (deprecated). Use `drawutilssvg` instead.
8506
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.
8507
8615
  * @version 2.8.0
8508
8616
  *
8509
8617
  * @file Vertex
@@ -9025,6 +9133,19 @@ var Vertex = /** @class */ (function () {
9025
9133
  this.y = -this.y;
9026
9134
  return this;
9027
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
+ };
9028
9149
  /**
9029
9150
  * Get a string representation of this vertex.
9030
9151
  *
@@ -9082,15 +9203,15 @@ var Vertex = /** @class */ (function () {
9082
9203
  * Example:
9083
9204
  * buildArrowHead( new Vertex(0,0), new Vertex(50,100), 8, 1.0, 1.0 )
9084
9205
  *
9085
- * @param {Vertex} zA - The start vertex of the vector to calculate the arrow head for.
9086
- * @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.
9087
9208
  * @param {number} headlen - The length of the arrow head (along the vector direction. A good value is 12).
9088
9209
  * @param {number} scaleX - The horizontal scaling during draw.
9089
9210
  * @param {number} scaleY - the vertical scaling during draw.
9090
9211
  **/
9091
9212
  // @DEPRECATED: use Vector.utils.buildArrowHead instead!!!
9092
9213
  buildArrowHead: function (zA, zB, headlen, scaleX, scaleY) {
9093
- // 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.");
9094
9215
  var angle = Math.atan2((zB.y - zA.y) * scaleY, (zB.x - zA.x) * scaleX);
9095
9216
  var vertices = [];
9096
9217
  vertices.push(new Vertex(zB.x * scaleX - headlen * Math.cos(angle), zB.y * scaleY - headlen * Math.sin(angle)));
@@ -9511,13 +9632,22 @@ exports.VertexListeners = VertexListeners;
9511
9632
  * @modified 2022-08-23 Fixed a type issue in the `setConfiguration` function.
9512
9633
  * @modified 2022-08-23 Fixed a type issue in the `path` function.
9513
9634
  * @modified 2023-02-10 The methods `setCurrentClassName` and `setCurrentId` also accept `null` now.
9514
- * @version 1.12.4
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
9515
9644
  **/
9516
9645
  Object.defineProperty(exports, "__esModule", ({ value: true }));
9517
9646
  exports.drawutils = void 0;
9518
9647
  var CubicBezierCurve_1 = __webpack_require__(510);
9519
9648
  var Vertex_1 = __webpack_require__(421);
9520
9649
  var drawutilssvg_1 = __webpack_require__(829);
9650
+ var Vector_1 = __webpack_require__(73);
9521
9651
  // Todo: rename this class to Drawutils?
9522
9652
  /**
9523
9653
  * @classdesc A wrapper class for basic drawing operations.
@@ -9538,10 +9668,48 @@ var drawutils = /** @class */ (function () {
9538
9668
  **/
9539
9669
  function drawutils(context, fillShapes) {
9540
9670
  this.ctx = context;
9671
+ // this.lineDash = [];
9541
9672
  this.offset = new Vertex_1.Vertex(0, 0);
9542
9673
  this.scale = new Vertex_1.Vertex(1, 1);
9543
9674
  this.fillShapes = fillShapes;
9544
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
+ };
9545
9713
  /**
9546
9714
  * Called before each draw cycle.
9547
9715
  * @param {UID=} uid - (optional) A UID identifying the currently drawn element(s).
@@ -9572,6 +9740,20 @@ var drawutils = /** @class */ (function () {
9572
9740
  drawutils.prototype.setConfiguration = function (configuration) {
9573
9741
  this.ctx.globalCompositeOperation = configuration.blendMode || "source-over";
9574
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
+ // }
9575
9757
  /**
9576
9758
  * This method shouled be called each time the currently drawn `Drawable` changes.
9577
9759
  * It is used by some libraries for identifying elemente on re-renders.
@@ -9598,17 +9780,20 @@ var drawutils = /** @class */ (function () {
9598
9780
  * Draw the line between the given two points with the specified (CSS-) color.
9599
9781
  *
9600
9782
  * @method line
9601
- * @param {Vertex} zA - The start point of the line.
9602
- * @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.
9603
9785
  * @param {string} color - Any valid CSS color string.
9604
9786
  * @param {number} lineWidth? - [optional] The line's width.
9787
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
9788
+ *
9605
9789
  * @return {void}
9606
9790
  * @instance
9607
9791
  * @memberof drawutils
9608
9792
  **/
9609
- drawutils.prototype.line = function (zA, zB, color, lineWidth) {
9793
+ drawutils.prototype.line = function (zA, zB, color, lineWidth, strokeOptions) {
9610
9794
  this.ctx.save();
9611
9795
  this.ctx.beginPath();
9796
+ this.applyStrokeOpts(strokeOptions);
9612
9797
  this.ctx.moveTo(this.offset.x + zA.x * this.scale.x, this.offset.y + zA.y * this.scale.y);
9613
9798
  this.ctx.lineTo(this.offset.x + zB.x * this.scale.x, this.offset.y + zB.y * this.scale.y);
9614
9799
  this.ctx.strokeStyle = color;
@@ -9620,22 +9805,76 @@ var drawutils = /** @class */ (function () {
9620
9805
  * Draw a line and an arrow at the end (zB) of the given line with the specified (CSS-) color.
9621
9806
  *
9622
9807
  * @method arrow
9623
- * @param {Vertex} zA - The start point of the arrow-line.
9624
- * @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.
9625
9810
  * @param {string} color - Any valid CSS color string.
9626
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
+ *
9627
9815
  * @return {void}
9628
9816
  * @instance
9629
9817
  * @memberof drawutils
9630
9818
  **/
9631
- drawutils.prototype.arrow = function (zA, zB, color, lineWidth) {
9632
- var headlen = 8; // length of head in pixels
9633
- // var vertices = PlotBoilerplate.utils.buildArrowHead( zA, zB, headlen, this.scale.x, this.scale.y );
9634
- // 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; }
9635
9869
  this.ctx.save();
9636
9870
  this.ctx.beginPath();
9637
- var vertices = Vertex_1.Vertex.utils.buildArrowHead(zA, zB, headlen, this.scale.x, this.scale.y);
9638
- 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);
9639
9878
  for (var i = 0; i < vertices.length; i++) {
9640
9879
  this.ctx.lineTo(this.offset.x + vertices[i].x, this.offset.y + vertices[i].y);
9641
9880
  }
@@ -9651,8 +9890,8 @@ var drawutils = /** @class */ (function () {
9651
9890
  *
9652
9891
  * @method image
9653
9892
  * @param {Image} image - The image object to draw.
9654
- * @param {Vertex} position - The position to draw the the upper left corner at.
9655
- * @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.
9656
9895
  * @param {number=0.0} alpha - (optional, default=0.0) The transparency (1.0=opaque, 0.0=transparent).
9657
9896
  * @return {void}
9658
9897
  * @instance
@@ -9682,7 +9921,7 @@ var drawutils = /** @class */ (function () {
9682
9921
  * @param {Image} textureImage - The image object to draw.
9683
9922
  * @param {Bounds} textureSize - The texture size to use; these are the original bounds to map the polygon vertices to.
9684
9923
  * @param {Polygon} polygon - The polygon to use as clip path.
9685
- * @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.
9686
9925
  * @param {number} rotation - The rotation to use for the polygon (and for the texture).
9687
9926
  * @param {XYCoords={x:0,y:0}} rotationCenter - (optional) The rotational center; default is center of bounding box.
9688
9927
  * @return {void}
@@ -9691,10 +9930,9 @@ var drawutils = /** @class */ (function () {
9691
9930
  **/
9692
9931
  drawutils.prototype.texturedPoly = function (textureImage, textureSize, polygon, polygonPosition, rotation) {
9693
9932
  var basePolygonBounds = polygon.getBounds();
9694
- var targetCenterDifference = polygonPosition.clone().difference(basePolygonBounds.getCenter());
9695
- // var rotationalOffset = rotationCenter ? polygonPosition.difference(rotationCenter) : { x: 0, y: 0 };
9696
- // var rotationalOffset = { x: 0, y: 0 };
9697
- 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);
9698
9936
  // Get the position offset of the polygon
9699
9937
  var targetTextureSize = new Vertex_1.Vertex(textureSize.width, textureSize.height);
9700
9938
  // var targetTextureOffset = new Vertex(-textureSize.width / 2, -textureSize.height / 2).sub(targetCenterDifference);
@@ -9717,53 +9955,83 @@ var drawutils = /** @class */ (function () {
9717
9955
  );
9718
9956
  this.ctx.restore();
9719
9957
  };
9720
- drawutils.prototype._texturedPoly = function (textureImage, textureSize, polygon, polygonPosition, rotation, rotationCenter) {
9721
- if (rotationCenter === void 0) { rotationCenter = { x: 0, y: 0 }; }
9722
- var basePolygonBounds = polygon.getBounds();
9723
- var targetCenterDifference = polygonPosition.clone().difference(basePolygonBounds.getCenter());
9724
- var rotationalOffset = rotationCenter ? polygonPosition.difference(rotationCenter) : { x: 0, y: 0 };
9725
- // var rotationalOffset = { x: 0, y: 0 };
9726
- var tileCenter = basePolygonBounds.getCenter().sub(targetCenterDifference);
9727
- // Get the position offset of the polygon
9728
- var targetTextureSize = new Vertex_1.Vertex(textureSize.width, textureSize.height);
9729
- var targetTextureOffset = new Vertex_1.Vertex(-textureSize.width / 2, -textureSize.height / 2).sub(targetCenterDifference);
9730
- this.ctx.save();
9731
- // this.ctx.translate(
9732
- // this.offset.x + (tileCenter.x - rotationalOffset.x * 0 + targetTextureOffset.x * 0.0) * this.scale.x,
9733
- // this.offset.y + (tileCenter.y - rotationalOffset.y * 0 + targetTextureOffset.y * 0.0) * this.scale.y
9734
- // );
9735
- 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);
9736
- this.ctx.rotate(rotation);
9737
- drawutils.helpers.clipPoly(this.ctx, {
9738
- x: (-targetCenterDifference.x * 1 - tileCenter.x - rotationalOffset.x) * this.scale.x,
9739
- y: (-targetCenterDifference.y * 1 - tileCenter.y - rotationalOffset.y) * this.scale.y
9740
- }, this.scale, polygon.vertices);
9741
- 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)
9742
10003
  textureImage.naturalHeight - 1, // To avoid errors substract 1 here.
9743
- (-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);
9744
- // const scaledTextureSize = new Bounds(
9745
- // new Vertex(
9746
- // -polygonPosition.x + targetTextureOffset.x - rotationalOffset.x,
9747
- // -polygonPosition.y + targetTextureOffset.y - rotationalOffset.y
9748
- // ).scaleXY(this.scale, rotationCenter),
9749
- // new Vertex(
9750
- // -polygonPosition.x + targetTextureOffset.x - rotationalOffset.x + targetTextureSize.x,
9751
- // -polygonPosition.y + targetTextureOffset.y - rotationalOffset.y + targetTextureSize.y
9752
- // ).scaleXY(this.scale, rotationCenter)
9753
- // );
9754
- // this.ctx.drawImage(
9755
- // textureImage,
9756
- // 0,
9757
- // 0,
9758
- // textureImage.naturalWidth - 1, // There is this horrible Safari bug (fixed in newer versions)
9759
- // textureImage.naturalHeight - 1, // To avoid errors substract 1 here.
9760
- // scaledTextureSize.min.x,
9761
- // scaledTextureSize.min.y,
9762
- // scaledTextureSize.width,
9763
- // scaledTextureSize.height
9764
- // );
9765
- this.ctx.restore();
9766
- };
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
+ */
9767
10035
  /**
9768
10036
  * Draw a rectangle.
9769
10037
  *
@@ -9772,10 +10040,16 @@ var drawutils = /** @class */ (function () {
9772
10040
  * @param {number} height - The height of the rectangle.
9773
10041
  * @param {string} color - The color to use.
9774
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
9775
10048
  **/
9776
- drawutils.prototype.rect = function (position, width, height, color, lineWidth) {
10049
+ drawutils.prototype.rect = function (position, width, height, color, lineWidth, strokeOptions) {
9777
10050
  this.ctx.save();
9778
10051
  this.ctx.beginPath();
10052
+ this.applyStrokeOpts(strokeOptions);
9779
10053
  this.ctx.moveTo(this.offset.x + position.x * this.scale.x, this.offset.y + position.y * this.scale.y);
9780
10054
  this.ctx.lineTo(this.offset.x + (position.x + width) * this.scale.x, this.offset.y + position.y * this.scale.y);
9781
10055
  this.ctx.lineTo(this.offset.x + (position.x + width) * this.scale.x, this.offset.y + (position.y + height) * this.scale.y);
@@ -9786,43 +10060,23 @@ var drawutils = /** @class */ (function () {
9786
10060
  this._fillOrDraw(color);
9787
10061
  this.ctx.restore();
9788
10062
  };
9789
- // +---------------------------------------------------------------------------------
9790
- // | This is the final helper function for drawing and filling stuff. It is not
9791
- // | intended to be used from the outside.
9792
- // |
9793
- // | When in draw mode it draws the current shape.
9794
- // | When in fill mode it fills the current shape.
9795
- // |
9796
- // | This function is usually only called internally.
9797
- // |
9798
- // | @param color A stroke/fill color to use.
9799
- // +-------------------------------
9800
- // TODO: convert this to a STATIC function.
9801
- drawutils.prototype._fillOrDraw = function (color) {
9802
- if (this.fillShapes) {
9803
- this.ctx.fillStyle = color;
9804
- this.ctx.fill();
9805
- }
9806
- else {
9807
- this.ctx.strokeStyle = color;
9808
- this.ctx.stroke();
9809
- }
9810
- };
9811
10063
  /**
9812
10064
  * Draw the given (cubic) bézier curve.
9813
10065
  *
9814
10066
  * @method cubicBezier
9815
- * @param {Vertex} startPoint - The start point of the cubic Bézier curve
9816
- * @param {Vertex} endPoint - The end point the cubic Bézier curve.
9817
- * @param {Vertex} startControlPoint - The start control point the cubic Bézier curve.
9818
- * @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.
9819
10071
  * @param {string} color - The CSS color to draw the curve with.
9820
10072
  * @param {number} lineWidth - (optional) The line width to use.
10073
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
10074
+ *
9821
10075
  * @return {void}
9822
10076
  * @instance
9823
10077
  * @memberof drawutils
9824
10078
  */
9825
- drawutils.prototype.cubicBezier = function (startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth) {
10079
+ drawutils.prototype.cubicBezier = function (startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, strokeOptions) {
9826
10080
  if (startPoint instanceof CubicBezierCurve_1.CubicBezierCurve) {
9827
10081
  this.cubicBezier(startPoint.startPoint, startPoint.endPoint, startPoint.startControlPoint, startPoint.endControlPoint, color, lineWidth);
9828
10082
  return;
@@ -9830,6 +10084,7 @@ var drawutils = /** @class */ (function () {
9830
10084
  // Draw curve
9831
10085
  this.ctx.save();
9832
10086
  this.ctx.beginPath();
10087
+ this.applyStrokeOpts(strokeOptions);
9833
10088
  this.ctx.moveTo(this.offset.x + startPoint.x * this.scale.x, this.offset.y + startPoint.y * this.scale.y);
9834
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);
9835
10090
  //this.ctx.closePath();
@@ -9841,19 +10096,22 @@ var drawutils = /** @class */ (function () {
9841
10096
  * Draw the given (quadratic) bézier curve.
9842
10097
  *
9843
10098
  * @method quadraticBezier
9844
- * @param {Vertex} startPoint - The start point of the cubic Bézier curve
9845
- * @param {Vertex} controlPoint - The control point the cubic Bézier curve.
9846
- * @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.
9847
10102
  * @param {string} color - The CSS color to draw the curve with.
9848
10103
  * @param {number|string} lineWidth - (optional) The line width to use.
10104
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
10105
+ *
9849
10106
  * @return {void}
9850
10107
  * @instance
9851
10108
  * @memberof drawutils
9852
10109
  */
9853
- drawutils.prototype.quadraticBezier = function (startPoint, controlPoint, endPoint, color, lineWidth) {
10110
+ drawutils.prototype.quadraticBezier = function (startPoint, controlPoint, endPoint, color, lineWidth, strokeOptions) {
9854
10111
  // Draw curve
9855
10112
  this.ctx.save();
9856
10113
  this.ctx.beginPath();
10114
+ this.applyStrokeOpts(strokeOptions);
9857
10115
  this.ctx.moveTo(this.offset.x + startPoint.x * this.scale.x, this.offset.y + startPoint.y * this.scale.y);
9858
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);
9859
10117
  this.ctx.lineWidth = lineWidth || 2;
@@ -9868,22 +10126,26 @@ var drawutils = /** @class */ (function () {
9868
10126
  * <pre> [ point1, point1_startControl, point2_endControl, point2, point2_startControl, point3_endControl, point3, ... pointN_endControl, pointN ]</pre>
9869
10127
  *
9870
10128
  * @method cubicBezierPath
9871
- * @param {Vertex[]} path - The cubic bezier path as described above.
10129
+ * @param {XYCoords[]} path - The cubic bezier path as described above.
9872
10130
  * @param {string} color - The CSS colot to draw the path with.
9873
10131
  * @param {number=1} lineWidth - (optional) The line width to use.
10132
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
10133
+ *
9874
10134
  * @return {void}
9875
10135
  * @instance
9876
10136
  * @memberof drawutils
9877
10137
  */
9878
- drawutils.prototype.cubicBezierPath = function (path, color, lineWidth) {
9879
- if (!path || path.length == 0)
10138
+ drawutils.prototype.cubicBezierPath = function (path, color, lineWidth, strokeOptions) {
10139
+ if (!path || path.length == 0) {
9880
10140
  return;
10141
+ }
9881
10142
  // Draw curve
9882
10143
  this.ctx.save();
9883
10144
  this.ctx.beginPath();
9884
10145
  var endPoint;
9885
10146
  var startControlPoint;
9886
10147
  var endControlPoint;
10148
+ this.applyStrokeOpts(strokeOptions);
9887
10149
  this.ctx.moveTo(this.offset.x + path[0].x * this.scale.x, this.offset.y + path[0].y * this.scale.y);
9888
10150
  for (var i = 1; i < path.length; i += 3) {
9889
10151
  startControlPoint = path[i];
@@ -9902,8 +10164,8 @@ var drawutils = /** @class */ (function () {
9902
10164
  * The colors for this are fixed and cannot be specified.
9903
10165
  *
9904
10166
  * @method handle
9905
- * @param {Vertex} startPoint - The start of the handle.
9906
- * @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.
9907
10169
  * @return {void}
9908
10170
  * @instance
9909
10171
  * @memberof drawutils
@@ -9918,21 +10180,21 @@ var drawutils = /** @class */ (function () {
9918
10180
  * Draw a handle line (with a light grey).
9919
10181
  *
9920
10182
  * @method handleLine
9921
- * @param {Vertex} startPoint - The start point to draw the handle at.
9922
- * @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.
9923
10185
  * @return {void}
9924
10186
  * @instance
9925
10187
  * @memberof drawutils
9926
10188
  */
9927
10189
  drawutils.prototype.handleLine = function (startPoint, endPoint) {
9928
10190
  // Draw handle lines
9929
- this.line(startPoint, endPoint, "rgb(192,192,192)");
10191
+ this.line(startPoint, endPoint, "rgba(128,128,128, 0.5)", undefined);
9930
10192
  };
9931
10193
  /**
9932
10194
  * Draw a 1x1 dot with the specified (CSS-) color.
9933
10195
  *
9934
10196
  * @method dot
9935
- * @param {Vertex} p - The position to draw the dot at.
10197
+ * @param {XYCoords} p - The position to draw the dot at.
9936
10198
  * @param {string} color - The CSS color to draw the dot with.
9937
10199
  * @return {void}
9938
10200
  * @instance
@@ -9941,6 +10203,7 @@ var drawutils = /** @class */ (function () {
9941
10203
  drawutils.prototype.dot = function (p, color) {
9942
10204
  this.ctx.save();
9943
10205
  this.ctx.beginPath();
10206
+ this.ctx.setLineDash([]); // Clear line-dash settings
9944
10207
  this.ctx.moveTo(Math.round(this.offset.x + this.scale.x * p.x), Math.round(this.offset.y + this.scale.y * p.y));
9945
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));
9946
10209
  this.ctx.closePath();
@@ -9952,7 +10215,7 @@ var drawutils = /** @class */ (function () {
9952
10215
  * Draw the given point with the specified (CSS-) color and radius 3.
9953
10216
  *
9954
10217
  * @method point
9955
- * @param {Vertex} p - The position to draw the point at.
10218
+ * @param {XYCoords} p - The position to draw the point at.
9956
10219
  * @param {string} color - The CSS color to draw the point with.
9957
10220
  * @return {void}
9958
10221
  * @instance
@@ -9960,6 +10223,7 @@ var drawutils = /** @class */ (function () {
9960
10223
  */
9961
10224
  drawutils.prototype.point = function (p, color) {
9962
10225
  var radius = 3;
10226
+ this.ctx.setLineDash([]); // Clear line-dash settings
9963
10227
  this.ctx.beginPath();
9964
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);
9965
10229
  this.ctx.closePath();
@@ -9972,15 +10236,18 @@ var drawutils = /** @class */ (function () {
9972
10236
  * Note that if the x- and y- scales are different the result will be an ellipse rather than a circle.
9973
10237
  *
9974
10238
  * @method circle
9975
- * @param {Vertex} center - The center of the circle.
10239
+ * @param {XYCoords} center - The center of the circle.
9976
10240
  * @param {number} radius - The radius of the circle.
9977
10241
  * @param {string} color - The CSS color to draw the circle with.
9978
10242
  * @param {number} lineWidth - The line width (optional, default=1).
10243
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
10244
+ *
9979
10245
  * @return {void}
9980
10246
  * @instance
9981
10247
  * @memberof drawutils
9982
10248
  */
9983
- drawutils.prototype.circle = function (center, radius, color, lineWidth) {
10249
+ drawutils.prototype.circle = function (center, radius, color, lineWidth, strokeOptions) {
10250
+ this.applyStrokeOpts(strokeOptions);
9984
10251
  this.ctx.beginPath();
9985
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);
9986
10253
  this.ctx.closePath();
@@ -9988,24 +10255,28 @@ var drawutils = /** @class */ (function () {
9988
10255
  this._fillOrDraw(color);
9989
10256
  };
9990
10257
  /**
9991
- * Draw a circular arc (section of a circle) with the given CSS color.
9992
- *
9993
- * @method circleArc
9994
- * @param {Vertex} center - The center of the circle.
9995
- * @param {number} radius - The radius of the circle.
9996
- * @param {number} startAngle - The angle to start at.
9997
- * @param {number} endAngle - The angle to end at.
9998
- * @param {string=#000000} color - The CSS color to draw the circle with.
9999
- * @param {number=1} lineWidth - The line width to use
10000
- // * @param {boolean=false} options.asSegment - If `true` then no beginPath and no draw will be applied (as part of larger path).
10001
- * @return {void}
10002
- * @instance
10003
- * @memberof drawutils
10004
- */
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
+ */
10005
10275
  drawutils.prototype.circleArc = function (center, radius, startAngle, endAngle, color, lineWidth, options) {
10006
10276
  if (!options || !options.asSegment) {
10007
10277
  this.ctx.beginPath();
10008
10278
  }
10279
+ this.applyStrokeOpts(options);
10009
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);
10010
10281
  if (!options || !options.asSegment) {
10011
10282
  // this.ctx.closePath();
@@ -10017,20 +10288,23 @@ var drawutils = /** @class */ (function () {
10017
10288
  * Draw an ellipse with the specified (CSS-) color and thw two radii.
10018
10289
  *
10019
10290
  * @method ellipse
10020
- * @param {Vertex} center - The center of the ellipse.
10291
+ * @param {XYCoords} center - The center of the ellipse.
10021
10292
  * @param {number} radiusX - The radius of the ellipse.
10022
10293
  * @param {number} radiusY - The radius of the ellipse.
10023
10294
  * @param {string} color - The CSS color to draw the ellipse with.
10024
10295
  * @param {number} lineWidth=1 - An optional line width param (default is 1).
10025
10296
  * @param {number=} rotation - (optional, default=0) The rotation of the ellipse.
10297
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
10298
+ *
10026
10299
  * @return {void}
10027
10300
  * @instance
10028
10301
  * @memberof drawutils
10029
10302
  */
10030
- drawutils.prototype.ellipse = function (center, radiusX, radiusY, color, lineWidth, rotation) {
10303
+ drawutils.prototype.ellipse = function (center, radiusX, radiusY, color, lineWidth, rotation, strokeOptions) {
10031
10304
  if (typeof rotation === "undefined") {
10032
10305
  rotation = 0.0;
10033
10306
  }
10307
+ this.applyStrokeOpts(strokeOptions);
10034
10308
  this.ctx.beginPath();
10035
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);
10036
10310
  this.ctx.closePath();
@@ -10047,11 +10321,14 @@ var drawutils = /** @class */ (function () {
10047
10321
  * @param {number} size - The size of the square.
10048
10322
  * @param {string} color - The CSS color to draw the square with.
10049
10323
  * @param {number} lineWidth - The line with to use (optional, default is 1).
10324
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
10325
+ *
10050
10326
  * @return {void}
10051
10327
  * @instance
10052
10328
  * @memberof drawutils
10053
10329
  */
10054
- drawutils.prototype.square = function (center, size, color, lineWidth) {
10330
+ drawutils.prototype.square = function (center, size, color, lineWidth, strokeOptions) {
10331
+ this.applyStrokeOpts(strokeOptions);
10055
10332
  this.ctx.beginPath();
10056
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);
10057
10334
  this.ctx.closePath();
@@ -10062,7 +10339,7 @@ var drawutils = /** @class */ (function () {
10062
10339
  * Draw a grid of horizontal and vertical lines with the given (CSS-) color.
10063
10340
  *
10064
10341
  * @method grid
10065
- * @param {Vertex} center - The center of the grid.
10342
+ * @param {XYCoords} center - The center of the grid.
10066
10343
  * @param {number} width - The total width of the grid (width/2 each to the left and to the right).
10067
10344
  * @param {number} height - The total height of the grid (height/2 each to the top and to the bottom).
10068
10345
  * @param {number} sizeX - The horizontal grid size.
@@ -10073,6 +10350,7 @@ var drawutils = /** @class */ (function () {
10073
10350
  * @memberof drawutils
10074
10351
  */
10075
10352
  drawutils.prototype.grid = function (center, width, height, sizeX, sizeY, color) {
10353
+ this.ctx.setLineDash([]); // Clear line-dash settings
10076
10354
  this.ctx.beginPath();
10077
10355
  var yMin = -Math.ceil((height * 0.5) / sizeY) * sizeY;
10078
10356
  var yMax = height / 2;
@@ -10097,7 +10375,7 @@ var drawutils = /** @class */ (function () {
10097
10375
  * This works analogue to the grid() function
10098
10376
  *
10099
10377
  * @method raster
10100
- * @param {Vertex} center - The center of the raster.
10378
+ * @param {XYCoords} center - The center of the raster.
10101
10379
  * @param {number} width - The total width of the raster (width/2 each to the left and to the right).
10102
10380
  * @param {number} height - The total height of the raster (height/2 each to the top and to the bottom).
10103
10381
  * @param {number} sizeX - The horizontal raster size.
@@ -10109,6 +10387,7 @@ var drawutils = /** @class */ (function () {
10109
10387
  */
10110
10388
  drawutils.prototype.raster = function (center, width, height, sizeX, sizeY, color) {
10111
10389
  this.ctx.save();
10390
+ this.ctx.setLineDash([]); // Clear line-dash settings
10112
10391
  this.ctx.beginPath();
10113
10392
  for (var x = -Math.ceil((width * 0.5) / sizeX) * sizeX; x < width / 2; x += sizeX) {
10114
10393
  for (var y = -Math.ceil((height * 0.5) / sizeY) * sizeY; y < height / 2; y += sizeY) {
@@ -10133,14 +10412,15 @@ var drawutils = /** @class */ (function () {
10133
10412
  * as even shaped diamonds.
10134
10413
  *
10135
10414
  * @method diamondHandle
10136
- * @param {Vertex} center - The center of the diamond.
10137
- * @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.
10138
10417
  * @param {string} color - The CSS color to draw the diamond with.
10139
10418
  * @return {void}
10140
10419
  * @instance
10141
10420
  * @memberof drawutils
10142
10421
  */
10143
10422
  drawutils.prototype.diamondHandle = function (center, size, color) {
10423
+ this.ctx.setLineDash([]); // Clear line-dash settings
10144
10424
  this.ctx.beginPath();
10145
10425
  this.ctx.moveTo(this.offset.x + center.x * this.scale.x - size / 2.0, this.offset.y + center.y * this.scale.y);
10146
10426
  this.ctx.lineTo(this.offset.x + center.x * this.scale.x, this.offset.y + center.y * this.scale.y - size / 2.0);
@@ -10158,14 +10438,15 @@ var drawutils = /** @class */ (function () {
10158
10438
  * as even shaped squares.
10159
10439
  *
10160
10440
  * @method squareHandle
10161
- * @param {Vertex} center - The center of the square.
10162
- * @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.
10163
10443
  * @param {string} color - The CSS color to draw the square with.
10164
10444
  * @return {void}
10165
10445
  * @instance
10166
10446
  * @memberof drawutils
10167
10447
  */
10168
10448
  drawutils.prototype.squareHandle = function (center, size, color) {
10449
+ this.ctx.setLineDash([]); // Clear line-dash settings
10169
10450
  this.ctx.beginPath();
10170
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);
10171
10452
  this.ctx.closePath();
@@ -10180,7 +10461,7 @@ var drawutils = /** @class */ (function () {
10180
10461
  * as even shaped circles.
10181
10462
  *
10182
10463
  * @method circleHandle
10183
- * @param {Vertex} center - The center of the circle.
10464
+ * @param {XYCoords} center - The center of the circle.
10184
10465
  * @param {number} radius - The radius of the circle.
10185
10466
  * @param {string} color - The CSS color to draw the circle with.
10186
10467
  * @return {void}
@@ -10189,6 +10470,7 @@ var drawutils = /** @class */ (function () {
10189
10470
  */
10190
10471
  drawutils.prototype.circleHandle = function (center, radius, color) {
10191
10472
  radius = radius || 3;
10473
+ this.ctx.setLineDash([]); // Clear line-dash settings
10192
10474
  this.ctx.beginPath();
10193
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);
10194
10476
  this.ctx.closePath();
@@ -10211,6 +10493,7 @@ var drawutils = /** @class */ (function () {
10211
10493
  */
10212
10494
  drawutils.prototype.crosshair = function (center, radius, color, lineWidth) {
10213
10495
  this.ctx.save();
10496
+ this.ctx.setLineDash([]); // Clear line-dash settings
10214
10497
  this.ctx.beginPath();
10215
10498
  this.ctx.moveTo(this.offset.x + center.x * this.scale.x - radius, this.offset.y + center.y * this.scale.y);
10216
10499
  this.ctx.lineTo(this.offset.x + center.x * this.scale.x + radius, this.offset.y + center.y * this.scale.y);
@@ -10238,6 +10521,7 @@ var drawutils = /** @class */ (function () {
10238
10521
  */
10239
10522
  drawutils.prototype.cross = function (center, radius, color, lineWidth) {
10240
10523
  this.ctx.save();
10524
+ this.ctx.setLineDash([]); // Clear line-dash settings
10241
10525
  this.ctx.beginPath();
10242
10526
  this.ctx.moveTo(this.offset.x + center.x * this.scale.x - radius, this.offset.y + center.y * this.scale.y - radius);
10243
10527
  this.ctx.lineTo(this.offset.x + center.x * this.scale.x + radius, this.offset.y + center.y * this.scale.y + radius);
@@ -10256,30 +10540,35 @@ var drawutils = /** @class */ (function () {
10256
10540
  * @param {Polygon} polygon - The polygon to draw.
10257
10541
  * @param {string} color - The CSS color to draw the polygon with.
10258
10542
  * @param {string} lineWidth - The line width to use.
10543
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
10544
+ *
10259
10545
  * @return {void}
10260
10546
  * @instance
10261
10547
  * @memberof drawutils
10262
10548
  */
10263
- drawutils.prototype.polygon = function (polygon, color, lineWidth) {
10264
- 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);
10265
10551
  };
10266
10552
  /**
10267
10553
  * Draw a polygon line (alternative function to the polygon).
10268
10554
  *
10269
10555
  * @method polyline
10270
- * @param {Vertex[]} vertices - The polygon vertices to draw.
10556
+ * @param {XYCoords[]} vertices - The polygon vertices to draw.
10271
10557
  * @param {boolan} isOpen - If true the polyline will not be closed at its end.
10272
10558
  * @param {string} color - The CSS color to draw the polygon with.
10273
10559
  * @param {number} lineWidth - The line width (default is 1.0);
10560
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
10561
+ *
10274
10562
  * @return {void}
10275
10563
  * @instance
10276
10564
  * @memberof drawutils
10277
10565
  */
10278
- drawutils.prototype.polyline = function (vertices, isOpen, color, lineWidth) {
10566
+ drawutils.prototype.polyline = function (vertices, isOpen, color, lineWidth, strokeOptions) {
10279
10567
  if (vertices.length <= 1) {
10280
10568
  return;
10281
10569
  }
10282
10570
  this.ctx.save();
10571
+ this.applyStrokeOpts(strokeOptions);
10283
10572
  this.ctx.beginPath();
10284
10573
  this.ctx.lineWidth = (lineWidth || 1.0) * this.scale.x;
10285
10574
  this.ctx.moveTo(this.offset.x + vertices[0].x * this.scale.x, this.offset.y + vertices[0].y * this.scale.y);
@@ -10391,6 +10680,8 @@ var drawutils = /** @class */ (function () {
10391
10680
  * @param {string=null} color - (optional) The color to draw this path with (default is null).
10392
10681
  * @param {number=1} lineWidth - (optional) the line width to use (default is 1).
10393
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`.
10394
10685
  * @instance
10395
10686
  * @memberof drawutils
10396
10687
  * @return {R} An instance representing the drawn path.
@@ -10402,6 +10693,7 @@ var drawutils = /** @class */ (function () {
10402
10693
  this.ctx.strokeStyle = color;
10403
10694
  }
10404
10695
  this.ctx.lineWidth = lineWidth || 1;
10696
+ this.applyStrokeOpts(options);
10405
10697
  if (this.fillShapes) {
10406
10698
  if (color) {
10407
10699
  this.ctx.fillStyle = color;
@@ -10467,7 +10759,12 @@ exports.drawutils = drawutils;
10467
10759
  * @modified 2022-03-27 Added the `texturedPoly` function.
10468
10760
  * @modified 2022-07-26 Adding `alpha` to the `image(...)` function.
10469
10761
  * @modified 2023-02-10 The methods `setCurrentClassName` and `setCurrentId` also accept `null` now.
10470
- * @version 0.0.9
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
10471
10768
  **/
10472
10769
  Object.defineProperty(exports, "__esModule", ({ value: true }));
10473
10770
  exports.drawutilsgl = void 0;
@@ -10564,6 +10861,20 @@ var drawutilsgl = /** @class */ (function () {
10564
10861
  drawutilsgl.prototype.setConfiguration = function (configuration) {
10565
10862
  // TODO
10566
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
+ // }
10567
10878
  /**
10568
10879
  * This method shouled be called each time the currently drawn `Drawable` changes.
10569
10880
  * It is used by some libraries for identifying elemente on re-renders.
@@ -10591,8 +10902,8 @@ var drawutilsgl = /** @class */ (function () {
10591
10902
  * Draw the line between the given two points with the specified (CSS-) color.
10592
10903
  *
10593
10904
  * @method line
10594
- * @param {Vertex} zA - The start point of the line.
10595
- * @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.
10596
10907
  * @param {string} color - Any valid CSS color string.
10597
10908
  * @return {void}
10598
10909
  * @instance
@@ -10641,9 +10952,10 @@ var drawutilsgl = /** @class */ (function () {
10641
10952
  * Draw a line and an arrow at the end (zB) of the given line with the specified (CSS-) color.
10642
10953
  *
10643
10954
  * @method arrow
10644
- * @param {Vertex} zA - The start point of the arrow-line.
10645
- * @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.
10646
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).
10647
10959
  * @return {void}
10648
10960
  * @instance
10649
10961
  * @memberof drawutils
@@ -10651,6 +10963,41 @@ var drawutilsgl = /** @class */ (function () {
10651
10963
  drawutilsgl.prototype.arrow = function (zA, zB, color) {
10652
10964
  // NOT YET IMPLEMENTED
10653
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
+ };
10654
11001
  /**
10655
11002
  * Draw an image at the given position with the given size.<br>
10656
11003
  * <br>
@@ -10658,8 +11005,8 @@ var drawutilsgl = /** @class */ (function () {
10658
11005
  *
10659
11006
  * @method image
10660
11007
  * @param {Image} image - The image object to draw.
10661
- * @param {Vertex} position - The position to draw the the upper left corner at.
10662
- * @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.
10663
11010
  * @param {number=0.0} alpha - (optional, default=0.0) The transparency (0.0=opaque, 1.0=transparent).
10664
11011
  * @return {void}
10665
11012
  * @instance
@@ -10678,7 +11025,7 @@ var drawutilsgl = /** @class */ (function () {
10678
11025
  * @param {Image} textureImage - The image object to draw.
10679
11026
  * @param {Bounds} textureSize - The texture size to use; these are the original bounds to map the polygon vertices to.
10680
11027
  * @param {Polygon} polygon - The polygon to use as clip path.
10681
- * @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.
10682
11029
  * @param {number} rotation - The rotation to use for the polygon (and for the texture).
10683
11030
  * @return {void}
10684
11031
  * @instance
@@ -10705,10 +11052,10 @@ var drawutilsgl = /** @class */ (function () {
10705
11052
  * Draw the given (cubic) bézier curve.
10706
11053
  *
10707
11054
  * @method cubicBezier
10708
- * @param {Vertex} startPoint - The start point of the cubic Bézier curve
10709
- * @param {Vertex} endPoint - The end point the cubic Bézier curve.
10710
- * @param {Vertex} startControlPoint - The start control point the cubic Bézier curve.
10711
- * @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.
10712
11059
  * @param {string} color - The CSS color to draw the curve with.
10713
11060
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
10714
11061
  * @return {void}
@@ -10726,7 +11073,7 @@ var drawutilsgl = /** @class */ (function () {
10726
11073
  * <pre> [ point1, point1_startControl, point2_endControl, point2, point2_startControl, point3_endControl, point3, ... pointN_endControl, pointN ]</pre>
10727
11074
  *
10728
11075
  * @method cubicBezierPath
10729
- * @param {Vertex[]} path - The cubic bezier path as described above.
11076
+ * @param {XYCoords[]} path - The cubic bezier path as described above.
10730
11077
  * @param {string} color - The CSS colot to draw the path with.
10731
11078
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
10732
11079
  * @return {void}
@@ -10742,8 +11089,8 @@ var drawutilsgl = /** @class */ (function () {
10742
11089
  * The colors for this are fixed and cannot be specified.
10743
11090
  *
10744
11091
  * @method handle
10745
- * @param {Vertex} startPoint - The start of the handle.
10746
- * @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.
10747
11094
  * @return {void}
10748
11095
  * @instance
10749
11096
  * @memberof drawutils
@@ -10755,8 +11102,8 @@ var drawutilsgl = /** @class */ (function () {
10755
11102
  * Draw a handle line (with a light grey).
10756
11103
  *
10757
11104
  * @method handleLine
10758
- * @param {Vertex} startPoint - The start point to draw the handle at.
10759
- * @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.
10760
11107
  * @return {void}
10761
11108
  * @instance
10762
11109
  * @memberof drawutils
@@ -10768,7 +11115,7 @@ var drawutilsgl = /** @class */ (function () {
10768
11115
  * Draw a 1x1 dot with the specified (CSS-) color.
10769
11116
  *
10770
11117
  * @method dot
10771
- * @param {Vertex} p - The position to draw the dot at.
11118
+ * @param {XYCoords} p - The position to draw the dot at.
10772
11119
  * @param {string} color - The CSS color to draw the dot with.
10773
11120
  * @return {void}
10774
11121
  * @instance
@@ -10781,7 +11128,7 @@ var drawutilsgl = /** @class */ (function () {
10781
11128
  * Draw the given point with the specified (CSS-) color and radius 3.
10782
11129
  *
10783
11130
  * @method point
10784
- * @param {Vertex} p - The position to draw the point at.
11131
+ * @param {XYCoords} p - The position to draw the point at.
10785
11132
  * @param {string} color - The CSS color to draw the point with.
10786
11133
  * @return {void}
10787
11134
  * @instance
@@ -10796,7 +11143,7 @@ var drawutilsgl = /** @class */ (function () {
10796
11143
  * Note that if the x- and y- scales are different the result will be an ellipse rather than a circle.
10797
11144
  *
10798
11145
  * @method circle
10799
- * @param {Vertex} center - The center of the circle.
11146
+ * @param {XYCoords} center - The center of the circle.
10800
11147
  * @param {number} radius - The radius of the circle.
10801
11148
  * @param {string} color - The CSS color to draw the circle with.
10802
11149
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
@@ -10811,7 +11158,7 @@ var drawutilsgl = /** @class */ (function () {
10811
11158
  * Draw a circular arc (section of a circle) with the given CSS color.
10812
11159
  *
10813
11160
  * @method circleArc
10814
- * @param {Vertex} center - The center of the circle.
11161
+ * @param {XYCoords} center - The center of the circle.
10815
11162
  * @param {number} radius - The radius of the circle.
10816
11163
  * @param {number} startAngle - The angle to start at.
10817
11164
  * @param {number} endAngle - The angle to end at.
@@ -10827,7 +11174,7 @@ var drawutilsgl = /** @class */ (function () {
10827
11174
  * Draw an ellipse with the specified (CSS-) color and thw two radii.
10828
11175
  *
10829
11176
  * @method ellipse
10830
- * @param {Vertex} center - The center of the ellipse.
11177
+ * @param {XYCoords} center - The center of the ellipse.
10831
11178
  * @param {number} radiusX - The radius of the ellipse.
10832
11179
  * @param {number} radiusY - The radius of the ellipse.
10833
11180
  * @param {string} color - The CSS color to draw the ellipse with.
@@ -10847,7 +11194,7 @@ var drawutilsgl = /** @class */ (function () {
10847
11194
  *
10848
11195
  * @method square
10849
11196
  * @param {XYCords} center - The center of the square.
10850
- * @param {Vertex} size - The size of the square.
11197
+ * @param {number} size - The size of the square.
10851
11198
  * @param {string} color - The CSS color to draw the square with.
10852
11199
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
10853
11200
  * @return {void}
@@ -10873,7 +11220,7 @@ var drawutilsgl = /** @class */ (function () {
10873
11220
  * Draw a grid of horizontal and vertical lines with the given (CSS-) color.
10874
11221
  *
10875
11222
  * @method grid
10876
- * @param {Vertex} center - The center of the grid.
11223
+ * @param {XYCoords} center - The center of the grid.
10877
11224
  * @param {number} width - The total width of the grid (width/2 each to the left and to the right).
10878
11225
  * @param {number} height - The total height of the grid (height/2 each to the top and to the bottom).
10879
11226
  * @param {number} sizeX - The horizontal grid size.
@@ -10892,7 +11239,7 @@ var drawutilsgl = /** @class */ (function () {
10892
11239
  * This works analogue to the grid() function
10893
11240
  *
10894
11241
  * @method raster
10895
- * @param {Vertex} center - The center of the raster.
11242
+ * @param {XYCoords} center - The center of the raster.
10896
11243
  * @param {number} width - The total width of the raster (width/2 each to the left and to the right).
10897
11244
  * @param {number} height - The total height of the raster (height/2 each to the top and to the bottom).
10898
11245
  * @param {number} sizeX - The horizontal raster size.
@@ -10913,8 +11260,8 @@ var drawutilsgl = /** @class */ (function () {
10913
11260
  * as even shaped diamonds.
10914
11261
  *
10915
11262
  * @method diamondHandle
10916
- * @param {Vertex} center - The center of the diamond.
10917
- * @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.
10918
11265
  * @param {string} color - The CSS color to draw the diamond with.
10919
11266
  * @return {void}
10920
11267
  * @instance
@@ -10931,8 +11278,8 @@ var drawutilsgl = /** @class */ (function () {
10931
11278
  * as even shaped squares.
10932
11279
  *
10933
11280
  * @method squareHandle
10934
- * @param {Vertex} center - The center of the square.
10935
- * @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.
10936
11283
  * @param {string} color - The CSS color to draw the square with.
10937
11284
  * @return {void}
10938
11285
  * @instance
@@ -10949,7 +11296,7 @@ var drawutilsgl = /** @class */ (function () {
10949
11296
  * as even shaped circles.
10950
11297
  *
10951
11298
  * @method circleHandle
10952
- * @param {Vertex} center - The center of the circle.
11299
+ * @param {XYCoords} center - The center of the circle.
10953
11300
  * @param {number} radius - The radius of the circle.
10954
11301
  * @param {string} color - The CSS color to draw the circle with.
10955
11302
  * @return {void}
@@ -11045,7 +11392,7 @@ var drawutilsgl = /** @class */ (function () {
11045
11392
  * Draw a polygon line (alternative function to the polygon).
11046
11393
  *
11047
11394
  * @method polyline
11048
- * @param {Vertex[]} vertices - The polygon vertices to draw.
11395
+ * @param {XYCoords[]} vertices - The polygon vertices to draw.
11049
11396
  * @param {boolan} isOpen - If true the polyline will not be closed at its end.
11050
11397
  * @param {string} color - The CSS color to draw the polygon with.
11051
11398
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
@@ -11237,7 +11584,15 @@ var GLU = /** @class */ (function () {
11237
11584
  * @modified 2022-11-10 Tweaking some type issues.
11238
11585
  * @modified 2023-02-04 Fixed a typo in the CSS classname for cubic Bézier paths: cubicBezier (was cubierBezier).
11239
11586
  * @modified 2023-02-10 The methods `setCurrentClassName` and `setCurrentId` also accept `null` now.
11240
- * @version 1.6.4
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
11241
11596
  **/
11242
11597
  Object.defineProperty(exports, "__esModule", ({ value: true }));
11243
11598
  exports.drawutilssvg = void 0;
@@ -11245,6 +11600,7 @@ var CircleSector_1 = __webpack_require__(946);
11245
11600
  var CubicBezierCurve_1 = __webpack_require__(510);
11246
11601
  var Vertex_1 = __webpack_require__(421);
11247
11602
  var UIDGenerator_1 = __webpack_require__(197);
11603
+ var Vector_1 = __webpack_require__(73);
11248
11604
  var RAD_TO_DEG = 180 / Math.PI;
11249
11605
  /**
11250
11606
  * @classdesc A helper class for basic SVG drawing operations. This class should
@@ -11280,6 +11636,9 @@ var drawutilssvg = /** @class */ (function () {
11280
11636
  this.cache = new Map();
11281
11637
  this.setSize(canvasSize);
11282
11638
  if (isSecondary) {
11639
+ if (!gNode || !bufferGNode || !nodeDefs || !bufferNodeDefs) {
11640
+ throw "Cannot create secondary svg draw lib with undefinde gNode|bufferGNode|nodeDefs|bufferNodeDefs.";
11641
+ }
11283
11642
  this.gNode = gNode;
11284
11643
  this.bufferGNode = bufferGNode;
11285
11644
  this.nodeDefs = nodeDefs;
@@ -11420,6 +11779,9 @@ var drawutilssvg = /** @class */ (function () {
11420
11779
  if (this.drawlibConfiguration.blendMode) {
11421
11780
  node.style["mix-blend-mode"] = this.drawlibConfiguration.blendMode;
11422
11781
  }
11782
+ // if (this.lineDashEnabled && this.lineDash && this.lineDash.length > 0 && drawutilssvg.nodeSupportsLineDash(nodeName)) {
11783
+ // node.setAttribute("stroke-dasharray", this.lineDash.join(" "));
11784
+ // }
11423
11785
  return node;
11424
11786
  };
11425
11787
  /**
@@ -11442,23 +11804,58 @@ var drawutilssvg = /** @class */ (function () {
11442
11804
  * @param {number=1} lineWidth - (optional) A line width to use for drawing (default is 1).
11443
11805
  * @return {SVGElement} The node itself (for chaining).
11444
11806
  */
11445
- 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) {
11446
11843
  if (this.curClassName) {
11447
11844
  node.setAttribute("class", className + " " + this.curClassName);
11448
11845
  }
11449
11846
  else {
11450
11847
  node.setAttribute("class", className);
11451
11848
  }
11452
- node.setAttribute("fill", this.fillShapes && color ? color : "none");
11453
- node.setAttribute("stroke", this.fillShapes ? "none" : color || "none");
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");
11454
11854
  node.setAttribute("stroke-width", "" + (lineWidth || 1));
11455
11855
  if (this.curId) {
11456
11856
  node.setAttribute("id", "" + this.curId); // Maybe React-style 'key' would be better?
11457
11857
  }
11458
- if (!node.parentNode) {
11459
- // Attach to DOM only if not already attached
11460
- this.bufferGNode.appendChild(node);
11461
- }
11858
+ this.applyStrokeOpts(node, strokeOptions);
11462
11859
  return node;
11463
11860
  };
11464
11861
  /**
@@ -11480,7 +11877,7 @@ var drawutilssvg = /** @class */ (function () {
11480
11877
  * that under the hood the same gl context and gl program will be used.
11481
11878
  */
11482
11879
  drawutilssvg.prototype.copyInstance = function (fillShapes) {
11483
- 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`
11484
11881
  true, // isSecondary
11485
11882
  this.gNode, this.bufferGNode, this.nodeDefs, this.bufferedNodeDefs);
11486
11883
  return copy;
@@ -11495,6 +11892,20 @@ var drawutilssvg = /** @class */ (function () {
11495
11892
  drawutilssvg.prototype.setConfiguration = function (configuration) {
11496
11893
  this.drawlibConfiguration = configuration;
11497
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
+ // }
11498
11909
  /**
11499
11910
  * This method shouled be called each time the currently drawn `Drawable` changes.
11500
11911
  * It is used by some libraries for identifying elemente on re-renders.
@@ -11569,6 +11980,27 @@ var drawutilssvg = /** @class */ (function () {
11569
11980
  this.nodeDefs = this.bufferedNodeDefs;
11570
11981
  this.bufferedNodeDefs = tmpDefsNode;
11571
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
+ };
11572
12004
  drawutilssvg.prototype._x = function (x) {
11573
12005
  return this.offset.x + this.scale.x * x;
11574
12006
  };
@@ -11579,47 +12011,104 @@ var drawutilssvg = /** @class */ (function () {
11579
12011
  * Draw the line between the given two points with the specified (CSS-) color.
11580
12012
  *
11581
12013
  * @method line
11582
- * @param {Vertex} zA - The start point of the line.
11583
- * @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.
11584
12016
  * @param {string} color - Any valid CSS color string.
11585
12017
  * @param {number=1} lineWidth? - [optional] The line's width.
12018
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
12019
+ *
11586
12020
  * @return {void}
11587
12021
  * @instance
11588
12022
  * @memberof drawutilssvg
11589
12023
  **/
11590
- drawutilssvg.prototype.line = function (zA, zB, color, lineWidth) {
11591
- var line = this.makeNode("line");
11592
- line.setAttribute("x1", "" + this._x(zA.x));
11593
- line.setAttribute("y1", "" + this._y(zA.y));
11594
- line.setAttribute("x2", "" + this._x(zB.x));
11595
- line.setAttribute("y2", "" + this._y(zB.y));
11596
- 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);
11597
12033
  };
11598
12034
  /**
11599
12035
  * Draw a line and an arrow at the end (zB) of the given line with the specified (CSS-) color.
11600
12036
  *
11601
12037
  * @method arrow
11602
- * @param {Vertex} zA - The start point of the arrow-line.
11603
- * @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.
11604
12040
  * @param {string} color - Any valid CSS color string.
11605
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
+ *
11606
12045
  * @return {void}
11607
12046
  * @instance
11608
12047
  * @memberof drawutilssvg
11609
12048
  **/
11610
- drawutilssvg.prototype.arrow = function (zA, zB, color, lineWidth) {
11611
- var node = this.makeNode("path");
11612
- var headlen = 8; // length of head in pixels
11613
- var vertices = Vertex_1.Vertex.utils.buildArrowHead(zA, zB, headlen, this.scale.x, this.scale.y);
11614
- var d = ["M", this._x(zA.x), this._y(zA.y)];
11615
- for (var i = 0; i <= vertices.length; i++) {
11616
- d.push("L");
11617
- // Note: only use offset here (the vertices are already scaled)
11618
- d.push(this.offset.x + vertices[i % vertices.length].x);
11619
- d.push(this.offset.y + vertices[i % vertices.length].y);
11620
- }
11621
- node.setAttribute("d", d.join(" "));
11622
- 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);
11623
12112
  };
11624
12113
  /**
11625
12114
  * Draw an image at the given position with the given size.<br>
@@ -11628,8 +12117,8 @@ var drawutilssvg = /** @class */ (function () {
11628
12117
  *
11629
12118
  * @method image
11630
12119
  * @param {Image} image - The image object to draw.
11631
- * @param {Vertex} position - The position to draw the the upper left corner at.
11632
- * @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.
11633
12122
  * @param {number=0.0} alpha - (optional, default=0.0) The transparency (1.0=opaque, 0.0=transparent).
11634
12123
  * @return {void}
11635
12124
  * @instance
@@ -11674,16 +12163,16 @@ var drawutilssvg = /** @class */ (function () {
11674
12163
  * @param {Image} textureImage - The image object to draw.
11675
12164
  * @param {Bounds} textureSize - The texture size to use; these are the original bounds to map the polygon vertices to.
11676
12165
  * @param {Polygon} polygon - The polygon to use as clip path.
11677
- * @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.
11678
12167
  * @param {number} rotation - The rotation to use for the polygon (and for the texture).
11679
12168
  * @return {void}
11680
12169
  * @instance
11681
12170
  * @memberof drawutilssvg
11682
12171
  **/
11683
12172
  drawutilssvg.prototype.texturedPoly = function (textureImage, textureSize, polygon, polygonPosition, rotation) {
11684
- var basePolygonBounds = polygon.getBounds();
12173
+ // const basePolygonBounds: Bounds = polygon.getBounds();
11685
12174
  var rotatedScalingOrigin = new Vertex_1.Vertex(textureSize.min).clone().rotate(rotation, polygonPosition);
11686
- var rotationCenter = polygonPosition.clone().add(rotatedScalingOrigin.difference(textureSize.min).inv());
12175
+ // const rotationCenter = polygonPosition.clone().add(rotatedScalingOrigin.difference(textureSize.min).inv());
11687
12176
  // Create something like this
11688
12177
  // ...
11689
12178
  // <defs>
@@ -11738,36 +12227,21 @@ var drawutilssvg = /** @class */ (function () {
11738
12227
  * Draw the given (cubic) bézier curve.
11739
12228
  *
11740
12229
  * @method cubicBezier
11741
- * @param {Vertex} startPoint - The start point of the cubic Bézier curve
11742
- * @param {Vertex} endPoint - The end point the cubic Bézier curve.
11743
- * @param {Vertex} startControlPoint - The start control point the cubic Bézier curve.
11744
- * @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.
11745
12234
  * @param {string} color - The CSS color to draw the curve with.
11746
12235
  * @param {number} lineWidth - (optional) The line width to use.
12236
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
12237
+ *
11747
12238
  * @return {void}
11748
12239
  * @instance
11749
12240
  * @memberof drawutilssvg
11750
12241
  */
11751
- drawutilssvg.prototype.cubicBezier = function (startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth) {
11752
- if (startPoint instanceof CubicBezierCurve_1.CubicBezierCurve) {
11753
- return this.cubicBezier(startPoint.startPoint, startPoint.endPoint, startPoint.startControlPoint, startPoint.endControlPoint, color, lineWidth);
11754
- }
11755
- var node = this.makeNode("path");
11756
- // Draw curve
11757
- var d = [
11758
- "M",
11759
- this._x(startPoint.x),
11760
- this._y(startPoint.y),
11761
- "C",
11762
- this._x(startControlPoint.x),
11763
- this._y(startControlPoint.y),
11764
- this._x(endControlPoint.x),
11765
- this._y(endControlPoint.y),
11766
- this._x(endPoint.x),
11767
- this._y(endPoint.y)
11768
- ];
11769
- node.setAttribute("d", d.join(" "));
11770
- return this._bindFillDraw(node, "cubicBezier", 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);
11771
12245
  };
11772
12246
  /**
11773
12247
  * Draw the given (cubic) Bézier path.
@@ -11777,17 +12251,21 @@ var drawutilssvg = /** @class */ (function () {
11777
12251
  * <pre> [ point1, point1_startControl, point2_endControl, point2, point2_startControl, point3_endControl, point3, ... pointN_endControl, pointN ]</pre>
11778
12252
  *
11779
12253
  * @method cubicBezierPath
11780
- * @param {Vertex[]} path - The cubic bezier path as described above.
12254
+ * @param {XYCoords[]} path - The cubic bezier path as described above.
11781
12255
  * @param {string} color - The CSS colot to draw the path with.
11782
12256
  * @param {number=1} lineWidth - (optional) The line width to use.
12257
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
12258
+ *
11783
12259
  * @return {void}
11784
12260
  * @instance
11785
12261
  * @memberof drawutilssvg
11786
12262
  */
11787
- drawutilssvg.prototype.cubicBezierPath = function (path, color, lineWidth) {
12263
+ drawutilssvg.prototype.cubicBezierPath = function (path, color, lineWidth, strokeOptions) {
11788
12264
  var node = this.makeNode("path");
11789
- if (!path || path.length == 0)
12265
+ this.applyStrokeOpts(node, strokeOptions);
12266
+ if (!path || path.length == 0) {
11790
12267
  return node;
12268
+ }
11791
12269
  // Draw curve
11792
12270
  var d = ["M", this._x(path[0].x), this._y(path[0].y)];
11793
12271
  // Draw curve path
@@ -11824,20 +12302,20 @@ var drawutilssvg = /** @class */ (function () {
11824
12302
  * Draw a handle line (with a light grey).
11825
12303
  *
11826
12304
  * @method handleLine
11827
- * @param {Vertex} startPoint - The start point to draw the handle at.
11828
- * @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.
11829
12307
  * @return {void}
11830
12308
  * @instance
11831
12309
  * @memberof drawutilssvg
11832
12310
  */
11833
12311
  drawutilssvg.prototype.handleLine = function (startPoint, endPoint) {
11834
- this.line(startPoint, endPoint, "rgb(192,192,192)");
12312
+ this.line(startPoint, endPoint, "rgb(128,128,128,0.5)");
11835
12313
  };
11836
12314
  /**
11837
12315
  * Draw a 1x1 dot with the specified (CSS-) color.
11838
12316
  *
11839
12317
  * @method dot
11840
- * @param {Vertex} p - The position to draw the dot at.
12318
+ * @param {XYCoords} p - The position to draw the dot at.
11841
12319
  * @param {string} color - The CSS color to draw the dot with.
11842
12320
  * @return {void}
11843
12321
  * @instance
@@ -11845,13 +12323,17 @@ var drawutilssvg = /** @class */ (function () {
11845
12323
  */
11846
12324
  drawutilssvg.prototype.dot = function (p, color) {
11847
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));
11848
12330
  return this._bindFillDraw(node, "dot", color, 1);
11849
12331
  };
11850
12332
  /**
11851
12333
  * Draw the given point with the specified (CSS-) color and radius 3.
11852
12334
  *
11853
12335
  * @method point
11854
- * @param {Vertex} p - The position to draw the point at.
12336
+ * @param {XYCoords} p - The position to draw the point at.
11855
12337
  * @param {string} color - The CSS color to draw the point with.
11856
12338
  * @return {void}
11857
12339
  * @instance
@@ -11871,17 +12353,20 @@ var drawutilssvg = /** @class */ (function () {
11871
12353
  * Note that if the x- and y- scales are different the result will be an ellipse rather than a circle.
11872
12354
  *
11873
12355
  * @method circle
11874
- * @param {Vertex} center - The center of the circle.
12356
+ * @param {XYCoords} center - The center of the circle.
11875
12357
  * @param {number} radius - The radius of the circle.
11876
12358
  * @param {string} color - The CSS color to draw the circle with.
11877
12359
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
12360
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
12361
+ *
11878
12362
  * @return {void}
11879
12363
  * @instance
11880
12364
  * @memberof drawutilssvg
11881
12365
  */
11882
- drawutilssvg.prototype.circle = function (center, radius, color, lineWidth) {
12366
+ drawutilssvg.prototype.circle = function (center, radius, color, lineWidth, strokeOptions) {
11883
12367
  // Todo: draw ellipse when scalex!=scaley
11884
12368
  var node = this.makeNode("circle");
12369
+ this.applyStrokeOpts(node, strokeOptions);
11885
12370
  node.setAttribute("cx", "" + this._x(center.x));
11886
12371
  node.setAttribute("cy", "" + this._y(center.y));
11887
12372
  node.setAttribute("r", "" + radius * this.scale.x); // y?
@@ -11891,17 +12376,20 @@ var drawutilssvg = /** @class */ (function () {
11891
12376
  * Draw a circular arc (section of a circle) with the given CSS color.
11892
12377
  *
11893
12378
  * @method circleArc
11894
- * @param {Vertex} center - The center of the circle.
12379
+ * @param {XYCoords} center - The center of the circle.
11895
12380
  * @param {number} radius - The radius of the circle.
11896
12381
  * @param {number} startAngle - The angle to start at.
11897
12382
  * @param {number} endAngle - The angle to end at.
11898
12383
  * @param {string} color - The CSS color to draw the circle with.
12384
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
12385
+ *
11899
12386
  * @return {void}
11900
12387
  * @instance
11901
12388
  * @memberof drawutilssvg
11902
12389
  */
11903
- drawutilssvg.prototype.circleArc = function (center, radius, startAngle, endAngle, color, lineWidth) {
12390
+ drawutilssvg.prototype.circleArc = function (center, radius, startAngle, endAngle, color, lineWidth, strokeOptions) {
11904
12391
  var node = this.makeNode("path");
12392
+ this.applyStrokeOpts(node, strokeOptions);
11905
12393
  var arcData = CircleSector_1.CircleSector.circleSectorUtils.describeSVGArc(this._x(center.x), this._y(center.y), radius * this.scale.x, // y?
11906
12394
  startAngle, endAngle);
11907
12395
  node.setAttribute("d", arcData.join(" "));
@@ -11911,21 +12399,24 @@ var drawutilssvg = /** @class */ (function () {
11911
12399
  * Draw an ellipse with the specified (CSS-) color and thw two radii.
11912
12400
  *
11913
12401
  * @method ellipse
11914
- * @param {Vertex} center - The center of the ellipse.
12402
+ * @param {XYCoords} center - The center of the ellipse.
11915
12403
  * @param {number} radiusX - The radius of the ellipse.
11916
12404
  * @param {number} radiusY - The radius of the ellipse.
11917
12405
  * @param {string} color - The CSS color to draw the ellipse with.
11918
12406
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
11919
12407
  * @param {number=} rotation - (optional, default=0) The rotation of the ellipse.
12408
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
12409
+ *
11920
12410
  * @return {void}
11921
12411
  * @instance
11922
12412
  * @memberof drawutilssvg
11923
12413
  */
11924
- drawutilssvg.prototype.ellipse = function (center, radiusX, radiusY, color, lineWidth, rotation) {
12414
+ drawutilssvg.prototype.ellipse = function (center, radiusX, radiusY, color, lineWidth, rotation, strokeOptions) {
11925
12415
  if (typeof rotation === "undefined") {
11926
12416
  rotation = 0.0;
11927
12417
  }
11928
12418
  var node = this.makeNode("ellipse");
12419
+ this.applyStrokeOpts(node, strokeOptions);
11929
12420
  node.setAttribute("cx", "" + this._x(center.x));
11930
12421
  node.setAttribute("cy", "" + this._y(center.y));
11931
12422
  node.setAttribute("rx", "" + radiusX * this.scale.x);
@@ -11941,15 +12432,18 @@ var drawutilssvg = /** @class */ (function () {
11941
12432
  *
11942
12433
  * @method square
11943
12434
  * @param {XYCoords} center - The center of the square.
11944
- * @param {Vertex} size - The size of the square.
12435
+ * @param {number} size - The size of the square.
11945
12436
  * @param {string} color - The CSS color to draw the square with.
11946
12437
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
11947
- * @return {void}
12438
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
12439
+ *
12440
+ * @return {SVGElement}
11948
12441
  * @instance
11949
12442
  * @memberof drawutilssvg
11950
12443
  */
11951
- drawutilssvg.prototype.square = function (center, size, color, lineWidth) {
12444
+ drawutilssvg.prototype.square = function (center, size, color, lineWidth, strokeOptions) {
11952
12445
  var node = this.makeNode("rectangle");
12446
+ this.applyStrokeOpts(node, strokeOptions);
11953
12447
  node.setAttribute("x", "" + this._x(center.x - size / 2.0));
11954
12448
  node.setAttribute("y", "" + this._y(center.y - size / 2.0));
11955
12449
  node.setAttribute("width", "" + size * this.scale.x);
@@ -11964,9 +12458,15 @@ var drawutilssvg = /** @class */ (function () {
11964
12458
  * @param {number} height - The height of the rectangle.
11965
12459
  * @param {string} color - The color to use.
11966
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
11967
12466
  **/
11968
- drawutilssvg.prototype.rect = function (position, width, height, color, lineWidth) {
12467
+ drawutilssvg.prototype.rect = function (position, width, height, color, lineWidth, strokeOptions) {
11969
12468
  var node = this.makeNode("rect");
12469
+ this.applyStrokeOpts(node, strokeOptions);
11970
12470
  node.setAttribute("x", "" + this._x(position.x));
11971
12471
  node.setAttribute("y", "" + this._y(position.y));
11972
12472
  node.setAttribute("width", "" + width * this.scale.x);
@@ -11977,7 +12477,7 @@ var drawutilssvg = /** @class */ (function () {
11977
12477
  * Draw a grid of horizontal and vertical lines with the given (CSS-) color.
11978
12478
  *
11979
12479
  * @method grid
11980
- * @param {Vertex} center - The center of the grid.
12480
+ * @param {XYCoords} center - The center of the grid.
11981
12481
  * @param {number} width - The total width of the grid (width/2 each to the left and to the right).
11982
12482
  * @param {number} height - The total height of the grid (height/2 each to the top and to the bottom).
11983
12483
  * @param {number} sizeX - The horizontal grid size.
@@ -12011,7 +12511,7 @@ var drawutilssvg = /** @class */ (function () {
12011
12511
  * This works analogue to the grid() function
12012
12512
  *
12013
12513
  * @method raster
12014
- * @param {Vertex} center - The center of the raster.
12514
+ * @param {XYCoords} center - The center of the raster.
12015
12515
  * @param {number} width - The total width of the raster (width/2 each to the left and to the right).
12016
12516
  * @param {number} height - The total height of the raster (height/2 each to the top and to the bottom).
12017
12517
  * @param {number} sizeX - The horizontal raster size.
@@ -12044,8 +12544,8 @@ var drawutilssvg = /** @class */ (function () {
12044
12544
  * as even shaped diamonds.
12045
12545
  *
12046
12546
  * @method diamondHandle
12047
- * @param {Vertex} center - The center of the diamond.
12048
- * @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.
12049
12549
  * @param {string} color - The CSS color to draw the diamond with.
12050
12550
  * @return {void}
12051
12551
  * @instance
@@ -12079,8 +12579,8 @@ var drawutilssvg = /** @class */ (function () {
12079
12579
  * as even shaped squares.
12080
12580
  *
12081
12581
  * @method squareHandle
12082
- * @param {Vertex} center - The center of the square.
12083
- * @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.
12084
12584
  * @param {string} color - The CSS color to draw the square with.
12085
12585
  * @return {void}
12086
12586
  * @instance
@@ -12102,7 +12602,7 @@ var drawutilssvg = /** @class */ (function () {
12102
12602
  * as even shaped circles.
12103
12603
  *
12104
12604
  * @method circleHandle
12105
- * @param {Vertex} center - The center of the circle.
12605
+ * @param {XYCoords} center - The center of the circle.
12106
12606
  * @param {number} radius - The radius of the circle.
12107
12607
  * @param {string} color - The CSS color to draw the circle with.
12108
12608
  * @return {void}
@@ -12201,18 +12701,22 @@ var drawutilssvg = /** @class */ (function () {
12201
12701
  * Draw a polygon line (alternative function to the polygon).
12202
12702
  *
12203
12703
  * @method polyline
12204
- * @param {Vertex[]} vertices - The polygon vertices to draw.
12704
+ * @param {XYCoords[]} vertices - The polygon vertices to draw.
12205
12705
  * @param {boolan} isOpen - If true the polyline will not be closed at its end.
12206
12706
  * @param {string} color - The CSS color to draw the polygon with.
12207
12707
  * @param {number=} lineWidth - (optional) The line width to use; default is 1.
12708
+ * @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
12709
+ *
12208
12710
  * @return {void}
12209
12711
  * @instance
12210
12712
  * @memberof drawutilssvg
12211
12713
  */
12212
- drawutilssvg.prototype.polyline = function (vertices, isOpen, color, lineWidth) {
12714
+ drawutilssvg.prototype.polyline = function (vertices, isOpen, color, lineWidth, strokeOptions) {
12213
12715
  var node = this.makeNode("path");
12214
- if (vertices.length == 0)
12716
+ this.applyStrokeOpts(node, strokeOptions);
12717
+ if (vertices.length == 0) {
12215
12718
  return node;
12719
+ }
12216
12720
  // Draw curve
12217
12721
  var d = ["M", this._x(vertices[0].x), this._y(vertices[0].y)];
12218
12722
  var n = vertices.length;
@@ -12315,12 +12819,16 @@ var drawutilssvg = /** @class */ (function () {
12315
12819
  * @param {string=null} color - (optional) The color to draw this path with (default is null).
12316
12820
  * @param {number=1} lineWidth - (optional) the line width to use (default is 1).
12317
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
+ *
12318
12825
  * @instance
12319
12826
  * @memberof drawutils
12320
12827
  * @return {R} An instance representing the drawn path.
12321
12828
  */
12322
12829
  drawutilssvg.prototype.path = function (pathData, color, lineWidth, options) {
12323
12830
  var node = this.makeNode("path");
12831
+ this.applyStrokeOpts(node, options);
12324
12832
  // Transform the path: in-place (fast) or copy (slower)
12325
12833
  var d = options && options.inplace ? pathData : drawutilssvg.copyPathData(pathData);
12326
12834
  drawutilssvg.transformPathData(d, this.offset, this.scale);
@@ -12346,7 +12854,7 @@ var drawutilssvg = /** @class */ (function () {
12346
12854
  }
12347
12855
  // Add a covering rect with the given background color
12348
12856
  this.curId = "background";
12349
- this.curClassName = undefined;
12857
+ this.curClassName = null; // undefined;
12350
12858
  var node = this.makeNode("rect");
12351
12859
  // For some strange reason SVG rotation transforms use degrees instead of radians
12352
12860
  // Note that the background does not scale with the zoom level (always covers full element)
@@ -12358,7 +12866,7 @@ var drawutilssvg = /** @class */ (function () {
12358
12866
  this._bindFillDraw(node, this.curId, null, null);
12359
12867
  node.setAttribute("fill", typeof color === "undefined" ? "none" : color);
12360
12868
  // Clear the current ID again
12361
- this.curId = undefined;
12869
+ this.curId = null; // undefined;
12362
12870
  };
12363
12871
  /**
12364
12872
  * A private helper function to clear all SVG nodes from the &gt;g> node.
@@ -12563,6 +13071,127 @@ var drawutilssvg = /** @class */ (function () {
12563
13071
  }
12564
13072
  } // END while
12565
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
+ };
12566
13195
  drawutilssvg.HEAD_XML = [
12567
13196
  '<?xml version="1.0" encoding="UTF-8" standalone="no"?>',
12568
13197
  '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" ',