plotboilerplate 1.20.2 → 1.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +2012 -1366
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/plotboilerplate.browser.min.js +1 -1
- package/dist/plotboilerplate.browser.min.js.map +1 -1
- package/dist/plotboilerplate.js +1199 -541
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +3 -2
- package/src/cjs/BezierPath.d.ts +27 -49
- package/src/cjs/BezierPath.js +67 -234
- package/src/cjs/BezierPath.js.map +1 -1
- package/src/cjs/Bounds.d.ts +14 -1
- package/src/cjs/Bounds.js +21 -1
- package/src/cjs/Bounds.js.map +1 -1
- package/src/cjs/CubicBezierCurve.d.ts +70 -1
- package/src/cjs/CubicBezierCurve.js +130 -12
- package/src/cjs/CubicBezierCurve.js.map +1 -1
- package/src/cjs/Line.d.ts +2 -1
- package/src/cjs/Line.js +1 -0
- package/src/cjs/Line.js.map +1 -1
- package/src/cjs/PBText.d.ts +2 -1
- package/src/cjs/PBText.js +10 -9
- package/src/cjs/PBText.js.map +1 -1
- package/src/cjs/PlotBoilerplate.d.ts +4 -13
- package/src/cjs/PlotBoilerplate.js +61 -15
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/Polygon.d.ts +47 -1
- package/src/cjs/Polygon.js +116 -1
- package/src/cjs/Polygon.js.map +1 -1
- package/src/cjs/VEllipse.js +1 -1
- package/src/cjs/VEllipse.js.map +1 -1
- package/src/cjs/Vector.d.ts +4 -4
- package/src/cjs/Vector.js +2 -2
- package/src/cjs/Vector.js.map +1 -1
- package/src/cjs/VertTuple.d.ts +2 -1
- package/src/cjs/VertTuple.js +4 -3
- package/src/cjs/VertTuple.js.map +1 -1
- package/src/cjs/Vertex.d.ts +14 -3
- package/src/cjs/Vertex.js +18 -3
- package/src/cjs/Vertex.js.map +1 -1
- package/src/cjs/draw.d.ts +154 -75
- package/src/cjs/draw.js +308 -137
- package/src/cjs/draw.js.map +1 -1
- package/src/cjs/drawgl.d.ts +87 -50
- package/src/cjs/drawgl.js +86 -31
- package/src/cjs/drawgl.js.map +1 -1
- package/src/cjs/drawutilssvg.d.ts +226 -53
- package/src/cjs/drawutilssvg.js +374 -92
- package/src/cjs/drawutilssvg.js.map +1 -1
- package/src/cjs/interfaces/DrawLib.d.ts +157 -79
- package/src/cjs/interfaces/DrawLib.js +6 -0
- package/src/cjs/interfaces/DrawLib.js.map +1 -1
- package/src/cjs/interfaces/core.d.ts +13 -2
- package/src/cjs/interfaces/core.js +1 -0
- package/src/cjs/interfaces/core.js.map +1 -1
- package/src/cjs/utils/Params.d.ts +15 -0
- package/src/cjs/utils/Params.js +49 -0
- package/src/cjs/utils/Params.js.map +1 -0
- package/src/cjs/utils/algorithms/ContourLineDetection.d.ts +150 -0
- package/src/cjs/utils/algorithms/ContourLineDetection.js +367 -0
- package/src/cjs/utils/algorithms/ContourLineDetection.js.map +1 -0
- package/src/cjs/utils/algorithms/clearDuplicateVertices.d.ts +21 -0
- package/src/cjs/utils/algorithms/clearDuplicateVertices.js +48 -0
- package/src/cjs/utils/algorithms/clearDuplicateVertices.js.map +1 -0
- package/src/cjs/utils/creategui.js +16 -10
- package/src/cjs/utils/datastructures/DataGrid2d.d.ts +47 -0
- package/src/cjs/utils/datastructures/DataGrid2d.js +20 -0
- package/src/cjs/utils/datastructures/DataGrid2d.js.map +1 -0
- package/src/cjs/utils/datastructures/DataGrid2dListAdapter.d.ts +65 -0
- package/src/cjs/utils/datastructures/DataGrid2dListAdapter.js +84 -0
- package/src/cjs/utils/datastructures/DataGrid2dListAdapter.js.map +1 -0
- package/src/cjs/utils/datastructures/GenericPath.d.ts +14 -3
- package/src/cjs/utils/datastructures/GenericPath.js +20 -3
- package/src/cjs/utils/datastructures/GenericPath.js.map +1 -1
- package/src/cjs/utils/detectDarkMode.d.ts +10 -0
- package/src/cjs/utils/detectDarkMode.js +32 -0
- package/src/cjs/utils/detectDarkMode.js.map +1 -0
- package/src/esm/BezierPath.d.ts +27 -49
- package/src/esm/BezierPath.js +67 -234
- package/src/esm/BezierPath.js.map +1 -1
- package/src/esm/Bounds.d.ts +14 -1
- package/src/esm/Bounds.js +19 -1
- package/src/esm/Bounds.js.map +1 -1
- package/src/esm/CubicBezierCurve.d.ts +70 -1
- package/src/esm/CubicBezierCurve.js +130 -12
- package/src/esm/CubicBezierCurve.js.map +1 -1
- package/src/esm/Line.d.ts +2 -1
- package/src/esm/Line.js +1 -0
- package/src/esm/Line.js.map +1 -1
- package/src/esm/PBText.d.ts +2 -1
- package/src/esm/PBText.js +10 -9
- package/src/esm/PBText.js.map +1 -1
- package/src/esm/PlotBoilerplate.d.ts +4 -13
- package/src/esm/PlotBoilerplate.js +62 -16
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/Polygon.d.ts +47 -1
- package/src/esm/Polygon.js +114 -1
- package/src/esm/Polygon.js.map +1 -1
- package/src/esm/VEllipse.js +1 -1
- package/src/esm/VEllipse.js.map +1 -1
- package/src/esm/Vector.d.ts +4 -4
- package/src/esm/Vector.js +2 -2
- package/src/esm/Vector.js.map +1 -1
- package/src/esm/VertTuple.d.ts +2 -1
- package/src/esm/VertTuple.js +4 -3
- package/src/esm/VertTuple.js.map +1 -1
- package/src/esm/Vertex.d.ts +14 -3
- package/src/esm/Vertex.js +18 -3
- package/src/esm/Vertex.js.map +1 -1
- package/src/esm/draw.d.ts +154 -75
- package/src/esm/draw.js +304 -135
- package/src/esm/draw.js.map +1 -1
- package/src/esm/drawgl.d.ts +87 -50
- package/src/esm/drawgl.js +86 -31
- package/src/esm/drawgl.js.map +1 -1
- package/src/esm/drawutilssvg.d.ts +226 -53
- package/src/esm/drawutilssvg.js +369 -92
- package/src/esm/drawutilssvg.js.map +1 -1
- package/src/esm/interfaces/DrawLib.d.ts +157 -79
- package/src/esm/interfaces/DrawLib.js +6 -0
- package/src/esm/interfaces/DrawLib.js.map +1 -1
- package/src/esm/interfaces/core.d.ts +13 -2
- package/src/esm/interfaces/core.js +1 -0
- package/src/esm/interfaces/core.js.map +1 -1
- package/src/esm/utils/Params.d.ts +15 -0
- package/src/esm/utils/Params.js +44 -0
- package/src/esm/utils/Params.js.map +1 -0
- package/src/esm/utils/algorithms/ContourLineDetection.d.ts +150 -0
- package/src/esm/utils/algorithms/ContourLineDetection.js +362 -0
- package/src/esm/utils/algorithms/ContourLineDetection.js.map +1 -0
- package/src/esm/utils/algorithms/clearDuplicateVertices.d.ts +21 -0
- package/src/esm/utils/algorithms/clearDuplicateVertices.js +44 -0
- package/src/esm/utils/algorithms/clearDuplicateVertices.js.map +1 -0
- package/src/esm/utils/datastructures/DataGrid2d.d.ts +47 -0
- package/src/esm/utils/datastructures/DataGrid2d.js +19 -0
- package/src/esm/utils/datastructures/DataGrid2d.js.map +1 -0
- package/src/esm/utils/datastructures/DataGrid2dListAdapter.d.ts +65 -0
- package/src/esm/utils/datastructures/DataGrid2dListAdapter.js +79 -0
- package/src/esm/utils/datastructures/DataGrid2dListAdapter.js.map +1 -0
- package/src/esm/utils/datastructures/GenericPath.d.ts +14 -3
- package/src/esm/utils/datastructures/GenericPath.js +20 -3
- package/src/esm/utils/datastructures/GenericPath.js.map +1 -1
- package/src/esm/utils/detectDarkMode.d.ts +10 -0
- package/src/esm/utils/detectDarkMode.js +28 -0
- package/src/esm/utils/detectDarkMode.js.map +1 -0
- package/src/ts/BezierPath.ts +72 -241
- package/src/ts/Bounds.ts +25 -1
- package/src/ts/CubicBezierCurve.ts +139 -12
- package/src/ts/Line.ts +2 -1
- package/src/ts/PBText.ts +10 -9
- package/src/ts/PlotBoilerplate.ts +56 -19
- package/src/ts/Polygon.ts +121 -1
- package/src/ts/VEllipse.ts +2 -2
- package/src/ts/Vector.ts +4 -4
- package/src/ts/VertTuple.ts +4 -3
- package/src/ts/Vertex.ts +20 -4
- package/src/ts/draw.ts +311 -115
- package/src/ts/drawgl.ts +133 -71
- package/src/ts/drawutilssvg.ts +543 -121
- package/src/ts/interfaces/DrawLib.ts +219 -83
- package/src/ts/interfaces/core.ts +14 -2
- package/src/ts/utils/Params.ts +47 -0
- package/src/ts/utils/algorithms/ContourLineDetection.ts +485 -0
- package/src/ts/utils/algorithms/clearDuplicateVertices.ts +49 -0
- package/src/ts/utils/datastructures/DataGrid2d.ts +54 -0
- package/src/ts/utils/datastructures/DataGrid2dListAdapter.ts +121 -0
- package/src/ts/utils/datastructures/GenericPath.ts +21 -3
- package/src/ts/utils/detectDarkMode.ts +30 -0
package/dist/plotboilerplate.js
CHANGED
|
@@ -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
|
-
* @
|
|
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(
|
|
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
|
-
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
|
|
2621
|
-
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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
|
|
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
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
-
|
|
6152
|
-
|
|
6153
|
-
|
|
6154
|
-
|
|
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
|
-
|
|
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,
|
|
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,11 @@ __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
|
-
* @
|
|
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
|
+
* @modified 2023-11-24 Added the `Polygon.containsPolygon(Polygon)' function.
|
|
6375
|
+
* @version 1.12.0
|
|
6353
6376
|
*
|
|
6354
6377
|
* @file Polygon
|
|
6355
6378
|
* @public
|
|
@@ -6358,6 +6381,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
6358
6381
|
exports.Polygon = void 0;
|
|
6359
6382
|
var BezierPath_1 = __webpack_require__(126);
|
|
6360
6383
|
var Bounds_1 = __webpack_require__(262);
|
|
6384
|
+
var Line_1 = __webpack_require__(831);
|
|
6361
6385
|
var UIDGenerator_1 = __webpack_require__(197);
|
|
6362
6386
|
var Vertex_1 = __webpack_require__(421);
|
|
6363
6387
|
/**
|
|
@@ -6464,6 +6488,34 @@ var Polygon = /** @class */ (function () {
|
|
|
6464
6488
|
}
|
|
6465
6489
|
return inside;
|
|
6466
6490
|
};
|
|
6491
|
+
/**
|
|
6492
|
+
* Check if the passed polygon is completly contained inside this polygon.
|
|
6493
|
+
*
|
|
6494
|
+
* This means:
|
|
6495
|
+
* - all polygon's vertices must be inside this polygon.
|
|
6496
|
+
* - the polygon has no edge intersections with this polygon.
|
|
6497
|
+
*
|
|
6498
|
+
* @param {Polygon} polygon - The polygon to check if contained.
|
|
6499
|
+
* @return {boolean}
|
|
6500
|
+
*/
|
|
6501
|
+
Polygon.prototype.containsPolygon = function (polygon) {
|
|
6502
|
+
for (var i = 0; i < polygon.vertices.length; i++) {
|
|
6503
|
+
if (!this.containsVert(polygon.vertices[i])) {
|
|
6504
|
+
return false;
|
|
6505
|
+
}
|
|
6506
|
+
}
|
|
6507
|
+
// All vertices are inside; check for intersections
|
|
6508
|
+
var lineSegment = new Line_1.Line(new Vertex_1.Vertex(), new Vertex_1.Vertex());
|
|
6509
|
+
for (var i = 0; i < polygon.vertices.length; i++) {
|
|
6510
|
+
lineSegment.a.set(polygon.vertices[i]);
|
|
6511
|
+
lineSegment.b.set(polygon.vertices[(i + 1) % polygon.vertices.length]);
|
|
6512
|
+
if (this.lineIntersections(lineSegment, true).length > 0) {
|
|
6513
|
+
// Current segment has intersection(s) with this polygon.
|
|
6514
|
+
return false;
|
|
6515
|
+
}
|
|
6516
|
+
}
|
|
6517
|
+
return true;
|
|
6518
|
+
};
|
|
6467
6519
|
/**
|
|
6468
6520
|
* Calculate the area of the given polygon (unsigned).
|
|
6469
6521
|
*
|
|
@@ -6557,6 +6609,88 @@ var Polygon = /** @class */ (function () {
|
|
|
6557
6609
|
}
|
|
6558
6610
|
return this;
|
|
6559
6611
|
};
|
|
6612
|
+
/**
|
|
6613
|
+
* Get all line intersections with this polygon.
|
|
6614
|
+
*
|
|
6615
|
+
* See demo `47-closest-vector-projection-on-polygon` for how it works.
|
|
6616
|
+
*
|
|
6617
|
+
* @param {VertTuple} line - The line to find intersections with.
|
|
6618
|
+
* @param {boolean} inVectorBoundsOnly - If set to true only intersecion points on the passed vector are returned (located strictly between start and end vertex).
|
|
6619
|
+
* @returns {Array<Vertex>} - An array of all intersections within the polygon bounds.
|
|
6620
|
+
*/
|
|
6621
|
+
Polygon.prototype.lineIntersections = function (line, inVectorBoundsOnly) {
|
|
6622
|
+
if (inVectorBoundsOnly === void 0) { inVectorBoundsOnly = false; }
|
|
6623
|
+
// Find the intersections of all lines inside the edge bounds
|
|
6624
|
+
var intersectionPoints = [];
|
|
6625
|
+
for (var i = 0; i < this.vertices.length; i++) {
|
|
6626
|
+
var polyLine = new Line_1.Line(this.vertices[i], this.vertices[(i + 1) % this.vertices.length]);
|
|
6627
|
+
var intersection = polyLine.intersection(line);
|
|
6628
|
+
// true => only inside bounds
|
|
6629
|
+
// ignore last edge if open
|
|
6630
|
+
if ((!this.isOpen || i + 1 !== this.vertices.length) &&
|
|
6631
|
+
intersection !== null &&
|
|
6632
|
+
polyLine.hasPoint(intersection, true) &&
|
|
6633
|
+
(!inVectorBoundsOnly || line.hasPoint(intersection, inVectorBoundsOnly))) {
|
|
6634
|
+
intersectionPoints.push(intersection);
|
|
6635
|
+
}
|
|
6636
|
+
}
|
|
6637
|
+
return intersectionPoints;
|
|
6638
|
+
};
|
|
6639
|
+
/**
|
|
6640
|
+
* Get the closest line-polygon-intersection point (closest the line point A).
|
|
6641
|
+
*
|
|
6642
|
+
* See demo `47-closest-vector-projection-on-polygon` for how it works.
|
|
6643
|
+
*
|
|
6644
|
+
* @param {VertTuple} line - The line to find intersections with.
|
|
6645
|
+
* @param {boolean} inVectorBoundsOnly - If set to true only intersecion points on the passed vector are considered (located strictly between start and end vertex).
|
|
6646
|
+
* @returns {Array<Vertex>} - An array of all intersections within the polygon bounds.
|
|
6647
|
+
*/
|
|
6648
|
+
Polygon.prototype.closestLineIntersection = function (line, inVectorBoundsOnly) {
|
|
6649
|
+
if (inVectorBoundsOnly === void 0) { inVectorBoundsOnly = false; }
|
|
6650
|
+
var allIntersections = this.lineIntersections(line, inVectorBoundsOnly);
|
|
6651
|
+
if (allIntersections.length <= 0) {
|
|
6652
|
+
// Empty polygon -> no intersections
|
|
6653
|
+
return null;
|
|
6654
|
+
}
|
|
6655
|
+
// Find the closest intersection
|
|
6656
|
+
var closestIntersection = new Vertex_1.Vertex(Number.MAX_VALUE, Number.MAX_VALUE);
|
|
6657
|
+
var curDist = Number.MAX_VALUE;
|
|
6658
|
+
for (var i in allIntersections) {
|
|
6659
|
+
var curVert = allIntersections[i];
|
|
6660
|
+
var dist = curVert.distance(line.a);
|
|
6661
|
+
if (dist < curDist) {
|
|
6662
|
+
// && line.hasPoint(curVert)) {
|
|
6663
|
+
curDist = dist;
|
|
6664
|
+
closestIntersection = curVert;
|
|
6665
|
+
}
|
|
6666
|
+
}
|
|
6667
|
+
return closestIntersection;
|
|
6668
|
+
};
|
|
6669
|
+
/**
|
|
6670
|
+
* Construct a new polygon from this polygon with more vertices on each edge. The
|
|
6671
|
+
* interpolation count determines the number of additional vertices on each edge.
|
|
6672
|
+
* An interpolation count of `0` will return a polygon that equals the source
|
|
6673
|
+
* polygon.
|
|
6674
|
+
*
|
|
6675
|
+
* @param {number} interpolationCount
|
|
6676
|
+
* @returns {Polygon} A polygon with `interpolationCount` more vertices (as as factor).
|
|
6677
|
+
*/
|
|
6678
|
+
Polygon.prototype.getInterpolationPolygon = function (interpolationCount) {
|
|
6679
|
+
var verts = [];
|
|
6680
|
+
for (var i = 0; i < this.vertices.length; i++) {
|
|
6681
|
+
var curVert = this.vertices[i];
|
|
6682
|
+
var nextVert = this.vertices[(i + 1) % this.vertices.length];
|
|
6683
|
+
verts.push(curVert.clone());
|
|
6684
|
+
// Add interpolation points
|
|
6685
|
+
if (!this.isOpen || i + 1 !== this.vertices.length) {
|
|
6686
|
+
var lerpAmount = 1.0 / (interpolationCount + 1);
|
|
6687
|
+
for (var j = 1; j <= interpolationCount; j++) {
|
|
6688
|
+
verts.push(curVert.clone().lerp(nextVert, lerpAmount * j));
|
|
6689
|
+
}
|
|
6690
|
+
}
|
|
6691
|
+
}
|
|
6692
|
+
return new Polygon(verts, this.isOpen);
|
|
6693
|
+
};
|
|
6560
6694
|
/**
|
|
6561
6695
|
* Convert this polygon into a new polygon with n evenly distributed vertices.
|
|
6562
6696
|
*
|
|
@@ -7586,7 +7720,7 @@ var VEllipse = /** @class */ (function () {
|
|
|
7586
7720
|
else {
|
|
7587
7721
|
var startTangent = this.tangentAt(curAngle);
|
|
7588
7722
|
var endTangent = this.tangentAt(nextAngle);
|
|
7589
|
-
// Find intersection
|
|
7723
|
+
// Find intersection (ignore that the result might be null in some extreme cases)
|
|
7590
7724
|
var intersection = startTangent.intersection(endTangent);
|
|
7591
7725
|
// What if intersection is undefined?
|
|
7592
7726
|
// --> This *can* not happen if segmentCount > 2 and height and width of the ellipse are not zero.
|
|
@@ -8131,8 +8265,8 @@ var Vector = /** @class */ (function (_super) {
|
|
|
8131
8265
|
* Example:
|
|
8132
8266
|
* buildArrowHead( new Vertex(0,0), new Vertex(50,100), 8, 1.0, 1.0 )
|
|
8133
8267
|
*
|
|
8134
|
-
* @param {
|
|
8135
|
-
* @param {
|
|
8268
|
+
* @param {XYCoords} zA - The start vertex of the vector to calculate the arrow head for.
|
|
8269
|
+
* @param {XYCoords} zB - The end vertex of the vector.
|
|
8136
8270
|
* @param {number} headlen - The length of the arrow head (along the vector direction. A good value is 12).
|
|
8137
8271
|
* @param {number} scaleX - The horizontal scaling during draw.
|
|
8138
8272
|
* @param {number} scaleY - the vertical scaling during draw.
|
|
@@ -8169,7 +8303,8 @@ exports.Vector = Vector;
|
|
|
8169
8303
|
* @modified 2020-12-04 Added the `hasPoint(XYCoords)` function.
|
|
8170
8304
|
* @modified 2021-01-20 Added UID.
|
|
8171
8305
|
* @modified 2022-02-02 Added the `destroy` method.
|
|
8172
|
-
* @
|
|
8306
|
+
* @modified 2023-09-29 Fixed a calculation error in the VertTuple.hasPoint() function; distance measure was broken!
|
|
8307
|
+
* @version 1.2.1
|
|
8173
8308
|
*/
|
|
8174
8309
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
8175
8310
|
exports.VertTuple = void 0;
|
|
@@ -8387,12 +8522,12 @@ var VertTuple = /** @class */ (function () {
|
|
|
8387
8522
|
VertTuple.prototype.hasPoint = function (point, insideBoundsOnly) {
|
|
8388
8523
|
var t = this.getClosestT(point);
|
|
8389
8524
|
// Compare to pointDistance?
|
|
8525
|
+
var distance = Math.sqrt(VertTuple.vtutils.dist2(point, this.vertAt(t)));
|
|
8390
8526
|
if (typeof insideBoundsOnly !== "undefined" && insideBoundsOnly) {
|
|
8391
|
-
var distance = Math.sqrt(VertTuple.vtutils.dist2(point, this.vertAt(t)));
|
|
8392
8527
|
return distance < Vertex_1.Vertex.EPSILON && t >= 0 && t <= 1;
|
|
8393
8528
|
}
|
|
8394
8529
|
else {
|
|
8395
|
-
return t >= 0 && t <= 1;
|
|
8530
|
+
return distance < Vertex_1.Vertex.EPSILON; // t >= 0 && t <= 1;
|
|
8396
8531
|
}
|
|
8397
8532
|
};
|
|
8398
8533
|
/**
|
|
@@ -8504,6 +8639,8 @@ exports.VertTuple = VertTuple;
|
|
|
8504
8639
|
* @modified 2022-02-02 Added the `destroy` method.
|
|
8505
8640
|
* @modified 2022-02-02 Cleared the `Vertex.toSVGString` function (deprecated). Use `drawutilssvg` instead.
|
|
8506
8641
|
* @modified 2022-11-28 Added the `subXY`, `subX` and `subY` methods to the `Vertex` class.
|
|
8642
|
+
* @modified 2023-09-29 Downgraded types for the `Vertex.utils.buildArrowHead` function (replacing Vertex params by more generic XYCoords type).
|
|
8643
|
+
* @modified 2023-09-29 Added the `Vertex.abs()` method as it seems useful.
|
|
8507
8644
|
* @version 2.8.0
|
|
8508
8645
|
*
|
|
8509
8646
|
* @file Vertex
|
|
@@ -9025,6 +9162,19 @@ var Vertex = /** @class */ (function () {
|
|
|
9025
9162
|
this.y = -this.y;
|
|
9026
9163
|
return this;
|
|
9027
9164
|
};
|
|
9165
|
+
/**
|
|
9166
|
+
* Set both coordinates of this vertex to their absolute value (abs(x), abs(y)).
|
|
9167
|
+
*
|
|
9168
|
+
* @method abs
|
|
9169
|
+
* @return {Vertex} this
|
|
9170
|
+
* @instance
|
|
9171
|
+
* @memberof Vertex
|
|
9172
|
+
*/
|
|
9173
|
+
Vertex.prototype.abs = function () {
|
|
9174
|
+
this.x = Math.abs(this.x);
|
|
9175
|
+
this.y = Math.abs(this.y);
|
|
9176
|
+
return this;
|
|
9177
|
+
};
|
|
9028
9178
|
/**
|
|
9029
9179
|
* Get a string representation of this vertex.
|
|
9030
9180
|
*
|
|
@@ -9082,15 +9232,15 @@ var Vertex = /** @class */ (function () {
|
|
|
9082
9232
|
* Example:
|
|
9083
9233
|
* buildArrowHead( new Vertex(0,0), new Vertex(50,100), 8, 1.0, 1.0 )
|
|
9084
9234
|
*
|
|
9085
|
-
* @param {
|
|
9086
|
-
* @param {
|
|
9235
|
+
* @param {XYCoords} zA - The start vertex of the vector to calculate the arrow head for.
|
|
9236
|
+
* @param {XYCoords} zB - The end vertex of the vector.
|
|
9087
9237
|
* @param {number} headlen - The length of the arrow head (along the vector direction. A good value is 12).
|
|
9088
9238
|
* @param {number} scaleX - The horizontal scaling during draw.
|
|
9089
9239
|
* @param {number} scaleY - the vertical scaling during draw.
|
|
9090
9240
|
**/
|
|
9091
9241
|
// @DEPRECATED: use Vector.utils.buildArrowHead instead!!!
|
|
9092
9242
|
buildArrowHead: function (zA, zB, headlen, scaleX, scaleY) {
|
|
9093
|
-
|
|
9243
|
+
console.warn("[DEPRECATION] Vertex.utils.buildArrowHead is deprecated. Please use Vector.utils.buildArrowHead instead.");
|
|
9094
9244
|
var angle = Math.atan2((zB.y - zA.y) * scaleY, (zB.x - zA.x) * scaleX);
|
|
9095
9245
|
var vertices = [];
|
|
9096
9246
|
vertices.push(new Vertex(zB.x * scaleX - headlen * Math.cos(angle), zB.y * scaleY - headlen * Math.sin(angle)));
|
|
@@ -9511,13 +9661,22 @@ exports.VertexListeners = VertexListeners;
|
|
|
9511
9661
|
* @modified 2022-08-23 Fixed a type issue in the `setConfiguration` function.
|
|
9512
9662
|
* @modified 2022-08-23 Fixed a type issue in the `path` function.
|
|
9513
9663
|
* @modified 2023-02-10 The methods `setCurrentClassName` and `setCurrentId` also accept `null` now.
|
|
9514
|
-
* @
|
|
9664
|
+
* @modified 2023-09-29 Removed unused method stub for texturedPoly helper function (cleanup).
|
|
9665
|
+
* @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.
|
|
9666
|
+
* @modified 2023-09-29 Added the `headLength` parameter to the 'DrawLib.arrow()` function.
|
|
9667
|
+
* @modified 2023-09-29 Added the `arrowHead(...)` function to the 'DrawLib.arrow()` interface.
|
|
9668
|
+
* @modified 2023-09-29 Added the `cubicBezierArrow(...)` function to the 'DrawLib.arrow()` interface.
|
|
9669
|
+
* @modified 2023-09-29 Added the `lineDashes` attribute.
|
|
9670
|
+
* @modified 2023-09-30 Adding `strokeOptions` param to these draw function: line, arrow, cubicBezierArrow, cubicBezier, cubicBezierPath, circle, circleArc, ellipse, square, rect, polygon, polyline.
|
|
9671
|
+
* @modified 2023-10-07 Adding the optional `arrowHeadBasePositionBuffer` param to the arrowHead(...) method.
|
|
9672
|
+
* @version 1.13.0
|
|
9515
9673
|
**/
|
|
9516
9674
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
9517
9675
|
exports.drawutils = void 0;
|
|
9518
9676
|
var CubicBezierCurve_1 = __webpack_require__(510);
|
|
9519
9677
|
var Vertex_1 = __webpack_require__(421);
|
|
9520
9678
|
var drawutilssvg_1 = __webpack_require__(829);
|
|
9679
|
+
var Vector_1 = __webpack_require__(73);
|
|
9521
9680
|
// Todo: rename this class to Drawutils?
|
|
9522
9681
|
/**
|
|
9523
9682
|
* @classdesc A wrapper class for basic drawing operations.
|
|
@@ -9538,10 +9697,48 @@ var drawutils = /** @class */ (function () {
|
|
|
9538
9697
|
**/
|
|
9539
9698
|
function drawutils(context, fillShapes) {
|
|
9540
9699
|
this.ctx = context;
|
|
9700
|
+
// this.lineDash = [];
|
|
9541
9701
|
this.offset = new Vertex_1.Vertex(0, 0);
|
|
9542
9702
|
this.scale = new Vertex_1.Vertex(1, 1);
|
|
9543
9703
|
this.fillShapes = fillShapes;
|
|
9544
9704
|
}
|
|
9705
|
+
/**
|
|
9706
|
+
* A private helper method to apply stroke options to the current
|
|
9707
|
+
* context.
|
|
9708
|
+
* @param {StrokeOptions=} strokeOptions -
|
|
9709
|
+
*/
|
|
9710
|
+
drawutils.prototype.applyStrokeOpts = function (strokeOptions) {
|
|
9711
|
+
var _this = this;
|
|
9712
|
+
var _a, _b;
|
|
9713
|
+
this.ctx.setLineDash(((_a = strokeOptions === null || strokeOptions === void 0 ? void 0 : strokeOptions.dashArray) !== null && _a !== void 0 ? _a : []).map(function (dashArrayElem) {
|
|
9714
|
+
// Note assume scale.x === scale.y
|
|
9715
|
+
// Invariant scale makes funny stuff anyway.
|
|
9716
|
+
return dashArrayElem * _this.scale.x;
|
|
9717
|
+
}));
|
|
9718
|
+
this.ctx.lineDashOffset = ((_b = strokeOptions === null || strokeOptions === void 0 ? void 0 : strokeOptions.dashOffset) !== null && _b !== void 0 ? _b : 0) * this.scale.x;
|
|
9719
|
+
};
|
|
9720
|
+
// +---------------------------------------------------------------------------------
|
|
9721
|
+
// | This is the final helper function for drawing and filling stuff. It is not
|
|
9722
|
+
// | intended to be used from the outside.
|
|
9723
|
+
// |
|
|
9724
|
+
// | When in draw mode it draws the current shape.
|
|
9725
|
+
// | When in fill mode it fills the current shape.
|
|
9726
|
+
// |
|
|
9727
|
+
// | This function is usually only called internally.
|
|
9728
|
+
// |
|
|
9729
|
+
// | @param color A stroke/fill color to use.
|
|
9730
|
+
// +-------------------------------
|
|
9731
|
+
// TODO: convert this to a STATIC function.
|
|
9732
|
+
drawutils.prototype._fillOrDraw = function (color) {
|
|
9733
|
+
if (this.fillShapes) {
|
|
9734
|
+
this.ctx.fillStyle = color;
|
|
9735
|
+
this.ctx.fill();
|
|
9736
|
+
}
|
|
9737
|
+
else {
|
|
9738
|
+
this.ctx.strokeStyle = color;
|
|
9739
|
+
this.ctx.stroke();
|
|
9740
|
+
}
|
|
9741
|
+
};
|
|
9545
9742
|
/**
|
|
9546
9743
|
* Called before each draw cycle.
|
|
9547
9744
|
* @param {UID=} uid - (optional) A UID identifying the currently drawn element(s).
|
|
@@ -9572,6 +9769,20 @@ var drawutils = /** @class */ (function () {
|
|
|
9572
9769
|
drawutils.prototype.setConfiguration = function (configuration) {
|
|
9573
9770
|
this.ctx.globalCompositeOperation = configuration.blendMode || "source-over";
|
|
9574
9771
|
};
|
|
9772
|
+
// /**
|
|
9773
|
+
// * Set or clear the line-dash configuration. Pass `null` for un-dashed lines.
|
|
9774
|
+
// *
|
|
9775
|
+
// * See https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray
|
|
9776
|
+
// * and https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash
|
|
9777
|
+
// * for how line dashes work.
|
|
9778
|
+
// *
|
|
9779
|
+
// * @method
|
|
9780
|
+
// * @param {Array<number> lineDashes - The line-dash array configuration.
|
|
9781
|
+
// * @returns {void}
|
|
9782
|
+
// */
|
|
9783
|
+
// setLineDash(lineDash: Array<number>) {
|
|
9784
|
+
// this.lineDash = lineDash;
|
|
9785
|
+
// }
|
|
9575
9786
|
/**
|
|
9576
9787
|
* This method shouled be called each time the currently drawn `Drawable` changes.
|
|
9577
9788
|
* It is used by some libraries for identifying elemente on re-renders.
|
|
@@ -9598,17 +9809,20 @@ var drawutils = /** @class */ (function () {
|
|
|
9598
9809
|
* Draw the line between the given two points with the specified (CSS-) color.
|
|
9599
9810
|
*
|
|
9600
9811
|
* @method line
|
|
9601
|
-
* @param {
|
|
9602
|
-
* @param {
|
|
9812
|
+
* @param {XYCoords} zA - The start point of the line.
|
|
9813
|
+
* @param {XYCoords} zB - The end point of the line.
|
|
9603
9814
|
* @param {string} color - Any valid CSS color string.
|
|
9604
9815
|
* @param {number} lineWidth? - [optional] The line's width.
|
|
9816
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
9817
|
+
*
|
|
9605
9818
|
* @return {void}
|
|
9606
9819
|
* @instance
|
|
9607
9820
|
* @memberof drawutils
|
|
9608
9821
|
**/
|
|
9609
|
-
drawutils.prototype.line = function (zA, zB, color, lineWidth) {
|
|
9822
|
+
drawutils.prototype.line = function (zA, zB, color, lineWidth, strokeOptions) {
|
|
9610
9823
|
this.ctx.save();
|
|
9611
9824
|
this.ctx.beginPath();
|
|
9825
|
+
this.applyStrokeOpts(strokeOptions);
|
|
9612
9826
|
this.ctx.moveTo(this.offset.x + zA.x * this.scale.x, this.offset.y + zA.y * this.scale.y);
|
|
9613
9827
|
this.ctx.lineTo(this.offset.x + zB.x * this.scale.x, this.offset.y + zB.y * this.scale.y);
|
|
9614
9828
|
this.ctx.strokeStyle = color;
|
|
@@ -9620,22 +9834,76 @@ var drawutils = /** @class */ (function () {
|
|
|
9620
9834
|
* Draw a line and an arrow at the end (zB) of the given line with the specified (CSS-) color.
|
|
9621
9835
|
*
|
|
9622
9836
|
* @method arrow
|
|
9623
|
-
* @param {
|
|
9624
|
-
* @param {
|
|
9837
|
+
* @param {XYCoords} zA - The start point of the arrow-line.
|
|
9838
|
+
* @param {XYCoords} zB - The end point of the arrow-line.
|
|
9625
9839
|
* @param {string} color - Any valid CSS color string.
|
|
9626
9840
|
* @param {number=} lineWidth - (optional) The line width to use; default is 1.
|
|
9841
|
+
* @param {headLength=8} headLength - (optional) The length of the arrow head (default is 8 units).
|
|
9842
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
9843
|
+
*
|
|
9627
9844
|
* @return {void}
|
|
9628
9845
|
* @instance
|
|
9629
9846
|
* @memberof drawutils
|
|
9630
9847
|
**/
|
|
9631
|
-
drawutils.prototype.arrow = function (zA, zB, color, lineWidth) {
|
|
9632
|
-
|
|
9633
|
-
|
|
9634
|
-
|
|
9848
|
+
drawutils.prototype.arrow = function (zA, zB, color, lineWidth, headLength, strokeOptions) {
|
|
9849
|
+
if (headLength === void 0) { headLength = 8; }
|
|
9850
|
+
var arrowHeadBasePosition = new Vertex_1.Vertex(0, 0);
|
|
9851
|
+
this.arrowHead(zA, zB, color, lineWidth, headLength, undefined, arrowHeadBasePosition); // Will NOT use dash configuration
|
|
9852
|
+
this.line(zA, arrowHeadBasePosition, color, lineWidth, strokeOptions); // Will use dash configuration
|
|
9853
|
+
};
|
|
9854
|
+
/**
|
|
9855
|
+
* 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.
|
|
9856
|
+
*
|
|
9857
|
+
* @method cubicBezierArrow
|
|
9858
|
+
* @param {XYCoords} startPoint - The start point of the cubic Bézier curve
|
|
9859
|
+
* @param {XYCoords} endPoint - The end point the cubic Bézier curve.
|
|
9860
|
+
* @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
|
|
9861
|
+
* @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
|
|
9862
|
+
* @param {string} color - The CSS color to draw the curve with.
|
|
9863
|
+
* @param {number} lineWidth - (optional) The line width to use.
|
|
9864
|
+
* @param {headLength=8} headLength - (optional) The length of the arrow head (default is 8 units).
|
|
9865
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
9866
|
+
*
|
|
9867
|
+
* @return {void}
|
|
9868
|
+
* @instance
|
|
9869
|
+
* @memberof DrawLib
|
|
9870
|
+
*/
|
|
9871
|
+
drawutils.prototype.cubicBezierArrow = function (startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, headLength, strokeOptions) {
|
|
9872
|
+
var arrowHeadBasePosition = new Vertex_1.Vertex(0, 0);
|
|
9873
|
+
// Will NOT use dash configuration
|
|
9874
|
+
this.arrowHead(endControlPoint, endPoint, color, lineWidth, headLength, undefined, arrowHeadBasePosition);
|
|
9875
|
+
var diff = arrowHeadBasePosition.difference(endPoint);
|
|
9876
|
+
// Will use dash configuration
|
|
9877
|
+
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);
|
|
9878
|
+
};
|
|
9879
|
+
/**
|
|
9880
|
+
* Draw just an arrow head a the end of an imaginary line (zB) of the given line width the specified (CSS-) color and size.
|
|
9881
|
+
*
|
|
9882
|
+
* @method arrow
|
|
9883
|
+
* @param {XYCoords} zA - The start point of the arrow-line.
|
|
9884
|
+
* @param {XYCoords} zB - The end point of the arrow-line.
|
|
9885
|
+
* @param {string} color - Any valid CSS color string.
|
|
9886
|
+
* @param {number=1} lineWidth - (optional) The line width to use; default is 1.
|
|
9887
|
+
* @param {number=8} headLength - (optional) The length of the arrow head (default is 8 pixels).
|
|
9888
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
9889
|
+
* @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.
|
|
9890
|
+
*
|
|
9891
|
+
* @return {void}
|
|
9892
|
+
* @instance
|
|
9893
|
+
* @memberof DrawLib
|
|
9894
|
+
**/
|
|
9895
|
+
drawutils.prototype.arrowHead = function (zA, zB, color, lineWidth, headLength, strokeOptions, arrowHeadBasePositionBuffer) {
|
|
9896
|
+
// var headLength: number = 8; // length of head in pixels
|
|
9897
|
+
if (headLength === void 0) { headLength = 8; }
|
|
9635
9898
|
this.ctx.save();
|
|
9636
9899
|
this.ctx.beginPath();
|
|
9637
|
-
|
|
9638
|
-
|
|
9900
|
+
this.applyStrokeOpts(strokeOptions);
|
|
9901
|
+
var vertices = Vector_1.Vector.utils.buildArrowHead(zA, zB, headLength, this.scale.x, this.scale.y);
|
|
9902
|
+
if (arrowHeadBasePositionBuffer) {
|
|
9903
|
+
arrowHeadBasePositionBuffer.x = vertices[0].x / this.scale.x;
|
|
9904
|
+
arrowHeadBasePositionBuffer.y = vertices[0].y / this.scale.y;
|
|
9905
|
+
}
|
|
9906
|
+
this.ctx.moveTo(this.offset.x + vertices[0].x, this.offset.y + vertices[0].y);
|
|
9639
9907
|
for (var i = 0; i < vertices.length; i++) {
|
|
9640
9908
|
this.ctx.lineTo(this.offset.x + vertices[i].x, this.offset.y + vertices[i].y);
|
|
9641
9909
|
}
|
|
@@ -9651,8 +9919,8 @@ var drawutils = /** @class */ (function () {
|
|
|
9651
9919
|
*
|
|
9652
9920
|
* @method image
|
|
9653
9921
|
* @param {Image} image - The image object to draw.
|
|
9654
|
-
* @param {
|
|
9655
|
-
* @param {
|
|
9922
|
+
* @param {XYCoords} position - The position to draw the the upper left corner at.
|
|
9923
|
+
* @param {XYCoords} size - The x/y-size to draw the image with.
|
|
9656
9924
|
* @param {number=0.0} alpha - (optional, default=0.0) The transparency (1.0=opaque, 0.0=transparent).
|
|
9657
9925
|
* @return {void}
|
|
9658
9926
|
* @instance
|
|
@@ -9682,7 +9950,7 @@ var drawutils = /** @class */ (function () {
|
|
|
9682
9950
|
* @param {Image} textureImage - The image object to draw.
|
|
9683
9951
|
* @param {Bounds} textureSize - The texture size to use; these are the original bounds to map the polygon vertices to.
|
|
9684
9952
|
* @param {Polygon} polygon - The polygon to use as clip path.
|
|
9685
|
-
* @param {
|
|
9953
|
+
* @param {XYCoords} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
|
|
9686
9954
|
* @param {number} rotation - The rotation to use for the polygon (and for the texture).
|
|
9687
9955
|
* @param {XYCoords={x:0,y:0}} rotationCenter - (optional) The rotational center; default is center of bounding box.
|
|
9688
9956
|
* @return {void}
|
|
@@ -9691,10 +9959,9 @@ var drawutils = /** @class */ (function () {
|
|
|
9691
9959
|
**/
|
|
9692
9960
|
drawutils.prototype.texturedPoly = function (textureImage, textureSize, polygon, polygonPosition, rotation) {
|
|
9693
9961
|
var basePolygonBounds = polygon.getBounds();
|
|
9694
|
-
var targetCenterDifference = polygonPosition.clone().difference(basePolygonBounds.getCenter());
|
|
9695
|
-
|
|
9696
|
-
// var
|
|
9697
|
-
var tileCenter = basePolygonBounds.getCenter().sub(targetCenterDifference);
|
|
9962
|
+
// var targetCenterDifference = polygonPosition.clone().difference(basePolygonBounds.getCenter());
|
|
9963
|
+
var targetCenterDifference = new Vertex_1.Vertex(polygonPosition.x, polygonPosition.y).difference(basePolygonBounds.getCenter());
|
|
9964
|
+
// var tileCenter = basePolygonBounds.getCenter().sub(targetCenterDifference);
|
|
9698
9965
|
// Get the position offset of the polygon
|
|
9699
9966
|
var targetTextureSize = new Vertex_1.Vertex(textureSize.width, textureSize.height);
|
|
9700
9967
|
// var targetTextureOffset = new Vertex(-textureSize.width / 2, -textureSize.height / 2).sub(targetCenterDifference);
|
|
@@ -9717,53 +9984,83 @@ var drawutils = /** @class */ (function () {
|
|
|
9717
9984
|
);
|
|
9718
9985
|
this.ctx.restore();
|
|
9719
9986
|
};
|
|
9720
|
-
|
|
9721
|
-
|
|
9722
|
-
|
|
9723
|
-
|
|
9724
|
-
|
|
9725
|
-
|
|
9726
|
-
|
|
9727
|
-
|
|
9728
|
-
|
|
9729
|
-
|
|
9730
|
-
|
|
9731
|
-
|
|
9732
|
-
|
|
9733
|
-
|
|
9734
|
-
|
|
9735
|
-
|
|
9736
|
-
|
|
9737
|
-
|
|
9738
|
-
|
|
9739
|
-
|
|
9740
|
-
|
|
9741
|
-
|
|
9987
|
+
/*
|
|
9988
|
+
_texturedPoly(
|
|
9989
|
+
textureImage: HTMLImageElement,
|
|
9990
|
+
textureSize: Bounds,
|
|
9991
|
+
polygon: Polygon,
|
|
9992
|
+
polygonPosition: XYCoords,
|
|
9993
|
+
rotation: number,
|
|
9994
|
+
rotationCenter: XYCoords = { x: 0, y: 0 }
|
|
9995
|
+
): void {
|
|
9996
|
+
var basePolygonBounds = polygon.getBounds();
|
|
9997
|
+
var targetCenterDifference = polygonPosition.clone().difference(basePolygonBounds.getCenter());
|
|
9998
|
+
var rotationalOffset = rotationCenter ? polygonPosition.difference(rotationCenter) : { x: 0, y: 0 };
|
|
9999
|
+
// var rotationalOffset = { x: 0, y: 0 };
|
|
10000
|
+
var tileCenter = basePolygonBounds.getCenter().sub(targetCenterDifference);
|
|
10001
|
+
|
|
10002
|
+
// Get the position offset of the polygon
|
|
10003
|
+
var targetTextureSize = new Vertex(textureSize.width, textureSize.height);
|
|
10004
|
+
var targetTextureOffset = new Vertex(-textureSize.width / 2, -textureSize.height / 2).sub(targetCenterDifference);
|
|
10005
|
+
|
|
10006
|
+
this.ctx.save();
|
|
10007
|
+
|
|
10008
|
+
// this.ctx.translate(
|
|
10009
|
+
// this.offset.x + (tileCenter.x - rotationalOffset.x * 0 + targetTextureOffset.x * 0.0) * this.scale.x,
|
|
10010
|
+
// this.offset.y + (tileCenter.y - rotationalOffset.y * 0 + targetTextureOffset.y * 0.0) * this.scale.y
|
|
10011
|
+
// );
|
|
10012
|
+
this.ctx.translate(
|
|
10013
|
+
this.offset.x + (tileCenter.x - rotationalOffset.x * 0 + targetTextureOffset.x * 0.0) * this.scale.x,
|
|
10014
|
+
this.offset.y + (tileCenter.y - rotationalOffset.y * 0 + targetTextureOffset.y * 0.0) * this.scale.y
|
|
10015
|
+
);
|
|
10016
|
+
this.ctx.rotate(rotation);
|
|
10017
|
+
|
|
10018
|
+
drawutils.helpers.clipPoly(
|
|
10019
|
+
this.ctx,
|
|
10020
|
+
{
|
|
10021
|
+
x: (-targetCenterDifference.x * 1 - tileCenter.x - rotationalOffset.x) * this.scale.x,
|
|
10022
|
+
y: (-targetCenterDifference.y * 1 - tileCenter.y - rotationalOffset.y) * this.scale.y
|
|
10023
|
+
},
|
|
10024
|
+
this.scale,
|
|
10025
|
+
polygon.vertices
|
|
10026
|
+
);
|
|
10027
|
+
this.ctx.drawImage(
|
|
10028
|
+
textureImage,
|
|
10029
|
+
0,
|
|
10030
|
+
0,
|
|
10031
|
+
textureImage.naturalWidth - 1, // There is this horrible Safari bug (fixed in newer versions)
|
|
9742
10032
|
textureImage.naturalHeight - 1, // To avoid errors substract 1 here.
|
|
9743
|
-
(-polygonPosition.x + targetTextureOffset.x * 1 - rotationalOffset.x * 1) * this.scale.x,
|
|
9744
|
-
|
|
9745
|
-
|
|
9746
|
-
|
|
9747
|
-
|
|
9748
|
-
|
|
9749
|
-
|
|
9750
|
-
|
|
9751
|
-
|
|
9752
|
-
|
|
9753
|
-
|
|
9754
|
-
|
|
9755
|
-
|
|
9756
|
-
|
|
9757
|
-
|
|
9758
|
-
|
|
9759
|
-
|
|
9760
|
-
|
|
9761
|
-
|
|
9762
|
-
|
|
9763
|
-
|
|
9764
|
-
|
|
9765
|
-
|
|
9766
|
-
|
|
10033
|
+
(-polygonPosition.x + targetTextureOffset.x * 1 - rotationalOffset.x * 1) * this.scale.x,
|
|
10034
|
+
(-polygonPosition.y + targetTextureOffset.y * 1 - rotationalOffset.y * 1) * this.scale.y,
|
|
10035
|
+
targetTextureSize.x * this.scale.x,
|
|
10036
|
+
targetTextureSize.y * this.scale.y
|
|
10037
|
+
);
|
|
10038
|
+
|
|
10039
|
+
// const scaledTextureSize = new Bounds(
|
|
10040
|
+
// new Vertex(
|
|
10041
|
+
// -polygonPosition.x + targetTextureOffset.x - rotationalOffset.x,
|
|
10042
|
+
// -polygonPosition.y + targetTextureOffset.y - rotationalOffset.y
|
|
10043
|
+
// ).scaleXY(this.scale, rotationCenter),
|
|
10044
|
+
// new Vertex(
|
|
10045
|
+
// -polygonPosition.x + targetTextureOffset.x - rotationalOffset.x + targetTextureSize.x,
|
|
10046
|
+
// -polygonPosition.y + targetTextureOffset.y - rotationalOffset.y + targetTextureSize.y
|
|
10047
|
+
// ).scaleXY(this.scale, rotationCenter)
|
|
10048
|
+
// );
|
|
10049
|
+
// this.ctx.drawImage(
|
|
10050
|
+
// textureImage,
|
|
10051
|
+
// 0,
|
|
10052
|
+
// 0,
|
|
10053
|
+
// textureImage.naturalWidth - 1, // There is this horrible Safari bug (fixed in newer versions)
|
|
10054
|
+
// textureImage.naturalHeight - 1, // To avoid errors substract 1 here.
|
|
10055
|
+
// scaledTextureSize.min.x,
|
|
10056
|
+
// scaledTextureSize.min.y,
|
|
10057
|
+
// scaledTextureSize.width,
|
|
10058
|
+
// scaledTextureSize.height
|
|
10059
|
+
// );
|
|
10060
|
+
|
|
10061
|
+
this.ctx.restore();
|
|
10062
|
+
}
|
|
10063
|
+
*/
|
|
9767
10064
|
/**
|
|
9768
10065
|
* Draw a rectangle.
|
|
9769
10066
|
*
|
|
@@ -9772,10 +10069,16 @@ var drawutils = /** @class */ (function () {
|
|
|
9772
10069
|
* @param {number} height - The height of the rectangle.
|
|
9773
10070
|
* @param {string} color - The color to use.
|
|
9774
10071
|
* @param {number=1} lineWidth - (optional) The line with to use (default is 1).
|
|
10072
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
10073
|
+
*
|
|
10074
|
+
* @return {void}
|
|
10075
|
+
* @instance
|
|
10076
|
+
* @memberof drawutils
|
|
9775
10077
|
**/
|
|
9776
|
-
drawutils.prototype.rect = function (position, width, height, color, lineWidth) {
|
|
10078
|
+
drawutils.prototype.rect = function (position, width, height, color, lineWidth, strokeOptions) {
|
|
9777
10079
|
this.ctx.save();
|
|
9778
10080
|
this.ctx.beginPath();
|
|
10081
|
+
this.applyStrokeOpts(strokeOptions);
|
|
9779
10082
|
this.ctx.moveTo(this.offset.x + position.x * this.scale.x, this.offset.y + position.y * this.scale.y);
|
|
9780
10083
|
this.ctx.lineTo(this.offset.x + (position.x + width) * this.scale.x, this.offset.y + position.y * this.scale.y);
|
|
9781
10084
|
this.ctx.lineTo(this.offset.x + (position.x + width) * this.scale.x, this.offset.y + (position.y + height) * this.scale.y);
|
|
@@ -9786,43 +10089,23 @@ var drawutils = /** @class */ (function () {
|
|
|
9786
10089
|
this._fillOrDraw(color);
|
|
9787
10090
|
this.ctx.restore();
|
|
9788
10091
|
};
|
|
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
10092
|
/**
|
|
9812
10093
|
* Draw the given (cubic) bézier curve.
|
|
9813
10094
|
*
|
|
9814
10095
|
* @method cubicBezier
|
|
9815
|
-
* @param {
|
|
9816
|
-
* @param {
|
|
9817
|
-
* @param {
|
|
9818
|
-
* @param {
|
|
10096
|
+
* @param {XYCoords} startPoint - The start point of the cubic Bézier curve
|
|
10097
|
+
* @param {XYCoords} endPoint - The end point the cubic Bézier curve.
|
|
10098
|
+
* @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
|
|
10099
|
+
* @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
|
|
9819
10100
|
* @param {string} color - The CSS color to draw the curve with.
|
|
9820
10101
|
* @param {number} lineWidth - (optional) The line width to use.
|
|
10102
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
10103
|
+
*
|
|
9821
10104
|
* @return {void}
|
|
9822
10105
|
* @instance
|
|
9823
10106
|
* @memberof drawutils
|
|
9824
10107
|
*/
|
|
9825
|
-
drawutils.prototype.cubicBezier = function (startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth) {
|
|
10108
|
+
drawutils.prototype.cubicBezier = function (startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, strokeOptions) {
|
|
9826
10109
|
if (startPoint instanceof CubicBezierCurve_1.CubicBezierCurve) {
|
|
9827
10110
|
this.cubicBezier(startPoint.startPoint, startPoint.endPoint, startPoint.startControlPoint, startPoint.endControlPoint, color, lineWidth);
|
|
9828
10111
|
return;
|
|
@@ -9830,6 +10113,7 @@ var drawutils = /** @class */ (function () {
|
|
|
9830
10113
|
// Draw curve
|
|
9831
10114
|
this.ctx.save();
|
|
9832
10115
|
this.ctx.beginPath();
|
|
10116
|
+
this.applyStrokeOpts(strokeOptions);
|
|
9833
10117
|
this.ctx.moveTo(this.offset.x + startPoint.x * this.scale.x, this.offset.y + startPoint.y * this.scale.y);
|
|
9834
10118
|
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
10119
|
//this.ctx.closePath();
|
|
@@ -9841,19 +10125,22 @@ var drawutils = /** @class */ (function () {
|
|
|
9841
10125
|
* Draw the given (quadratic) bézier curve.
|
|
9842
10126
|
*
|
|
9843
10127
|
* @method quadraticBezier
|
|
9844
|
-
* @param {
|
|
9845
|
-
* @param {
|
|
9846
|
-
* @param {
|
|
10128
|
+
* @param {XYCoords} startPoint - The start point of the cubic Bézier curve
|
|
10129
|
+
* @param {XYCoords} controlPoint - The control point the cubic Bézier curve.
|
|
10130
|
+
* @param {XYCoords} endPoint - The end control point the cubic Bézier curve.
|
|
9847
10131
|
* @param {string} color - The CSS color to draw the curve with.
|
|
9848
10132
|
* @param {number|string} lineWidth - (optional) The line width to use.
|
|
10133
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
10134
|
+
*
|
|
9849
10135
|
* @return {void}
|
|
9850
10136
|
* @instance
|
|
9851
10137
|
* @memberof drawutils
|
|
9852
10138
|
*/
|
|
9853
|
-
drawutils.prototype.quadraticBezier = function (startPoint, controlPoint, endPoint, color, lineWidth) {
|
|
10139
|
+
drawutils.prototype.quadraticBezier = function (startPoint, controlPoint, endPoint, color, lineWidth, strokeOptions) {
|
|
9854
10140
|
// Draw curve
|
|
9855
10141
|
this.ctx.save();
|
|
9856
10142
|
this.ctx.beginPath();
|
|
10143
|
+
this.applyStrokeOpts(strokeOptions);
|
|
9857
10144
|
this.ctx.moveTo(this.offset.x + startPoint.x * this.scale.x, this.offset.y + startPoint.y * this.scale.y);
|
|
9858
10145
|
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
10146
|
this.ctx.lineWidth = lineWidth || 2;
|
|
@@ -9868,22 +10155,26 @@ var drawutils = /** @class */ (function () {
|
|
|
9868
10155
|
* <pre> [ point1, point1_startControl, point2_endControl, point2, point2_startControl, point3_endControl, point3, ... pointN_endControl, pointN ]</pre>
|
|
9869
10156
|
*
|
|
9870
10157
|
* @method cubicBezierPath
|
|
9871
|
-
* @param {
|
|
10158
|
+
* @param {XYCoords[]} path - The cubic bezier path as described above.
|
|
9872
10159
|
* @param {string} color - The CSS colot to draw the path with.
|
|
9873
10160
|
* @param {number=1} lineWidth - (optional) The line width to use.
|
|
10161
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
10162
|
+
*
|
|
9874
10163
|
* @return {void}
|
|
9875
10164
|
* @instance
|
|
9876
10165
|
* @memberof drawutils
|
|
9877
10166
|
*/
|
|
9878
|
-
drawutils.prototype.cubicBezierPath = function (path, color, lineWidth) {
|
|
9879
|
-
if (!path || path.length == 0)
|
|
10167
|
+
drawutils.prototype.cubicBezierPath = function (path, color, lineWidth, strokeOptions) {
|
|
10168
|
+
if (!path || path.length == 0) {
|
|
9880
10169
|
return;
|
|
10170
|
+
}
|
|
9881
10171
|
// Draw curve
|
|
9882
10172
|
this.ctx.save();
|
|
9883
10173
|
this.ctx.beginPath();
|
|
9884
10174
|
var endPoint;
|
|
9885
10175
|
var startControlPoint;
|
|
9886
10176
|
var endControlPoint;
|
|
10177
|
+
this.applyStrokeOpts(strokeOptions);
|
|
9887
10178
|
this.ctx.moveTo(this.offset.x + path[0].x * this.scale.x, this.offset.y + path[0].y * this.scale.y);
|
|
9888
10179
|
for (var i = 1; i < path.length; i += 3) {
|
|
9889
10180
|
startControlPoint = path[i];
|
|
@@ -9902,8 +10193,8 @@ var drawutils = /** @class */ (function () {
|
|
|
9902
10193
|
* The colors for this are fixed and cannot be specified.
|
|
9903
10194
|
*
|
|
9904
10195
|
* @method handle
|
|
9905
|
-
* @param {
|
|
9906
|
-
* @param {
|
|
10196
|
+
* @param {XYCoords} startPoint - The start of the handle.
|
|
10197
|
+
* @param {XYCoords} endPoint - The end point of the handle.
|
|
9907
10198
|
* @return {void}
|
|
9908
10199
|
* @instance
|
|
9909
10200
|
* @memberof drawutils
|
|
@@ -9918,21 +10209,21 @@ var drawutils = /** @class */ (function () {
|
|
|
9918
10209
|
* Draw a handle line (with a light grey).
|
|
9919
10210
|
*
|
|
9920
10211
|
* @method handleLine
|
|
9921
|
-
* @param {
|
|
9922
|
-
* @param {
|
|
10212
|
+
* @param {XYCoords} startPoint - The start point to draw the handle at.
|
|
10213
|
+
* @param {XYCoords} endPoint - The end point to draw the handle at.
|
|
9923
10214
|
* @return {void}
|
|
9924
10215
|
* @instance
|
|
9925
10216
|
* @memberof drawutils
|
|
9926
10217
|
*/
|
|
9927
10218
|
drawutils.prototype.handleLine = function (startPoint, endPoint) {
|
|
9928
10219
|
// Draw handle lines
|
|
9929
|
-
this.line(startPoint, endPoint, "
|
|
10220
|
+
this.line(startPoint, endPoint, "rgba(128,128,128, 0.5)", undefined);
|
|
9930
10221
|
};
|
|
9931
10222
|
/**
|
|
9932
10223
|
* Draw a 1x1 dot with the specified (CSS-) color.
|
|
9933
10224
|
*
|
|
9934
10225
|
* @method dot
|
|
9935
|
-
* @param {
|
|
10226
|
+
* @param {XYCoords} p - The position to draw the dot at.
|
|
9936
10227
|
* @param {string} color - The CSS color to draw the dot with.
|
|
9937
10228
|
* @return {void}
|
|
9938
10229
|
* @instance
|
|
@@ -9941,6 +10232,7 @@ var drawutils = /** @class */ (function () {
|
|
|
9941
10232
|
drawutils.prototype.dot = function (p, color) {
|
|
9942
10233
|
this.ctx.save();
|
|
9943
10234
|
this.ctx.beginPath();
|
|
10235
|
+
this.ctx.setLineDash([]); // Clear line-dash settings
|
|
9944
10236
|
this.ctx.moveTo(Math.round(this.offset.x + this.scale.x * p.x), Math.round(this.offset.y + this.scale.y * p.y));
|
|
9945
10237
|
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
10238
|
this.ctx.closePath();
|
|
@@ -9952,7 +10244,7 @@ var drawutils = /** @class */ (function () {
|
|
|
9952
10244
|
* Draw the given point with the specified (CSS-) color and radius 3.
|
|
9953
10245
|
*
|
|
9954
10246
|
* @method point
|
|
9955
|
-
* @param {
|
|
10247
|
+
* @param {XYCoords} p - The position to draw the point at.
|
|
9956
10248
|
* @param {string} color - The CSS color to draw the point with.
|
|
9957
10249
|
* @return {void}
|
|
9958
10250
|
* @instance
|
|
@@ -9960,6 +10252,7 @@ var drawutils = /** @class */ (function () {
|
|
|
9960
10252
|
*/
|
|
9961
10253
|
drawutils.prototype.point = function (p, color) {
|
|
9962
10254
|
var radius = 3;
|
|
10255
|
+
this.ctx.setLineDash([]); // Clear line-dash settings
|
|
9963
10256
|
this.ctx.beginPath();
|
|
9964
10257
|
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
10258
|
this.ctx.closePath();
|
|
@@ -9972,15 +10265,18 @@ var drawutils = /** @class */ (function () {
|
|
|
9972
10265
|
* Note that if the x- and y- scales are different the result will be an ellipse rather than a circle.
|
|
9973
10266
|
*
|
|
9974
10267
|
* @method circle
|
|
9975
|
-
* @param {
|
|
10268
|
+
* @param {XYCoords} center - The center of the circle.
|
|
9976
10269
|
* @param {number} radius - The radius of the circle.
|
|
9977
10270
|
* @param {string} color - The CSS color to draw the circle with.
|
|
9978
10271
|
* @param {number} lineWidth - The line width (optional, default=1).
|
|
10272
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
10273
|
+
*
|
|
9979
10274
|
* @return {void}
|
|
9980
10275
|
* @instance
|
|
9981
10276
|
* @memberof drawutils
|
|
9982
10277
|
*/
|
|
9983
|
-
drawutils.prototype.circle = function (center, radius, color, lineWidth) {
|
|
10278
|
+
drawutils.prototype.circle = function (center, radius, color, lineWidth, strokeOptions) {
|
|
10279
|
+
this.applyStrokeOpts(strokeOptions);
|
|
9984
10280
|
this.ctx.beginPath();
|
|
9985
10281
|
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
10282
|
this.ctx.closePath();
|
|
@@ -9988,24 +10284,28 @@ var drawutils = /** @class */ (function () {
|
|
|
9988
10284
|
this._fillOrDraw(color);
|
|
9989
10285
|
};
|
|
9990
10286
|
/**
|
|
9991
|
-
|
|
9992
|
-
|
|
9993
|
-
|
|
9994
|
-
|
|
9995
|
-
|
|
9996
|
-
|
|
9997
|
-
|
|
9998
|
-
|
|
9999
|
-
|
|
10000
|
-
|
|
10001
|
-
|
|
10002
|
-
|
|
10003
|
-
|
|
10004
|
-
|
|
10287
|
+
* Draw a circular arc (section of a circle) with the given CSS color.
|
|
10288
|
+
*
|
|
10289
|
+
* @method circleArc
|
|
10290
|
+
* @param {XYCoords} center - The center of the circle.
|
|
10291
|
+
* @param {number} radius - The radius of the circle.
|
|
10292
|
+
* @param {number} startAngle - The angle to start at.
|
|
10293
|
+
* @param {number} endAngle - The angle to end at.
|
|
10294
|
+
* @param {string=#000000} color - The CSS color to draw the circle with.
|
|
10295
|
+
* @param {number=1} lineWidth - The line width to use
|
|
10296
|
+
* @param {boolean=false} options.asSegment - If `true` then no beginPath and no draw will be applied (as part of larger path).
|
|
10297
|
+
* @param {number=} options.dashOffset - (optional) `See StrokeOptions`.
|
|
10298
|
+
* @param {number=[]} options.dashArray - (optional) `See StrokeOptions`.
|
|
10299
|
+
*
|
|
10300
|
+
* @return {void}
|
|
10301
|
+
* @instance
|
|
10302
|
+
* @memberof drawutils
|
|
10303
|
+
*/
|
|
10005
10304
|
drawutils.prototype.circleArc = function (center, radius, startAngle, endAngle, color, lineWidth, options) {
|
|
10006
10305
|
if (!options || !options.asSegment) {
|
|
10007
10306
|
this.ctx.beginPath();
|
|
10008
10307
|
}
|
|
10308
|
+
this.applyStrokeOpts(options);
|
|
10009
10309
|
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
10310
|
if (!options || !options.asSegment) {
|
|
10011
10311
|
// this.ctx.closePath();
|
|
@@ -10017,20 +10317,23 @@ var drawutils = /** @class */ (function () {
|
|
|
10017
10317
|
* Draw an ellipse with the specified (CSS-) color and thw two radii.
|
|
10018
10318
|
*
|
|
10019
10319
|
* @method ellipse
|
|
10020
|
-
* @param {
|
|
10320
|
+
* @param {XYCoords} center - The center of the ellipse.
|
|
10021
10321
|
* @param {number} radiusX - The radius of the ellipse.
|
|
10022
10322
|
* @param {number} radiusY - The radius of the ellipse.
|
|
10023
10323
|
* @param {string} color - The CSS color to draw the ellipse with.
|
|
10024
10324
|
* @param {number} lineWidth=1 - An optional line width param (default is 1).
|
|
10025
10325
|
* @param {number=} rotation - (optional, default=0) The rotation of the ellipse.
|
|
10326
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
10327
|
+
*
|
|
10026
10328
|
* @return {void}
|
|
10027
10329
|
* @instance
|
|
10028
10330
|
* @memberof drawutils
|
|
10029
10331
|
*/
|
|
10030
|
-
drawutils.prototype.ellipse = function (center, radiusX, radiusY, color, lineWidth, rotation) {
|
|
10332
|
+
drawutils.prototype.ellipse = function (center, radiusX, radiusY, color, lineWidth, rotation, strokeOptions) {
|
|
10031
10333
|
if (typeof rotation === "undefined") {
|
|
10032
10334
|
rotation = 0.0;
|
|
10033
10335
|
}
|
|
10336
|
+
this.applyStrokeOpts(strokeOptions);
|
|
10034
10337
|
this.ctx.beginPath();
|
|
10035
10338
|
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
10339
|
this.ctx.closePath();
|
|
@@ -10047,11 +10350,14 @@ var drawutils = /** @class */ (function () {
|
|
|
10047
10350
|
* @param {number} size - The size of the square.
|
|
10048
10351
|
* @param {string} color - The CSS color to draw the square with.
|
|
10049
10352
|
* @param {number} lineWidth - The line with to use (optional, default is 1).
|
|
10353
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
10354
|
+
*
|
|
10050
10355
|
* @return {void}
|
|
10051
10356
|
* @instance
|
|
10052
10357
|
* @memberof drawutils
|
|
10053
10358
|
*/
|
|
10054
|
-
drawutils.prototype.square = function (center, size, color, lineWidth) {
|
|
10359
|
+
drawutils.prototype.square = function (center, size, color, lineWidth, strokeOptions) {
|
|
10360
|
+
this.applyStrokeOpts(strokeOptions);
|
|
10055
10361
|
this.ctx.beginPath();
|
|
10056
10362
|
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
10363
|
this.ctx.closePath();
|
|
@@ -10062,7 +10368,7 @@ var drawutils = /** @class */ (function () {
|
|
|
10062
10368
|
* Draw a grid of horizontal and vertical lines with the given (CSS-) color.
|
|
10063
10369
|
*
|
|
10064
10370
|
* @method grid
|
|
10065
|
-
* @param {
|
|
10371
|
+
* @param {XYCoords} center - The center of the grid.
|
|
10066
10372
|
* @param {number} width - The total width of the grid (width/2 each to the left and to the right).
|
|
10067
10373
|
* @param {number} height - The total height of the grid (height/2 each to the top and to the bottom).
|
|
10068
10374
|
* @param {number} sizeX - The horizontal grid size.
|
|
@@ -10073,6 +10379,7 @@ var drawutils = /** @class */ (function () {
|
|
|
10073
10379
|
* @memberof drawutils
|
|
10074
10380
|
*/
|
|
10075
10381
|
drawutils.prototype.grid = function (center, width, height, sizeX, sizeY, color) {
|
|
10382
|
+
this.ctx.setLineDash([]); // Clear line-dash settings
|
|
10076
10383
|
this.ctx.beginPath();
|
|
10077
10384
|
var yMin = -Math.ceil((height * 0.5) / sizeY) * sizeY;
|
|
10078
10385
|
var yMax = height / 2;
|
|
@@ -10097,7 +10404,7 @@ var drawutils = /** @class */ (function () {
|
|
|
10097
10404
|
* This works analogue to the grid() function
|
|
10098
10405
|
*
|
|
10099
10406
|
* @method raster
|
|
10100
|
-
* @param {
|
|
10407
|
+
* @param {XYCoords} center - The center of the raster.
|
|
10101
10408
|
* @param {number} width - The total width of the raster (width/2 each to the left and to the right).
|
|
10102
10409
|
* @param {number} height - The total height of the raster (height/2 each to the top and to the bottom).
|
|
10103
10410
|
* @param {number} sizeX - The horizontal raster size.
|
|
@@ -10109,6 +10416,7 @@ var drawutils = /** @class */ (function () {
|
|
|
10109
10416
|
*/
|
|
10110
10417
|
drawutils.prototype.raster = function (center, width, height, sizeX, sizeY, color) {
|
|
10111
10418
|
this.ctx.save();
|
|
10419
|
+
this.ctx.setLineDash([]); // Clear line-dash settings
|
|
10112
10420
|
this.ctx.beginPath();
|
|
10113
10421
|
for (var x = -Math.ceil((width * 0.5) / sizeX) * sizeX; x < width / 2; x += sizeX) {
|
|
10114
10422
|
for (var y = -Math.ceil((height * 0.5) / sizeY) * sizeY; y < height / 2; y += sizeY) {
|
|
@@ -10133,14 +10441,15 @@ var drawutils = /** @class */ (function () {
|
|
|
10133
10441
|
* as even shaped diamonds.
|
|
10134
10442
|
*
|
|
10135
10443
|
* @method diamondHandle
|
|
10136
|
-
* @param {
|
|
10137
|
-
* @param {
|
|
10444
|
+
* @param {XYCoords} center - The center of the diamond.
|
|
10445
|
+
* @param {number} size - The x/y-size of the diamond.
|
|
10138
10446
|
* @param {string} color - The CSS color to draw the diamond with.
|
|
10139
10447
|
* @return {void}
|
|
10140
10448
|
* @instance
|
|
10141
10449
|
* @memberof drawutils
|
|
10142
10450
|
*/
|
|
10143
10451
|
drawutils.prototype.diamondHandle = function (center, size, color) {
|
|
10452
|
+
this.ctx.setLineDash([]); // Clear line-dash settings
|
|
10144
10453
|
this.ctx.beginPath();
|
|
10145
10454
|
this.ctx.moveTo(this.offset.x + center.x * this.scale.x - size / 2.0, this.offset.y + center.y * this.scale.y);
|
|
10146
10455
|
this.ctx.lineTo(this.offset.x + center.x * this.scale.x, this.offset.y + center.y * this.scale.y - size / 2.0);
|
|
@@ -10158,14 +10467,15 @@ var drawutils = /** @class */ (function () {
|
|
|
10158
10467
|
* as even shaped squares.
|
|
10159
10468
|
*
|
|
10160
10469
|
* @method squareHandle
|
|
10161
|
-
* @param {
|
|
10162
|
-
* @param {
|
|
10470
|
+
* @param {XYCoords} center - The center of the square.
|
|
10471
|
+
* @param {number} size - The x/y-size of the square.
|
|
10163
10472
|
* @param {string} color - The CSS color to draw the square with.
|
|
10164
10473
|
* @return {void}
|
|
10165
10474
|
* @instance
|
|
10166
10475
|
* @memberof drawutils
|
|
10167
10476
|
*/
|
|
10168
10477
|
drawutils.prototype.squareHandle = function (center, size, color) {
|
|
10478
|
+
this.ctx.setLineDash([]); // Clear line-dash settings
|
|
10169
10479
|
this.ctx.beginPath();
|
|
10170
10480
|
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
10481
|
this.ctx.closePath();
|
|
@@ -10180,7 +10490,7 @@ var drawutils = /** @class */ (function () {
|
|
|
10180
10490
|
* as even shaped circles.
|
|
10181
10491
|
*
|
|
10182
10492
|
* @method circleHandle
|
|
10183
|
-
* @param {
|
|
10493
|
+
* @param {XYCoords} center - The center of the circle.
|
|
10184
10494
|
* @param {number} radius - The radius of the circle.
|
|
10185
10495
|
* @param {string} color - The CSS color to draw the circle with.
|
|
10186
10496
|
* @return {void}
|
|
@@ -10189,6 +10499,7 @@ var drawutils = /** @class */ (function () {
|
|
|
10189
10499
|
*/
|
|
10190
10500
|
drawutils.prototype.circleHandle = function (center, radius, color) {
|
|
10191
10501
|
radius = radius || 3;
|
|
10502
|
+
this.ctx.setLineDash([]); // Clear line-dash settings
|
|
10192
10503
|
this.ctx.beginPath();
|
|
10193
10504
|
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
10505
|
this.ctx.closePath();
|
|
@@ -10211,6 +10522,7 @@ var drawutils = /** @class */ (function () {
|
|
|
10211
10522
|
*/
|
|
10212
10523
|
drawutils.prototype.crosshair = function (center, radius, color, lineWidth) {
|
|
10213
10524
|
this.ctx.save();
|
|
10525
|
+
this.ctx.setLineDash([]); // Clear line-dash settings
|
|
10214
10526
|
this.ctx.beginPath();
|
|
10215
10527
|
this.ctx.moveTo(this.offset.x + center.x * this.scale.x - radius, this.offset.y + center.y * this.scale.y);
|
|
10216
10528
|
this.ctx.lineTo(this.offset.x + center.x * this.scale.x + radius, this.offset.y + center.y * this.scale.y);
|
|
@@ -10238,6 +10550,7 @@ var drawutils = /** @class */ (function () {
|
|
|
10238
10550
|
*/
|
|
10239
10551
|
drawutils.prototype.cross = function (center, radius, color, lineWidth) {
|
|
10240
10552
|
this.ctx.save();
|
|
10553
|
+
this.ctx.setLineDash([]); // Clear line-dash settings
|
|
10241
10554
|
this.ctx.beginPath();
|
|
10242
10555
|
this.ctx.moveTo(this.offset.x + center.x * this.scale.x - radius, this.offset.y + center.y * this.scale.y - radius);
|
|
10243
10556
|
this.ctx.lineTo(this.offset.x + center.x * this.scale.x + radius, this.offset.y + center.y * this.scale.y + radius);
|
|
@@ -10256,30 +10569,35 @@ var drawutils = /** @class */ (function () {
|
|
|
10256
10569
|
* @param {Polygon} polygon - The polygon to draw.
|
|
10257
10570
|
* @param {string} color - The CSS color to draw the polygon with.
|
|
10258
10571
|
* @param {string} lineWidth - The line width to use.
|
|
10572
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
10573
|
+
*
|
|
10259
10574
|
* @return {void}
|
|
10260
10575
|
* @instance
|
|
10261
10576
|
* @memberof drawutils
|
|
10262
10577
|
*/
|
|
10263
|
-
drawutils.prototype.polygon = function (polygon, color, lineWidth) {
|
|
10264
|
-
this.polyline(polygon.vertices, polygon.isOpen, color, lineWidth);
|
|
10578
|
+
drawutils.prototype.polygon = function (polygon, color, lineWidth, strokeOptions) {
|
|
10579
|
+
this.polyline(polygon.vertices, polygon.isOpen, color, lineWidth, strokeOptions);
|
|
10265
10580
|
};
|
|
10266
10581
|
/**
|
|
10267
10582
|
* Draw a polygon line (alternative function to the polygon).
|
|
10268
10583
|
*
|
|
10269
10584
|
* @method polyline
|
|
10270
|
-
* @param {
|
|
10585
|
+
* @param {XYCoords[]} vertices - The polygon vertices to draw.
|
|
10271
10586
|
* @param {boolan} isOpen - If true the polyline will not be closed at its end.
|
|
10272
10587
|
* @param {string} color - The CSS color to draw the polygon with.
|
|
10273
10588
|
* @param {number} lineWidth - The line width (default is 1.0);
|
|
10589
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
10590
|
+
*
|
|
10274
10591
|
* @return {void}
|
|
10275
10592
|
* @instance
|
|
10276
10593
|
* @memberof drawutils
|
|
10277
10594
|
*/
|
|
10278
|
-
drawutils.prototype.polyline = function (vertices, isOpen, color, lineWidth) {
|
|
10595
|
+
drawutils.prototype.polyline = function (vertices, isOpen, color, lineWidth, strokeOptions) {
|
|
10279
10596
|
if (vertices.length <= 1) {
|
|
10280
10597
|
return;
|
|
10281
10598
|
}
|
|
10282
10599
|
this.ctx.save();
|
|
10600
|
+
this.applyStrokeOpts(strokeOptions);
|
|
10283
10601
|
this.ctx.beginPath();
|
|
10284
10602
|
this.ctx.lineWidth = (lineWidth || 1.0) * this.scale.x;
|
|
10285
10603
|
this.ctx.moveTo(this.offset.x + vertices[0].x * this.scale.x, this.offset.y + vertices[0].y * this.scale.y);
|
|
@@ -10391,6 +10709,8 @@ var drawutils = /** @class */ (function () {
|
|
|
10391
10709
|
* @param {string=null} color - (optional) The color to draw this path with (default is null).
|
|
10392
10710
|
* @param {number=1} lineWidth - (optional) the line width to use (default is 1).
|
|
10393
10711
|
* @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.
|
|
10712
|
+
* @param {number=} options.dashOffset - (optional) `See StrokeOptions`.
|
|
10713
|
+
* @param {number=[]} options.dashArray - (optional) `See StrokeOptions`.
|
|
10394
10714
|
* @instance
|
|
10395
10715
|
* @memberof drawutils
|
|
10396
10716
|
* @return {R} An instance representing the drawn path.
|
|
@@ -10402,6 +10722,7 @@ var drawutils = /** @class */ (function () {
|
|
|
10402
10722
|
this.ctx.strokeStyle = color;
|
|
10403
10723
|
}
|
|
10404
10724
|
this.ctx.lineWidth = lineWidth || 1;
|
|
10725
|
+
this.applyStrokeOpts(options);
|
|
10405
10726
|
if (this.fillShapes) {
|
|
10406
10727
|
if (color) {
|
|
10407
10728
|
this.ctx.fillStyle = color;
|
|
@@ -10467,7 +10788,12 @@ exports.drawutils = drawutils;
|
|
|
10467
10788
|
* @modified 2022-03-27 Added the `texturedPoly` function.
|
|
10468
10789
|
* @modified 2022-07-26 Adding `alpha` to the `image(...)` function.
|
|
10469
10790
|
* @modified 2023-02-10 The methods `setCurrentClassName` and `setCurrentId` also accept `null` now.
|
|
10470
|
-
* @
|
|
10791
|
+
* @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.
|
|
10792
|
+
* @modified 2023-09-29 Added the `headLength` parameter to the 'DrawLib.arrow()` function.
|
|
10793
|
+
* @modified 2023-09-29 Added the `arrowHead(...)` function to the 'DrawLib.arrow()` interface.
|
|
10794
|
+
* @modified 2023-09-29 Added the `cubicBezierArrow(...)` function to the 'DrawLib.arrow()` interface.
|
|
10795
|
+
* @modified 2023-09-29 Added the `lineDashes` attribute.
|
|
10796
|
+
* @version 0.0.10
|
|
10471
10797
|
**/
|
|
10472
10798
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
10473
10799
|
exports.drawutilsgl = void 0;
|
|
@@ -10564,6 +10890,20 @@ var drawutilsgl = /** @class */ (function () {
|
|
|
10564
10890
|
drawutilsgl.prototype.setConfiguration = function (configuration) {
|
|
10565
10891
|
// TODO
|
|
10566
10892
|
};
|
|
10893
|
+
// /**
|
|
10894
|
+
// * Set or clear the line-dash configuration. Pass `null` for un-dashed lines.
|
|
10895
|
+
// *
|
|
10896
|
+
// * See https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray
|
|
10897
|
+
// * and https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash
|
|
10898
|
+
// * for how line dashes work.
|
|
10899
|
+
// *
|
|
10900
|
+
// * @method
|
|
10901
|
+
// * @param {Array<number> lineDashes - The line-dash array configuration.
|
|
10902
|
+
// * @returns {void}
|
|
10903
|
+
// */
|
|
10904
|
+
// setLineDash(lineDashes: Array<number>) {
|
|
10905
|
+
// // TODO
|
|
10906
|
+
// }
|
|
10567
10907
|
/**
|
|
10568
10908
|
* This method shouled be called each time the currently drawn `Drawable` changes.
|
|
10569
10909
|
* It is used by some libraries for identifying elemente on re-renders.
|
|
@@ -10591,8 +10931,8 @@ var drawutilsgl = /** @class */ (function () {
|
|
|
10591
10931
|
* Draw the line between the given two points with the specified (CSS-) color.
|
|
10592
10932
|
*
|
|
10593
10933
|
* @method line
|
|
10594
|
-
* @param {
|
|
10595
|
-
* @param {
|
|
10934
|
+
* @param {XYCoords} zA - The start point of the line.
|
|
10935
|
+
* @param {XYCoords} zB - The end point of the line.
|
|
10596
10936
|
* @param {string} color - Any valid CSS color string.
|
|
10597
10937
|
* @return {void}
|
|
10598
10938
|
* @instance
|
|
@@ -10641,9 +10981,10 @@ var drawutilsgl = /** @class */ (function () {
|
|
|
10641
10981
|
* Draw a line and an arrow at the end (zB) of the given line with the specified (CSS-) color.
|
|
10642
10982
|
*
|
|
10643
10983
|
* @method arrow
|
|
10644
|
-
* @param {
|
|
10645
|
-
* @param {
|
|
10984
|
+
* @param {XYCoords} zA - The start point of the arrow-line.
|
|
10985
|
+
* @param {XYCoords} zB - The end point of the arrow-line.
|
|
10646
10986
|
* @param {string} color - Any valid CSS color string.
|
|
10987
|
+
* @param {headLength=8} headLength - (optional) The length of the arrow head (default is 8 units).
|
|
10647
10988
|
* @return {void}
|
|
10648
10989
|
* @instance
|
|
10649
10990
|
* @memberof drawutils
|
|
@@ -10651,6 +10992,41 @@ var drawutilsgl = /** @class */ (function () {
|
|
|
10651
10992
|
drawutilsgl.prototype.arrow = function (zA, zB, color) {
|
|
10652
10993
|
// NOT YET IMPLEMENTED
|
|
10653
10994
|
};
|
|
10995
|
+
/**
|
|
10996
|
+
* 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.
|
|
10997
|
+
*
|
|
10998
|
+
* @method cubicBezierArrow
|
|
10999
|
+
* @param {XYCoords} startPoint - The start point of the cubic Bézier curve
|
|
11000
|
+
* @param {XYCoords} endPoint - The end point the cubic Bézier curve.
|
|
11001
|
+
* @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
|
|
11002
|
+
* @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
|
|
11003
|
+
* @param {string} color - The CSS color to draw the curve with.
|
|
11004
|
+
* @param {number} lineWidth - (optional) The line width to use.
|
|
11005
|
+
* @param {headLength=8} headLength - (optional) The length of the arrow head (default is 8 units).
|
|
11006
|
+
*
|
|
11007
|
+
* @return {void}
|
|
11008
|
+
* @instance
|
|
11009
|
+
* @memberof DrawLib
|
|
11010
|
+
*/
|
|
11011
|
+
drawutilsgl.prototype.cubicBezierArrow = function (startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, headLength) {
|
|
11012
|
+
// NOT YET IMPLEMENTED
|
|
11013
|
+
};
|
|
11014
|
+
/**
|
|
11015
|
+
* Draw just an arrow head a the end of an imaginary line (zB) of the given line width the specified (CSS-) color and size.
|
|
11016
|
+
*
|
|
11017
|
+
* @method arrow
|
|
11018
|
+
* @param {XYCoords} zA - The start point of the arrow-line.
|
|
11019
|
+
* @param {XYCoords} zB - The end point of the arrow-line.
|
|
11020
|
+
* @param {string} color - Any valid CSS color string.
|
|
11021
|
+
* @param {number=1} lineWidth - (optional) The line width to use; default is 1.
|
|
11022
|
+
* @param {number=8} headLength - (optional) The length of the arrow head (default is 8 pixels).
|
|
11023
|
+
* @return {void}
|
|
11024
|
+
* @instance
|
|
11025
|
+
* @memberof DrawLib
|
|
11026
|
+
**/
|
|
11027
|
+
drawutilsgl.prototype.arrowHead = function (zA, zB, color, lineWidth, headLength) {
|
|
11028
|
+
// NOT YET IMPLEMENTED
|
|
11029
|
+
};
|
|
10654
11030
|
/**
|
|
10655
11031
|
* Draw an image at the given position with the given size.<br>
|
|
10656
11032
|
* <br>
|
|
@@ -10658,8 +11034,8 @@ var drawutilsgl = /** @class */ (function () {
|
|
|
10658
11034
|
*
|
|
10659
11035
|
* @method image
|
|
10660
11036
|
* @param {Image} image - The image object to draw.
|
|
10661
|
-
* @param {
|
|
10662
|
-
* @param {
|
|
11037
|
+
* @param {XYCoords} position - The position to draw the the upper left corner at.
|
|
11038
|
+
* @param {XYCoords} size - The x/y-size to draw the image with.
|
|
10663
11039
|
* @param {number=0.0} alpha - (optional, default=0.0) The transparency (0.0=opaque, 1.0=transparent).
|
|
10664
11040
|
* @return {void}
|
|
10665
11041
|
* @instance
|
|
@@ -10678,7 +11054,7 @@ var drawutilsgl = /** @class */ (function () {
|
|
|
10678
11054
|
* @param {Image} textureImage - The image object to draw.
|
|
10679
11055
|
* @param {Bounds} textureSize - The texture size to use; these are the original bounds to map the polygon vertices to.
|
|
10680
11056
|
* @param {Polygon} polygon - The polygon to use as clip path.
|
|
10681
|
-
* @param {
|
|
11057
|
+
* @param {XYCoords} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
|
|
10682
11058
|
* @param {number} rotation - The rotation to use for the polygon (and for the texture).
|
|
10683
11059
|
* @return {void}
|
|
10684
11060
|
* @instance
|
|
@@ -10705,10 +11081,10 @@ var drawutilsgl = /** @class */ (function () {
|
|
|
10705
11081
|
* Draw the given (cubic) bézier curve.
|
|
10706
11082
|
*
|
|
10707
11083
|
* @method cubicBezier
|
|
10708
|
-
* @param {
|
|
10709
|
-
* @param {
|
|
10710
|
-
* @param {
|
|
10711
|
-
* @param {
|
|
11084
|
+
* @param {XYCoords} startPoint - The start point of the cubic Bézier curve
|
|
11085
|
+
* @param {XYCoords} endPoint - The end point the cubic Bézier curve.
|
|
11086
|
+
* @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
|
|
11087
|
+
* @param {VertXYCoordsex} endControlPoint - The end control point the cubic Bézier curve.
|
|
10712
11088
|
* @param {string} color - The CSS color to draw the curve with.
|
|
10713
11089
|
* @param {number=} lineWidth - (optional) The line width to use; default is 1.
|
|
10714
11090
|
* @return {void}
|
|
@@ -10726,7 +11102,7 @@ var drawutilsgl = /** @class */ (function () {
|
|
|
10726
11102
|
* <pre> [ point1, point1_startControl, point2_endControl, point2, point2_startControl, point3_endControl, point3, ... pointN_endControl, pointN ]</pre>
|
|
10727
11103
|
*
|
|
10728
11104
|
* @method cubicBezierPath
|
|
10729
|
-
* @param {
|
|
11105
|
+
* @param {XYCoords[]} path - The cubic bezier path as described above.
|
|
10730
11106
|
* @param {string} color - The CSS colot to draw the path with.
|
|
10731
11107
|
* @param {number=} lineWidth - (optional) The line width to use; default is 1.
|
|
10732
11108
|
* @return {void}
|
|
@@ -10742,8 +11118,8 @@ var drawutilsgl = /** @class */ (function () {
|
|
|
10742
11118
|
* The colors for this are fixed and cannot be specified.
|
|
10743
11119
|
*
|
|
10744
11120
|
* @method handle
|
|
10745
|
-
* @param {
|
|
10746
|
-
* @param {
|
|
11121
|
+
* @param {XYCoords} startPoint - The start of the handle.
|
|
11122
|
+
* @param {XYCoords} endPoint - The end point of the handle.
|
|
10747
11123
|
* @return {void}
|
|
10748
11124
|
* @instance
|
|
10749
11125
|
* @memberof drawutils
|
|
@@ -10755,8 +11131,8 @@ var drawutilsgl = /** @class */ (function () {
|
|
|
10755
11131
|
* Draw a handle line (with a light grey).
|
|
10756
11132
|
*
|
|
10757
11133
|
* @method handleLine
|
|
10758
|
-
* @param {
|
|
10759
|
-
* @param {
|
|
11134
|
+
* @param {XYCoords} startPoint - The start point to draw the handle at.
|
|
11135
|
+
* @param {XYCoords} endPoint - The end point to draw the handle at.
|
|
10760
11136
|
* @return {void}
|
|
10761
11137
|
* @instance
|
|
10762
11138
|
* @memberof drawutils
|
|
@@ -10768,7 +11144,7 @@ var drawutilsgl = /** @class */ (function () {
|
|
|
10768
11144
|
* Draw a 1x1 dot with the specified (CSS-) color.
|
|
10769
11145
|
*
|
|
10770
11146
|
* @method dot
|
|
10771
|
-
* @param {
|
|
11147
|
+
* @param {XYCoords} p - The position to draw the dot at.
|
|
10772
11148
|
* @param {string} color - The CSS color to draw the dot with.
|
|
10773
11149
|
* @return {void}
|
|
10774
11150
|
* @instance
|
|
@@ -10781,7 +11157,7 @@ var drawutilsgl = /** @class */ (function () {
|
|
|
10781
11157
|
* Draw the given point with the specified (CSS-) color and radius 3.
|
|
10782
11158
|
*
|
|
10783
11159
|
* @method point
|
|
10784
|
-
* @param {
|
|
11160
|
+
* @param {XYCoords} p - The position to draw the point at.
|
|
10785
11161
|
* @param {string} color - The CSS color to draw the point with.
|
|
10786
11162
|
* @return {void}
|
|
10787
11163
|
* @instance
|
|
@@ -10796,7 +11172,7 @@ var drawutilsgl = /** @class */ (function () {
|
|
|
10796
11172
|
* Note that if the x- and y- scales are different the result will be an ellipse rather than a circle.
|
|
10797
11173
|
*
|
|
10798
11174
|
* @method circle
|
|
10799
|
-
* @param {
|
|
11175
|
+
* @param {XYCoords} center - The center of the circle.
|
|
10800
11176
|
* @param {number} radius - The radius of the circle.
|
|
10801
11177
|
* @param {string} color - The CSS color to draw the circle with.
|
|
10802
11178
|
* @param {number=} lineWidth - (optional) The line width to use; default is 1.
|
|
@@ -10811,7 +11187,7 @@ var drawutilsgl = /** @class */ (function () {
|
|
|
10811
11187
|
* Draw a circular arc (section of a circle) with the given CSS color.
|
|
10812
11188
|
*
|
|
10813
11189
|
* @method circleArc
|
|
10814
|
-
* @param {
|
|
11190
|
+
* @param {XYCoords} center - The center of the circle.
|
|
10815
11191
|
* @param {number} radius - The radius of the circle.
|
|
10816
11192
|
* @param {number} startAngle - The angle to start at.
|
|
10817
11193
|
* @param {number} endAngle - The angle to end at.
|
|
@@ -10827,7 +11203,7 @@ var drawutilsgl = /** @class */ (function () {
|
|
|
10827
11203
|
* Draw an ellipse with the specified (CSS-) color and thw two radii.
|
|
10828
11204
|
*
|
|
10829
11205
|
* @method ellipse
|
|
10830
|
-
* @param {
|
|
11206
|
+
* @param {XYCoords} center - The center of the ellipse.
|
|
10831
11207
|
* @param {number} radiusX - The radius of the ellipse.
|
|
10832
11208
|
* @param {number} radiusY - The radius of the ellipse.
|
|
10833
11209
|
* @param {string} color - The CSS color to draw the ellipse with.
|
|
@@ -10847,7 +11223,7 @@ var drawutilsgl = /** @class */ (function () {
|
|
|
10847
11223
|
*
|
|
10848
11224
|
* @method square
|
|
10849
11225
|
* @param {XYCords} center - The center of the square.
|
|
10850
|
-
* @param {
|
|
11226
|
+
* @param {number} size - The size of the square.
|
|
10851
11227
|
* @param {string} color - The CSS color to draw the square with.
|
|
10852
11228
|
* @param {number=} lineWidth - (optional) The line width to use; default is 1.
|
|
10853
11229
|
* @return {void}
|
|
@@ -10873,7 +11249,7 @@ var drawutilsgl = /** @class */ (function () {
|
|
|
10873
11249
|
* Draw a grid of horizontal and vertical lines with the given (CSS-) color.
|
|
10874
11250
|
*
|
|
10875
11251
|
* @method grid
|
|
10876
|
-
* @param {
|
|
11252
|
+
* @param {XYCoords} center - The center of the grid.
|
|
10877
11253
|
* @param {number} width - The total width of the grid (width/2 each to the left and to the right).
|
|
10878
11254
|
* @param {number} height - The total height of the grid (height/2 each to the top and to the bottom).
|
|
10879
11255
|
* @param {number} sizeX - The horizontal grid size.
|
|
@@ -10892,7 +11268,7 @@ var drawutilsgl = /** @class */ (function () {
|
|
|
10892
11268
|
* This works analogue to the grid() function
|
|
10893
11269
|
*
|
|
10894
11270
|
* @method raster
|
|
10895
|
-
* @param {
|
|
11271
|
+
* @param {XYCoords} center - The center of the raster.
|
|
10896
11272
|
* @param {number} width - The total width of the raster (width/2 each to the left and to the right).
|
|
10897
11273
|
* @param {number} height - The total height of the raster (height/2 each to the top and to the bottom).
|
|
10898
11274
|
* @param {number} sizeX - The horizontal raster size.
|
|
@@ -10913,8 +11289,8 @@ var drawutilsgl = /** @class */ (function () {
|
|
|
10913
11289
|
* as even shaped diamonds.
|
|
10914
11290
|
*
|
|
10915
11291
|
* @method diamondHandle
|
|
10916
|
-
* @param {
|
|
10917
|
-
* @param {
|
|
11292
|
+
* @param {XYCoords} center - The center of the diamond.
|
|
11293
|
+
* @param {number} size - The x/y-size of the diamond.
|
|
10918
11294
|
* @param {string} color - The CSS color to draw the diamond with.
|
|
10919
11295
|
* @return {void}
|
|
10920
11296
|
* @instance
|
|
@@ -10931,8 +11307,8 @@ var drawutilsgl = /** @class */ (function () {
|
|
|
10931
11307
|
* as even shaped squares.
|
|
10932
11308
|
*
|
|
10933
11309
|
* @method squareHandle
|
|
10934
|
-
* @param {
|
|
10935
|
-
* @param {
|
|
11310
|
+
* @param {XYCoords} center - The center of the square.
|
|
11311
|
+
* @param {number} size - The x/y-size of the square.
|
|
10936
11312
|
* @param {string} color - The CSS color to draw the square with.
|
|
10937
11313
|
* @return {void}
|
|
10938
11314
|
* @instance
|
|
@@ -10949,7 +11325,7 @@ var drawutilsgl = /** @class */ (function () {
|
|
|
10949
11325
|
* as even shaped circles.
|
|
10950
11326
|
*
|
|
10951
11327
|
* @method circleHandle
|
|
10952
|
-
* @param {
|
|
11328
|
+
* @param {XYCoords} center - The center of the circle.
|
|
10953
11329
|
* @param {number} radius - The radius of the circle.
|
|
10954
11330
|
* @param {string} color - The CSS color to draw the circle with.
|
|
10955
11331
|
* @return {void}
|
|
@@ -11045,7 +11421,7 @@ var drawutilsgl = /** @class */ (function () {
|
|
|
11045
11421
|
* Draw a polygon line (alternative function to the polygon).
|
|
11046
11422
|
*
|
|
11047
11423
|
* @method polyline
|
|
11048
|
-
* @param {
|
|
11424
|
+
* @param {XYCoords[]} vertices - The polygon vertices to draw.
|
|
11049
11425
|
* @param {boolan} isOpen - If true the polyline will not be closed at its end.
|
|
11050
11426
|
* @param {string} color - The CSS color to draw the polygon with.
|
|
11051
11427
|
* @param {number=} lineWidth - (optional) The line width to use; default is 1.
|
|
@@ -11237,7 +11613,15 @@ var GLU = /** @class */ (function () {
|
|
|
11237
11613
|
* @modified 2022-11-10 Tweaking some type issues.
|
|
11238
11614
|
* @modified 2023-02-04 Fixed a typo in the CSS classname for cubic Bézier paths: cubicBezier (was cubierBezier).
|
|
11239
11615
|
* @modified 2023-02-10 The methods `setCurrentClassName` and `setCurrentId` also accept `null` now.
|
|
11240
|
-
* @
|
|
11616
|
+
* @modified 2023-09-29 Added initialization checks for null parameters.
|
|
11617
|
+
* @modified 2023-09-29 Added a missing implementation to the `drawurilssvg.do(XYCoords,string)` function. Didn't draw anything.
|
|
11618
|
+
* @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.
|
|
11619
|
+
* @modified 2023-09-29 Added the `headLength` parameter to the 'DrawLib.arrow()` function.
|
|
11620
|
+
* @modified 2023-09-29 Added the `arrowHead(...)` function to the 'DrawLib.arrow()` interface.
|
|
11621
|
+
* @modified 2023-09-29 Added the `cubicBezierArrow(...)` function to the 'DrawLib.arrow()` interface.
|
|
11622
|
+
* @modified 2023-10-04 Adding `strokeOptions` param to these draw function: line, arrow, cubicBezierArrow, cubicBezier, cubicBezierPath, circle, circleArc, ellipse, square, rect, polygon, polyline.
|
|
11623
|
+
*
|
|
11624
|
+
* @version 1.6.7
|
|
11241
11625
|
**/
|
|
11242
11626
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
11243
11627
|
exports.drawutilssvg = void 0;
|
|
@@ -11245,6 +11629,7 @@ var CircleSector_1 = __webpack_require__(946);
|
|
|
11245
11629
|
var CubicBezierCurve_1 = __webpack_require__(510);
|
|
11246
11630
|
var Vertex_1 = __webpack_require__(421);
|
|
11247
11631
|
var UIDGenerator_1 = __webpack_require__(197);
|
|
11632
|
+
var Vector_1 = __webpack_require__(73);
|
|
11248
11633
|
var RAD_TO_DEG = 180 / Math.PI;
|
|
11249
11634
|
/**
|
|
11250
11635
|
* @classdesc A helper class for basic SVG drawing operations. This class should
|
|
@@ -11280,6 +11665,9 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
11280
11665
|
this.cache = new Map();
|
|
11281
11666
|
this.setSize(canvasSize);
|
|
11282
11667
|
if (isSecondary) {
|
|
11668
|
+
if (!gNode || !bufferGNode || !nodeDefs || !bufferNodeDefs) {
|
|
11669
|
+
throw "Cannot create secondary svg draw lib with undefinde gNode|bufferGNode|nodeDefs|bufferNodeDefs.";
|
|
11670
|
+
}
|
|
11283
11671
|
this.gNode = gNode;
|
|
11284
11672
|
this.bufferGNode = bufferGNode;
|
|
11285
11673
|
this.nodeDefs = nodeDefs;
|
|
@@ -11420,6 +11808,9 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
11420
11808
|
if (this.drawlibConfiguration.blendMode) {
|
|
11421
11809
|
node.style["mix-blend-mode"] = this.drawlibConfiguration.blendMode;
|
|
11422
11810
|
}
|
|
11811
|
+
// if (this.lineDashEnabled && this.lineDash && this.lineDash.length > 0 && drawutilssvg.nodeSupportsLineDash(nodeName)) {
|
|
11812
|
+
// node.setAttribute("stroke-dasharray", this.lineDash.join(" "));
|
|
11813
|
+
// }
|
|
11423
11814
|
return node;
|
|
11424
11815
|
};
|
|
11425
11816
|
/**
|
|
@@ -11442,23 +11833,58 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
11442
11833
|
* @param {number=1} lineWidth - (optional) A line width to use for drawing (default is 1).
|
|
11443
11834
|
* @return {SVGElement} The node itself (for chaining).
|
|
11444
11835
|
*/
|
|
11445
|
-
drawutilssvg.prototype._bindFillDraw = function (node, className, color, lineWidth) {
|
|
11836
|
+
drawutilssvg.prototype._bindFillDraw = function (node, className, color, lineWidth, strokeOptions) {
|
|
11837
|
+
this._configureNode(node, className, this.fillShapes, color, lineWidth, strokeOptions);
|
|
11838
|
+
return this._bindNode(node, undefined);
|
|
11839
|
+
};
|
|
11840
|
+
/**
|
|
11841
|
+
* Bind this given node to a parent. If no parent is passed then the global
|
|
11842
|
+
* node buffer will be used.
|
|
11843
|
+
*
|
|
11844
|
+
* @method _bindNode
|
|
11845
|
+
* @private
|
|
11846
|
+
* @instance
|
|
11847
|
+
* @memberof drawutilssvg
|
|
11848
|
+
* @param {SVGElement} node - The SVG node to bind.
|
|
11849
|
+
* @param {SVGElement=} bindingParent - (optional) You may pass node other than the glober buffer node.
|
|
11850
|
+
* @returns {SVGElement} The passed node itself.
|
|
11851
|
+
*/
|
|
11852
|
+
drawutilssvg.prototype._bindNode = function (node, bindingParent) {
|
|
11853
|
+
if (!node.parentNode) {
|
|
11854
|
+
// Attach to DOM only if not already attached
|
|
11855
|
+
(bindingParent !== null && bindingParent !== void 0 ? bindingParent : this.bufferGNode).appendChild(node);
|
|
11856
|
+
}
|
|
11857
|
+
return node;
|
|
11858
|
+
};
|
|
11859
|
+
/**
|
|
11860
|
+
* Add custom CSS class names and the globally defined CSS classname to the
|
|
11861
|
+
* given node.
|
|
11862
|
+
*
|
|
11863
|
+
* @method addCSSClasses
|
|
11864
|
+
* @private
|
|
11865
|
+
* @instance
|
|
11866
|
+
* @memberof drawutilssvg
|
|
11867
|
+
* @param {SVGElement} node - The SVG node to bind.
|
|
11868
|
+
* @param {string} className - The additional custom classname to add.
|
|
11869
|
+
* @returns {void}
|
|
11870
|
+
*/
|
|
11871
|
+
drawutilssvg.prototype._addCSSClasses = function (node, className) {
|
|
11446
11872
|
if (this.curClassName) {
|
|
11447
11873
|
node.setAttribute("class", className + " " + this.curClassName);
|
|
11448
11874
|
}
|
|
11449
11875
|
else {
|
|
11450
11876
|
node.setAttribute("class", className);
|
|
11451
11877
|
}
|
|
11452
|
-
|
|
11453
|
-
|
|
11878
|
+
};
|
|
11879
|
+
drawutilssvg.prototype._configureNode = function (node, className, fillMode, color, lineWidth, strokeOptions) {
|
|
11880
|
+
this._addCSSClasses(node, className);
|
|
11881
|
+
node.setAttribute("fill", fillMode && color ? color : "none");
|
|
11882
|
+
node.setAttribute("stroke", fillMode ? "none" : color || "none");
|
|
11454
11883
|
node.setAttribute("stroke-width", "" + (lineWidth || 1));
|
|
11455
11884
|
if (this.curId) {
|
|
11456
11885
|
node.setAttribute("id", "" + this.curId); // Maybe React-style 'key' would be better?
|
|
11457
11886
|
}
|
|
11458
|
-
|
|
11459
|
-
// Attach to DOM only if not already attached
|
|
11460
|
-
this.bufferGNode.appendChild(node);
|
|
11461
|
-
}
|
|
11887
|
+
this.applyStrokeOpts(node, strokeOptions);
|
|
11462
11888
|
return node;
|
|
11463
11889
|
};
|
|
11464
11890
|
/**
|
|
@@ -11480,7 +11906,7 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
11480
11906
|
* that under the hood the same gl context and gl program will be used.
|
|
11481
11907
|
*/
|
|
11482
11908
|
drawutilssvg.prototype.copyInstance = function (fillShapes) {
|
|
11483
|
-
var copy = new drawutilssvg(this.svgNode, this.offset, this.scale, this.canvasSize, fillShapes, null, // no DrawConfig
|
|
11909
|
+
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
11910
|
true, // isSecondary
|
|
11485
11911
|
this.gNode, this.bufferGNode, this.nodeDefs, this.bufferedNodeDefs);
|
|
11486
11912
|
return copy;
|
|
@@ -11495,6 +11921,20 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
11495
11921
|
drawutilssvg.prototype.setConfiguration = function (configuration) {
|
|
11496
11922
|
this.drawlibConfiguration = configuration;
|
|
11497
11923
|
};
|
|
11924
|
+
// /**
|
|
11925
|
+
// * Set or clear the line-dash configuration. Pass `null` for un-dashed lines.
|
|
11926
|
+
// *
|
|
11927
|
+
// * See https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray
|
|
11928
|
+
// * and https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash
|
|
11929
|
+
// * for how line dashes work.
|
|
11930
|
+
// *
|
|
11931
|
+
// * @method
|
|
11932
|
+
// * @param {Array<number> lineDashes - The line-dash array configuration.
|
|
11933
|
+
// * @returns {void}
|
|
11934
|
+
// */
|
|
11935
|
+
// setLineDash(lineDashes: Array<number>) {
|
|
11936
|
+
// this.lineDash = lineDashes;
|
|
11937
|
+
// }
|
|
11498
11938
|
/**
|
|
11499
11939
|
* This method shouled be called each time the currently drawn `Drawable` changes.
|
|
11500
11940
|
* It is used by some libraries for identifying elemente on re-renders.
|
|
@@ -11569,6 +12009,27 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
11569
12009
|
this.nodeDefs = this.bufferedNodeDefs;
|
|
11570
12010
|
this.bufferedNodeDefs = tmpDefsNode;
|
|
11571
12011
|
};
|
|
12012
|
+
/**
|
|
12013
|
+
* A private helper method to apply stroke options to the current
|
|
12014
|
+
* context.
|
|
12015
|
+
* @param {StrokeOptions=} strokeOptions -
|
|
12016
|
+
*/
|
|
12017
|
+
drawutilssvg.prototype.applyStrokeOpts = function (node, strokeOptions) {
|
|
12018
|
+
var _this = this;
|
|
12019
|
+
if (strokeOptions &&
|
|
12020
|
+
strokeOptions.dashArray &&
|
|
12021
|
+
strokeOptions.dashArray.length > 0 &&
|
|
12022
|
+
drawutilssvg.nodeSupportsLineDash(node.tagName)) {
|
|
12023
|
+
node.setAttribute("stroke-dasharray", strokeOptions.dashArray
|
|
12024
|
+
.map(function (dashArayElem) {
|
|
12025
|
+
return dashArayElem * _this.scale.x;
|
|
12026
|
+
})
|
|
12027
|
+
.join(" "));
|
|
12028
|
+
if (strokeOptions.dashOffset) {
|
|
12029
|
+
node.setAttribute("stroke-dashoffset", "" + strokeOptions.dashOffset * this.scale.x);
|
|
12030
|
+
}
|
|
12031
|
+
}
|
|
12032
|
+
};
|
|
11572
12033
|
drawutilssvg.prototype._x = function (x) {
|
|
11573
12034
|
return this.offset.x + this.scale.x * x;
|
|
11574
12035
|
};
|
|
@@ -11579,47 +12040,104 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
11579
12040
|
* Draw the line between the given two points with the specified (CSS-) color.
|
|
11580
12041
|
*
|
|
11581
12042
|
* @method line
|
|
11582
|
-
* @param {
|
|
11583
|
-
* @param {
|
|
12043
|
+
* @param {XYCoords} zA - The start point of the line.
|
|
12044
|
+
* @param {XYCoords} zB - The end point of the line.
|
|
11584
12045
|
* @param {string} color - Any valid CSS color string.
|
|
11585
12046
|
* @param {number=1} lineWidth? - [optional] The line's width.
|
|
12047
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
12048
|
+
*
|
|
11586
12049
|
* @return {void}
|
|
11587
12050
|
* @instance
|
|
11588
12051
|
* @memberof drawutilssvg
|
|
11589
12052
|
**/
|
|
11590
|
-
drawutilssvg.prototype.line = function (zA, zB, color, lineWidth) {
|
|
11591
|
-
|
|
11592
|
-
|
|
11593
|
-
line.setAttribute("
|
|
11594
|
-
line.setAttribute("
|
|
11595
|
-
line.setAttribute("
|
|
11596
|
-
|
|
12053
|
+
drawutilssvg.prototype.line = function (zA, zB, color, lineWidth, strokeOptions) {
|
|
12054
|
+
// const line: SVGElement = this.makeNode("line");
|
|
12055
|
+
// this.applyStrokeOpts(line, strokeOptions);
|
|
12056
|
+
// line.setAttribute("x1", `${this._x(zA.x)}`);
|
|
12057
|
+
// line.setAttribute("y1", `${this._y(zA.y)}`);
|
|
12058
|
+
// line.setAttribute("x2", `${this._x(zB.x)}`);
|
|
12059
|
+
// line.setAttribute("y2", `${this._y(zB.y)}`);
|
|
12060
|
+
var line = this.makeLineNode(zA, zB, color, lineWidth, strokeOptions);
|
|
12061
|
+
return this._bindFillDraw(line, "line", color, lineWidth || 1, strokeOptions);
|
|
11597
12062
|
};
|
|
11598
12063
|
/**
|
|
11599
12064
|
* Draw a line and an arrow at the end (zB) of the given line with the specified (CSS-) color.
|
|
11600
12065
|
*
|
|
11601
12066
|
* @method arrow
|
|
11602
|
-
* @param {
|
|
11603
|
-
* @param {
|
|
12067
|
+
* @param {XYCoords} zA - The start point of the arrow-line.
|
|
12068
|
+
* @param {XYCoords} zB - The end point of the arrow-line.
|
|
11604
12069
|
* @param {string} color - Any valid CSS color string.
|
|
11605
12070
|
* @param {number=} lineWidth - (optional) The line width to use; default is 1.
|
|
12071
|
+
* @param {headLength=8} headLength - (optional) The length of the arrow head (default is 8 units).
|
|
12072
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
12073
|
+
*
|
|
11606
12074
|
* @return {void}
|
|
11607
12075
|
* @instance
|
|
11608
12076
|
* @memberof drawutilssvg
|
|
11609
12077
|
**/
|
|
11610
|
-
drawutilssvg.prototype.arrow = function (zA, zB, color, lineWidth) {
|
|
11611
|
-
|
|
11612
|
-
var
|
|
11613
|
-
var
|
|
11614
|
-
|
|
11615
|
-
|
|
11616
|
-
|
|
11617
|
-
|
|
11618
|
-
|
|
11619
|
-
|
|
11620
|
-
|
|
11621
|
-
|
|
11622
|
-
|
|
12078
|
+
drawutilssvg.prototype.arrow = function (zA, zB, color, lineWidth, headLength, strokeOptions) {
|
|
12079
|
+
if (headLength === void 0) { headLength = 8; }
|
|
12080
|
+
var group = this.makeNode("g");
|
|
12081
|
+
var arrowHeadBasePosition = { x: 0, y: 0 };
|
|
12082
|
+
// Just create the child nodes, don't bind them to the root node.
|
|
12083
|
+
var arrowHead = this.makeArrowHeadNode(zA, zB, color, lineWidth, headLength, undefined, arrowHeadBasePosition);
|
|
12084
|
+
var line = this.makeLineNode(zA, arrowHeadBasePosition, color, lineWidth, strokeOptions);
|
|
12085
|
+
group.appendChild(line);
|
|
12086
|
+
group.appendChild(arrowHead);
|
|
12087
|
+
this._addCSSClasses(group, "linear-arrow");
|
|
12088
|
+
this._bindNode(group, undefined);
|
|
12089
|
+
return group;
|
|
12090
|
+
};
|
|
12091
|
+
/**
|
|
12092
|
+
* 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.
|
|
12093
|
+
*
|
|
12094
|
+
* @method cubicBezierArrow
|
|
12095
|
+
* @param {XYCoords} startPoint - The start point of the cubic Bézier curve
|
|
12096
|
+
* @param {XYCoords} endPoint - The end point the cubic Bézier curve.
|
|
12097
|
+
* @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
|
|
12098
|
+
* @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
|
|
12099
|
+
* @param {string} color - The CSS color to draw the curve with.
|
|
12100
|
+
* @param {number} lineWidth - (optional) The line width to use.
|
|
12101
|
+
* @param {headLength=8} headLength - (optional) The length of the arrow head (default is 8 units).
|
|
12102
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
12103
|
+
*
|
|
12104
|
+
* @return {void}
|
|
12105
|
+
* @instance
|
|
12106
|
+
* @memberof DrawLib
|
|
12107
|
+
*/
|
|
12108
|
+
drawutilssvg.prototype.cubicBezierArrow = function (startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, headLength, strokeOptions) {
|
|
12109
|
+
if (headLength === void 0) { headLength = 8; }
|
|
12110
|
+
var group = this.makeNode("g");
|
|
12111
|
+
// Just create the child nodes, don't bind them to the root node.
|
|
12112
|
+
var arrowHeadBasePosition = new Vertex_1.Vertex(0, 0);
|
|
12113
|
+
var arrowHead = this.makeArrowHeadNode(endControlPoint, endPoint, color, lineWidth, headLength, undefined, arrowHeadBasePosition);
|
|
12114
|
+
var diff = arrowHeadBasePosition.difference(endPoint);
|
|
12115
|
+
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);
|
|
12116
|
+
group.appendChild(bezier);
|
|
12117
|
+
group.appendChild(arrowHead);
|
|
12118
|
+
this._addCSSClasses(group, "cubicbezier-arrow");
|
|
12119
|
+
this._bindNode(group, undefined);
|
|
12120
|
+
return group;
|
|
12121
|
+
};
|
|
12122
|
+
/**
|
|
12123
|
+
* Draw just an arrow head a the end of an imaginary line (zB) of the given line width the specified (CSS-) color and size.
|
|
12124
|
+
*
|
|
12125
|
+
* @method arrow
|
|
12126
|
+
* @param {XYCoords} zA - The start point of the arrow-line.
|
|
12127
|
+
* @param {XYCoords} zB - The end point of the arrow-line.
|
|
12128
|
+
* @param {string} color - Any valid CSS color string.
|
|
12129
|
+
* @param {number=1} lineWidth - (optional) The line width to use; default is 1.
|
|
12130
|
+
* @param {number=8} headLength - (optional) The length of the arrow head (default is 8 pixels).
|
|
12131
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
12132
|
+
*
|
|
12133
|
+
* @return {void}
|
|
12134
|
+
* @instance
|
|
12135
|
+
* @memberof DrawLib
|
|
12136
|
+
**/
|
|
12137
|
+
drawutilssvg.prototype.arrowHead = function (zA, zB, color, lineWidth, headLength, strokeOptions) {
|
|
12138
|
+
if (headLength === void 0) { headLength = 8; }
|
|
12139
|
+
var node = this.makeArrowHeadNode(zA, zB, color, lineWidth, headLength, strokeOptions);
|
|
12140
|
+
return this._bindFillDraw(node, "arrowhead", color, lineWidth || 1, strokeOptions);
|
|
11623
12141
|
};
|
|
11624
12142
|
/**
|
|
11625
12143
|
* Draw an image at the given position with the given size.<br>
|
|
@@ -11628,8 +12146,8 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
11628
12146
|
*
|
|
11629
12147
|
* @method image
|
|
11630
12148
|
* @param {Image} image - The image object to draw.
|
|
11631
|
-
* @param {
|
|
11632
|
-
* @param {
|
|
12149
|
+
* @param {XYCoords} position - The position to draw the the upper left corner at.
|
|
12150
|
+
* @param {XYCoords} size - The x/y-size to draw the image with.
|
|
11633
12151
|
* @param {number=0.0} alpha - (optional, default=0.0) The transparency (1.0=opaque, 0.0=transparent).
|
|
11634
12152
|
* @return {void}
|
|
11635
12153
|
* @instance
|
|
@@ -11674,16 +12192,16 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
11674
12192
|
* @param {Image} textureImage - The image object to draw.
|
|
11675
12193
|
* @param {Bounds} textureSize - The texture size to use; these are the original bounds to map the polygon vertices to.
|
|
11676
12194
|
* @param {Polygon} polygon - The polygon to use as clip path.
|
|
11677
|
-
* @param {
|
|
12195
|
+
* @param {XYCoords} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
|
|
11678
12196
|
* @param {number} rotation - The rotation to use for the polygon (and for the texture).
|
|
11679
12197
|
* @return {void}
|
|
11680
12198
|
* @instance
|
|
11681
12199
|
* @memberof drawutilssvg
|
|
11682
12200
|
**/
|
|
11683
12201
|
drawutilssvg.prototype.texturedPoly = function (textureImage, textureSize, polygon, polygonPosition, rotation) {
|
|
11684
|
-
|
|
12202
|
+
// const basePolygonBounds: Bounds = polygon.getBounds();
|
|
11685
12203
|
var rotatedScalingOrigin = new Vertex_1.Vertex(textureSize.min).clone().rotate(rotation, polygonPosition);
|
|
11686
|
-
|
|
12204
|
+
// const rotationCenter = polygonPosition.clone().add(rotatedScalingOrigin.difference(textureSize.min).inv());
|
|
11687
12205
|
// Create something like this
|
|
11688
12206
|
// ...
|
|
11689
12207
|
// <defs>
|
|
@@ -11738,36 +12256,21 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
11738
12256
|
* Draw the given (cubic) bézier curve.
|
|
11739
12257
|
*
|
|
11740
12258
|
* @method cubicBezier
|
|
11741
|
-
* @param {
|
|
11742
|
-
* @param {
|
|
11743
|
-
* @param {
|
|
11744
|
-
* @param {
|
|
12259
|
+
* @param {XYCoords} startPoint - The start point of the cubic Bézier curve
|
|
12260
|
+
* @param {XYCoords} endPoint - The end point the cubic Bézier curve.
|
|
12261
|
+
* @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
|
|
12262
|
+
* @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
|
|
11745
12263
|
* @param {string} color - The CSS color to draw the curve with.
|
|
11746
12264
|
* @param {number} lineWidth - (optional) The line width to use.
|
|
12265
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
12266
|
+
*
|
|
11747
12267
|
* @return {void}
|
|
11748
12268
|
* @instance
|
|
11749
12269
|
* @memberof drawutilssvg
|
|
11750
12270
|
*/
|
|
11751
|
-
drawutilssvg.prototype.cubicBezier = function (startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth) {
|
|
11752
|
-
|
|
11753
|
-
|
|
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);
|
|
12271
|
+
drawutilssvg.prototype.cubicBezier = function (startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, strokeOptions) {
|
|
12272
|
+
var node = this.makeCubicBezierNode(startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, strokeOptions);
|
|
12273
|
+
return this._bindNode(node, undefined);
|
|
11771
12274
|
};
|
|
11772
12275
|
/**
|
|
11773
12276
|
* Draw the given (cubic) Bézier path.
|
|
@@ -11777,17 +12280,21 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
11777
12280
|
* <pre> [ point1, point1_startControl, point2_endControl, point2, point2_startControl, point3_endControl, point3, ... pointN_endControl, pointN ]</pre>
|
|
11778
12281
|
*
|
|
11779
12282
|
* @method cubicBezierPath
|
|
11780
|
-
* @param {
|
|
12283
|
+
* @param {XYCoords[]} path - The cubic bezier path as described above.
|
|
11781
12284
|
* @param {string} color - The CSS colot to draw the path with.
|
|
11782
12285
|
* @param {number=1} lineWidth - (optional) The line width to use.
|
|
12286
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
12287
|
+
*
|
|
11783
12288
|
* @return {void}
|
|
11784
12289
|
* @instance
|
|
11785
12290
|
* @memberof drawutilssvg
|
|
11786
12291
|
*/
|
|
11787
|
-
drawutilssvg.prototype.cubicBezierPath = function (path, color, lineWidth) {
|
|
12292
|
+
drawutilssvg.prototype.cubicBezierPath = function (path, color, lineWidth, strokeOptions) {
|
|
11788
12293
|
var node = this.makeNode("path");
|
|
11789
|
-
|
|
12294
|
+
this.applyStrokeOpts(node, strokeOptions);
|
|
12295
|
+
if (!path || path.length == 0) {
|
|
11790
12296
|
return node;
|
|
12297
|
+
}
|
|
11791
12298
|
// Draw curve
|
|
11792
12299
|
var d = ["M", this._x(path[0].x), this._y(path[0].y)];
|
|
11793
12300
|
// Draw curve path
|
|
@@ -11824,20 +12331,20 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
11824
12331
|
* Draw a handle line (with a light grey).
|
|
11825
12332
|
*
|
|
11826
12333
|
* @method handleLine
|
|
11827
|
-
* @param {
|
|
11828
|
-
* @param {
|
|
12334
|
+
* @param {XYCoords} startPoint - The start point to draw the handle at.
|
|
12335
|
+
* @param {XYCoords} endPoint - The end point to draw the handle at.
|
|
11829
12336
|
* @return {void}
|
|
11830
12337
|
* @instance
|
|
11831
12338
|
* @memberof drawutilssvg
|
|
11832
12339
|
*/
|
|
11833
12340
|
drawutilssvg.prototype.handleLine = function (startPoint, endPoint) {
|
|
11834
|
-
this.line(startPoint, endPoint, "rgb(
|
|
12341
|
+
this.line(startPoint, endPoint, "rgb(128,128,128,0.5)");
|
|
11835
12342
|
};
|
|
11836
12343
|
/**
|
|
11837
12344
|
* Draw a 1x1 dot with the specified (CSS-) color.
|
|
11838
12345
|
*
|
|
11839
12346
|
* @method dot
|
|
11840
|
-
* @param {
|
|
12347
|
+
* @param {XYCoords} p - The position to draw the dot at.
|
|
11841
12348
|
* @param {string} color - The CSS color to draw the dot with.
|
|
11842
12349
|
* @return {void}
|
|
11843
12350
|
* @instance
|
|
@@ -11845,13 +12352,17 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
11845
12352
|
*/
|
|
11846
12353
|
drawutilssvg.prototype.dot = function (p, color) {
|
|
11847
12354
|
var node = this.makeNode("line");
|
|
12355
|
+
node.setAttribute("x1", "" + this._x(p.x));
|
|
12356
|
+
node.setAttribute("y1", "" + this._y(p.y));
|
|
12357
|
+
node.setAttribute("x2", "" + this._x(p.x));
|
|
12358
|
+
node.setAttribute("y2", "" + this._y(p.y));
|
|
11848
12359
|
return this._bindFillDraw(node, "dot", color, 1);
|
|
11849
12360
|
};
|
|
11850
12361
|
/**
|
|
11851
12362
|
* Draw the given point with the specified (CSS-) color and radius 3.
|
|
11852
12363
|
*
|
|
11853
12364
|
* @method point
|
|
11854
|
-
* @param {
|
|
12365
|
+
* @param {XYCoords} p - The position to draw the point at.
|
|
11855
12366
|
* @param {string} color - The CSS color to draw the point with.
|
|
11856
12367
|
* @return {void}
|
|
11857
12368
|
* @instance
|
|
@@ -11871,17 +12382,20 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
11871
12382
|
* Note that if the x- and y- scales are different the result will be an ellipse rather than a circle.
|
|
11872
12383
|
*
|
|
11873
12384
|
* @method circle
|
|
11874
|
-
* @param {
|
|
12385
|
+
* @param {XYCoords} center - The center of the circle.
|
|
11875
12386
|
* @param {number} radius - The radius of the circle.
|
|
11876
12387
|
* @param {string} color - The CSS color to draw the circle with.
|
|
11877
12388
|
* @param {number=} lineWidth - (optional) The line width to use; default is 1.
|
|
12389
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
12390
|
+
*
|
|
11878
12391
|
* @return {void}
|
|
11879
12392
|
* @instance
|
|
11880
12393
|
* @memberof drawutilssvg
|
|
11881
12394
|
*/
|
|
11882
|
-
drawutilssvg.prototype.circle = function (center, radius, color, lineWidth) {
|
|
12395
|
+
drawutilssvg.prototype.circle = function (center, radius, color, lineWidth, strokeOptions) {
|
|
11883
12396
|
// Todo: draw ellipse when scalex!=scaley
|
|
11884
12397
|
var node = this.makeNode("circle");
|
|
12398
|
+
this.applyStrokeOpts(node, strokeOptions);
|
|
11885
12399
|
node.setAttribute("cx", "" + this._x(center.x));
|
|
11886
12400
|
node.setAttribute("cy", "" + this._y(center.y));
|
|
11887
12401
|
node.setAttribute("r", "" + radius * this.scale.x); // y?
|
|
@@ -11891,17 +12405,20 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
11891
12405
|
* Draw a circular arc (section of a circle) with the given CSS color.
|
|
11892
12406
|
*
|
|
11893
12407
|
* @method circleArc
|
|
11894
|
-
* @param {
|
|
12408
|
+
* @param {XYCoords} center - The center of the circle.
|
|
11895
12409
|
* @param {number} radius - The radius of the circle.
|
|
11896
12410
|
* @param {number} startAngle - The angle to start at.
|
|
11897
12411
|
* @param {number} endAngle - The angle to end at.
|
|
11898
12412
|
* @param {string} color - The CSS color to draw the circle with.
|
|
12413
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
12414
|
+
*
|
|
11899
12415
|
* @return {void}
|
|
11900
12416
|
* @instance
|
|
11901
12417
|
* @memberof drawutilssvg
|
|
11902
12418
|
*/
|
|
11903
|
-
drawutilssvg.prototype.circleArc = function (center, radius, startAngle, endAngle, color, lineWidth) {
|
|
12419
|
+
drawutilssvg.prototype.circleArc = function (center, radius, startAngle, endAngle, color, lineWidth, strokeOptions) {
|
|
11904
12420
|
var node = this.makeNode("path");
|
|
12421
|
+
this.applyStrokeOpts(node, strokeOptions);
|
|
11905
12422
|
var arcData = CircleSector_1.CircleSector.circleSectorUtils.describeSVGArc(this._x(center.x), this._y(center.y), radius * this.scale.x, // y?
|
|
11906
12423
|
startAngle, endAngle);
|
|
11907
12424
|
node.setAttribute("d", arcData.join(" "));
|
|
@@ -11911,21 +12428,24 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
11911
12428
|
* Draw an ellipse with the specified (CSS-) color and thw two radii.
|
|
11912
12429
|
*
|
|
11913
12430
|
* @method ellipse
|
|
11914
|
-
* @param {
|
|
12431
|
+
* @param {XYCoords} center - The center of the ellipse.
|
|
11915
12432
|
* @param {number} radiusX - The radius of the ellipse.
|
|
11916
12433
|
* @param {number} radiusY - The radius of the ellipse.
|
|
11917
12434
|
* @param {string} color - The CSS color to draw the ellipse with.
|
|
11918
12435
|
* @param {number=} lineWidth - (optional) The line width to use; default is 1.
|
|
11919
12436
|
* @param {number=} rotation - (optional, default=0) The rotation of the ellipse.
|
|
12437
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
12438
|
+
*
|
|
11920
12439
|
* @return {void}
|
|
11921
12440
|
* @instance
|
|
11922
12441
|
* @memberof drawutilssvg
|
|
11923
12442
|
*/
|
|
11924
|
-
drawutilssvg.prototype.ellipse = function (center, radiusX, radiusY, color, lineWidth, rotation) {
|
|
12443
|
+
drawutilssvg.prototype.ellipse = function (center, radiusX, radiusY, color, lineWidth, rotation, strokeOptions) {
|
|
11925
12444
|
if (typeof rotation === "undefined") {
|
|
11926
12445
|
rotation = 0.0;
|
|
11927
12446
|
}
|
|
11928
12447
|
var node = this.makeNode("ellipse");
|
|
12448
|
+
this.applyStrokeOpts(node, strokeOptions);
|
|
11929
12449
|
node.setAttribute("cx", "" + this._x(center.x));
|
|
11930
12450
|
node.setAttribute("cy", "" + this._y(center.y));
|
|
11931
12451
|
node.setAttribute("rx", "" + radiusX * this.scale.x);
|
|
@@ -11941,15 +12461,18 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
11941
12461
|
*
|
|
11942
12462
|
* @method square
|
|
11943
12463
|
* @param {XYCoords} center - The center of the square.
|
|
11944
|
-
* @param {
|
|
12464
|
+
* @param {number} size - The size of the square.
|
|
11945
12465
|
* @param {string} color - The CSS color to draw the square with.
|
|
11946
12466
|
* @param {number=} lineWidth - (optional) The line width to use; default is 1.
|
|
11947
|
-
* @
|
|
12467
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
12468
|
+
*
|
|
12469
|
+
* @return {SVGElement}
|
|
11948
12470
|
* @instance
|
|
11949
12471
|
* @memberof drawutilssvg
|
|
11950
12472
|
*/
|
|
11951
|
-
drawutilssvg.prototype.square = function (center, size, color, lineWidth) {
|
|
12473
|
+
drawutilssvg.prototype.square = function (center, size, color, lineWidth, strokeOptions) {
|
|
11952
12474
|
var node = this.makeNode("rectangle");
|
|
12475
|
+
this.applyStrokeOpts(node, strokeOptions);
|
|
11953
12476
|
node.setAttribute("x", "" + this._x(center.x - size / 2.0));
|
|
11954
12477
|
node.setAttribute("y", "" + this._y(center.y - size / 2.0));
|
|
11955
12478
|
node.setAttribute("width", "" + size * this.scale.x);
|
|
@@ -11964,9 +12487,15 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
11964
12487
|
* @param {number} height - The height of the rectangle.
|
|
11965
12488
|
* @param {string} color - The color to use.
|
|
11966
12489
|
* @param {number=1} lineWidth - (optional) The line with to use (default is 1).
|
|
12490
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
12491
|
+
*
|
|
12492
|
+
* @return {SVGElement}
|
|
12493
|
+
* @instance
|
|
12494
|
+
* @memberof drawutilssvg
|
|
11967
12495
|
**/
|
|
11968
|
-
drawutilssvg.prototype.rect = function (position, width, height, color, lineWidth) {
|
|
12496
|
+
drawutilssvg.prototype.rect = function (position, width, height, color, lineWidth, strokeOptions) {
|
|
11969
12497
|
var node = this.makeNode("rect");
|
|
12498
|
+
this.applyStrokeOpts(node, strokeOptions);
|
|
11970
12499
|
node.setAttribute("x", "" + this._x(position.x));
|
|
11971
12500
|
node.setAttribute("y", "" + this._y(position.y));
|
|
11972
12501
|
node.setAttribute("width", "" + width * this.scale.x);
|
|
@@ -11977,7 +12506,7 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
11977
12506
|
* Draw a grid of horizontal and vertical lines with the given (CSS-) color.
|
|
11978
12507
|
*
|
|
11979
12508
|
* @method grid
|
|
11980
|
-
* @param {
|
|
12509
|
+
* @param {XYCoords} center - The center of the grid.
|
|
11981
12510
|
* @param {number} width - The total width of the grid (width/2 each to the left and to the right).
|
|
11982
12511
|
* @param {number} height - The total height of the grid (height/2 each to the top and to the bottom).
|
|
11983
12512
|
* @param {number} sizeX - The horizontal grid size.
|
|
@@ -12011,7 +12540,7 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
12011
12540
|
* This works analogue to the grid() function
|
|
12012
12541
|
*
|
|
12013
12542
|
* @method raster
|
|
12014
|
-
* @param {
|
|
12543
|
+
* @param {XYCoords} center - The center of the raster.
|
|
12015
12544
|
* @param {number} width - The total width of the raster (width/2 each to the left and to the right).
|
|
12016
12545
|
* @param {number} height - The total height of the raster (height/2 each to the top and to the bottom).
|
|
12017
12546
|
* @param {number} sizeX - The horizontal raster size.
|
|
@@ -12044,8 +12573,8 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
12044
12573
|
* as even shaped diamonds.
|
|
12045
12574
|
*
|
|
12046
12575
|
* @method diamondHandle
|
|
12047
|
-
* @param {
|
|
12048
|
-
* @param {
|
|
12576
|
+
* @param {XYCoords} center - The center of the diamond.
|
|
12577
|
+
* @param {number} size - The x/y-size of the diamond.
|
|
12049
12578
|
* @param {string} color - The CSS color to draw the diamond with.
|
|
12050
12579
|
* @return {void}
|
|
12051
12580
|
* @instance
|
|
@@ -12079,8 +12608,8 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
12079
12608
|
* as even shaped squares.
|
|
12080
12609
|
*
|
|
12081
12610
|
* @method squareHandle
|
|
12082
|
-
* @param {
|
|
12083
|
-
* @param {
|
|
12611
|
+
* @param {XYCoords} center - The center of the square.
|
|
12612
|
+
* @param {XYCoords} size - The x/y-size of the square.
|
|
12084
12613
|
* @param {string} color - The CSS color to draw the square with.
|
|
12085
12614
|
* @return {void}
|
|
12086
12615
|
* @instance
|
|
@@ -12102,7 +12631,7 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
12102
12631
|
* as even shaped circles.
|
|
12103
12632
|
*
|
|
12104
12633
|
* @method circleHandle
|
|
12105
|
-
* @param {
|
|
12634
|
+
* @param {XYCoords} center - The center of the circle.
|
|
12106
12635
|
* @param {number} radius - The radius of the circle.
|
|
12107
12636
|
* @param {string} color - The CSS color to draw the circle with.
|
|
12108
12637
|
* @return {void}
|
|
@@ -12201,18 +12730,22 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
12201
12730
|
* Draw a polygon line (alternative function to the polygon).
|
|
12202
12731
|
*
|
|
12203
12732
|
* @method polyline
|
|
12204
|
-
* @param {
|
|
12733
|
+
* @param {XYCoords[]} vertices - The polygon vertices to draw.
|
|
12205
12734
|
* @param {boolan} isOpen - If true the polyline will not be closed at its end.
|
|
12206
12735
|
* @param {string} color - The CSS color to draw the polygon with.
|
|
12207
12736
|
* @param {number=} lineWidth - (optional) The line width to use; default is 1.
|
|
12737
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Stroke settings to use.
|
|
12738
|
+
*
|
|
12208
12739
|
* @return {void}
|
|
12209
12740
|
* @instance
|
|
12210
12741
|
* @memberof drawutilssvg
|
|
12211
12742
|
*/
|
|
12212
|
-
drawutilssvg.prototype.polyline = function (vertices, isOpen, color, lineWidth) {
|
|
12743
|
+
drawutilssvg.prototype.polyline = function (vertices, isOpen, color, lineWidth, strokeOptions) {
|
|
12213
12744
|
var node = this.makeNode("path");
|
|
12214
|
-
|
|
12745
|
+
this.applyStrokeOpts(node, strokeOptions);
|
|
12746
|
+
if (vertices.length == 0) {
|
|
12215
12747
|
return node;
|
|
12748
|
+
}
|
|
12216
12749
|
// Draw curve
|
|
12217
12750
|
var d = ["M", this._x(vertices[0].x), this._y(vertices[0].y)];
|
|
12218
12751
|
var n = vertices.length;
|
|
@@ -12315,12 +12848,16 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
12315
12848
|
* @param {string=null} color - (optional) The color to draw this path with (default is null).
|
|
12316
12849
|
* @param {number=1} lineWidth - (optional) the line width to use (default is 1).
|
|
12317
12850
|
* @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.
|
|
12851
|
+
* @param {number=} options.dashOffset - (optional) `See StrokeOptions`.
|
|
12852
|
+
* @param {number=[]} options.dashArray - (optional) `See StrokeOptions`.
|
|
12853
|
+
*
|
|
12318
12854
|
* @instance
|
|
12319
12855
|
* @memberof drawutils
|
|
12320
12856
|
* @return {R} An instance representing the drawn path.
|
|
12321
12857
|
*/
|
|
12322
12858
|
drawutilssvg.prototype.path = function (pathData, color, lineWidth, options) {
|
|
12323
12859
|
var node = this.makeNode("path");
|
|
12860
|
+
this.applyStrokeOpts(node, options);
|
|
12324
12861
|
// Transform the path: in-place (fast) or copy (slower)
|
|
12325
12862
|
var d = options && options.inplace ? pathData : drawutilssvg.copyPathData(pathData);
|
|
12326
12863
|
drawutilssvg.transformPathData(d, this.offset, this.scale);
|
|
@@ -12346,7 +12883,7 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
12346
12883
|
}
|
|
12347
12884
|
// Add a covering rect with the given background color
|
|
12348
12885
|
this.curId = "background";
|
|
12349
|
-
this.curClassName = undefined;
|
|
12886
|
+
this.curClassName = null; // undefined;
|
|
12350
12887
|
var node = this.makeNode("rect");
|
|
12351
12888
|
// For some strange reason SVG rotation transforms use degrees instead of radians
|
|
12352
12889
|
// Note that the background does not scale with the zoom level (always covers full element)
|
|
@@ -12358,7 +12895,7 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
12358
12895
|
this._bindFillDraw(node, this.curId, null, null);
|
|
12359
12896
|
node.setAttribute("fill", typeof color === "undefined" ? "none" : color);
|
|
12360
12897
|
// Clear the current ID again
|
|
12361
|
-
this.curId = undefined;
|
|
12898
|
+
this.curId = null; // undefined;
|
|
12362
12899
|
};
|
|
12363
12900
|
/**
|
|
12364
12901
|
* A private helper function to clear all SVG nodes from the >g> node.
|
|
@@ -12563,6 +13100,127 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
12563
13100
|
}
|
|
12564
13101
|
} // END while
|
|
12565
13102
|
}; // END transformPathData
|
|
13103
|
+
drawutilssvg.nodeSupportsLineDash = function (nodeName) {
|
|
13104
|
+
return ["line", "path", "circle", "ellipse", "rectangle", "rect"].includes(nodeName);
|
|
13105
|
+
};
|
|
13106
|
+
/**
|
|
13107
|
+
* Creates a basic <line> node with start and end coordinates. The created node will not
|
|
13108
|
+
* be bound to any root node.
|
|
13109
|
+
*
|
|
13110
|
+
* @private
|
|
13111
|
+
* @method makeLineNode
|
|
13112
|
+
* @param {XYCoords} zA - The line's start position.
|
|
13113
|
+
* @param {XYCoords} zB - The line's start position.
|
|
13114
|
+
* @param {string} color - The CSS color to draw the point with.
|
|
13115
|
+
* @param {number=1} lineWidth - (optional) The line width to use.
|
|
13116
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Additional stroke options to use.
|
|
13117
|
+
* @param {string=} classNameOverride - (optional) If nothing is passed the default classname 'path' will be used.
|
|
13118
|
+
* @return {SVGLineElement}
|
|
13119
|
+
* @instance
|
|
13120
|
+
* @memberof drawutilssvg
|
|
13121
|
+
*/
|
|
13122
|
+
drawutilssvg.prototype.makeLineNode = function (zA, zB, color, lineWidth, strokeOptions, classNameOverride) {
|
|
13123
|
+
var line = this.makeNode("line");
|
|
13124
|
+
line.setAttribute("x1", "" + this._x(zA.x));
|
|
13125
|
+
line.setAttribute("y1", "" + this._y(zA.y));
|
|
13126
|
+
line.setAttribute("x2", "" + this._x(zB.x));
|
|
13127
|
+
line.setAttribute("y2", "" + this._y(zB.y));
|
|
13128
|
+
this._configureNode(line, classNameOverride !== null && classNameOverride !== void 0 ? classNameOverride : "line", this.fillShapes, color, lineWidth || 1, strokeOptions);
|
|
13129
|
+
return line;
|
|
13130
|
+
};
|
|
13131
|
+
/**
|
|
13132
|
+
* Creates a basic <path> node with given path string data. The created node will not
|
|
13133
|
+
* be bound to any root node.
|
|
13134
|
+
*
|
|
13135
|
+
* @private
|
|
13136
|
+
* @method makePathNode
|
|
13137
|
+
* @param {string} pathString - The path data (must be a valid path data string).
|
|
13138
|
+
* @param {string} color - The CSS color to draw the point with.
|
|
13139
|
+
* @param {number=1} lineWidth - (optional) The line width to use.
|
|
13140
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Additional stroke options to use.
|
|
13141
|
+
* @param {string=} classNameOverride - (optional) If nothing is passed the default classname 'path' will be used.
|
|
13142
|
+
* @return {SVGPathElement}
|
|
13143
|
+
* @instance
|
|
13144
|
+
* @memberof drawutilssvg
|
|
13145
|
+
*/
|
|
13146
|
+
drawutilssvg.prototype.makePathNode = function (pathString, color, lineWidth, strokeOptions, classNameOverride) {
|
|
13147
|
+
var path = this.makeNode("path");
|
|
13148
|
+
path.setAttribute("d", pathString);
|
|
13149
|
+
this._configureNode(path, classNameOverride !== null && classNameOverride !== void 0 ? classNameOverride : "path", this.fillShapes, color, lineWidth || 1, strokeOptions);
|
|
13150
|
+
return path;
|
|
13151
|
+
};
|
|
13152
|
+
/**
|
|
13153
|
+
* Creates a basic arrow head node (<path> node) at the end of the given line coordinates. The created node will not
|
|
13154
|
+
* be bound to any root node.
|
|
13155
|
+
*
|
|
13156
|
+
* @private
|
|
13157
|
+
* @method makeArrowHeadNode
|
|
13158
|
+
* @param {string} pathString - The path data (must be a valid path data string).
|
|
13159
|
+
* @param {string} color - The CSS color to draw the point with.
|
|
13160
|
+
* @param {number=1} lineWidth - (optional) The line width to use.
|
|
13161
|
+
* @param {number=8} headLength - (optional) The length of the arrow head; if none is specified then the head will be 8 absolute units long.
|
|
13162
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Additional stroke options to use.
|
|
13163
|
+
* @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.
|
|
13164
|
+
* @return {SVGPathElement}
|
|
13165
|
+
* @instance
|
|
13166
|
+
* @memberof drawutilssvg
|
|
13167
|
+
*/
|
|
13168
|
+
drawutilssvg.prototype.makeArrowHeadNode = function (zA, zB, color, lineWidth, headLength, strokeOptions, arrowHeadBasePositionBuffer) {
|
|
13169
|
+
if (headLength === void 0) { headLength = 8; }
|
|
13170
|
+
var vertices = Vector_1.Vector.utils.buildArrowHead(zA, zB, headLength, this.scale.x, this.scale.y);
|
|
13171
|
+
var d = ["M", this.offset.x + vertices[0].x, this.offset.y + vertices[0].y];
|
|
13172
|
+
if (arrowHeadBasePositionBuffer) {
|
|
13173
|
+
arrowHeadBasePositionBuffer.x = vertices[0].x / this.scale.x;
|
|
13174
|
+
arrowHeadBasePositionBuffer.y = vertices[0].y / this.scale.y;
|
|
13175
|
+
}
|
|
13176
|
+
for (var i = 1; i <= vertices.length; i++) {
|
|
13177
|
+
d.push("L");
|
|
13178
|
+
// Note: only use offset here (the vertices are already scaled)
|
|
13179
|
+
d.push(this.offset.x + vertices[i % vertices.length].x);
|
|
13180
|
+
d.push(this.offset.y + vertices[i % vertices.length].y);
|
|
13181
|
+
}
|
|
13182
|
+
var node = this.makePathNode(d.join(" "), color, lineWidth, strokeOptions, "arrowhead");
|
|
13183
|
+
return node;
|
|
13184
|
+
};
|
|
13185
|
+
/**
|
|
13186
|
+
* Creates a basic cubic Bézier path node (<path> node) with the given cubic Bézier data. The created node will not
|
|
13187
|
+
* be bound to any root node.
|
|
13188
|
+
*
|
|
13189
|
+
* @private
|
|
13190
|
+
* @method makeCubicBezierNode
|
|
13191
|
+
* @param {XYCoords} startPoint - The start point of the cubic Bézier curve
|
|
13192
|
+
* @param {XYCoords} endPoint - The end point the cubic Bézier curve.
|
|
13193
|
+
* @param {XYCoords} startControlPoint - The start control point the cubic Bézier curve.
|
|
13194
|
+
* @param {XYCoords} endControlPoint - The end control point the cubic Bézier curve.
|
|
13195
|
+
* @param {string} color - The CSS color to draw the point with.
|
|
13196
|
+
* @param {number=1} lineWidth - (optional) The line width to use.
|
|
13197
|
+
* @param {StrokeOptions=} strokeOptions - (optional) Additional stroke options to use.
|
|
13198
|
+
* @param {string=} classNameOverride - (optional) If nothing is passed the default classname 'path' will be used.
|
|
13199
|
+
* @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.
|
|
13200
|
+
* @return {SVGPathElement}
|
|
13201
|
+
* @instance
|
|
13202
|
+
* @memberof drawutilssvg
|
|
13203
|
+
*/
|
|
13204
|
+
drawutilssvg.prototype.makeCubicBezierNode = function (startPoint, endPoint, startControlPoint, endControlPoint, color, lineWidth, strokeOptions) {
|
|
13205
|
+
if (startPoint instanceof CubicBezierCurve_1.CubicBezierCurve) {
|
|
13206
|
+
return this.cubicBezier(startPoint.startPoint, startPoint.endPoint, startPoint.startControlPoint, startPoint.endControlPoint, color, lineWidth);
|
|
13207
|
+
}
|
|
13208
|
+
// Draw curve
|
|
13209
|
+
var d = [
|
|
13210
|
+
"M",
|
|
13211
|
+
this._x(startPoint.x),
|
|
13212
|
+
this._y(startPoint.y),
|
|
13213
|
+
"C",
|
|
13214
|
+
this._x(startControlPoint.x),
|
|
13215
|
+
this._y(startControlPoint.y),
|
|
13216
|
+
this._x(endControlPoint.x),
|
|
13217
|
+
this._y(endControlPoint.y),
|
|
13218
|
+
this._x(endPoint.x),
|
|
13219
|
+
this._y(endPoint.y)
|
|
13220
|
+
];
|
|
13221
|
+
var node = this.makePathNode(d.join(" "), color, lineWidth, strokeOptions, "cubicBezier");
|
|
13222
|
+
return node;
|
|
13223
|
+
};
|
|
12566
13224
|
drawutilssvg.HEAD_XML = [
|
|
12567
13225
|
'<?xml version="1.0" encoding="UTF-8" standalone="no"?>',
|
|
12568
13226
|
'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" ',
|