plotboilerplate 1.12.10 → 1.16.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/README.md +5 -1
- package/changelog.md +50 -0
- package/dist/index.esm.js +999 -510
- 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 +1013 -509
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +1 -1
- package/src/cjs/BezierPath.d.ts +45 -2
- package/src/cjs/BezierPath.js +114 -18
- package/src/cjs/BezierPath.js.map +1 -1
- package/src/cjs/Circle.d.ts +25 -10
- package/src/cjs/Circle.js +38 -33
- package/src/cjs/Circle.js.map +1 -1
- package/src/cjs/CircleSector.d.ts +27 -13
- package/src/cjs/CircleSector.js +38 -23
- package/src/cjs/CircleSector.js.map +1 -1
- package/src/cjs/CubicBezierCurve.d.ts +17 -1
- package/src/cjs/CubicBezierCurve.js +78 -79
- package/src/cjs/CubicBezierCurve.js.map +1 -1
- package/src/cjs/KeyHandler.d.ts +10 -3
- package/src/cjs/KeyHandler.js +28 -23
- package/src/cjs/KeyHandler.js.map +1 -1
- package/src/cjs/Line.d.ts +2 -1
- package/src/cjs/Line.js +19 -18
- package/src/cjs/Line.js.map +1 -1
- package/src/cjs/MouseHandler.js +43 -53
- package/src/cjs/MouseHandler.js.map +1 -1
- package/src/cjs/PBImage.d.ts +16 -1
- package/src/cjs/PBImage.js +13 -3
- package/src/cjs/PBImage.js.map +1 -1
- package/src/cjs/PBText.d.ts +130 -0
- package/src/cjs/PBText.js +76 -0
- package/src/cjs/PBText.js.map +1 -0
- package/src/cjs/PlotBoilerplate.d.ts +2 -1
- package/src/cjs/PlotBoilerplate.js +44 -16
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/Polygon.d.ts +37 -1
- package/src/cjs/Polygon.js +131 -54
- package/src/cjs/Polygon.js.map +1 -1
- package/src/cjs/Triangle.d.ts +16 -1
- package/src/cjs/Triangle.js +50 -54
- package/src/cjs/Triangle.js.map +1 -1
- package/src/cjs/VEllipse.d.ts +16 -1
- package/src/cjs/VEllipse.js +25 -12
- package/src/cjs/VEllipse.js.map +1 -1
- package/src/cjs/VEllipseSector.d.ts +15 -1
- package/src/cjs/VEllipseSector.js +11 -1
- package/src/cjs/VEllipseSector.js.map +1 -1
- package/src/cjs/Vector.d.ts +3 -1
- package/src/cjs/Vector.js +32 -36
- package/src/cjs/Vector.js.map +1 -1
- package/src/cjs/VertTuple.d.ts +15 -1
- package/src/cjs/VertTuple.js +14 -19
- package/src/cjs/VertTuple.js.map +1 -1
- package/src/cjs/Vertex.d.ts +66 -4
- package/src/cjs/Vertex.js +99 -17
- package/src/cjs/Vertex.js.map +1 -1
- package/src/cjs/VertexListeners.d.ts +12 -8
- package/src/cjs/VertexListeners.js +18 -25
- package/src/cjs/VertexListeners.js.map +1 -1
- package/src/cjs/draw.d.ts +30 -2
- package/src/cjs/draw.js +51 -6
- package/src/cjs/draw.js.map +1 -1
- package/src/cjs/drawgl.d.ts +29 -2
- package/src/cjs/drawgl.js +21 -4
- package/src/cjs/drawgl.js.map +1 -1
- package/src/cjs/drawutilssvg.d.ts +25 -7
- package/src/cjs/drawutilssvg.js +62 -14
- package/src/cjs/drawutilssvg.js.map +1 -1
- package/src/cjs/entry.js +1 -0
- package/src/cjs/index.d.ts +1 -0
- package/src/cjs/index.js +1 -0
- package/src/cjs/index.js.map +1 -1
- package/src/cjs/interfaces/DrawLib.d.ts +27 -6
- package/src/cjs/interfaces/DrawLib.js +3 -0
- package/src/cjs/interfaces/DrawLib.js.map +1 -1
- package/src/cjs/interfaces/core.d.ts +9 -1
- package/src/cjs/interfaces/core.js +1 -0
- package/src/cjs/interfaces/core.js.map +1 -1
- package/src/cjs/utils/creategui.js +1 -1
- package/src/cjs/utils/findInVertexArray.d.ts +19 -0
- package/src/cjs/utils/findInVertexArray.js +29 -0
- package/src/cjs/utils/findInVertexArray.js.map +1 -0
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.d.ts +15 -0
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.js +55 -28
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
- package/src/cjs/utils/io/DndFileHandler.d.ts +63 -0
- package/src/cjs/utils/io/DndFileHandler.js +112 -0
- package/src/cjs/utils/io/DndFileHandler.js.map +1 -0
- package/src/cjs/utils/io/FileDrop.d.ts +98 -0
- package/src/cjs/utils/io/FileDrop.js +142 -0
- package/src/cjs/utils/io/FileDrop.js.map +1 -0
- package/src/esm/BezierPath.d.ts +45 -2
- package/src/esm/BezierPath.js +114 -18
- package/src/esm/BezierPath.js.map +1 -1
- package/src/esm/Circle.d.ts +25 -10
- package/src/esm/Circle.js +38 -33
- package/src/esm/Circle.js.map +1 -1
- package/src/esm/CircleSector.d.ts +27 -13
- package/src/esm/CircleSector.js +38 -23
- package/src/esm/CircleSector.js.map +1 -1
- package/src/esm/CubicBezierCurve.d.ts +17 -1
- package/src/esm/CubicBezierCurve.js +78 -79
- package/src/esm/CubicBezierCurve.js.map +1 -1
- package/src/esm/KeyHandler.d.ts +10 -3
- package/src/esm/KeyHandler.js +28 -23
- package/src/esm/KeyHandler.js.map +1 -1
- package/src/esm/Line.d.ts +2 -1
- package/src/esm/Line.js +19 -18
- package/src/esm/Line.js.map +1 -1
- package/src/esm/MouseHandler.js +43 -53
- package/src/esm/MouseHandler.js.map +1 -1
- package/src/esm/PBImage.d.ts +16 -1
- package/src/esm/PBImage.js +13 -3
- package/src/esm/PBImage.js.map +1 -1
- package/src/esm/PBText.d.ts +130 -0
- package/src/esm/PBText.js +71 -0
- package/src/esm/PBText.js.map +1 -0
- package/src/esm/PlotBoilerplate.d.ts +2 -1
- package/src/esm/PlotBoilerplate.js +44 -16
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/Polygon.d.ts +37 -1
- package/src/esm/Polygon.js +131 -54
- package/src/esm/Polygon.js.map +1 -1
- package/src/esm/Triangle.d.ts +16 -1
- package/src/esm/Triangle.js +50 -54
- package/src/esm/Triangle.js.map +1 -1
- package/src/esm/VEllipse.d.ts +16 -1
- package/src/esm/VEllipse.js +25 -12
- package/src/esm/VEllipse.js.map +1 -1
- package/src/esm/VEllipseSector.d.ts +15 -1
- package/src/esm/VEllipseSector.js +11 -1
- package/src/esm/VEllipseSector.js.map +1 -1
- package/src/esm/Vector.d.ts +3 -1
- package/src/esm/Vector.js +32 -36
- package/src/esm/Vector.js.map +1 -1
- package/src/esm/VertTuple.d.ts +15 -1
- package/src/esm/VertTuple.js +14 -19
- package/src/esm/VertTuple.js.map +1 -1
- package/src/esm/Vertex.d.ts +66 -4
- package/src/esm/Vertex.js +99 -17
- package/src/esm/Vertex.js.map +1 -1
- package/src/esm/VertexListeners.d.ts +12 -8
- package/src/esm/VertexListeners.js +18 -25
- package/src/esm/VertexListeners.js.map +1 -1
- package/src/esm/draw.d.ts +30 -2
- package/src/esm/draw.js +51 -6
- package/src/esm/draw.js.map +1 -1
- package/src/esm/drawgl.d.ts +29 -2
- package/src/esm/drawgl.js +21 -4
- package/src/esm/drawgl.js.map +1 -1
- package/src/esm/drawutilssvg.d.ts +25 -7
- package/src/esm/drawutilssvg.js +62 -14
- package/src/esm/drawutilssvg.js.map +1 -1
- package/src/esm/entry.js +1 -0
- package/src/esm/index.d.ts +1 -0
- package/src/esm/index.js +1 -0
- package/src/esm/index.js.map +1 -1
- package/src/esm/interfaces/DrawLib.d.ts +27 -6
- package/src/esm/interfaces/DrawLib.js +3 -0
- package/src/esm/interfaces/DrawLib.js.map +1 -1
- package/src/esm/interfaces/core.d.ts +9 -1
- package/src/esm/interfaces/core.js +1 -0
- package/src/esm/interfaces/core.js.map +1 -1
- package/src/esm/utils/findInVertexArray.d.ts +19 -0
- package/src/esm/utils/findInVertexArray.js +25 -0
- package/src/esm/utils/findInVertexArray.js.map +1 -0
- package/src/esm/utils/helpers/BezierPathInteractionHelper.d.ts +15 -0
- package/src/esm/utils/helpers/BezierPathInteractionHelper.js +54 -28
- package/src/esm/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
- package/src/esm/utils/io/DndFileHandler.d.ts +63 -0
- package/src/esm/utils/io/DndFileHandler.js +106 -0
- package/src/esm/utils/io/DndFileHandler.js.map +1 -0
- package/src/esm/utils/io/FileDrop.d.ts +98 -0
- package/src/esm/utils/io/FileDrop.js +136 -0
- package/src/esm/utils/io/FileDrop.js.map +1 -0
- package/src/ts/BezierPath.ts +133 -16
- package/src/ts/Circle.ts +213 -200
- package/src/ts/CircleSector.ts +171 -141
- package/src/ts/CubicBezierCurve.ts +777 -810
- package/src/ts/KeyHandler.ts +221 -212
- package/src/ts/Line.ts +77 -80
- package/src/ts/MouseHandler.ts +356 -368
- package/src/ts/PBImage.ts +81 -68
- package/src/ts/PBText.ts +166 -0
- package/src/ts/PlotBoilerplate.ts +48 -20
- package/src/ts/Polygon.ts +519 -451
- package/src/ts/Triangle.ts +484 -489
- package/src/ts/VEllipse.ts +36 -11
- package/src/ts/VEllipseSector.ts +20 -1
- package/src/ts/Vector.ts +164 -160
- package/src/ts/VertTuple.ts +333 -338
- package/src/ts/Vertex.ts +117 -16
- package/src/ts/VertexListeners.ts +248 -266
- package/src/ts/draw.ts +71 -8
- package/src/ts/drawgl.ts +48 -8
- package/src/ts/drawutilssvg.ts +94 -17
- package/src/ts/index.ts +1 -0
- package/src/ts/interfaces/DrawLib.ts +30 -4
- package/src/ts/interfaces/core.ts +9 -0
- package/src/ts/utils/findInVertexArray.ts +28 -0
- package/src/ts/utils/helpers/BezierPathInteractionHelper.ts +61 -30
- package/src/ts/utils/io/FileDrop.ts +178 -0
- package/dist/plotboilerplate.browser.min.js.LICENSE.txt +0 -8
- package/src/ts/utils/algorithms/clearPolygonDuplicateVertices.ts~ +0 -5
- package/src/ts/utils/algorithms/findPolygonSelfIntersections.ts~ +0 -45
- package/src/ts/utils/algorithms/sh-tmp.ts~ +0 -59
- package/src/ts/utils/algorithms/splitPolygonToNonIntersecting.ts~ +0 -113
- package/src/ts/utils/algorithms/sutherlandHodgman.ts~ +0 -88
package/dist/plotboilerplate.js
CHANGED
|
@@ -445,7 +445,10 @@ class AlloyFinger {
|
|
|
445
445
|
* @modified 2020-07-24 Added the getClosestT(Vertex) function.
|
|
446
446
|
* @modified 2020-12-29 Constructor is now private (no explicit use intended).
|
|
447
447
|
* @modified 2021-05-25 Added BezierPath.fromReducedList( Array<number> ).
|
|
448
|
-
* @
|
|
448
|
+
* @modified 2022-01-31 Added `BezierPath.getEvenDistributionVertices(number)`.
|
|
449
|
+
* @modified 2022-02-02 Added the `destroy` method.
|
|
450
|
+
* @modified 2022-02-02 Cleared the `toSVGString` function (deprecated). Use `drawutilssvg` instead.
|
|
451
|
+
* @version 2.5.0
|
|
449
452
|
*
|
|
450
453
|
* @file BezierPath
|
|
451
454
|
* @public
|
|
@@ -882,6 +885,35 @@ var BezierPath = /** @class */ (function () {
|
|
|
882
885
|
this.updateArcLengths();
|
|
883
886
|
return this;
|
|
884
887
|
};
|
|
888
|
+
/**
|
|
889
|
+
* Scale the whole bezier path by the given uniform factor.
|
|
890
|
+
*
|
|
891
|
+
* @method scale
|
|
892
|
+
* @param {Vertex} anchor - The scale origin to scale from.
|
|
893
|
+
* @param {number} scaleFactor - The scalar to be multiplied with.
|
|
894
|
+
* @instance
|
|
895
|
+
* @memberof BezierPath
|
|
896
|
+
* @return {BezierPath} this for chaining.
|
|
897
|
+
**/
|
|
898
|
+
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
|
+
return this.scaleXY({ x: scaleFactor, y: scaleFactor }, anchor);
|
|
916
|
+
};
|
|
885
917
|
/**
|
|
886
918
|
* Scale the whole bezier path by the given (x,y)-factors.
|
|
887
919
|
*
|
|
@@ -892,19 +924,19 @@ var BezierPath = /** @class */ (function () {
|
|
|
892
924
|
* @memberof BezierPath
|
|
893
925
|
* @return {BezierPath} this for chaining.
|
|
894
926
|
**/
|
|
895
|
-
BezierPath.prototype.
|
|
927
|
+
BezierPath.prototype.scaleXY = function (scaleFactors, anchor) {
|
|
896
928
|
for (var i = 0; i < this.bezierCurves.length; i++) {
|
|
897
929
|
var curve = this.bezierCurves[i];
|
|
898
|
-
curve.getStartPoint().
|
|
899
|
-
curve.getStartControlPoint().
|
|
900
|
-
curve.getEndControlPoint().
|
|
930
|
+
curve.getStartPoint().scaleXY(scaleFactors, anchor);
|
|
931
|
+
curve.getStartControlPoint().scaleXY(scaleFactors, anchor);
|
|
932
|
+
curve.getEndControlPoint().scaleXY(scaleFactors, anchor);
|
|
901
933
|
// Do NOT scale the end point here!
|
|
902
934
|
// Don't forget that the curves are connected and on curve's end point
|
|
903
935
|
// the the successor's start point (same instance)!
|
|
904
936
|
}
|
|
905
937
|
// Finally move the last end point (was not scaled yet)
|
|
906
938
|
if (this.bezierCurves.length > 0 && !this.adjustCircular) {
|
|
907
|
-
this.bezierCurves[this.bezierCurves.length - 1].getEndPoint().
|
|
939
|
+
this.bezierCurves[this.bezierCurves.length - 1].getEndPoint().scaleXY(scaleFactors, anchor);
|
|
908
940
|
}
|
|
909
941
|
this.updateArcLengths();
|
|
910
942
|
return this;
|
|
@@ -1313,6 +1345,59 @@ var BezierPath = /** @class */ (function () {
|
|
|
1313
1345
|
}
|
|
1314
1346
|
return new Bounds_1.Bounds(min, max);
|
|
1315
1347
|
};
|
|
1348
|
+
/**
|
|
1349
|
+
* Get n 'equally' distributed vertices along this Bézier path.
|
|
1350
|
+
*
|
|
1351
|
+
* As the changing curvature of the B slines makes prediction of distances difficult, the
|
|
1352
|
+
* returned vertices' distances are only relatively equal:
|
|
1353
|
+
* - the distance grows where curvature is large.
|
|
1354
|
+
* - the distance shrinks where curvature is small.
|
|
1355
|
+
*
|
|
1356
|
+
* Only the distance mean of all consecutive is 1/n-th of the total arc length.
|
|
1357
|
+
*
|
|
1358
|
+
* Usually this approximation is good enough for most use cases.
|
|
1359
|
+
*
|
|
1360
|
+
* @param {number} pointCount - (must be at least 2) The number of desired points (start and end point included).
|
|
1361
|
+
* @return {Array<Vertex>}
|
|
1362
|
+
*/
|
|
1363
|
+
BezierPath.prototype.getEvenDistributionVertices = function (pointCount) {
|
|
1364
|
+
if (pointCount < 2) {
|
|
1365
|
+
throw new Error("pointCount must be larger than one; is " + pointCount + ".");
|
|
1366
|
+
}
|
|
1367
|
+
var result = [];
|
|
1368
|
+
if (this.bezierCurves.length === 0) {
|
|
1369
|
+
return result;
|
|
1370
|
+
}
|
|
1371
|
+
// Fetch and add the start point from the source polygon
|
|
1372
|
+
var polygonPoint = new Vertex_1.Vertex(this.bezierCurves[0].startPoint);
|
|
1373
|
+
result.push(polygonPoint);
|
|
1374
|
+
// if (this.bezierCurves.length === 1) {
|
|
1375
|
+
// return result;
|
|
1376
|
+
// }
|
|
1377
|
+
var perimeter = this.totalArcLength;
|
|
1378
|
+
var stepSize = perimeter / (pointCount - 1);
|
|
1379
|
+
var n = this.bezierCurves.length;
|
|
1380
|
+
var curveIndex = 0;
|
|
1381
|
+
var segmentLength = this.bezierCurves[0].arcLength;
|
|
1382
|
+
var curSegmentU = stepSize;
|
|
1383
|
+
var i = 1;
|
|
1384
|
+
while (i < pointCount && curveIndex < n) {
|
|
1385
|
+
// Check if next eq point is inside this segment
|
|
1386
|
+
if (curSegmentU < segmentLength) {
|
|
1387
|
+
var newPoint = this.bezierCurves[curveIndex].getPoint(curSegmentU);
|
|
1388
|
+
result.push(newPoint);
|
|
1389
|
+
curSegmentU += stepSize;
|
|
1390
|
+
i++;
|
|
1391
|
+
}
|
|
1392
|
+
else {
|
|
1393
|
+
curveIndex++;
|
|
1394
|
+
curSegmentU = curSegmentU - segmentLength;
|
|
1395
|
+
segmentLength = curveIndex < n ? this.bezierCurves[curveIndex].arcLength : 0;
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
result.push(new Vertex_1.Vertex(this.bezierCurves[n - 1].endPoint));
|
|
1399
|
+
return result;
|
|
1400
|
+
};
|
|
1316
1401
|
/**
|
|
1317
1402
|
* Clone this BezierPath (deep clone).
|
|
1318
1403
|
*
|
|
@@ -1370,19 +1455,30 @@ var BezierPath = /** @class */ (function () {
|
|
|
1370
1455
|
* @return {string} The SVG string.
|
|
1371
1456
|
**/
|
|
1372
1457
|
BezierPath.prototype.toSVGString = function (options) {
|
|
1373
|
-
options = options || {};
|
|
1374
|
-
var buffer = [];
|
|
1375
|
-
buffer.push("<path");
|
|
1376
|
-
if (options.className)
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1458
|
+
// options = options || {};
|
|
1459
|
+
// var buffer: Array<string> = [];
|
|
1460
|
+
// buffer.push("<path");
|
|
1461
|
+
// if (options.className) buffer.push(' class="' + options.className + '"');
|
|
1462
|
+
// buffer.push(' d="');
|
|
1463
|
+
// for (var c = 0; c < this.bezierCurves.length; c++) {
|
|
1464
|
+
// if (c > 0) buffer.push(" ");
|
|
1465
|
+
// buffer.push(this.bezierCurves[c].toSVGPathData());
|
|
1466
|
+
// }
|
|
1467
|
+
// buffer.push('" />');
|
|
1468
|
+
// return buffer.join("");
|
|
1469
|
+
console.warn("[Deprecation] Warning: the BezierPath.toSVGString method is deprecated and does not return and valid SVG data any more. Please use `drawutilssvg` instead.");
|
|
1470
|
+
return "";
|
|
1471
|
+
};
|
|
1472
|
+
/**
|
|
1473
|
+
* This function should invalidate any installed listeners and invalidate this object.
|
|
1474
|
+
* After calling this function the object might not hold valid data any more and
|
|
1475
|
+
* should not be used.
|
|
1476
|
+
*/
|
|
1477
|
+
BezierPath.prototype.destroy = function () {
|
|
1478
|
+
for (var i = 0; i < this.bezierCurves.length; i++) {
|
|
1479
|
+
this.bezierCurves[i].destroy();
|
|
1383
1480
|
}
|
|
1384
|
-
|
|
1385
|
-
return buffer.join("");
|
|
1481
|
+
this.isDestroyed = true;
|
|
1386
1482
|
};
|
|
1387
1483
|
/**
|
|
1388
1484
|
* Create a JSON string representation of this bézier curve.
|
|
@@ -1701,7 +1797,9 @@ exports.Bounds = Bounds;
|
|
|
1701
1797
|
* @modified 2020-09-07 Changed the vertAt function by switching sin and cos! The old version did not return the correct vertex (by angle) accoring to the assumed circle math.
|
|
1702
1798
|
* @modified 2020-10-16 Added the containsCircle(...) function.
|
|
1703
1799
|
* @modified 2021-01-20 Added UID.
|
|
1704
|
-
* @
|
|
1800
|
+
* @modified 2022-02-02 Added the `destroy` method.
|
|
1801
|
+
* @modified 2022-02-02 Cleared the `toSVGString` function (deprecated). Use `drawutilssvg` instead.
|
|
1802
|
+
* @version 1.3.0
|
|
1705
1803
|
**/
|
|
1706
1804
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1707
1805
|
exports.Circle = void 0;
|
|
@@ -1738,7 +1836,6 @@ var Circle = /** @class */ (function () {
|
|
|
1738
1836
|
this.center = center;
|
|
1739
1837
|
this.radius = radius;
|
|
1740
1838
|
}
|
|
1741
|
-
;
|
|
1742
1839
|
/**
|
|
1743
1840
|
* Check if the given circle is fully contained inside this circle.
|
|
1744
1841
|
*
|
|
@@ -1751,7 +1848,6 @@ var Circle = /** @class */ (function () {
|
|
|
1751
1848
|
Circle.prototype.containsCircle = function (circle) {
|
|
1752
1849
|
return this.center.distance(circle.center) + circle.radius < this.radius;
|
|
1753
1850
|
};
|
|
1754
|
-
;
|
|
1755
1851
|
/**
|
|
1756
1852
|
* Calculate the distance from this circle to the given line.
|
|
1757
1853
|
*
|
|
@@ -1770,7 +1866,6 @@ var Circle = /** @class */ (function () {
|
|
|
1770
1866
|
var closestPointOnLine = line.getClosestPoint(this.center);
|
|
1771
1867
|
return closestPointOnLine.distance(this.center) - this.radius;
|
|
1772
1868
|
};
|
|
1773
|
-
;
|
|
1774
1869
|
/**
|
|
1775
1870
|
* Get the vertex on the this circle for the given angle.
|
|
1776
1871
|
*
|
|
@@ -1784,7 +1879,6 @@ var Circle = /** @class */ (function () {
|
|
|
1784
1879
|
// Find the point on the circle respective the angle. Then move relative to center.
|
|
1785
1880
|
return Circle.circleUtils.vertAt(angle, this.radius).add(this.center);
|
|
1786
1881
|
};
|
|
1787
|
-
;
|
|
1788
1882
|
/**
|
|
1789
1883
|
* Get a tangent line of this circle for a given angle.
|
|
1790
1884
|
*
|
|
@@ -1801,7 +1895,6 @@ var Circle = /** @class */ (function () {
|
|
|
1801
1895
|
// Construct the perpendicular of the line in point a. Then move relative to center.
|
|
1802
1896
|
return new Vector_1.Vector(pointA, new Vertex_1.Vertex(0, 0)).add(this.center).perp();
|
|
1803
1897
|
};
|
|
1804
|
-
;
|
|
1805
1898
|
/**
|
|
1806
1899
|
* Calculate the intersection points (if exists) with the given circle.
|
|
1807
1900
|
*
|
|
@@ -1841,47 +1934,55 @@ var Circle = /** @class */ (function () {
|
|
|
1841
1934
|
// x4 = P2.x - h*(P1.y - P0.y)/d;
|
|
1842
1935
|
// y4 = P2.y + h*(P1.x - P0.x)/d;
|
|
1843
1936
|
// return pair<Point, Point>(Point(x3, y3), Point(x4, y4));
|
|
1844
|
-
// }
|
|
1937
|
+
// }
|
|
1845
1938
|
var p0 = this.center;
|
|
1846
1939
|
var p1 = circle.center;
|
|
1847
1940
|
var d = p0.distance(p1);
|
|
1848
1941
|
var a = (this.radius * this.radius - circle.radius * circle.radius + d * d) / (2 * d);
|
|
1849
1942
|
var h = Math.sqrt(this.radius * this.radius - a * a);
|
|
1850
1943
|
var p2 = p1.clone().scale(a / d, p0);
|
|
1851
|
-
var x3 = p2.x + h * (p1.y - p0.y) / d;
|
|
1852
|
-
var y3 = p2.y - h * (p1.x - p0.x) / d;
|
|
1853
|
-
var x4 = p2.x - h * (p1.y - p0.y) / d;
|
|
1854
|
-
var y4 = p2.y + h * (p1.x - p0.x) / d;
|
|
1944
|
+
var x3 = p2.x + (h * (p1.y - p0.y)) / d;
|
|
1945
|
+
var y3 = p2.y - (h * (p1.x - p0.x)) / d;
|
|
1946
|
+
var x4 = p2.x - (h * (p1.y - p0.y)) / d;
|
|
1947
|
+
var y4 = p2.y + (h * (p1.x - p0.x)) / d;
|
|
1855
1948
|
return new Line_1.Line(new Vertex_1.Vertex(x3, y3), new Vertex_1.Vertex(x4, y4));
|
|
1856
1949
|
};
|
|
1857
|
-
;
|
|
1858
1950
|
/**
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1951
|
+
* Create an SVG representation of this circle.
|
|
1952
|
+
*
|
|
1953
|
+
* @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
|
|
1954
|
+
* @method toSVGString
|
|
1955
|
+
* @param {object=} options - An optional set of options, like 'className'.
|
|
1956
|
+
* @return {string} A string representing the SVG code for this vertex.
|
|
1957
|
+
* @instance
|
|
1958
|
+
* @memberof Circle
|
|
1959
|
+
*/
|
|
1868
1960
|
Circle.prototype.toSVGString = function (options) {
|
|
1869
|
-
options = options || {};
|
|
1870
|
-
var buffer = [];
|
|
1871
|
-
buffer.push(
|
|
1872
|
-
if (options.className)
|
|
1873
|
-
|
|
1874
|
-
buffer.push('
|
|
1875
|
-
buffer.push('
|
|
1876
|
-
buffer.push(
|
|
1877
|
-
buffer.
|
|
1878
|
-
return
|
|
1961
|
+
// options = options || {};
|
|
1962
|
+
// var buffer: Array<string> = [];
|
|
1963
|
+
// buffer.push("<circle");
|
|
1964
|
+
// if (options.className) buffer.push(' class="' + options.className + '"');
|
|
1965
|
+
// buffer.push(' cx="' + this.center.x + '"');
|
|
1966
|
+
// buffer.push(' cy="' + this.center.y + '"');
|
|
1967
|
+
// buffer.push(' r="' + this.radius + '"');
|
|
1968
|
+
// buffer.push(" />");
|
|
1969
|
+
// return buffer.join("");
|
|
1970
|
+
console.warn("[Deprecation] Warning: the Circle.toSVGString method is deprecated and does not return and valid SVG data any more. Please use `drawutilssvg` instead.");
|
|
1971
|
+
return "";
|
|
1972
|
+
};
|
|
1973
|
+
/**
|
|
1974
|
+
* This function should invalidate any installed listeners and invalidate this object.
|
|
1975
|
+
* After calling this function the object might not hold valid data any more and
|
|
1976
|
+
* should not be used.
|
|
1977
|
+
*/
|
|
1978
|
+
Circle.prototype.destroy = function () {
|
|
1979
|
+
this.center.destroy();
|
|
1980
|
+
this.isDestroyed = true;
|
|
1879
1981
|
};
|
|
1880
|
-
;
|
|
1881
1982
|
Circle.circleUtils = {
|
|
1882
1983
|
vertAt: function (angle, radius) {
|
|
1883
1984
|
/* return new Vertex( Math.sin(angle) * radius,
|
|
1884
|
-
|
|
1985
|
+
Math.cos(angle) * radius ); */
|
|
1885
1986
|
return new Vertex_1.Vertex(Math.cos(angle) * radius, Math.sin(angle) * radius);
|
|
1886
1987
|
}
|
|
1887
1988
|
};
|
|
@@ -1935,27 +2036,42 @@ var CircleSector = /** @class */ (function () {
|
|
|
1935
2036
|
this.startAngle = startAngle;
|
|
1936
2037
|
this.endAngle = endAngle;
|
|
1937
2038
|
}
|
|
1938
|
-
;
|
|
1939
2039
|
/**
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
2040
|
+
* Create an SVG representation of this circle.
|
|
2041
|
+
*
|
|
2042
|
+
* @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
|
|
2043
|
+
* @method toSVGString
|
|
2044
|
+
* @param {object=} options - An optional set of options, like 'className'.
|
|
2045
|
+
* @return {string} A string representing the SVG code for this vertex.
|
|
2046
|
+
* @instance
|
|
2047
|
+
* @memberof Circle
|
|
2048
|
+
*/
|
|
1948
2049
|
CircleSector.prototype.toSVGString = function (options) {
|
|
1949
|
-
options = options || {};
|
|
1950
|
-
var buffer = [];
|
|
1951
|
-
buffer.push(
|
|
1952
|
-
if (options.className)
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
2050
|
+
// options = options || {};
|
|
2051
|
+
// var buffer: Array<string> = [];
|
|
2052
|
+
// buffer.push("<path ");
|
|
2053
|
+
// if (options.className) buffer.push(' class="' + options.className + '"');
|
|
2054
|
+
// const data: SVGPathParams = CircleSector.circleSectorUtils.describeSVGArc(
|
|
2055
|
+
// this.circle.center.x,
|
|
2056
|
+
// this.circle.center.y,
|
|
2057
|
+
// this.circle.radius,
|
|
2058
|
+
// this.startAngle,
|
|
2059
|
+
// this.endAngle
|
|
2060
|
+
// );
|
|
2061
|
+
// buffer.push(' d="' + data.join(" ") + '" />');
|
|
2062
|
+
// return buffer.join("");
|
|
2063
|
+
console.warn("[Deprecation] Warning: the CircleSector.toSVGString method is deprecated and does not return and valid SVG data any more. Please use `drawutilssvg` instead.");
|
|
2064
|
+
return "";
|
|
2065
|
+
};
|
|
2066
|
+
/**
|
|
2067
|
+
* This function should invalidate any installed listeners and invalidate this object.
|
|
2068
|
+
* After calling this function the object might not hold valid data any more and
|
|
2069
|
+
* should not be used.
|
|
2070
|
+
*/
|
|
2071
|
+
CircleSector.prototype.destroy = function () {
|
|
2072
|
+
this.circle.destroy();
|
|
2073
|
+
this.isDestroyed = true;
|
|
1957
2074
|
};
|
|
1958
|
-
;
|
|
1959
2075
|
CircleSector.circleSectorUtils = {
|
|
1960
2076
|
/**
|
|
1961
2077
|
* Helper function to convert polar circle coordinates to cartesian coordinates.
|
|
@@ -1963,11 +2079,11 @@ var CircleSector = /** @class */ (function () {
|
|
|
1963
2079
|
* TODO: generalize for ellipses (two radii).
|
|
1964
2080
|
*
|
|
1965
2081
|
* @param {number} angle - The angle in radians.
|
|
1966
|
-
|
|
2082
|
+
*/
|
|
1967
2083
|
polarToCartesian: function (centerX, centerY, radius, angle) {
|
|
1968
2084
|
return {
|
|
1969
|
-
x: centerX +
|
|
1970
|
-
y: centerY +
|
|
2085
|
+
x: centerX + radius * Math.cos(angle),
|
|
2086
|
+
y: centerY + radius * Math.sin(angle)
|
|
1971
2087
|
};
|
|
1972
2088
|
},
|
|
1973
2089
|
/**
|
|
@@ -1980,7 +2096,7 @@ var CircleSector = /** @class */ (function () {
|
|
|
1980
2096
|
* @return [ 'A', radiusx, radiusy, rotation=0, largeArcFlag=1|0, sweepFlag=0, endx, endy ]
|
|
1981
2097
|
*/
|
|
1982
2098
|
describeSVGArc: function (x, y, radius, startAngle, endAngle, options) {
|
|
1983
|
-
if (typeof options ===
|
|
2099
|
+
if (typeof options === "undefined")
|
|
1984
2100
|
options = { moveToStart: true };
|
|
1985
2101
|
var end = CircleSector.circleSectorUtils.polarToCartesian(x, y, radius, endAngle);
|
|
1986
2102
|
var start = CircleSector.circleSectorUtils.polarToCartesian(x, y, radius, startAngle);
|
|
@@ -2005,7 +2121,7 @@ var CircleSector = /** @class */ (function () {
|
|
|
2005
2121
|
}
|
|
2006
2122
|
var pathData = [];
|
|
2007
2123
|
if (options.moveToStart) {
|
|
2008
|
-
pathData.push(
|
|
2124
|
+
pathData.push("M", start.x, start.y);
|
|
2009
2125
|
}
|
|
2010
2126
|
pathData.push("A", radius, radius, 0, largeArcFlag, sweepFlag, end.x, end.y);
|
|
2011
2127
|
return pathData;
|
|
@@ -2042,7 +2158,9 @@ exports.CircleSector = CircleSector;
|
|
|
2042
2158
|
* @modified 2020-07-14 Changed the moveCurvePoint(...,Vertex) to moveCurvePoint(...,XYCoords), which is more generic.
|
|
2043
2159
|
* @modified 2020-07-24 Added the getClosestT function and the helper function locateIntervalByDistance(...).
|
|
2044
2160
|
* @modified 2021-01-20 Added UID.
|
|
2045
|
-
* @
|
|
2161
|
+
* @modified 2022-02-02 Added the `destroy` method.
|
|
2162
|
+
* @modified 2022-02-02 Cleared the `toSVGPathData` function (deprecated). Use `drawutilssvg` instead.
|
|
2163
|
+
* @version 2.6.0
|
|
2046
2164
|
*
|
|
2047
2165
|
* @file CubicBezierCurve
|
|
2048
2166
|
* @public
|
|
@@ -2097,7 +2215,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2097
2215
|
this.arcLength = null;
|
|
2098
2216
|
this.updateArcLengths();
|
|
2099
2217
|
}
|
|
2100
|
-
;
|
|
2101
2218
|
/**
|
|
2102
2219
|
* Move the given curve point (the start point, end point or one of the two
|
|
2103
2220
|
* control points).
|
|
@@ -2134,7 +2251,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2134
2251
|
if (updateArcLengths)
|
|
2135
2252
|
this.updateArcLengths();
|
|
2136
2253
|
};
|
|
2137
|
-
;
|
|
2138
2254
|
/**
|
|
2139
2255
|
* Translate the whole curve by the given {x,y} amount: moves all four points.
|
|
2140
2256
|
*
|
|
@@ -2151,7 +2267,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2151
2267
|
this.endPoint.add(amount);
|
|
2152
2268
|
return this;
|
|
2153
2269
|
};
|
|
2154
|
-
;
|
|
2155
2270
|
/**
|
|
2156
2271
|
* Reverse this curve, means swapping start- and end-point and swapping
|
|
2157
2272
|
* start-control- and end-control-point.
|
|
@@ -2170,7 +2285,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2170
2285
|
this.endControlPoint = tmp;
|
|
2171
2286
|
return this;
|
|
2172
2287
|
};
|
|
2173
|
-
;
|
|
2174
2288
|
/**
|
|
2175
2289
|
* Get the total curve length.<br>
|
|
2176
2290
|
* <br>
|
|
@@ -2189,7 +2303,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2189
2303
|
CubicBezierCurve.prototype.getLength = function () {
|
|
2190
2304
|
return this.arcLength;
|
|
2191
2305
|
};
|
|
2192
|
-
;
|
|
2193
2306
|
/**
|
|
2194
2307
|
* Uptate the internal arc segment buffer and their lengths.<br>
|
|
2195
2308
|
* <br>
|
|
@@ -2227,7 +2340,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2227
2340
|
}
|
|
2228
2341
|
this.arcLength = newLength;
|
|
2229
2342
|
};
|
|
2230
|
-
;
|
|
2231
2343
|
/**
|
|
2232
2344
|
* Get a 't' (relative position on curve) with the closest distance to point 'p'.
|
|
2233
2345
|
*
|
|
@@ -2250,7 +2362,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2250
2362
|
} while (iteration < 4 && this.getPointAt(result.tPrev).distance(this.getPointAt(result.tNext)) > desiredEpsilon);
|
|
2251
2363
|
return result.t;
|
|
2252
2364
|
};
|
|
2253
|
-
;
|
|
2254
2365
|
/**
|
|
2255
2366
|
* This helper function locates the 't' on a fixed step interval with the minimal distance
|
|
2256
2367
|
* between the curve (at 't') and the given point.
|
|
@@ -2279,12 +2390,12 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2279
2390
|
minDist = dist;
|
|
2280
2391
|
}
|
|
2281
2392
|
}
|
|
2282
|
-
return {
|
|
2393
|
+
return {
|
|
2394
|
+
t: tStart + tDiff * (minIndex / stepCount),
|
|
2283
2395
|
tPrev: tStart + tDiff * (Math.max(0, minIndex - 1) / stepCount),
|
|
2284
2396
|
tNext: tStart + tDiff * (Math.min(stepCount, minIndex + 1) / stepCount)
|
|
2285
2397
|
};
|
|
2286
2398
|
};
|
|
2287
|
-
;
|
|
2288
2399
|
/**
|
|
2289
2400
|
* Get the bounds of this bezier curve.
|
|
2290
2401
|
*
|
|
@@ -2306,7 +2417,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2306
2417
|
}
|
|
2307
2418
|
return new Bounds_1.Bounds(min, max);
|
|
2308
2419
|
};
|
|
2309
|
-
;
|
|
2310
2420
|
/**
|
|
2311
2421
|
* Get the start point of the curve.<br>
|
|
2312
2422
|
* <br>
|
|
@@ -2320,7 +2430,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2320
2430
|
CubicBezierCurve.prototype.getStartPoint = function () {
|
|
2321
2431
|
return this.startPoint;
|
|
2322
2432
|
};
|
|
2323
|
-
;
|
|
2324
2433
|
/**
|
|
2325
2434
|
* Get the end point of the curve.<br>
|
|
2326
2435
|
* <br>
|
|
@@ -2334,7 +2443,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2334
2443
|
CubicBezierCurve.prototype.getEndPoint = function () {
|
|
2335
2444
|
return this.endPoint;
|
|
2336
2445
|
};
|
|
2337
|
-
;
|
|
2338
2446
|
/**
|
|
2339
2447
|
* Get the start control point of the curve.<br>
|
|
2340
2448
|
* <br>
|
|
@@ -2348,7 +2456,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2348
2456
|
CubicBezierCurve.prototype.getStartControlPoint = function () {
|
|
2349
2457
|
return this.startControlPoint;
|
|
2350
2458
|
};
|
|
2351
|
-
;
|
|
2352
2459
|
/**
|
|
2353
2460
|
* Get the end control point of the curve.<br>
|
|
2354
2461
|
* <br>
|
|
@@ -2362,7 +2469,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2362
2469
|
CubicBezierCurve.prototype.getEndControlPoint = function () {
|
|
2363
2470
|
return this.endControlPoint;
|
|
2364
2471
|
};
|
|
2365
|
-
;
|
|
2366
2472
|
/**
|
|
2367
2473
|
* Get one of the four curve points specified by the passt point ID.
|
|
2368
2474
|
*
|
|
@@ -2383,7 +2489,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2383
2489
|
return this.endControlPoint;
|
|
2384
2490
|
throw new Error("Invalid point ID '" + id + "'.");
|
|
2385
2491
|
};
|
|
2386
|
-
;
|
|
2387
2492
|
/**
|
|
2388
2493
|
* Get the curve point at a given position t, where t is in [0,1].<br>
|
|
2389
2494
|
* <br>
|
|
@@ -2398,13 +2503,16 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2398
2503
|
**/
|
|
2399
2504
|
CubicBezierCurve.prototype.getPointAt = function (t) {
|
|
2400
2505
|
// Perform some powerful math magic
|
|
2401
|
-
var x = this.startPoint.x * Math.pow(1.0 - t, 3) +
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2506
|
+
var x = this.startPoint.x * Math.pow(1.0 - t, 3) +
|
|
2507
|
+
this.startControlPoint.x * 3 * t * Math.pow(1.0 - t, 2) +
|
|
2508
|
+
this.endControlPoint.x * 3 * Math.pow(t, 2) * (1.0 - t) +
|
|
2509
|
+
this.endPoint.x * Math.pow(t, 3);
|
|
2510
|
+
var y = this.startPoint.y * Math.pow(1.0 - t, 3) +
|
|
2511
|
+
this.startControlPoint.y * 3 * t * Math.pow(1.0 - t, 2) +
|
|
2512
|
+
this.endControlPoint.y * 3 * Math.pow(t, 2) * (1.0 - t) +
|
|
2513
|
+
this.endPoint.y * Math.pow(t, 3);
|
|
2405
2514
|
return new Vertex_1.Vertex(x, y);
|
|
2406
2515
|
};
|
|
2407
|
-
;
|
|
2408
2516
|
/**
|
|
2409
2517
|
* Get the curve point at a given position u, where u is in [0,arcLength].<br>
|
|
2410
2518
|
* <br>
|
|
@@ -2420,7 +2528,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2420
2528
|
CubicBezierCurve.prototype.getPoint = function (u) {
|
|
2421
2529
|
return this.getPointAt(u / this.arcLength);
|
|
2422
2530
|
};
|
|
2423
|
-
;
|
|
2424
2531
|
/**
|
|
2425
2532
|
* Get the curve tangent vector at a given absolute curve position t in [0,1].<br>
|
|
2426
2533
|
* <br>
|
|
@@ -2441,18 +2548,11 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2441
2548
|
var t2 = t * t;
|
|
2442
2549
|
// (1 - t)^2 = (1-t)*(1-t) = 1 - t - t + t^2 = 1 - 2*t + t^2
|
|
2443
2550
|
var nt2 = 1 - 2 * t + t2;
|
|
2444
|
-
var tX = -3 * a.x * nt2 +
|
|
2445
|
-
|
|
2446
|
-
c.x * (6 * (t - t2) - 3 * t2) +
|
|
2447
|
-
3 * d.x * t2;
|
|
2448
|
-
var tY = -3 * a.y * nt2 +
|
|
2449
|
-
b.y * (3 * nt2 - 6 * (t - t2)) +
|
|
2450
|
-
c.y * (6 * (t - t2) - 3 * t2) +
|
|
2451
|
-
3 * d.y * t2;
|
|
2551
|
+
var tX = -3 * a.x * nt2 + b.x * (3 * nt2 - 6 * (t - t2)) + c.x * (6 * (t - t2) - 3 * t2) + 3 * d.x * t2;
|
|
2552
|
+
var tY = -3 * a.y * nt2 + b.y * (3 * nt2 - 6 * (t - t2)) + c.y * (6 * (t - t2) - 3 * t2) + 3 * d.y * t2;
|
|
2452
2553
|
// Note: my implementation does NOT normalize tangent vectors!
|
|
2453
2554
|
return new Vertex_1.Vertex(tX, tY);
|
|
2454
2555
|
};
|
|
2455
|
-
;
|
|
2456
2556
|
/**
|
|
2457
2557
|
* Get a sub curve at the given start end end offsets (values between 0.0 and 1.0).
|
|
2458
2558
|
*
|
|
@@ -2478,7 +2578,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2478
2578
|
// pb.draw.cubicBezier( startVec.a, endVec.a, startVec.b, endVec.b, '#8800ff', 2 );
|
|
2479
2579
|
return new CubicBezierCurve(startVec.a, endVec.a, startVec.b, endVec.b);
|
|
2480
2580
|
};
|
|
2481
|
-
;
|
|
2482
2581
|
/**
|
|
2483
2582
|
* Convert a relative curve position u to the absolute curve position t.
|
|
2484
2583
|
*
|
|
@@ -2489,9 +2588,8 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2489
2588
|
* @return {number}
|
|
2490
2589
|
**/
|
|
2491
2590
|
CubicBezierCurve.prototype.convertU2T = function (u) {
|
|
2492
|
-
return Math.max(0.0, Math.min(1.0,
|
|
2591
|
+
return Math.max(0.0, Math.min(1.0, u / this.arcLength));
|
|
2493
2592
|
};
|
|
2494
|
-
;
|
|
2495
2593
|
/**
|
|
2496
2594
|
* Get the curve tangent vector at a given relative position u in [0,arcLength].<br>
|
|
2497
2595
|
* <br>
|
|
@@ -2506,7 +2604,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2506
2604
|
CubicBezierCurve.prototype.getTangent = function (u) {
|
|
2507
2605
|
return this.getTangentAt(this.convertU2T(u));
|
|
2508
2606
|
};
|
|
2509
|
-
;
|
|
2510
2607
|
/**
|
|
2511
2608
|
* Get the curve perpendicular at a given relative position u in [0,arcLength] as a vector.<br>
|
|
2512
2609
|
* <br>
|
|
@@ -2521,7 +2618,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2521
2618
|
CubicBezierCurve.prototype.getPerpendicular = function (u) {
|
|
2522
2619
|
return this.getPerpendicularAt(this.convertU2T(u));
|
|
2523
2620
|
};
|
|
2524
|
-
;
|
|
2525
2621
|
/**
|
|
2526
2622
|
* Get the curve perpendicular at a given absolute position t in [0,1] as a vector.<br>
|
|
2527
2623
|
* <br>
|
|
@@ -2537,7 +2633,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2537
2633
|
var tangentVector = this.getTangentAt(t);
|
|
2538
2634
|
return new Vertex_1.Vertex(tangentVector.y, -tangentVector.x);
|
|
2539
2635
|
};
|
|
2540
|
-
;
|
|
2541
2636
|
/**
|
|
2542
2637
|
* Clone this Bézier curve (deep clone).
|
|
2543
2638
|
*
|
|
@@ -2549,7 +2644,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2549
2644
|
CubicBezierCurve.prototype.clone = function () {
|
|
2550
2645
|
return new CubicBezierCurve(this.getStartPoint().clone(), this.getEndPoint().clone(), this.getStartControlPoint().clone(), this.getEndControlPoint().clone());
|
|
2551
2646
|
};
|
|
2552
|
-
;
|
|
2553
2647
|
/**
|
|
2554
2648
|
* Check if this and the specified curve are equal.<br>
|
|
2555
2649
|
* <br>
|
|
@@ -2568,17 +2662,25 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2568
2662
|
// Let's see if this restricted version works out.
|
|
2569
2663
|
if (!curve)
|
|
2570
2664
|
return false;
|
|
2571
|
-
if (!curve.startPoint ||
|
|
2572
|
-
!curve.endPoint ||
|
|
2573
|
-
!curve.startControlPoint ||
|
|
2574
|
-
!curve.endControlPoint)
|
|
2665
|
+
if (!curve.startPoint || !curve.endPoint || !curve.startControlPoint || !curve.endControlPoint)
|
|
2575
2666
|
return false;
|
|
2576
|
-
return this.startPoint.equals(curve.startPoint)
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2667
|
+
return (this.startPoint.equals(curve.startPoint) &&
|
|
2668
|
+
this.endPoint.equals(curve.endPoint) &&
|
|
2669
|
+
this.startControlPoint.equals(curve.startControlPoint) &&
|
|
2670
|
+
this.endControlPoint.equals(curve.endControlPoint));
|
|
2671
|
+
};
|
|
2672
|
+
/**
|
|
2673
|
+
* This function should invalidate any installed listeners and invalidate this object.
|
|
2674
|
+
* After calling this function the object might not hold valid data any more and
|
|
2675
|
+
* should not be used.
|
|
2676
|
+
*/
|
|
2677
|
+
CubicBezierCurve.prototype.destroy = function () {
|
|
2678
|
+
this.startPoint.destroy();
|
|
2679
|
+
this.endPoint.destroy();
|
|
2680
|
+
this.startControlPoint.destroy();
|
|
2681
|
+
this.endControlPoint.destroy();
|
|
2682
|
+
this.isDestroyed = true;
|
|
2580
2683
|
};
|
|
2581
|
-
;
|
|
2582
2684
|
/**
|
|
2583
2685
|
* Quick check for class instance.
|
|
2584
2686
|
* Is there a better way?
|
|
@@ -2604,7 +2706,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2604
2706
|
*/
|
|
2605
2707
|
return obj instanceof CubicBezierCurve;
|
|
2606
2708
|
};
|
|
2607
|
-
;
|
|
2608
2709
|
/**
|
|
2609
2710
|
* Create an SVG path data representation of this bézier curve.
|
|
2610
2711
|
*
|
|
@@ -2613,32 +2714,34 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2613
2714
|
* or in other words<br>
|
|
2614
2715
|
* <pre>'M startoint.x startPoint.y C startControlPoint.x startControlPoint.y endControlPoint.x endControlPoint.y endPoint.x endPoint.y'</pre>
|
|
2615
2716
|
*
|
|
2717
|
+
* @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
|
|
2616
2718
|
* @method toSVGPathData
|
|
2617
2719
|
* @instance
|
|
2618
2720
|
* @memberof CubicBezierCurve
|
|
2619
2721
|
* @return {string} The SVG path data string.
|
|
2620
2722
|
**/
|
|
2621
2723
|
CubicBezierCurve.prototype.toSVGPathData = function () {
|
|
2622
|
-
var buffer = [];
|
|
2623
|
-
buffer.push(
|
|
2624
|
-
buffer.push(this.startPoint.x.toString());
|
|
2625
|
-
buffer.push(
|
|
2626
|
-
buffer.push(this.startPoint.y.toString());
|
|
2627
|
-
buffer.push(
|
|
2628
|
-
buffer.push(this.startControlPoint.x.toString());
|
|
2629
|
-
buffer.push(
|
|
2630
|
-
buffer.push(this.startControlPoint.y.toString());
|
|
2631
|
-
buffer.push(
|
|
2632
|
-
buffer.push(this.endControlPoint.x.toString());
|
|
2633
|
-
buffer.push(
|
|
2634
|
-
buffer.push(this.endControlPoint.y.toString());
|
|
2635
|
-
buffer.push(
|
|
2636
|
-
buffer.push(this.endPoint.x.toString());
|
|
2637
|
-
buffer.push(
|
|
2638
|
-
buffer.push(this.endPoint.y.toString());
|
|
2639
|
-
return buffer.join(
|
|
2724
|
+
// var buffer: Array<string> = [];
|
|
2725
|
+
// buffer.push("M ");
|
|
2726
|
+
// buffer.push(this.startPoint.x.toString());
|
|
2727
|
+
// buffer.push(" ");
|
|
2728
|
+
// buffer.push(this.startPoint.y.toString());
|
|
2729
|
+
// buffer.push(" C ");
|
|
2730
|
+
// buffer.push(this.startControlPoint.x.toString());
|
|
2731
|
+
// buffer.push(" ");
|
|
2732
|
+
// buffer.push(this.startControlPoint.y.toString());
|
|
2733
|
+
// buffer.push(" ");
|
|
2734
|
+
// buffer.push(this.endControlPoint.x.toString());
|
|
2735
|
+
// buffer.push(" ");
|
|
2736
|
+
// buffer.push(this.endControlPoint.y.toString());
|
|
2737
|
+
// buffer.push(" ");
|
|
2738
|
+
// buffer.push(this.endPoint.x.toString());
|
|
2739
|
+
// buffer.push(" ");
|
|
2740
|
+
// buffer.push(this.endPoint.y.toString());
|
|
2741
|
+
// return buffer.join("");
|
|
2742
|
+
console.warn("[Deprecation] Warning: the CubicBezierCurve.toSVGPathData method is deprecated and does not return and valid SVG data any more. Please use `drawutilssvg` instead.");
|
|
2743
|
+
return "";
|
|
2640
2744
|
};
|
|
2641
|
-
;
|
|
2642
2745
|
/**
|
|
2643
2746
|
* Convert this curve to a JSON string.
|
|
2644
2747
|
*
|
|
@@ -2651,18 +2754,33 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2651
2754
|
CubicBezierCurve.prototype.toJSON = function (prettyFormat) {
|
|
2652
2755
|
var jsonString = "{ " + // begin object
|
|
2653
2756
|
(prettyFormat ? "\n\t" : "") +
|
|
2654
|
-
"
|
|
2757
|
+
'"startPoint" : [' +
|
|
2758
|
+
this.getStartPoint().x +
|
|
2759
|
+
"," +
|
|
2760
|
+
this.getStartPoint().y +
|
|
2761
|
+
"], " +
|
|
2655
2762
|
(prettyFormat ? "\n\t" : "") +
|
|
2656
|
-
"
|
|
2763
|
+
'"endPoint" : [' +
|
|
2764
|
+
this.getEndPoint().x +
|
|
2765
|
+
"," +
|
|
2766
|
+
this.getEndPoint().y +
|
|
2767
|
+
"], " +
|
|
2657
2768
|
(prettyFormat ? "\n\t" : "") +
|
|
2658
|
-
"
|
|
2769
|
+
'"startControlPoint": [' +
|
|
2770
|
+
this.getStartControlPoint().x +
|
|
2771
|
+
"," +
|
|
2772
|
+
this.getStartControlPoint().y +
|
|
2773
|
+
"], " +
|
|
2659
2774
|
(prettyFormat ? "\n\t" : "") +
|
|
2660
|
-
"
|
|
2775
|
+
'"endControlPoint" : [' +
|
|
2776
|
+
this.getEndControlPoint().x +
|
|
2777
|
+
"," +
|
|
2778
|
+
this.getEndControlPoint().y +
|
|
2779
|
+
"]" +
|
|
2661
2780
|
(prettyFormat ? "\n\t" : "") +
|
|
2662
2781
|
" }"; // end object
|
|
2663
2782
|
return jsonString;
|
|
2664
2783
|
};
|
|
2665
|
-
;
|
|
2666
2784
|
/**
|
|
2667
2785
|
* Parse a Bézier curve from the given JSON string.
|
|
2668
2786
|
*
|
|
@@ -2677,7 +2795,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2677
2795
|
var obj = JSON.parse(jsonString);
|
|
2678
2796
|
return CubicBezierCurve.fromObject(obj);
|
|
2679
2797
|
};
|
|
2680
|
-
;
|
|
2681
2798
|
/**
|
|
2682
2799
|
* Try to convert the passed object to a CubicBezierCurve.
|
|
2683
2800
|
*
|
|
@@ -2692,16 +2809,15 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2692
2809
|
if (typeof obj !== "object")
|
|
2693
2810
|
throw "Can only build from object.";
|
|
2694
2811
|
if (!obj.startPoint)
|
|
2695
|
-
throw
|
|
2812
|
+
throw 'Object member "startPoint" missing.';
|
|
2696
2813
|
if (!obj.endPoint)
|
|
2697
|
-
throw
|
|
2814
|
+
throw 'Object member "endPoint" missing.';
|
|
2698
2815
|
if (!obj.startControlPoint)
|
|
2699
|
-
throw
|
|
2816
|
+
throw 'Object member "startControlPoint" missing.';
|
|
2700
2817
|
if (!obj.endControlPoint)
|
|
2701
|
-
throw
|
|
2818
|
+
throw 'Object member "endControlPoint" missing.';
|
|
2702
2819
|
return new CubicBezierCurve(new Vertex_1.Vertex(obj.startPoint[0], obj.startPoint[1]), new Vertex_1.Vertex(obj.endPoint[0], obj.endPoint[1]), new Vertex_1.Vertex(obj.startControlPoint[0], obj.startControlPoint[1]), new Vertex_1.Vertex(obj.endControlPoint[0], obj.endControlPoint[1]));
|
|
2703
2820
|
};
|
|
2704
|
-
;
|
|
2705
2821
|
/**
|
|
2706
2822
|
* Convert a 4-element array of vertices to a cubic bézier curve.
|
|
2707
2823
|
*
|
|
@@ -2718,7 +2834,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2718
2834
|
throw "Can only build from array with four elements.";
|
|
2719
2835
|
return new CubicBezierCurve(arr[0], arr[1], arr[2], arr[3]);
|
|
2720
2836
|
};
|
|
2721
|
-
;
|
|
2722
2837
|
/** @constant {number} */
|
|
2723
2838
|
CubicBezierCurve.START_POINT = 0;
|
|
2724
2839
|
/** @constant {number} */
|
|
@@ -2841,7 +2956,8 @@ exports.Grid = Grid;
|
|
|
2841
2956
|
* @modified 2020-07-28 Changed the `delete` key code from 8 to 46.
|
|
2842
2957
|
* @modified 2020-10-04 Changed `window` to `globalThis`.
|
|
2843
2958
|
* @modified 2020-10-04 Added extended JSDoc.
|
|
2844
|
-
* @
|
|
2959
|
+
* @modified 2022-02-02 Added the `destroy` method.
|
|
2960
|
+
* @version 1.1.0
|
|
2845
2961
|
*
|
|
2846
2962
|
* @file KeyHandler
|
|
2847
2963
|
* @public
|
|
@@ -2874,7 +2990,7 @@ var KeyHandler = /** @class */ (function () {
|
|
|
2874
2990
|
* @memberof KeyHandler
|
|
2875
2991
|
* @param {HTMLElement} options.element (optional) The HTML element to listen on; if null then 'window' will be used.
|
|
2876
2992
|
* @param {boolean} options.trackAll (optional) Set to true if you want to keep track of _all_ keys (keyStatus).
|
|
2877
|
-
|
|
2993
|
+
**/
|
|
2878
2994
|
function KeyHandler(options) {
|
|
2879
2995
|
this.downListeners = [];
|
|
2880
2996
|
this.pressListeners = [];
|
|
@@ -2893,7 +3009,6 @@ var KeyHandler = /** @class */ (function () {
|
|
|
2893
3009
|
// Install the listeners
|
|
2894
3010
|
this.installListeners();
|
|
2895
3011
|
}
|
|
2896
|
-
;
|
|
2897
3012
|
/**
|
|
2898
3013
|
* A helper function to fire key events from this KeyHandler.
|
|
2899
3014
|
*
|
|
@@ -2911,7 +3026,6 @@ var KeyHandler = /** @class */ (function () {
|
|
|
2911
3026
|
}
|
|
2912
3027
|
return hasListener;
|
|
2913
3028
|
};
|
|
2914
|
-
;
|
|
2915
3029
|
/**
|
|
2916
3030
|
* Internal function to fire a new keydown event to all listeners.
|
|
2917
3031
|
* You should not call this function on your own unless you know what you do.
|
|
@@ -2927,10 +3041,9 @@ var KeyHandler = /** @class */ (function () {
|
|
|
2927
3041
|
KeyHandler.prototype.fireDownEvent = function (e, handler) {
|
|
2928
3042
|
if (handler.fireEvent(e, handler.downListeners) || handler.trackAllKeys) {
|
|
2929
3043
|
// Down event has listeners. Update key state.
|
|
2930
|
-
handler.keyStates[e.keyCode] =
|
|
3044
|
+
handler.keyStates[e.keyCode] = "down";
|
|
2931
3045
|
}
|
|
2932
3046
|
};
|
|
2933
|
-
;
|
|
2934
3047
|
/**
|
|
2935
3048
|
* Internal function to fire a new keypress event to all listeners.
|
|
2936
3049
|
* You should not call this function on your own unless you know what you do.
|
|
@@ -2946,7 +3059,6 @@ var KeyHandler = /** @class */ (function () {
|
|
|
2946
3059
|
KeyHandler.prototype.firePressEvent = function (e, handler) {
|
|
2947
3060
|
handler.fireEvent(e, handler.pressListeners);
|
|
2948
3061
|
};
|
|
2949
|
-
;
|
|
2950
3062
|
/**
|
|
2951
3063
|
* Internal function to fire a new keyup event to all listeners.
|
|
2952
3064
|
* You should not call this function on your own unless you know what you do.
|
|
@@ -2965,20 +3077,18 @@ var KeyHandler = /** @class */ (function () {
|
|
|
2965
3077
|
delete handler.keyStates[e.keyCode];
|
|
2966
3078
|
}
|
|
2967
3079
|
};
|
|
2968
|
-
;
|
|
2969
3080
|
/**
|
|
2970
3081
|
* Resolve the key/name code.
|
|
2971
3082
|
*/
|
|
2972
3083
|
KeyHandler.key2code = function (key) {
|
|
2973
|
-
if (typeof key ==
|
|
3084
|
+
if (typeof key == "number")
|
|
2974
3085
|
return key;
|
|
2975
|
-
if (typeof key !=
|
|
3086
|
+
if (typeof key != "string")
|
|
2976
3087
|
throw "Unknown key name or key type (should be a string or integer): " + key;
|
|
2977
3088
|
if (KeyHandler.KEY_CODES[key])
|
|
2978
3089
|
return KeyHandler.KEY_CODES[key];
|
|
2979
3090
|
throw "Unknown key (cannot resolve key code): " + key;
|
|
2980
3091
|
};
|
|
2981
|
-
;
|
|
2982
3092
|
/**
|
|
2983
3093
|
* Install the required listeners into the initially passed element.
|
|
2984
3094
|
*
|
|
@@ -2987,20 +3097,24 @@ var KeyHandler = /** @class */ (function () {
|
|
|
2987
3097
|
*/
|
|
2988
3098
|
KeyHandler.prototype.installListeners = function () {
|
|
2989
3099
|
var _self = this;
|
|
2990
|
-
this.element.addEventListener(
|
|
2991
|
-
|
|
2992
|
-
|
|
3100
|
+
this.element.addEventListener("keydown", (this._keyDownListener = function (e) {
|
|
3101
|
+
_self.fireDownEvent(e, _self);
|
|
3102
|
+
}));
|
|
3103
|
+
this.element.addEventListener("keypress", (this._keyPressListener = function (e) {
|
|
3104
|
+
_self.firePressEvent(e, _self);
|
|
3105
|
+
}));
|
|
3106
|
+
this.element.addEventListener("keyup", (this._keyUpListener = function (e) {
|
|
3107
|
+
_self.fireUpEvent(e, _self);
|
|
3108
|
+
}));
|
|
2993
3109
|
};
|
|
2994
|
-
;
|
|
2995
3110
|
/**
|
|
2996
3111
|
* Remove all installed event listeners from the underlying element.
|
|
2997
3112
|
*/
|
|
2998
3113
|
KeyHandler.prototype.releaseListeners = function () {
|
|
2999
|
-
this.element.removeEventListener(
|
|
3000
|
-
this.element.removeEventListener(
|
|
3001
|
-
this.element.removeEventListener(
|
|
3114
|
+
this.element.removeEventListener("keydown", this._keyDownListener);
|
|
3115
|
+
this.element.removeEventListener("keypress", this._keyPressListener);
|
|
3116
|
+
this.element.removeEventListener("keyup", this._keyUpListener);
|
|
3002
3117
|
};
|
|
3003
|
-
;
|
|
3004
3118
|
/**
|
|
3005
3119
|
* Listen for key down. This function allows chaining.
|
|
3006
3120
|
*
|
|
@@ -3017,7 +3131,6 @@ var KeyHandler = /** @class */ (function () {
|
|
|
3017
3131
|
this.downListeners.push({ key: key, keyCode: KeyHandler.key2code(key), listener: listener });
|
|
3018
3132
|
return this;
|
|
3019
3133
|
};
|
|
3020
|
-
;
|
|
3021
3134
|
/**
|
|
3022
3135
|
* Listen for key press.
|
|
3023
3136
|
*
|
|
@@ -3034,7 +3147,6 @@ var KeyHandler = /** @class */ (function () {
|
|
|
3034
3147
|
this.pressListeners.push({ key: key, keyCode: KeyHandler.key2code(key), listener: listener });
|
|
3035
3148
|
return this;
|
|
3036
3149
|
};
|
|
3037
|
-
;
|
|
3038
3150
|
/**
|
|
3039
3151
|
* Listen for key up.
|
|
3040
3152
|
*
|
|
@@ -3051,22 +3163,30 @@ var KeyHandler = /** @class */ (function () {
|
|
|
3051
3163
|
this.upListeners.push({ key: key, keyCode: KeyHandler.key2code(key), listener: listener });
|
|
3052
3164
|
return this;
|
|
3053
3165
|
};
|
|
3054
|
-
;
|
|
3055
3166
|
/**
|
|
3056
3167
|
* Check if a specific key is currently held pressed.
|
|
3057
3168
|
*
|
|
3058
3169
|
* @param {string|number} key - Any key identifier, key code or one from the KEY_CODES list.
|
|
3059
3170
|
*/
|
|
3060
3171
|
KeyHandler.prototype.isDown = function (key) {
|
|
3061
|
-
if (typeof key ==
|
|
3172
|
+
if (typeof key == "number")
|
|
3062
3173
|
return this.keyStates[key] ? true : false;
|
|
3063
3174
|
else
|
|
3064
3175
|
return this.keyStates[KeyHandler.key2code(key)] ? true : false;
|
|
3065
3176
|
};
|
|
3177
|
+
/**
|
|
3178
|
+
* This function should invalidate any installed listeners and invalidate this object.
|
|
3179
|
+
* After calling this function the object might not hold valid data any more and
|
|
3180
|
+
* should not be used any more.
|
|
3181
|
+
*/
|
|
3182
|
+
KeyHandler.prototype.destroy = function () {
|
|
3183
|
+
this.releaseListeners();
|
|
3184
|
+
};
|
|
3066
3185
|
/**
|
|
3067
3186
|
* Source:
|
|
3068
3187
|
* https://keycode.info/
|
|
3069
3188
|
*/
|
|
3189
|
+
// prettier-ignore
|
|
3070
3190
|
KeyHandler.KEY_CODES = {
|
|
3071
3191
|
'break': 3,
|
|
3072
3192
|
'backspace': 8,
|
|
@@ -3284,7 +3404,8 @@ exports.KeyHandler = KeyHandler;
|
|
|
3284
3404
|
* @modified 2020-03-16 The Line.angle(Line) parameter is now optional. The baseline (x-axis) will be used if not defined.
|
|
3285
3405
|
* @modified 2020-03-23 Ported to Typescript from JS.
|
|
3286
3406
|
* @modified 2020-12-04 The `intersection` function returns undefined if both lines are parallel.
|
|
3287
|
-
* @
|
|
3407
|
+
* @modified 2022-02-02 Added the `destroy` method.
|
|
3408
|
+
* @version 2.2.0
|
|
3288
3409
|
*
|
|
3289
3410
|
* @file Line
|
|
3290
3411
|
* @public
|
|
@@ -3348,20 +3469,19 @@ var Line = /** @class */ (function (_super) {
|
|
|
3348
3469
|
return null;
|
|
3349
3470
|
var a = this.a.y - line.a.y;
|
|
3350
3471
|
var b = this.a.x - line.a.x;
|
|
3351
|
-
var numerator1 = (
|
|
3352
|
-
var numerator2 = (
|
|
3472
|
+
var numerator1 = (line.b.x - line.a.x) * a - (line.b.y - line.a.y) * b;
|
|
3473
|
+
var numerator2 = (this.b.x - this.a.x) * a - (this.b.y - this.a.y) * b;
|
|
3353
3474
|
a = numerator1 / denominator; // NaN if parallel lines
|
|
3354
3475
|
b = numerator2 / denominator;
|
|
3355
3476
|
// Catch NaN?
|
|
3356
|
-
var x = this.a.x +
|
|
3357
|
-
var y = this.a.y +
|
|
3477
|
+
var x = this.a.x + a * (this.b.x - this.a.x);
|
|
3478
|
+
var y = this.a.y + a * (this.b.y - this.a.y);
|
|
3358
3479
|
if (isNaN(a) || isNaN(x) || isNaN(y)) {
|
|
3359
3480
|
return undefined;
|
|
3360
3481
|
}
|
|
3361
3482
|
// if we cast these lines infinitely in both directions, they intersect here:
|
|
3362
3483
|
return new Vertex_1.Vertex(x, y);
|
|
3363
3484
|
};
|
|
3364
|
-
;
|
|
3365
3485
|
/**
|
|
3366
3486
|
* Create an SVG representation of this line.
|
|
3367
3487
|
*
|
|
@@ -3374,19 +3494,20 @@ var Line = /** @class */ (function (_super) {
|
|
|
3374
3494
|
* @memberof Line
|
|
3375
3495
|
**/
|
|
3376
3496
|
Line.prototype.toSVGString = function (options) {
|
|
3377
|
-
options = options || {};
|
|
3378
|
-
var buffer = [];
|
|
3379
|
-
buffer.push('<line');
|
|
3380
|
-
if
|
|
3381
|
-
|
|
3382
|
-
buffer.push(' x1="' + this.a.x + '"');
|
|
3383
|
-
buffer.push(' y1="' + this.a.y + '"');
|
|
3384
|
-
buffer.push(' x2="' + this.b.x + '"');
|
|
3385
|
-
buffer.push(' y2="' + this.b.y + '"');
|
|
3386
|
-
buffer.push(' />');
|
|
3387
|
-
return buffer.join('');
|
|
3497
|
+
// options = options || {};
|
|
3498
|
+
// var buffer = [];
|
|
3499
|
+
// buffer.push( '<line' );
|
|
3500
|
+
// if( options.className )
|
|
3501
|
+
// buffer.push( ' class="' + options.className + '"' );
|
|
3502
|
+
// buffer.push( ' x1="' + this.a.x + '"' );
|
|
3503
|
+
// buffer.push( ' y1="' + this.a.y + '"' );
|
|
3504
|
+
// buffer.push( ' x2="' + this.b.x + '"' );
|
|
3505
|
+
// buffer.push( ' y2="' + this.b.y + '"' );
|
|
3506
|
+
// buffer.push( ' />' );
|
|
3507
|
+
// return buffer.join('');
|
|
3508
|
+
console.warn("[Deprecation] Warning: the Line.toSVGString method is deprecated and does not return and valid SVG data any more. Please use `drawutilssvg` instead.");
|
|
3509
|
+
return "";
|
|
3388
3510
|
};
|
|
3389
|
-
;
|
|
3390
3511
|
return Line;
|
|
3391
3512
|
}(VertTuple_1.VertTuple));
|
|
3392
3513
|
exports.Line = Line;
|
|
@@ -3548,41 +3669,41 @@ var MouseHandler = /** @class */ (function () {
|
|
|
3548
3669
|
// | drag offset, ...) to the callbacks.
|
|
3549
3670
|
// +-------------------------------------------------
|
|
3550
3671
|
var _self = this;
|
|
3551
|
-
this.handlers[
|
|
3672
|
+
this.handlers["mousemove"] = function (e) {
|
|
3552
3673
|
if (_self.listeners.mousemove)
|
|
3553
|
-
_self.listeners.mousemove(_self.mkParams(e,
|
|
3674
|
+
_self.listeners.mousemove(_self.mkParams(e, "mousemove"));
|
|
3554
3675
|
if (_self.mouseDragPos && _self.listeners.drag)
|
|
3555
|
-
_self.listeners.drag(_self.mkParams(e,
|
|
3676
|
+
_self.listeners.drag(_self.mkParams(e, "drag"));
|
|
3556
3677
|
if (_self.mouseDownPos)
|
|
3557
3678
|
_self.mouseDragPos = _self.relPos(e);
|
|
3558
3679
|
};
|
|
3559
|
-
this.handlers[
|
|
3680
|
+
this.handlers["mouseup"] = function (e) {
|
|
3560
3681
|
if (_self.listeners.mouseup)
|
|
3561
|
-
_self.listeners.mouseup(_self.mkParams(e,
|
|
3682
|
+
_self.listeners.mouseup(_self.mkParams(e, "mouseup"));
|
|
3562
3683
|
_self.mouseDragPos = undefined;
|
|
3563
3684
|
_self.mouseDownPos = undefined;
|
|
3564
3685
|
_self.mouseButton = -1;
|
|
3565
3686
|
};
|
|
3566
|
-
this.handlers[
|
|
3687
|
+
this.handlers["mousedown"] = function (e) {
|
|
3567
3688
|
_self.mouseDragPos = _self.relPos(e);
|
|
3568
3689
|
_self.mouseDownPos = _self.relPos(e);
|
|
3569
3690
|
_self.mouseButton = e.button;
|
|
3570
3691
|
if (_self.listeners.mousedown)
|
|
3571
|
-
_self.listeners.mousedown(_self.mkParams(e,
|
|
3692
|
+
_self.listeners.mousedown(_self.mkParams(e, "mousedown"));
|
|
3572
3693
|
};
|
|
3573
|
-
this.handlers[
|
|
3694
|
+
this.handlers["click"] = function (e) {
|
|
3574
3695
|
if (_self.listeners.click)
|
|
3575
|
-
_self.listeners.click(_self.mkParams(e,
|
|
3696
|
+
_self.listeners.click(_self.mkParams(e, "click"));
|
|
3576
3697
|
};
|
|
3577
|
-
this.handlers[
|
|
3698
|
+
this.handlers["wheel"] = function (e) {
|
|
3578
3699
|
if (_self.listeners.wheel)
|
|
3579
|
-
_self.listeners.wheel(_self.mkParams(e,
|
|
3700
|
+
_self.listeners.wheel(_self.mkParams(e, "wheel"));
|
|
3580
3701
|
};
|
|
3581
|
-
this.element.addEventListener(
|
|
3582
|
-
this.element.addEventListener(
|
|
3583
|
-
this.element.addEventListener(
|
|
3584
|
-
this.element.addEventListener(
|
|
3585
|
-
this.element.addEventListener(
|
|
3702
|
+
this.element.addEventListener("mousemove", this.handlers["mousemove"]);
|
|
3703
|
+
this.element.addEventListener("mouseup", this.handlers["mouseup"]);
|
|
3704
|
+
this.element.addEventListener("mousedown", this.handlers["mousedown"]);
|
|
3705
|
+
this.element.addEventListener("click", this.handlers["click"]);
|
|
3706
|
+
this.element.addEventListener("wheel", this.handlers["wheel"]);
|
|
3586
3707
|
}
|
|
3587
3708
|
/**
|
|
3588
3709
|
* Get relative position from the given MouseEvent.
|
|
@@ -3595,11 +3716,8 @@ var MouseHandler = /** @class */ (function () {
|
|
|
3595
3716
|
* @return {XYCoords} The relative mouse coordinates.
|
|
3596
3717
|
*/
|
|
3597
3718
|
MouseHandler.prototype.relPos = function (e) {
|
|
3598
|
-
return { x: e.offsetX,
|
|
3599
|
-
y: e.offsetY
|
|
3600
|
-
};
|
|
3719
|
+
return { x: e.offsetX, y: e.offsetY };
|
|
3601
3720
|
};
|
|
3602
|
-
;
|
|
3603
3721
|
/**
|
|
3604
3722
|
* Build the extended event params.
|
|
3605
3723
|
*
|
|
@@ -3625,8 +3743,8 @@ var MouseHandler = /** @class */ (function () {
|
|
|
3625
3743
|
rightButton: this.mouseButton == 2,
|
|
3626
3744
|
mouseDownPos: this.mouseDownPos,
|
|
3627
3745
|
draggedFrom: this.mouseDragPos,
|
|
3628
|
-
wasDragged:
|
|
3629
|
-
dragAmount:
|
|
3746
|
+
wasDragged: this.mouseDownPos != null && (this.mouseDownPos.x != rel.x || this.mouseDownPos.y != rel.y),
|
|
3747
|
+
dragAmount: this.mouseDownPos != null ? { x: rel.x - this.mouseDragPos.x, y: rel.y - this.mouseDragPos.y } : { x: 0, y: 0 }
|
|
3630
3748
|
};
|
|
3631
3749
|
return xEvent;
|
|
3632
3750
|
};
|
|
@@ -3677,14 +3795,13 @@ var MouseHandler = /** @class */ (function () {
|
|
|
3677
3795
|
*/
|
|
3678
3796
|
MouseHandler.prototype.drag = function (callback) {
|
|
3679
3797
|
if (this.listeners.drag)
|
|
3680
|
-
this.throwAlreadyInstalled(
|
|
3798
|
+
this.throwAlreadyInstalled("drag");
|
|
3681
3799
|
this.listeners.drag = callback;
|
|
3682
|
-
this.listenFor(
|
|
3683
|
-
this.listenFor(
|
|
3684
|
-
this.listenFor(
|
|
3800
|
+
this.listenFor("mousedown");
|
|
3801
|
+
this.listenFor("mousemove");
|
|
3802
|
+
this.listenFor("mouseup");
|
|
3685
3803
|
return this;
|
|
3686
3804
|
};
|
|
3687
|
-
;
|
|
3688
3805
|
/**
|
|
3689
3806
|
* Installer function to listen for a specific event: mouse-move.
|
|
3690
3807
|
* Pass your callbacks here.
|
|
@@ -3699,12 +3816,11 @@ var MouseHandler = /** @class */ (function () {
|
|
|
3699
3816
|
*/
|
|
3700
3817
|
MouseHandler.prototype.move = function (callback) {
|
|
3701
3818
|
if (this.listeners.mousemove)
|
|
3702
|
-
this.throwAlreadyInstalled(
|
|
3703
|
-
this.listenFor(
|
|
3819
|
+
this.throwAlreadyInstalled("mousemove");
|
|
3820
|
+
this.listenFor("mousemove");
|
|
3704
3821
|
this.listeners.mousemove = callback;
|
|
3705
3822
|
return this;
|
|
3706
3823
|
};
|
|
3707
|
-
;
|
|
3708
3824
|
/**
|
|
3709
3825
|
* Installer function to listen for a specific event: mouse-up.
|
|
3710
3826
|
* Pass your callbacks here.
|
|
@@ -3719,12 +3835,11 @@ var MouseHandler = /** @class */ (function () {
|
|
|
3719
3835
|
*/
|
|
3720
3836
|
MouseHandler.prototype.up = function (callback) {
|
|
3721
3837
|
if (this.listeners.mouseup)
|
|
3722
|
-
this.throwAlreadyInstalled(
|
|
3723
|
-
this.listenFor(
|
|
3838
|
+
this.throwAlreadyInstalled("mouseup");
|
|
3839
|
+
this.listenFor("mouseup");
|
|
3724
3840
|
this.listeners.mouseup = callback;
|
|
3725
3841
|
return this;
|
|
3726
3842
|
};
|
|
3727
|
-
;
|
|
3728
3843
|
/**
|
|
3729
3844
|
* Installer function to listen for a specific event: mouse-down.
|
|
3730
3845
|
* Pass your callbacks here.
|
|
@@ -3739,12 +3854,11 @@ var MouseHandler = /** @class */ (function () {
|
|
|
3739
3854
|
*/
|
|
3740
3855
|
MouseHandler.prototype.down = function (callback) {
|
|
3741
3856
|
if (this.listeners.mousedown)
|
|
3742
|
-
this.throwAlreadyInstalled(
|
|
3743
|
-
this.listenFor(
|
|
3857
|
+
this.throwAlreadyInstalled("mousedown");
|
|
3858
|
+
this.listenFor("mousedown");
|
|
3744
3859
|
this.listeners.mousedown = callback;
|
|
3745
3860
|
return this;
|
|
3746
3861
|
};
|
|
3747
|
-
;
|
|
3748
3862
|
/**
|
|
3749
3863
|
* Installer function to listen for a specific event: mouse-click.
|
|
3750
3864
|
* Pass your callbacks here.
|
|
@@ -3759,12 +3873,11 @@ var MouseHandler = /** @class */ (function () {
|
|
|
3759
3873
|
*/
|
|
3760
3874
|
MouseHandler.prototype.click = function (callback) {
|
|
3761
3875
|
if (this.listeners.click)
|
|
3762
|
-
this.throwAlreadyInstalled(
|
|
3763
|
-
this.listenFor(
|
|
3876
|
+
this.throwAlreadyInstalled("click");
|
|
3877
|
+
this.listenFor("click");
|
|
3764
3878
|
this.listeners.click = callback;
|
|
3765
3879
|
return this;
|
|
3766
3880
|
};
|
|
3767
|
-
;
|
|
3768
3881
|
/**
|
|
3769
3882
|
* Installer function to listen for a specific event: mouse-wheel.
|
|
3770
3883
|
* Pass your callbacks here.
|
|
@@ -3779,12 +3892,11 @@ var MouseHandler = /** @class */ (function () {
|
|
|
3779
3892
|
*/
|
|
3780
3893
|
MouseHandler.prototype.wheel = function (callback) {
|
|
3781
3894
|
if (this.listeners.wheel)
|
|
3782
|
-
this.throwAlreadyInstalled(
|
|
3783
|
-
this.listenFor(
|
|
3895
|
+
this.throwAlreadyInstalled("wheel");
|
|
3896
|
+
this.listenFor("wheel");
|
|
3784
3897
|
this.listeners.wheel = callback;
|
|
3785
3898
|
return this;
|
|
3786
3899
|
};
|
|
3787
|
-
;
|
|
3788
3900
|
/**
|
|
3789
3901
|
* An internal function to throw events.
|
|
3790
3902
|
*
|
|
@@ -3798,7 +3910,6 @@ var MouseHandler = /** @class */ (function () {
|
|
|
3798
3910
|
MouseHandler.prototype.throwAlreadyInstalled = function (name) {
|
|
3799
3911
|
throw "This MouseHandler already has a '" + name + "' callback. To keep the code simple there is only room for one.";
|
|
3800
3912
|
};
|
|
3801
|
-
;
|
|
3802
3913
|
/**
|
|
3803
3914
|
* Call this when your work is done.
|
|
3804
3915
|
*
|
|
@@ -3811,16 +3922,16 @@ var MouseHandler = /** @class */ (function () {
|
|
|
3811
3922
|
* @return {void}
|
|
3812
3923
|
*/
|
|
3813
3924
|
MouseHandler.prototype.destroy = function () {
|
|
3814
|
-
this.unlistenFor(
|
|
3815
|
-
this.unlistenFor(
|
|
3816
|
-
this.unlistenFor(
|
|
3817
|
-
this.unlistenFor(
|
|
3818
|
-
this.unlistenFor(
|
|
3819
|
-
this.element.removeEventListener(
|
|
3820
|
-
this.element.removeEventListener(
|
|
3821
|
-
this.element.removeEventListener(
|
|
3822
|
-
this.element.removeEventListener(
|
|
3823
|
-
this.element.removeEventListener(
|
|
3925
|
+
this.unlistenFor("mousedown");
|
|
3926
|
+
this.unlistenFor("mousemove");
|
|
3927
|
+
this.unlistenFor("moseup");
|
|
3928
|
+
this.unlistenFor("click");
|
|
3929
|
+
this.unlistenFor("wheel");
|
|
3930
|
+
this.element.removeEventListener("mousemove", this.handlers["mousemove"]);
|
|
3931
|
+
this.element.removeEventListener("mouseup", this.handlers["mousedown"]);
|
|
3932
|
+
this.element.removeEventListener("mousedown", this.handlers["mousedown"]);
|
|
3933
|
+
this.element.removeEventListener("click", this.handlers["click"]);
|
|
3934
|
+
this.element.removeEventListener("wheel", this.handlers["wheel"]);
|
|
3824
3935
|
};
|
|
3825
3936
|
return MouseHandler;
|
|
3826
3937
|
}());
|
|
@@ -3839,7 +3950,9 @@ exports.MouseHandler = MouseHandler;
|
|
|
3839
3950
|
* @modified 2019-03-23 Added JSDoc tags.
|
|
3840
3951
|
* @modified 2020-03-25 Ported this class from vanilla-JS to Typescript.
|
|
3841
3952
|
* @modified 2021-01-20 Added UID.
|
|
3842
|
-
* @
|
|
3953
|
+
* @modified 2022-02-02 Added the `destroy` method.
|
|
3954
|
+
* @modified 2022-02-02 Cleared the `PBImage.toSVGString` function (deprecated). Use `drawutilssvg` instead.
|
|
3955
|
+
* @version 1.2.0
|
|
3843
3956
|
*
|
|
3844
3957
|
* @file PBImage
|
|
3845
3958
|
* @fileoverview As native Image objects have only a position and with
|
|
@@ -3877,7 +3990,6 @@ var PBImage = /** @class */ (function () {
|
|
|
3877
3990
|
this.upperLeft = upperLeft;
|
|
3878
3991
|
this.lowerRight = lowerRight;
|
|
3879
3992
|
}
|
|
3880
|
-
;
|
|
3881
3993
|
/**
|
|
3882
3994
|
* Convert this vertex to SVG code.
|
|
3883
3995
|
*
|
|
@@ -3892,7 +4004,16 @@ var PBImage = /** @class */ (function () {
|
|
|
3892
4004
|
console.warn("PBImage is not yet SVG serializable. Returning empty SVG string.");
|
|
3893
4005
|
return "";
|
|
3894
4006
|
};
|
|
3895
|
-
|
|
4007
|
+
/**
|
|
4008
|
+
* This function should invalidate any installed listeners and invalidate this object.
|
|
4009
|
+
* After calling this function the object might not hold valid data any more and
|
|
4010
|
+
* should not be used.
|
|
4011
|
+
*/
|
|
4012
|
+
PBImage.prototype.destroy = function () {
|
|
4013
|
+
this.upperLeft.destroy();
|
|
4014
|
+
this.lowerRight.destroy();
|
|
4015
|
+
this.isDestroyed = true;
|
|
4016
|
+
};
|
|
3896
4017
|
return PBImage;
|
|
3897
4018
|
}());
|
|
3898
4019
|
exports.PBImage = PBImage;
|
|
@@ -3900,6 +4021,88 @@ exports.PBImage = PBImage;
|
|
|
3900
4021
|
|
|
3901
4022
|
/***/ }),
|
|
3902
4023
|
|
|
4024
|
+
/***/ 196:
|
|
4025
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
4026
|
+
|
|
4027
|
+
|
|
4028
|
+
/**
|
|
4029
|
+
* @author Ikaros Kappler
|
|
4030
|
+
* @date 2021-11-16
|
|
4031
|
+
* @modified 2022-02-02 Added the `destroy` method.
|
|
4032
|
+
* @version 1.1.0
|
|
4033
|
+
**/
|
|
4034
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
4035
|
+
exports.PBText = void 0;
|
|
4036
|
+
var UIDGenerator_1 = __webpack_require__(197);
|
|
4037
|
+
var Vertex_1 = __webpack_require__(421);
|
|
4038
|
+
/**
|
|
4039
|
+
* @classdesc A simple text element: position, fontSize, fontFamily, color, textAlign, lineHeight and rotation.
|
|
4040
|
+
*
|
|
4041
|
+
* @requires FontOptions
|
|
4042
|
+
* @requires FontSize
|
|
4043
|
+
* @requires FontStyle
|
|
4044
|
+
* @requires FontWeight
|
|
4045
|
+
* @requires Vertex
|
|
4046
|
+
* @requires SVGSerializale
|
|
4047
|
+
* @requires UID
|
|
4048
|
+
* @requires UIDGenerator
|
|
4049
|
+
**/
|
|
4050
|
+
var PBText = /** @class */ (function () {
|
|
4051
|
+
/**
|
|
4052
|
+
* Create a new circle with given center point and radius.
|
|
4053
|
+
*
|
|
4054
|
+
* @constructor
|
|
4055
|
+
* @name Circle
|
|
4056
|
+
* @param {Vertex} center - The center point of the circle.
|
|
4057
|
+
* @param {number} radius - The radius of the circle.
|
|
4058
|
+
*/
|
|
4059
|
+
function PBText(text, anchor, options) {
|
|
4060
|
+
/**
|
|
4061
|
+
* Required to generate proper CSS classes and other class related IDs.
|
|
4062
|
+
**/
|
|
4063
|
+
this.className = "PBText";
|
|
4064
|
+
this.uid = UIDGenerator_1.UIDGenerator.next();
|
|
4065
|
+
this.text = text;
|
|
4066
|
+
this.anchor = anchor !== null && anchor !== void 0 ? anchor : new Vertex_1.Vertex();
|
|
4067
|
+
this.color = options.color;
|
|
4068
|
+
this.fontFamily = options.fontFamily;
|
|
4069
|
+
this.fontSize = options.fontSize;
|
|
4070
|
+
this.fontStyle = options.fontStyle;
|
|
4071
|
+
this.fontWeight = options.fontWeight;
|
|
4072
|
+
this.lineHeight = options.lineHeight;
|
|
4073
|
+
this.textAlign = options.textAlign;
|
|
4074
|
+
this.rotation = options.rotation;
|
|
4075
|
+
}
|
|
4076
|
+
/**
|
|
4077
|
+
* Create an SVG representation of this circle.
|
|
4078
|
+
*
|
|
4079
|
+
* @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
|
|
4080
|
+
* @method toSVGString
|
|
4081
|
+
* @param {object=} options - An optional set of options, like 'className'.
|
|
4082
|
+
* @return {string} A string representing the SVG code for this vertex.
|
|
4083
|
+
* @instance
|
|
4084
|
+
* @memberof Circle
|
|
4085
|
+
*/
|
|
4086
|
+
PBText.prototype.toSVGString = function (options) {
|
|
4087
|
+
console.warn("[PBText.toSVGString()] This function is not implemented as it defines a deprecated method. Use the 'drawutilssvg.text()' method instead.");
|
|
4088
|
+
return "";
|
|
4089
|
+
};
|
|
4090
|
+
/**
|
|
4091
|
+
* This function should invalidate any installed listeners and invalidate this object.
|
|
4092
|
+
* After calling this function the object might not hold valid data any more and
|
|
4093
|
+
* should not be used.
|
|
4094
|
+
*/
|
|
4095
|
+
PBText.prototype.destroy = function () {
|
|
4096
|
+
this.anchor.destroy();
|
|
4097
|
+
this.isDestroyed = true;
|
|
4098
|
+
};
|
|
4099
|
+
return PBText;
|
|
4100
|
+
}()); // END class
|
|
4101
|
+
exports.PBText = PBText;
|
|
4102
|
+
//# sourceMappingURL=PBText.js.map
|
|
4103
|
+
|
|
4104
|
+
/***/ }),
|
|
4105
|
+
|
|
3903
4106
|
/***/ 919:
|
|
3904
4107
|
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
3905
4108
|
|
|
@@ -3980,7 +4183,8 @@ var __webpack_unused_export__;
|
|
|
3980
4183
|
* @modified 2021-03-03 Added the `VEllipseSector` drawable.
|
|
3981
4184
|
* @modified 2021-03-29 Clearing `currentClassName` and `currentId` after drawing each drawable.
|
|
3982
4185
|
* @modified 2021-04-25 Extending `remove` to accept arrays of drawables.
|
|
3983
|
-
* @
|
|
4186
|
+
* @modified 2021-11-16 Adding the `PBText` drawable.
|
|
4187
|
+
* @version 1.15.0
|
|
3984
4188
|
*
|
|
3985
4189
|
* @file PlotBoilerplate
|
|
3986
4190
|
* @fileoverview The main class.
|
|
@@ -4008,6 +4212,7 @@ var VEllipseSector_1 = __webpack_require__(965);
|
|
|
4008
4212
|
var Vector_1 = __webpack_require__(73);
|
|
4009
4213
|
var Vertex_1 = __webpack_require__(421);
|
|
4010
4214
|
var VertexAttr_1 = __webpack_require__(861);
|
|
4215
|
+
var PBText_1 = __webpack_require__(196);
|
|
4011
4216
|
/**
|
|
4012
4217
|
* @classdesc The main class of the PlotBoilerplate.
|
|
4013
4218
|
*
|
|
@@ -4246,6 +4451,12 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
4246
4451
|
image: {
|
|
4247
4452
|
color: "#a8a8a8",
|
|
4248
4453
|
lineWidth: 1
|
|
4454
|
+
},
|
|
4455
|
+
text: {
|
|
4456
|
+
color: "rgba(192,0,128,0.5)",
|
|
4457
|
+
lineWidth: 1,
|
|
4458
|
+
fill: true,
|
|
4459
|
+
anchor: true
|
|
4249
4460
|
}
|
|
4250
4461
|
}; // END drawConfig
|
|
4251
4462
|
// +---------------------------------------------------------------------------------
|
|
@@ -4367,7 +4578,7 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
4367
4578
|
var blob = new Blob([svgCode], { type: "image/svg;charset=utf-8" });
|
|
4368
4579
|
// See documentation for FileSaver.js for usage.
|
|
4369
4580
|
// https://github.com/eligrey/FileSaver.js
|
|
4370
|
-
if (typeof globalThis["saveAs"]
|
|
4581
|
+
if (typeof globalThis["saveAs"] !== "function")
|
|
4371
4582
|
throw "Cannot save file; did you load the ./utils/savefile helper function and the eligrey/SaveFile library?";
|
|
4372
4583
|
var _saveAs = globalThis["saveAs"];
|
|
4373
4584
|
_saveAs(blob, "plotboilerplate.svg");
|
|
@@ -4473,7 +4684,6 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
4473
4684
|
PlotBoilerplate.prototype.add = function (drawable, redraw) {
|
|
4474
4685
|
if (Array.isArray(drawable)) {
|
|
4475
4686
|
var arr = drawable;
|
|
4476
|
-
// for( var i in arr )
|
|
4477
4687
|
for (var i = 0; i < arr.length; i++) {
|
|
4478
4688
|
this.add(arr[i], false);
|
|
4479
4689
|
}
|
|
@@ -4519,9 +4729,9 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
4519
4729
|
}
|
|
4520
4730
|
else if (drawable instanceof Polygon_1.Polygon) {
|
|
4521
4731
|
this.drawables.push(drawable);
|
|
4522
|
-
|
|
4523
|
-
for (var i = 0; i < drawable.vertices.length; i++)
|
|
4732
|
+
for (var i = 0; i < drawable.vertices.length; i++) {
|
|
4524
4733
|
this.vertices.push(drawable.vertices[i]);
|
|
4734
|
+
}
|
|
4525
4735
|
}
|
|
4526
4736
|
else if (drawable instanceof Triangle_1.Triangle) {
|
|
4527
4737
|
this.drawables.push(drawable);
|
|
@@ -4533,8 +4743,9 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
4533
4743
|
this.drawables.push(drawable);
|
|
4534
4744
|
var bezierPath = drawable;
|
|
4535
4745
|
for (var i = 0; i < bezierPath.bezierCurves.length; i++) {
|
|
4536
|
-
if (!drawable.adjustCircular && i == 0)
|
|
4746
|
+
if (!drawable.adjustCircular && i == 0) {
|
|
4537
4747
|
this.vertices.push(bezierPath.bezierCurves[i].startPoint);
|
|
4748
|
+
}
|
|
4538
4749
|
this.vertices.push(bezierPath.bezierCurves[i].endPoint);
|
|
4539
4750
|
this.vertices.push(bezierPath.bezierCurves[i].startControlPoint);
|
|
4540
4751
|
this.vertices.push(bezierPath.bezierCurves[i].endControlPoint);
|
|
@@ -4553,6 +4764,11 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
4553
4764
|
});
|
|
4554
4765
|
drawable.lowerRight.attr.selectable = false;
|
|
4555
4766
|
}
|
|
4767
|
+
else if (drawable instanceof PBText_1.PBText) {
|
|
4768
|
+
this.vertices.push(drawable.anchor);
|
|
4769
|
+
this.drawables.push(drawable);
|
|
4770
|
+
drawable.anchor.attr.selectable = false;
|
|
4771
|
+
}
|
|
4556
4772
|
else {
|
|
4557
4773
|
throw "Cannot add drawable of unrecognized type: " + typeof drawable + ".";
|
|
4558
4774
|
}
|
|
@@ -4600,7 +4816,7 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
4600
4816
|
}
|
|
4601
4817
|
}
|
|
4602
4818
|
for (var i = 0; i < this.drawables.length; i++) {
|
|
4603
|
-
if (this.drawables[i] === drawable) {
|
|
4819
|
+
if (this.drawables[i] === drawable || this.drawables[i].uid === drawable.uid) {
|
|
4604
4820
|
this.drawables.splice(i, 1);
|
|
4605
4821
|
if (removeWithVertices) {
|
|
4606
4822
|
// Check if some listeners need to be removed
|
|
@@ -4651,6 +4867,9 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
4651
4867
|
this.removeVertex(drawable.upperLeft, false);
|
|
4652
4868
|
this.removeVertex(drawable.lowerRight, false);
|
|
4653
4869
|
}
|
|
4870
|
+
else if (drawable instanceof PBText_1.PBText) {
|
|
4871
|
+
this.removeVertex(drawable.anchor, false);
|
|
4872
|
+
}
|
|
4654
4873
|
} // END removeWithVertices
|
|
4655
4874
|
if (redraw) {
|
|
4656
4875
|
this.redraw();
|
|
@@ -4672,8 +4891,9 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
4672
4891
|
for (var i = 0; i < this.vertices.length; i++) {
|
|
4673
4892
|
if (this.vertices[i] === vert) {
|
|
4674
4893
|
this.vertices.splice(i, 1);
|
|
4675
|
-
if (redraw)
|
|
4894
|
+
if (redraw) {
|
|
4676
4895
|
this.redraw();
|
|
4896
|
+
}
|
|
4677
4897
|
return;
|
|
4678
4898
|
}
|
|
4679
4899
|
}
|
|
@@ -4708,8 +4928,9 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
4708
4928
|
**/
|
|
4709
4929
|
PlotBoilerplate.prototype.getVertexNear = function (pixelPosition, pixelTolerance) {
|
|
4710
4930
|
var p = this.locatePointNear(this.transformMousePosition(pixelPosition.x, pixelPosition.y), pixelTolerance / Math.min(this.config.cssScaleX, this.config.cssScaleY));
|
|
4711
|
-
if (p && p.typeName == "vertex")
|
|
4931
|
+
if (p && p.typeName == "vertex") {
|
|
4712
4932
|
return this.vertices[p.vindex];
|
|
4933
|
+
}
|
|
4713
4934
|
return undefined;
|
|
4714
4935
|
};
|
|
4715
4936
|
/**
|
|
@@ -4976,6 +5197,16 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
4976
5197
|
d.lowerRight.attr.renderTime = renderTime;
|
|
4977
5198
|
}
|
|
4978
5199
|
}
|
|
5200
|
+
else if (d instanceof PBText_1.PBText) {
|
|
5201
|
+
fill.setCurrentId(d.uid);
|
|
5202
|
+
fill.text(d.text, d.anchor.x, d.anchor.y, d);
|
|
5203
|
+
if (this.drawConfig.text.anchor) {
|
|
5204
|
+
draw.setCurrentId(d.uid + "_a0");
|
|
5205
|
+
draw.setCurrentClassName(d.className + "-anchor");
|
|
5206
|
+
(this.drawConfig.text.fill ? fill : draw).point(d.anchor, this.drawConfig.text.color);
|
|
5207
|
+
}
|
|
5208
|
+
d.anchor.attr.renderTime = renderTime;
|
|
5209
|
+
}
|
|
4979
5210
|
else {
|
|
4980
5211
|
console.error("Cannot draw object. Unknown class.");
|
|
4981
5212
|
}
|
|
@@ -5255,7 +5486,6 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
5255
5486
|
// Apply the zoom (the tolerant area should not shrink or grow when zooming)
|
|
5256
5487
|
tolerance /= _self.draw.scale.x;
|
|
5257
5488
|
// Search in vertices
|
|
5258
|
-
// for( var vindex in _self.vertices ) {
|
|
5259
5489
|
for (var vindex = 0; vindex < _self.vertices.length; vindex++) {
|
|
5260
5490
|
var vert = _self.vertices[vindex];
|
|
5261
5491
|
if ((vert.attr.draggable || vert.attr.selectable) && vert.distance(point) < tolerance) {
|
|
@@ -5275,10 +5505,7 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
5275
5505
|
* @return {void}
|
|
5276
5506
|
**/
|
|
5277
5507
|
PlotBoilerplate.prototype.handleClick = function (e) {
|
|
5278
|
-
// x:number,y:number) {
|
|
5279
5508
|
var _self = this;
|
|
5280
|
-
// const x:number = e.params.pos.x;
|
|
5281
|
-
//const y:number = e.params.pos.y;
|
|
5282
5509
|
var p = this.locatePointNear(_self.transformMousePosition(e.params.pos.x, e.params.pos.y), PlotBoilerplate.DEFAULT_CLICK_TOLERANCE / Math.min(_self.config.cssScaleX, _self.config.cssScaleY));
|
|
5283
5510
|
if (p) {
|
|
5284
5511
|
_self.vertices[p.vindex].listeners.fireClickEvent(e);
|
|
@@ -5295,7 +5522,7 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
5295
5522
|
}
|
|
5296
5523
|
_self.redraw();
|
|
5297
5524
|
}
|
|
5298
|
-
else if (this.keyHandler.isDown("y")
|
|
5525
|
+
else if (this.keyHandler.isDown("y")) {
|
|
5299
5526
|
_self.vertices[p.vindex].attr.bezierAutoAdjust = !_self.vertices[p.vindex].attr.bezierAutoAdjust;
|
|
5300
5527
|
_self.redraw();
|
|
5301
5528
|
}
|
|
@@ -5593,6 +5820,7 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
5593
5820
|
_self.draggedElements = [];
|
|
5594
5821
|
};
|
|
5595
5822
|
var afProps = {
|
|
5823
|
+
// touchStart: (evt: TouchEvent) => {
|
|
5596
5824
|
touchStart: function (evt) {
|
|
5597
5825
|
if (evt.touches.length == 1) {
|
|
5598
5826
|
touchMovePos = new Vertex_1.Vertex(relPos_1({ x: evt.touches[0].clientX, y: evt.touches[0].clientY }));
|
|
@@ -5695,10 +5923,13 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
5695
5923
|
_self.redraw();
|
|
5696
5924
|
}
|
|
5697
5925
|
}; // END afProps
|
|
5698
|
-
if (window["createAlloyFinger"])
|
|
5926
|
+
if (window["createAlloyFinger"]) {
|
|
5699
5927
|
window["createAlloyFinger"](this.eventCatcher ? this.eventCatcher : this.canvas, afProps);
|
|
5700
|
-
|
|
5928
|
+
}
|
|
5929
|
+
else {
|
|
5930
|
+
/* tslint:disable-next-line */
|
|
5701
5931
|
new alloyfinger_typescript_1.default(this.eventCatcher ? this.eventCatcher : this.canvas, afProps);
|
|
5932
|
+
}
|
|
5702
5933
|
}
|
|
5703
5934
|
catch (e) {
|
|
5704
5935
|
console.error("Failed to initialize AlloyFinger!");
|
|
@@ -5999,7 +6230,11 @@ __webpack_unused_export__ = PlotBoilerplate;
|
|
|
5999
6230
|
* @modified 2021-01-29 Added the `isClockwise` function.
|
|
6000
6231
|
* @modified 2021-01-29 Added the `area` function.
|
|
6001
6232
|
* @modified 2021-01-29 Changed the param type for `containsVert` from Vertex to XYCoords.
|
|
6002
|
-
* @
|
|
6233
|
+
* @modified 2021-12-14 Added the `perimeter()` function.
|
|
6234
|
+
* @modified 2021-12-16 Added the `getEvenDistributionPolygon()` function.
|
|
6235
|
+
* @modified 2022-02-02 Added the `destroy` method.
|
|
6236
|
+
* @modified 2022-02-02 Cleared the `Polygon.toSVGString` function (deprecated). Use `drawutilssvg` instead.
|
|
6237
|
+
* @version 1.9.0
|
|
6003
6238
|
*
|
|
6004
6239
|
* @file Polygon
|
|
6005
6240
|
* @public
|
|
@@ -6036,12 +6271,11 @@ var Polygon = /** @class */ (function () {
|
|
|
6036
6271
|
**/
|
|
6037
6272
|
this.className = "Polygon";
|
|
6038
6273
|
this.uid = UIDGenerator_1.UIDGenerator.next();
|
|
6039
|
-
if (typeof vertices ==
|
|
6274
|
+
if (typeof vertices == "undefined")
|
|
6040
6275
|
vertices = [];
|
|
6041
6276
|
this.vertices = vertices;
|
|
6042
6277
|
this.isOpen = isOpen;
|
|
6043
6278
|
}
|
|
6044
|
-
;
|
|
6045
6279
|
/**
|
|
6046
6280
|
* Add a vertex to the end of the `vertices` array.
|
|
6047
6281
|
*
|
|
@@ -6053,7 +6287,6 @@ var Polygon = /** @class */ (function () {
|
|
|
6053
6287
|
Polygon.prototype.addVertex = function (vert) {
|
|
6054
6288
|
this.vertices.push(vert);
|
|
6055
6289
|
};
|
|
6056
|
-
;
|
|
6057
6290
|
/**
|
|
6058
6291
|
* Get the polygon vertex at the given position (index).
|
|
6059
6292
|
*
|
|
@@ -6076,7 +6309,6 @@ var Polygon = /** @class */ (function () {
|
|
|
6076
6309
|
else
|
|
6077
6310
|
return this.vertices[index % this.vertices.length];
|
|
6078
6311
|
};
|
|
6079
|
-
;
|
|
6080
6312
|
/**
|
|
6081
6313
|
* Move the polygon's vertices by the given amount.
|
|
6082
6314
|
*
|
|
@@ -6092,7 +6324,6 @@ var Polygon = /** @class */ (function () {
|
|
|
6092
6324
|
}
|
|
6093
6325
|
return this;
|
|
6094
6326
|
};
|
|
6095
|
-
;
|
|
6096
6327
|
/**
|
|
6097
6328
|
* Check if the given vertex is inside this polygon.<br>
|
|
6098
6329
|
* <br>
|
|
@@ -6112,14 +6343,12 @@ var Polygon = /** @class */ (function () {
|
|
|
6112
6343
|
for (var i = 0, j = this.vertices.length - 1; i < this.vertices.length; j = i++) {
|
|
6113
6344
|
var xi = this.vertices[i].x, yi = this.vertices[i].y;
|
|
6114
6345
|
var xj = this.vertices[j].x, yj = this.vertices[j].y;
|
|
6115
|
-
var intersect =
|
|
6116
|
-
&& (vert.x < (xj - xi) * (vert.y - yi) / (yj - yi) + xi);
|
|
6346
|
+
var intersect = yi > vert.y != yj > vert.y && vert.x < ((xj - xi) * (vert.y - yi)) / (yj - yi) + xi;
|
|
6117
6347
|
if (intersect)
|
|
6118
6348
|
inside = !inside;
|
|
6119
6349
|
}
|
|
6120
6350
|
return inside;
|
|
6121
6351
|
};
|
|
6122
|
-
;
|
|
6123
6352
|
/**
|
|
6124
6353
|
* Calculate the area of the given polygon (unsigned).
|
|
6125
6354
|
*
|
|
@@ -6133,7 +6362,6 @@ var Polygon = /** @class */ (function () {
|
|
|
6133
6362
|
Polygon.prototype.area = function () {
|
|
6134
6363
|
return Polygon.utils.area(this.vertices);
|
|
6135
6364
|
};
|
|
6136
|
-
;
|
|
6137
6365
|
/**
|
|
6138
6366
|
* Calulate the signed polyon area by interpreting the polygon as a matrix
|
|
6139
6367
|
* and calculating its determinant.
|
|
@@ -6146,7 +6374,6 @@ var Polygon = /** @class */ (function () {
|
|
|
6146
6374
|
Polygon.prototype.signedArea = function () {
|
|
6147
6375
|
return Polygon.utils.signedArea(this.vertices);
|
|
6148
6376
|
};
|
|
6149
|
-
;
|
|
6150
6377
|
/**
|
|
6151
6378
|
* Get the winding order of this polgon: clockwise or counterclockwise.
|
|
6152
6379
|
*
|
|
@@ -6158,7 +6385,28 @@ var Polygon = /** @class */ (function () {
|
|
|
6158
6385
|
Polygon.prototype.isClockwise = function () {
|
|
6159
6386
|
return Polygon.utils.signedArea(this.vertices) < 0;
|
|
6160
6387
|
};
|
|
6161
|
-
|
|
6388
|
+
/**
|
|
6389
|
+
* Get the perimeter of this polygon.
|
|
6390
|
+
* The perimeter is the absolute length of the outline.
|
|
6391
|
+
*
|
|
6392
|
+
* If this polygon is open then the last segment (connecting the first and the
|
|
6393
|
+
* last vertex) will be skipped.
|
|
6394
|
+
*
|
|
6395
|
+
* @method perimeter
|
|
6396
|
+
* @instance
|
|
6397
|
+
* @memberof Polygon
|
|
6398
|
+
* @return {number}
|
|
6399
|
+
*/
|
|
6400
|
+
Polygon.prototype.perimeter = function () {
|
|
6401
|
+
var length = 0;
|
|
6402
|
+
for (var i = 1; i < this.vertices.length; i++) {
|
|
6403
|
+
length += this.vertices[i - 1].distance(this.vertices[i]);
|
|
6404
|
+
}
|
|
6405
|
+
if (!this.isOpen && this.vertices.length > 1) {
|
|
6406
|
+
length += this.vertices[0].distance(this.vertices[this.vertices.length - 1]);
|
|
6407
|
+
}
|
|
6408
|
+
return length;
|
|
6409
|
+
};
|
|
6162
6410
|
/**
|
|
6163
6411
|
* Scale the polygon relative to the given center.
|
|
6164
6412
|
*
|
|
@@ -6171,14 +6419,13 @@ var Polygon = /** @class */ (function () {
|
|
|
6171
6419
|
**/
|
|
6172
6420
|
Polygon.prototype.scale = function (factor, center) {
|
|
6173
6421
|
for (var i in this.vertices) {
|
|
6174
|
-
if (typeof this.vertices[i].scale ==
|
|
6422
|
+
if (typeof this.vertices[i].scale == "function")
|
|
6175
6423
|
this.vertices[i].scale(factor, center);
|
|
6176
6424
|
else
|
|
6177
|
-
console.log(
|
|
6425
|
+
console.log("There seems to be a null vertex!", this.vertices[i]);
|
|
6178
6426
|
}
|
|
6179
6427
|
return this;
|
|
6180
6428
|
};
|
|
6181
|
-
;
|
|
6182
6429
|
/**
|
|
6183
6430
|
* Rotate the polygon around the given center.
|
|
6184
6431
|
*
|
|
@@ -6195,7 +6442,52 @@ var Polygon = /** @class */ (function () {
|
|
|
6195
6442
|
}
|
|
6196
6443
|
return this;
|
|
6197
6444
|
};
|
|
6198
|
-
|
|
6445
|
+
/**
|
|
6446
|
+
* Convert this polygon into a new polygon with n evenly distributed vertices.
|
|
6447
|
+
*
|
|
6448
|
+
* @param {number} pointCount - Must not be negative.
|
|
6449
|
+
*/
|
|
6450
|
+
Polygon.prototype.getEvenDistributionPolygon = function (pointCount) {
|
|
6451
|
+
if (pointCount <= 0) {
|
|
6452
|
+
throw new Error("pointCount must be larger than zero; is " + pointCount + ".");
|
|
6453
|
+
}
|
|
6454
|
+
var result = new Polygon([], this.isOpen);
|
|
6455
|
+
if (this.vertices.length === 0) {
|
|
6456
|
+
return result;
|
|
6457
|
+
}
|
|
6458
|
+
// Fetch and add the start point from the source polygon
|
|
6459
|
+
var polygonPoint = new Vertex_1.Vertex(this.vertices[0]);
|
|
6460
|
+
result.vertices.push(polygonPoint);
|
|
6461
|
+
if (this.vertices.length === 1) {
|
|
6462
|
+
return result;
|
|
6463
|
+
}
|
|
6464
|
+
var perimeter = this.perimeter();
|
|
6465
|
+
var stepSize = perimeter / pointCount;
|
|
6466
|
+
var n = this.vertices.length;
|
|
6467
|
+
var polygonIndex = 1;
|
|
6468
|
+
var nextPolygonPoint = new Vertex_1.Vertex(this.vertices[1]);
|
|
6469
|
+
var segmentLength = polygonPoint.distance(nextPolygonPoint);
|
|
6470
|
+
var loopMax = this.isOpen ? n : n + 1;
|
|
6471
|
+
var curSegmentU = stepSize;
|
|
6472
|
+
var i = 1;
|
|
6473
|
+
while (i < pointCount && polygonIndex < loopMax) {
|
|
6474
|
+
// Check if next eq point is inside this segment
|
|
6475
|
+
if (curSegmentU < segmentLength) {
|
|
6476
|
+
var newPoint = polygonPoint.clone().lerpAbs(nextPolygonPoint, curSegmentU);
|
|
6477
|
+
result.vertices.push(newPoint);
|
|
6478
|
+
curSegmentU += stepSize;
|
|
6479
|
+
i++;
|
|
6480
|
+
}
|
|
6481
|
+
else {
|
|
6482
|
+
polygonIndex++;
|
|
6483
|
+
polygonPoint = nextPolygonPoint;
|
|
6484
|
+
nextPolygonPoint = new Vertex_1.Vertex(this.vertices[polygonIndex % n]);
|
|
6485
|
+
curSegmentU = curSegmentU - segmentLength;
|
|
6486
|
+
segmentLength = polygonPoint.distance(nextPolygonPoint);
|
|
6487
|
+
}
|
|
6488
|
+
}
|
|
6489
|
+
return result;
|
|
6490
|
+
};
|
|
6199
6491
|
/**
|
|
6200
6492
|
* Get the bounding box (bounds) of this polygon.
|
|
6201
6493
|
*
|
|
@@ -6207,7 +6499,6 @@ var Polygon = /** @class */ (function () {
|
|
|
6207
6499
|
Polygon.prototype.getBounds = function () {
|
|
6208
6500
|
return Bounds_1.Bounds.computeFromVertices(this.vertices);
|
|
6209
6501
|
};
|
|
6210
|
-
;
|
|
6211
6502
|
/**
|
|
6212
6503
|
* Convert this polygon to a sequence of quadratic Bézier curves.<br>
|
|
6213
6504
|
* <br>
|
|
@@ -6239,7 +6530,6 @@ var Polygon = /** @class */ (function () {
|
|
|
6239
6530
|
}
|
|
6240
6531
|
return qbezier;
|
|
6241
6532
|
};
|
|
6242
|
-
;
|
|
6243
6533
|
/**
|
|
6244
6534
|
* Convert this polygon to a quadratic bezier curve, represented as an SVG data string.
|
|
6245
6535
|
*
|
|
@@ -6252,13 +6542,12 @@ var Polygon = /** @class */ (function () {
|
|
|
6252
6542
|
var qdata = this.toQuadraticBezierData();
|
|
6253
6543
|
if (qdata.length == 0)
|
|
6254
6544
|
return "";
|
|
6255
|
-
var buffer = [
|
|
6545
|
+
var buffer = ["M " + qdata[0].x + " " + qdata[0].y];
|
|
6256
6546
|
for (var i = 1; i < qdata.length; i += 2) {
|
|
6257
|
-
buffer.push(
|
|
6547
|
+
buffer.push("Q " + qdata[i].x + " " + qdata[i].y + ", " + qdata[i + 1].x + " " + qdata[i + 1].y);
|
|
6258
6548
|
}
|
|
6259
|
-
return buffer.join(
|
|
6549
|
+
return buffer.join(" ");
|
|
6260
6550
|
};
|
|
6261
|
-
;
|
|
6262
6551
|
/**
|
|
6263
6552
|
* Convert this polygon to a sequence of cubic Bézier curves.<br>
|
|
6264
6553
|
* <br>
|
|
@@ -6275,7 +6564,7 @@ var Polygon = /** @class */ (function () {
|
|
|
6275
6564
|
* @memberof Polygon
|
|
6276
6565
|
**/
|
|
6277
6566
|
Polygon.prototype.toCubicBezierData = function (threshold) {
|
|
6278
|
-
if (typeof threshold ==
|
|
6567
|
+
if (typeof threshold == "undefined")
|
|
6279
6568
|
threshold = 1.0;
|
|
6280
6569
|
if (this.vertices.length < 3)
|
|
6281
6570
|
return [];
|
|
@@ -6299,7 +6588,6 @@ var Polygon = /** @class */ (function () {
|
|
|
6299
6588
|
}
|
|
6300
6589
|
return cbezier;
|
|
6301
6590
|
};
|
|
6302
|
-
;
|
|
6303
6591
|
/**
|
|
6304
6592
|
* Convert this polygon to a cubic bezier curve, represented as an SVG data string.
|
|
6305
6593
|
*
|
|
@@ -6312,13 +6600,23 @@ var Polygon = /** @class */ (function () {
|
|
|
6312
6600
|
var qdata = this.toCubicBezierData(threshold);
|
|
6313
6601
|
if (qdata.length == 0)
|
|
6314
6602
|
return "";
|
|
6315
|
-
var buffer = [
|
|
6603
|
+
var buffer = ["M " + qdata[0].x + " " + qdata[0].y];
|
|
6316
6604
|
for (var i = 1; i < qdata.length; i += 3) {
|
|
6317
|
-
buffer.push(
|
|
6318
|
-
|
|
6319
|
-
|
|
6605
|
+
buffer.push("C " +
|
|
6606
|
+
qdata[i].x +
|
|
6607
|
+
" " +
|
|
6608
|
+
qdata[i].y +
|
|
6609
|
+
", " +
|
|
6610
|
+
qdata[i + 1].x +
|
|
6611
|
+
" " +
|
|
6612
|
+
qdata[i + 1].y +
|
|
6613
|
+
", " +
|
|
6614
|
+
qdata[i + 2].x +
|
|
6615
|
+
" " +
|
|
6616
|
+
qdata[i + 2].y);
|
|
6617
|
+
}
|
|
6618
|
+
return buffer.join(" ");
|
|
6320
6619
|
};
|
|
6321
|
-
;
|
|
6322
6620
|
/**
|
|
6323
6621
|
* Convert this polygon to a cubic bezier path instance.
|
|
6324
6622
|
*
|
|
@@ -6337,7 +6635,6 @@ var Polygon = /** @class */ (function () {
|
|
|
6337
6635
|
}
|
|
6338
6636
|
return BezierPath_1.BezierPath.fromArray(pathdata);
|
|
6339
6637
|
};
|
|
6340
|
-
;
|
|
6341
6638
|
/**
|
|
6342
6639
|
* Create an SVG representation of this polygon.
|
|
6343
6640
|
*
|
|
@@ -6349,31 +6646,42 @@ var Polygon = /** @class */ (function () {
|
|
|
6349
6646
|
* @memberof Polygon
|
|
6350
6647
|
**/
|
|
6351
6648
|
Polygon.prototype.toSVGString = function (options) {
|
|
6352
|
-
options = options || {};
|
|
6353
|
-
var buffer = [];
|
|
6354
|
-
buffer.push(
|
|
6355
|
-
if (options.className)
|
|
6356
|
-
|
|
6357
|
-
|
|
6358
|
-
|
|
6359
|
-
|
|
6360
|
-
|
|
6361
|
-
|
|
6362
|
-
|
|
6363
|
-
|
|
6364
|
-
|
|
6365
|
-
|
|
6366
|
-
|
|
6367
|
-
|
|
6368
|
-
|
|
6369
|
-
|
|
6370
|
-
|
|
6371
|
-
|
|
6649
|
+
// options = options || {};
|
|
6650
|
+
// var buffer: Array<string> = [];
|
|
6651
|
+
// buffer.push("<path");
|
|
6652
|
+
// if (options.className) buffer.push(' class="' + options.className + '"');
|
|
6653
|
+
// buffer.push(' d="');
|
|
6654
|
+
// if (this.vertices.length > 0) {
|
|
6655
|
+
// buffer.push("M ");
|
|
6656
|
+
// buffer.push(this.vertices[0].x.toString());
|
|
6657
|
+
// buffer.push(" ");
|
|
6658
|
+
// buffer.push(this.vertices[0].y.toString());
|
|
6659
|
+
// for (var i = 1; i < this.vertices.length; i++) {
|
|
6660
|
+
// buffer.push(" L ");
|
|
6661
|
+
// buffer.push(this.vertices[i].x.toString());
|
|
6662
|
+
// buffer.push(" ");
|
|
6663
|
+
// buffer.push(this.vertices[i].y.toString());
|
|
6664
|
+
// }
|
|
6665
|
+
// if (!this.isOpen) {
|
|
6666
|
+
// buffer.push(" Z");
|
|
6667
|
+
// }
|
|
6668
|
+
// }
|
|
6669
|
+
// buffer.push('" />');
|
|
6670
|
+
// return buffer.join("");
|
|
6671
|
+
console.warn("[Deprecation] Warning: the Polygon.toSVGString method is deprecated and does not return and valid SVG data any more. Please use `drawutilssvg` instead.");
|
|
6672
|
+
return "";
|
|
6673
|
+
};
|
|
6674
|
+
/**
|
|
6675
|
+
* This function should invalidate any installed listeners and invalidate this object.
|
|
6676
|
+
* After calling this function the object might not hold valid data any more and
|
|
6677
|
+
* should not be used.
|
|
6678
|
+
*/
|
|
6679
|
+
Polygon.prototype.destroy = function () {
|
|
6680
|
+
for (var i = 0; i < this.vertices.length; i++) {
|
|
6681
|
+
this.vertices[i].destroy();
|
|
6372
6682
|
}
|
|
6373
|
-
|
|
6374
|
-
return buffer.join('');
|
|
6683
|
+
this.isDestroyed = true;
|
|
6375
6684
|
};
|
|
6376
|
-
;
|
|
6377
6685
|
Polygon.utils = {
|
|
6378
6686
|
/**
|
|
6379
6687
|
* Calculate the area of the given polygon (unsigned).
|
|
@@ -6392,8 +6700,8 @@ var Polygon = /** @class */ (function () {
|
|
|
6392
6700
|
var addY = vertices[(i + 1) % l].y;
|
|
6393
6701
|
var subX = vertices[(i + 1) % l].x;
|
|
6394
6702
|
var subY = vertices[i].y;
|
|
6395
|
-
total +=
|
|
6396
|
-
total -=
|
|
6703
|
+
total += addX * addY * 0.5;
|
|
6704
|
+
total -= subX * subY * 0.5;
|
|
6397
6705
|
}
|
|
6398
6706
|
return Math.abs(total);
|
|
6399
6707
|
},
|
|
@@ -6446,7 +6754,9 @@ exports.Polygon = Polygon;
|
|
|
6446
6754
|
* @modified 2020-12-28 Added the `getArea` function.
|
|
6447
6755
|
* @modified 2021-01-20 Added UID.
|
|
6448
6756
|
* @modified 2021-01-22 Always updating circumcircle when retieving it.
|
|
6449
|
-
* @
|
|
6757
|
+
* @modified 2022-02-02 Added the `destroy` method.
|
|
6758
|
+
* @modified 2022-02-02 Cleared the `Triangle.toSVGString` function (deprecated). Use `drawutilssvg` instead.
|
|
6759
|
+
* @version 2.6.0
|
|
6450
6760
|
*
|
|
6451
6761
|
* @file Triangle
|
|
6452
6762
|
* @fileoverview A simple triangle class: three vertices.
|
|
@@ -6516,7 +6826,6 @@ var Triangle = /** @class */ (function () {
|
|
|
6516
6826
|
throw "Cannot create triangle from array with less than three vertices (" + arr.length + ")";
|
|
6517
6827
|
return new Triangle(arr[0], arr[1], arr[2]);
|
|
6518
6828
|
};
|
|
6519
|
-
;
|
|
6520
6829
|
/**
|
|
6521
6830
|
* Get the area of this triangle. The returned area is never negative.
|
|
6522
6831
|
*
|
|
@@ -6532,7 +6841,6 @@ var Triangle = /** @class */ (function () {
|
|
|
6532
6841
|
Triangle.prototype.getArea = function () {
|
|
6533
6842
|
return Math.abs(Triangle.utils.signedArea(this.a.x, this.a.y, this.b.x, this.b.y, this.c.x, this.c.y));
|
|
6534
6843
|
};
|
|
6535
|
-
;
|
|
6536
6844
|
/**
|
|
6537
6845
|
* Get the centroid of this triangle.
|
|
6538
6846
|
*
|
|
@@ -6546,7 +6854,6 @@ var Triangle = /** @class */ (function () {
|
|
|
6546
6854
|
Triangle.prototype.getCentroid = function () {
|
|
6547
6855
|
return new Vertex_1.Vertex((this.a.x + this.b.x + this.c.x) / 3, (this.a.y + this.b.y + this.c.y) / 3);
|
|
6548
6856
|
};
|
|
6549
|
-
;
|
|
6550
6857
|
/**
|
|
6551
6858
|
* Scale the triangle towards its centroid.
|
|
6552
6859
|
*
|
|
@@ -6563,7 +6870,6 @@ var Triangle = /** @class */ (function () {
|
|
|
6563
6870
|
this.c.scale(factor, centroid);
|
|
6564
6871
|
return this;
|
|
6565
6872
|
};
|
|
6566
|
-
;
|
|
6567
6873
|
/**
|
|
6568
6874
|
* Get the circumcircle of this triangle.
|
|
6569
6875
|
*
|
|
@@ -6580,11 +6886,10 @@ var Triangle = /** @class */ (function () {
|
|
|
6580
6886
|
* @memberof Triangle
|
|
6581
6887
|
*/
|
|
6582
6888
|
Triangle.prototype.getCircumcircle = function () {
|
|
6583
|
-
// if( !this.center || !this.radius )
|
|
6889
|
+
// if( !this.center || !this.radius )
|
|
6584
6890
|
this.calcCircumcircle();
|
|
6585
6891
|
return new Circle_1.Circle(this.center.clone(), this.radius);
|
|
6586
6892
|
};
|
|
6587
|
-
;
|
|
6588
6893
|
/**
|
|
6589
6894
|
* Check if this triangle and the passed triangle share an
|
|
6590
6895
|
* adjacent edge.
|
|
@@ -6604,7 +6909,6 @@ var Triangle = /** @class */ (function () {
|
|
|
6604
6909
|
var c = this.c.equals(tri.a) || this.c.equals(tri.b) || this.c.equals(tri.c);
|
|
6605
6910
|
return (a && b) || (a && c) || (b && c);
|
|
6606
6911
|
};
|
|
6607
|
-
;
|
|
6608
6912
|
/**
|
|
6609
6913
|
* Get that vertex of this triangle (a,b,c) that is not vert1 nor vert2 of
|
|
6610
6914
|
* the passed two.
|
|
@@ -6617,14 +6921,13 @@ var Triangle = /** @class */ (function () {
|
|
|
6617
6921
|
* @memberof Triangle
|
|
6618
6922
|
*/
|
|
6619
6923
|
Triangle.prototype.getThirdVertex = function (vert1, vert2) {
|
|
6620
|
-
if (this.a.equals(vert1) && this.b.equals(vert2) || this.a.equals(vert2) && this.b.equals(vert1))
|
|
6924
|
+
if ((this.a.equals(vert1) && this.b.equals(vert2)) || (this.a.equals(vert2) && this.b.equals(vert1)))
|
|
6621
6925
|
return this.c;
|
|
6622
|
-
if (this.b.equals(vert1) && this.c.equals(vert2) || this.b.equals(vert2) && this.c.equals(vert1))
|
|
6926
|
+
if ((this.b.equals(vert1) && this.c.equals(vert2)) || (this.b.equals(vert2) && this.c.equals(vert1)))
|
|
6623
6927
|
return this.a;
|
|
6624
6928
|
//if( this.c.equals(vert1) && this.a.equals(vert2) || this.c.equals(vert2) && this.a.equals(vert1) )
|
|
6625
6929
|
return this.b;
|
|
6626
6930
|
};
|
|
6627
|
-
;
|
|
6628
6931
|
/**
|
|
6629
6932
|
* Re-compute the circumcircle of this triangle (if the vertices
|
|
6630
6933
|
* have changed).
|
|
@@ -6664,8 +6967,7 @@ var Triangle = /** @class */ (function () {
|
|
|
6664
6967
|
}
|
|
6665
6968
|
this.radius_squared = dx * dx + dy * dy;
|
|
6666
6969
|
this.radius = Math.sqrt(this.radius_squared);
|
|
6667
|
-
};
|
|
6668
|
-
; // END calcCircumcircle
|
|
6970
|
+
}; // END calcCircumcircle
|
|
6669
6971
|
/**
|
|
6670
6972
|
* Check if the passed vertex is inside this triangle's
|
|
6671
6973
|
* circumcircle.
|
|
@@ -6680,9 +6982,8 @@ var Triangle = /** @class */ (function () {
|
|
|
6680
6982
|
var dx = this.center.x - v.x;
|
|
6681
6983
|
var dy = this.center.y - v.y;
|
|
6682
6984
|
var dist_squared = dx * dx + dy * dy;
|
|
6683
|
-
return
|
|
6985
|
+
return dist_squared <= this.radius_squared;
|
|
6684
6986
|
};
|
|
6685
|
-
;
|
|
6686
6987
|
/**
|
|
6687
6988
|
* Get the rectangular bounds for this triangle.
|
|
6688
6989
|
*
|
|
@@ -6694,7 +6995,6 @@ var Triangle = /** @class */ (function () {
|
|
|
6694
6995
|
Triangle.prototype.bounds = function () {
|
|
6695
6996
|
return new Bounds_1.Bounds(new Vertex_1.Vertex(Triangle.utils.min3(this.a.x, this.b.x, this.c.x), Triangle.utils.min3(this.a.y, this.b.y, this.c.y)), new Vertex_1.Vertex(Triangle.utils.max3(this.a.x, this.b.x, this.c.x), Triangle.utils.max3(this.a.y, this.b.y, this.c.y)));
|
|
6696
6997
|
};
|
|
6697
|
-
;
|
|
6698
6998
|
/**
|
|
6699
6999
|
* Convert this triangle to a polygon instance.
|
|
6700
7000
|
*
|
|
@@ -6708,7 +7008,6 @@ var Triangle = /** @class */ (function () {
|
|
|
6708
7008
|
Triangle.prototype.toPolygon = function () {
|
|
6709
7009
|
return new Polygon_1.Polygon([this.a, this.b, this.c]);
|
|
6710
7010
|
};
|
|
6711
|
-
;
|
|
6712
7011
|
/**
|
|
6713
7012
|
* Get the determinant of this triangle.
|
|
6714
7013
|
*
|
|
@@ -6721,7 +7020,6 @@ var Triangle = /** @class */ (function () {
|
|
|
6721
7020
|
// (b.y - a.y)*(c.x - b.x) - (c.y - b.y)*(b.x - a.x);
|
|
6722
7021
|
return (this.b.y - this.a.y) * (this.c.x - this.b.x) - (this.c.y - this.b.y) * (this.b.x - this.a.x);
|
|
6723
7022
|
};
|
|
6724
|
-
;
|
|
6725
7023
|
/**
|
|
6726
7024
|
* Checks if the passed vertex (p) is inside this triangle.
|
|
6727
7025
|
*
|
|
@@ -6736,7 +7034,6 @@ var Triangle = /** @class */ (function () {
|
|
|
6736
7034
|
Triangle.prototype.containsPoint = function (p) {
|
|
6737
7035
|
return Triangle.utils.pointIsInTriangle(p.x, p.y, this.a.x, this.a.y, this.b.x, this.b.y, this.c.x, this.c.y);
|
|
6738
7036
|
};
|
|
6739
|
-
;
|
|
6740
7037
|
/**
|
|
6741
7038
|
* Get that inner triangle which defines the maximal incircle.
|
|
6742
7039
|
*
|
|
@@ -6755,7 +7052,6 @@ var Triangle = /** @class */ (function () {
|
|
|
6755
7052
|
var circleIntersC = lineC.getClosestPoint(intersection);
|
|
6756
7053
|
return new Triangle(circleIntersA, circleIntersB, circleIntersC);
|
|
6757
7054
|
};
|
|
6758
|
-
;
|
|
6759
7055
|
/**
|
|
6760
7056
|
* Get the incircle of this triangle. That is the circle that touches each side
|
|
6761
7057
|
* of this triangle in exactly one point.
|
|
@@ -6767,7 +7063,6 @@ var Triangle = /** @class */ (function () {
|
|
|
6767
7063
|
Triangle.prototype.getIncircle = function () {
|
|
6768
7064
|
return this.getIncircularTriangle().getCircumcircle();
|
|
6769
7065
|
};
|
|
6770
|
-
;
|
|
6771
7066
|
/**
|
|
6772
7067
|
* Get the incenter of this triangle (which is the center of the circumcircle).
|
|
6773
7068
|
*
|
|
@@ -6781,7 +7076,6 @@ var Triangle = /** @class */ (function () {
|
|
|
6781
7076
|
this.calcCircumcircle();
|
|
6782
7077
|
return this.center.clone();
|
|
6783
7078
|
};
|
|
6784
|
-
;
|
|
6785
7079
|
/**
|
|
6786
7080
|
* Converts this triangle into a human-readable string.
|
|
6787
7081
|
*
|
|
@@ -6791,9 +7085,8 @@ var Triangle = /** @class */ (function () {
|
|
|
6791
7085
|
* @memberof Triangle
|
|
6792
7086
|
*/
|
|
6793
7087
|
Triangle.prototype.toString = function () {
|
|
6794
|
-
return
|
|
7088
|
+
return "{ a : " + this.a.toString() + ", b : " + this.b.toString() + ", c : " + this.c.toString() + "}";
|
|
6795
7089
|
};
|
|
6796
|
-
;
|
|
6797
7090
|
/**
|
|
6798
7091
|
* Create an SVG representation of this triangle.
|
|
6799
7092
|
*
|
|
@@ -6805,32 +7098,43 @@ var Triangle = /** @class */ (function () {
|
|
|
6805
7098
|
* @memberof Triangle
|
|
6806
7099
|
**/
|
|
6807
7100
|
Triangle.prototype.toSVGString = function (options) {
|
|
6808
|
-
options = options || {};
|
|
6809
|
-
var buffer = [];
|
|
6810
|
-
buffer.push(
|
|
6811
|
-
if (options.className)
|
|
6812
|
-
|
|
6813
|
-
|
|
6814
|
-
|
|
6815
|
-
|
|
6816
|
-
|
|
6817
|
-
|
|
6818
|
-
|
|
6819
|
-
|
|
6820
|
-
|
|
6821
|
-
|
|
6822
|
-
|
|
6823
|
-
|
|
6824
|
-
|
|
6825
|
-
|
|
6826
|
-
|
|
6827
|
-
|
|
6828
|
-
|
|
6829
|
-
|
|
6830
|
-
buffer.
|
|
6831
|
-
return
|
|
7101
|
+
// options = options || {};
|
|
7102
|
+
// var buffer = [];
|
|
7103
|
+
// buffer.push("<path");
|
|
7104
|
+
// if (options.className) buffer.push(' class="' + options.className + '"');
|
|
7105
|
+
// buffer.push(' d="');
|
|
7106
|
+
// var vertices = [this.a, this.b, this.c];
|
|
7107
|
+
// if (vertices.length > 0) {
|
|
7108
|
+
// buffer.push("M ");
|
|
7109
|
+
// buffer.push(vertices[0].x);
|
|
7110
|
+
// buffer.push(" ");
|
|
7111
|
+
// buffer.push(vertices[0].y);
|
|
7112
|
+
// for (var i = 1; i < vertices.length; i++) {
|
|
7113
|
+
// buffer.push(" L ");
|
|
7114
|
+
// buffer.push(vertices[i].x);
|
|
7115
|
+
// buffer.push(" ");
|
|
7116
|
+
// buffer.push(vertices[i].y);
|
|
7117
|
+
// }
|
|
7118
|
+
// //if( !this.isOpen ) {
|
|
7119
|
+
// buffer.push(" Z");
|
|
7120
|
+
// //}
|
|
7121
|
+
// }
|
|
7122
|
+
// buffer.push('" />');
|
|
7123
|
+
// return buffer.join("");
|
|
7124
|
+
console.warn("[Deprecation] Warning: the Triangle.toSVGString method is deprecated and does not return and valid SVG data any more. Please use `drawutilssvg` instead.");
|
|
7125
|
+
return "";
|
|
7126
|
+
};
|
|
7127
|
+
/**
|
|
7128
|
+
* This function should invalidate any installed listeners and invalidate this object.
|
|
7129
|
+
* After calling this function the object might not hold valid data any more and
|
|
7130
|
+
* should not be used.
|
|
7131
|
+
*/
|
|
7132
|
+
Triangle.prototype.destroy = function () {
|
|
7133
|
+
this.a.destroy();
|
|
7134
|
+
this.b.destroy();
|
|
7135
|
+
this.c.destroy();
|
|
7136
|
+
this.isDestroyed = true;
|
|
6832
7137
|
};
|
|
6833
|
-
;
|
|
6834
7138
|
/**
|
|
6835
7139
|
* An epsilon for comparison.
|
|
6836
7140
|
* This should be the same epsilon as in Vertex.
|
|
@@ -6841,10 +7145,10 @@ var Triangle = /** @class */ (function () {
|
|
|
6841
7145
|
Triangle.utils = {
|
|
6842
7146
|
// Used in the bounds() function.
|
|
6843
7147
|
max3: function (a, b, c) {
|
|
6844
|
-
return
|
|
7148
|
+
return a >= b && a >= c ? a : b >= a && b >= c ? b : c;
|
|
6845
7149
|
},
|
|
6846
7150
|
min3: function (a, b, c) {
|
|
6847
|
-
return
|
|
7151
|
+
return a <= b && a <= c ? a : b <= a && b <= c ? b : c;
|
|
6848
7152
|
},
|
|
6849
7153
|
signedArea: function (p0x, p0y, p1x, p1y, p2x, p2y) {
|
|
6850
7154
|
return 0.5 * (-p1y * p2x + p0y * (-p1x + p2x) + p0x * (p1y - p2y) + p1x * p2y);
|
|
@@ -6860,9 +7164,9 @@ var Triangle = /** @class */ (function () {
|
|
|
6860
7164
|
// http://stackoverflow.com/questions/2049582/how-to-determine-a-point-in-a-2d-triangle
|
|
6861
7165
|
// var area : number = 1/2*(-p1y*p2x + p0y*(-p1x + p2x) + p0x*(p1y - p2y) + p1x*p2y);
|
|
6862
7166
|
var area = Triangle.utils.signedArea(p0x, p0y, p1x, p1y, p2x, p2y);
|
|
6863
|
-
var s = 1 / (2 * area) * (p0y * p2x - p0x * p2y + (p2y - p0y) * px + (p0x - p2x) * py);
|
|
6864
|
-
var t = 1 / (2 * area) * (p0x * p1y - p0y * p1x + (p0y - p1y) * px + (p1x - p0x) * py);
|
|
6865
|
-
return s > 0 && t > 0 &&
|
|
7167
|
+
var s = (1 / (2 * area)) * (p0y * p2x - p0x * p2y + (p2y - p0y) * px + (p0x - p2x) * py);
|
|
7168
|
+
var t = (1 / (2 * area)) * (p0x * p1y - p0y * p1x + (p0y - p1y) * px + (p1x - p0x) * py);
|
|
7169
|
+
return s > 0 && t > 0 && 1 - s - t > 0;
|
|
6866
7170
|
}
|
|
6867
7171
|
};
|
|
6868
7172
|
return Triangle;
|
|
@@ -6918,7 +7222,9 @@ exports.UIDGenerator = UIDGenerator;
|
|
|
6918
7222
|
* @modified 2021-03-10 Added the `toCubicBezier` method.
|
|
6919
7223
|
* @modified 2021-03-15 Added `VEllipse.quarterSegmentCount` and `VEllipse.scale` functions.
|
|
6920
7224
|
* @modified 2021-03-19 Added the `VEllipse.rotate` function.
|
|
6921
|
-
* @
|
|
7225
|
+
* @modified 2022-02-02 Added the `destroy` method.
|
|
7226
|
+
* @modified 2022-02-02 Cleared the `VEllipse.toSVGString` function (deprecated). Use `drawutilssvg` instead.
|
|
7227
|
+
* @version 1.3.0
|
|
6922
7228
|
*
|
|
6923
7229
|
* @file VEllipse
|
|
6924
7230
|
* @fileoverview Ellipses with a center and an x- and a y-axis (stored as a vertex).
|
|
@@ -7251,17 +7557,28 @@ var VEllipse = /** @class */ (function () {
|
|
|
7251
7557
|
* @return string The SVG string
|
|
7252
7558
|
*/
|
|
7253
7559
|
VEllipse.prototype.toSVGString = function (options) {
|
|
7254
|
-
options = options || {};
|
|
7255
|
-
var buffer = [];
|
|
7256
|
-
buffer.push("<ellipse");
|
|
7257
|
-
if (options.className)
|
|
7258
|
-
|
|
7259
|
-
buffer.push('
|
|
7260
|
-
buffer.push('
|
|
7261
|
-
buffer.push('
|
|
7262
|
-
buffer.push(
|
|
7263
|
-
buffer.
|
|
7264
|
-
return
|
|
7560
|
+
// options = options || {};
|
|
7561
|
+
// var buffer: Array<string> = [];
|
|
7562
|
+
// buffer.push("<ellipse");
|
|
7563
|
+
// if (options.className) buffer.push(' class="' + options.className + '"');
|
|
7564
|
+
// buffer.push(' cx="' + this.center.x + '"');
|
|
7565
|
+
// buffer.push(' cy="' + this.center.y + '"');
|
|
7566
|
+
// buffer.push(' rx="' + this.axis.x + '"');
|
|
7567
|
+
// buffer.push(' ry="' + this.axis.y + '"');
|
|
7568
|
+
// buffer.push(" />");
|
|
7569
|
+
// return buffer.join("");
|
|
7570
|
+
console.warn("[Deprecation] Warning: the VEllipse.toSVGString method is deprecated and does not return and valid SVG data any more. Please use `drawutilssvg` instead.");
|
|
7571
|
+
return "";
|
|
7572
|
+
};
|
|
7573
|
+
/**
|
|
7574
|
+
* This function should invalidate any installed listeners and invalidate this object.
|
|
7575
|
+
* After calling this function the object might not hold valid data any more and
|
|
7576
|
+
* should not be used.
|
|
7577
|
+
*/
|
|
7578
|
+
VEllipse.prototype.destroy = function () {
|
|
7579
|
+
this.center.destroy();
|
|
7580
|
+
this.axis.destroy();
|
|
7581
|
+
this.isDestroyed = true;
|
|
7265
7582
|
};
|
|
7266
7583
|
/**
|
|
7267
7584
|
* A static collection of ellipse-related helper functions.
|
|
@@ -7337,7 +7654,8 @@ exports.VEllipse = VEllipse;
|
|
|
7337
7654
|
*
|
|
7338
7655
|
* @author Ikaros Kappler
|
|
7339
7656
|
* @date 2021-02-26
|
|
7340
|
-
* @
|
|
7657
|
+
* @modified 2022-02-02 Added the `destroy` method.
|
|
7658
|
+
* @version 1.1.0
|
|
7341
7659
|
*/
|
|
7342
7660
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
7343
7661
|
exports.VEllipseSector = void 0;
|
|
@@ -7431,6 +7749,15 @@ var VEllipseSector = /** @class */ (function () {
|
|
|
7431
7749
|
}
|
|
7432
7750
|
return curves;
|
|
7433
7751
|
};
|
|
7752
|
+
/**
|
|
7753
|
+
* This function should invalidate any installed listeners and invalidate this object.
|
|
7754
|
+
* After calling this function the object might not hold valid data any more and
|
|
7755
|
+
* should not be used.
|
|
7756
|
+
*/
|
|
7757
|
+
VEllipseSector.prototype.destroy = function () {
|
|
7758
|
+
this.ellipse.destroy();
|
|
7759
|
+
this.isDestroyed = true;
|
|
7760
|
+
};
|
|
7434
7761
|
VEllipseSector.ellipseSectorUtils = {
|
|
7435
7762
|
/**
|
|
7436
7763
|
* Helper function to convert an elliptic section to SVG arc params (for the `d` attribute).
|
|
@@ -7615,7 +7942,9 @@ exports.VEllipseSector = VEllipseSector;
|
|
|
7615
7942
|
* @modified 2019-12-04 Added the Vector.inv() function.
|
|
7616
7943
|
* @modified 2020-03-23 Ported to Typescript from JS.
|
|
7617
7944
|
* @modified 2021-01-20 Added UID.
|
|
7618
|
-
* @
|
|
7945
|
+
* @modified 2022-02-02 Added the `destroy` method.
|
|
7946
|
+
* @modified 2022-02-02 Cleared the `Vector.toSVGString` function (deprecated). Use `drawutilssvg` instead.
|
|
7947
|
+
* @version 1.4.0
|
|
7619
7948
|
*
|
|
7620
7949
|
* @file Vector
|
|
7621
7950
|
* @public
|
|
@@ -7665,7 +7994,6 @@ var Vector = /** @class */ (function (_super) {
|
|
|
7665
7994
|
_this.className = "Vector";
|
|
7666
7995
|
return _this;
|
|
7667
7996
|
}
|
|
7668
|
-
;
|
|
7669
7997
|
/**
|
|
7670
7998
|
* Get the perpendicular of this vector which is located at a.
|
|
7671
7999
|
*
|
|
@@ -7680,7 +8008,6 @@ var Vector = /** @class */ (function (_super) {
|
|
|
7680
8008
|
v.b.add(this.a);
|
|
7681
8009
|
return v;
|
|
7682
8010
|
};
|
|
7683
|
-
;
|
|
7684
8011
|
/**
|
|
7685
8012
|
* The inverse of a vector is a vector witht the same magnitude but oppose direction.
|
|
7686
8013
|
*
|
|
@@ -7694,7 +8021,6 @@ var Vector = /** @class */ (function (_super) {
|
|
|
7694
8021
|
this.b = tmp;
|
|
7695
8022
|
return this;
|
|
7696
8023
|
};
|
|
7697
|
-
;
|
|
7698
8024
|
/**
|
|
7699
8025
|
* This function computes the inverse of the vector, which means 'a' stays untouched.
|
|
7700
8026
|
*
|
|
@@ -7705,7 +8031,6 @@ var Vector = /** @class */ (function (_super) {
|
|
|
7705
8031
|
this.b.y = this.a.y - (this.b.y - this.a.y);
|
|
7706
8032
|
return this;
|
|
7707
8033
|
};
|
|
7708
|
-
;
|
|
7709
8034
|
/**
|
|
7710
8035
|
* Get the intersection if this vector and the specified vector.
|
|
7711
8036
|
*
|
|
@@ -7721,16 +8046,15 @@ var Vector = /** @class */ (function (_super) {
|
|
|
7721
8046
|
return null;
|
|
7722
8047
|
var a = this.a.y - line.a.y;
|
|
7723
8048
|
var b = this.a.x - line.a.x;
|
|
7724
|
-
var numerator1 = (
|
|
7725
|
-
var numerator2 = (
|
|
8049
|
+
var numerator1 = (line.b.x - line.a.x) * a - (line.b.y - line.a.y) * b;
|
|
8050
|
+
var numerator2 = (this.b.x - this.a.x) * a - (this.b.y - this.a.y) * b;
|
|
7726
8051
|
a = numerator1 / denominator; // NaN if parallel lines
|
|
7727
8052
|
b = numerator2 / denominator;
|
|
7728
8053
|
// TODO:
|
|
7729
8054
|
// FOR A VECTOR THE LINE-INTERSECTION MUST BE ON BOTH VECTORS
|
|
7730
8055
|
// if we cast these lines infinitely in both directions, they intersect here:
|
|
7731
|
-
return new Vertex_1.Vertex(this.a.x +
|
|
8056
|
+
return new Vertex_1.Vertex(this.a.x + a * (this.b.x - this.a.x), this.a.y + a * (this.b.y - this.a.y));
|
|
7732
8057
|
};
|
|
7733
|
-
;
|
|
7734
8058
|
/**
|
|
7735
8059
|
* Create an SVG representation of this line.
|
|
7736
8060
|
*
|
|
@@ -7743,31 +8067,30 @@ var Vector = /** @class */ (function (_super) {
|
|
|
7743
8067
|
* @memberof Vector
|
|
7744
8068
|
**/
|
|
7745
8069
|
Vector.prototype.toSVGString = function (options) {
|
|
7746
|
-
options = options || {};
|
|
7747
|
-
var buffer = [];
|
|
7748
|
-
var vertices = Vector.utils.buildArrowHead(this.a, this.b, 8, 1.0, 1.0);
|
|
7749
|
-
buffer.push(
|
|
7750
|
-
if (options.className)
|
|
7751
|
-
|
|
7752
|
-
buffer.push(
|
|
7753
|
-
buffer.push('
|
|
7754
|
-
buffer.push('
|
|
7755
|
-
buffer.push('
|
|
7756
|
-
buffer.push('
|
|
7757
|
-
buffer.push(
|
|
7758
|
-
|
|
7759
|
-
//
|
|
7760
|
-
|
|
7761
|
-
|
|
7762
|
-
|
|
7763
|
-
|
|
7764
|
-
|
|
7765
|
-
|
|
7766
|
-
buffer.
|
|
7767
|
-
|
|
7768
|
-
return
|
|
8070
|
+
// options = options || {};
|
|
8071
|
+
// var buffer = [];
|
|
8072
|
+
// var vertices = Vector.utils.buildArrowHead(this.a, this.b, 8, 1.0, 1.0);
|
|
8073
|
+
// buffer.push("<g");
|
|
8074
|
+
// if (options.className) buffer.push(' class="' + options.className + '"');
|
|
8075
|
+
// buffer.push(">");
|
|
8076
|
+
// buffer.push(" <line");
|
|
8077
|
+
// buffer.push(' x1="' + this.a.x + '"');
|
|
8078
|
+
// buffer.push(' y1="' + this.a.y + '"');
|
|
8079
|
+
// buffer.push(' x2="' + vertices[0].x + '"');
|
|
8080
|
+
// buffer.push(' y2="' + vertices[0].y + '"');
|
|
8081
|
+
// buffer.push(" />");
|
|
8082
|
+
// // Add arrow head
|
|
8083
|
+
// buffer.push(' <polygon points="');
|
|
8084
|
+
// for (var i = 0; i < vertices.length; i++) {
|
|
8085
|
+
// if (i > 0) buffer.push(" ");
|
|
8086
|
+
// buffer.push("" + vertices[i].x + "," + vertices[i].y);
|
|
8087
|
+
// }
|
|
8088
|
+
// buffer.push('"/>');
|
|
8089
|
+
// buffer.push("</g>");
|
|
8090
|
+
// return buffer.join("");
|
|
8091
|
+
console.warn("[Deprecation] Warning: the Vector.toSVGString method is deprecated and does not return and valid SVG data any more. Please use `drawutilssvg` instead.");
|
|
8092
|
+
return "";
|
|
7769
8093
|
};
|
|
7770
|
-
;
|
|
7771
8094
|
Vector.utils = {
|
|
7772
8095
|
/**
|
|
7773
8096
|
* Generate a four-point arrow head, starting at the vector end minus the
|
|
@@ -7797,10 +8120,10 @@ var Vector = /** @class */ (function (_super) {
|
|
|
7797
8120
|
buildArrowHead: function (zA, zB, headlen, scaleX, scaleY) {
|
|
7798
8121
|
var angle = Math.atan2((zB.y - zA.y) * scaleY, (zB.x - zA.x) * scaleX);
|
|
7799
8122
|
var vertices = [];
|
|
7800
|
-
vertices.push(new Vertex_1.Vertex(zB.x * scaleX -
|
|
7801
|
-
vertices.push(new Vertex_1.Vertex(zB.x * scaleX -
|
|
8123
|
+
vertices.push(new Vertex_1.Vertex(zB.x * scaleX - headlen * Math.cos(angle), zB.y * scaleY - headlen * Math.sin(angle)));
|
|
8124
|
+
vertices.push(new Vertex_1.Vertex(zB.x * scaleX - headlen * 1.35 * Math.cos(angle - Math.PI / 8), zB.y * scaleY - headlen * 1.35 * Math.sin(angle - Math.PI / 8)));
|
|
7802
8125
|
vertices.push(new Vertex_1.Vertex(zB.x * scaleX, zB.y * scaleY));
|
|
7803
|
-
vertices.push(new Vertex_1.Vertex(zB.x * scaleX -
|
|
8126
|
+
vertices.push(new Vertex_1.Vertex(zB.x * scaleX - headlen * 1.35 * Math.cos(angle + Math.PI / 8), zB.y * scaleY - headlen * 1.35 * Math.sin(angle + Math.PI / 8)));
|
|
7804
8127
|
return vertices;
|
|
7805
8128
|
}
|
|
7806
8129
|
};
|
|
@@ -7825,7 +8148,8 @@ exports.Vector = Vector;
|
|
|
7825
8148
|
* @modified 2020-12-04 Changed `getClosestT` param from `Vertex` to `XYCoords` (generalized).
|
|
7826
8149
|
* @modified 2020-12-04 Added the `hasPoint(XYCoords)` function.
|
|
7827
8150
|
* @modified 2021-01-20 Added UID.
|
|
7828
|
-
* @
|
|
8151
|
+
* @modified 2022-02-02 Added the `destroy` method.
|
|
8152
|
+
* @version 1.2.0
|
|
7829
8153
|
*/
|
|
7830
8154
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
7831
8155
|
exports.VertTuple = void 0;
|
|
@@ -7863,7 +8187,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
7863
8187
|
VertTuple.prototype.length = function () {
|
|
7864
8188
|
return Math.sqrt(Math.pow(this.b.x - this.a.x, 2) + Math.pow(this.b.y - this.a.y, 2));
|
|
7865
8189
|
};
|
|
7866
|
-
;
|
|
7867
8190
|
/**
|
|
7868
8191
|
* Set the length of this vector to the given amount. This only works if this
|
|
7869
8192
|
* vector is not a null vector.
|
|
@@ -7876,7 +8199,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
7876
8199
|
VertTuple.prototype.setLength = function (length) {
|
|
7877
8200
|
return this.scale(length / this.length());
|
|
7878
8201
|
};
|
|
7879
|
-
;
|
|
7880
8202
|
/**
|
|
7881
8203
|
* Substract the given vertex from this line's end points.
|
|
7882
8204
|
*
|
|
@@ -7891,7 +8213,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
7891
8213
|
this.b.sub(amount);
|
|
7892
8214
|
return this;
|
|
7893
8215
|
};
|
|
7894
|
-
;
|
|
7895
8216
|
/**
|
|
7896
8217
|
* Add the given vertex to this line's end points.
|
|
7897
8218
|
*
|
|
@@ -7906,7 +8227,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
7906
8227
|
this.b.add(amount);
|
|
7907
8228
|
return this;
|
|
7908
8229
|
};
|
|
7909
|
-
;
|
|
7910
8230
|
/**
|
|
7911
8231
|
* Normalize this line (set to length 1).
|
|
7912
8232
|
*
|
|
@@ -7919,7 +8239,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
7919
8239
|
this.b.set(this.a.x + (this.b.x - this.a.x) / this.length(), this.a.y + (this.b.y - this.a.y) / this.length());
|
|
7920
8240
|
return this;
|
|
7921
8241
|
};
|
|
7922
|
-
;
|
|
7923
8242
|
/**
|
|
7924
8243
|
* Scale this line by the given factor.
|
|
7925
8244
|
*
|
|
@@ -7933,7 +8252,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
7933
8252
|
this.b.set(this.a.x + (this.b.x - this.a.x) * factor, this.a.y + (this.b.y - this.a.y) * factor);
|
|
7934
8253
|
return this;
|
|
7935
8254
|
};
|
|
7936
|
-
;
|
|
7937
8255
|
/**
|
|
7938
8256
|
* Move this line to a new location.
|
|
7939
8257
|
*
|
|
@@ -7949,7 +8267,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
7949
8267
|
this.b.add(diff);
|
|
7950
8268
|
return this;
|
|
7951
8269
|
};
|
|
7952
|
-
;
|
|
7953
8270
|
/**
|
|
7954
8271
|
* Get the angle between this and the passed line (in radians).
|
|
7955
8272
|
*
|
|
@@ -7960,7 +8277,7 @@ var VertTuple = /** @class */ (function () {
|
|
|
7960
8277
|
* @memberof VertTuple
|
|
7961
8278
|
**/
|
|
7962
8279
|
VertTuple.prototype.angle = function (line) {
|
|
7963
|
-
if (line == null || typeof line ==
|
|
8280
|
+
if (line == null || typeof line == "undefined") {
|
|
7964
8281
|
line = this.factory(new Vertex_1.Vertex(0, 0), new Vertex_1.Vertex(100, 0));
|
|
7965
8282
|
}
|
|
7966
8283
|
// Compute the angle from x axis and the return the difference :)
|
|
@@ -7970,7 +8287,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
7970
8287
|
// The result might be negative, but isn't it usually nicer to determine angles in positive values only?
|
|
7971
8288
|
return Math.atan2(v1.x, v1.y) - Math.atan2(v0.x, v0.y);
|
|
7972
8289
|
};
|
|
7973
|
-
;
|
|
7974
8290
|
/**
|
|
7975
8291
|
* Get line point at position t in [0 ... 1]:<br>
|
|
7976
8292
|
* <pre>[P(0)]=[A]--------------------[P(t)]------[B]=[P(1)]</pre><br>
|
|
@@ -7986,7 +8302,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
7986
8302
|
VertTuple.prototype.vertAt = function (t) {
|
|
7987
8303
|
return new Vertex_1.Vertex(this.a.x + (this.b.x - this.a.x) * t, this.a.y + (this.b.y - this.a.y) * t);
|
|
7988
8304
|
};
|
|
7989
|
-
;
|
|
7990
8305
|
/**
|
|
7991
8306
|
* Get the denominator of this and the given line.
|
|
7992
8307
|
*
|
|
@@ -8000,9 +8315,8 @@ var VertTuple = /** @class */ (function () {
|
|
|
8000
8315
|
**/
|
|
8001
8316
|
VertTuple.prototype.denominator = function (line) {
|
|
8002
8317
|
// http://jsfiddle.net/justin_c_rounds/Gd2S2/
|
|
8003
|
-
return (
|
|
8318
|
+
return (line.b.y - line.a.y) * (this.b.x - this.a.x) - (line.b.x - line.a.x) * (this.b.y - this.a.y);
|
|
8004
8319
|
};
|
|
8005
|
-
;
|
|
8006
8320
|
/**
|
|
8007
8321
|
* Checks if this and the given line are co-linear.
|
|
8008
8322
|
*
|
|
@@ -8017,7 +8331,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
8017
8331
|
VertTuple.prototype.colinear = function (line) {
|
|
8018
8332
|
return Math.abs(this.denominator(line)) < Vertex_1.Vertex.EPSILON;
|
|
8019
8333
|
};
|
|
8020
|
-
;
|
|
8021
8334
|
/**
|
|
8022
8335
|
* Get the closest position T from this line to the specified point.
|
|
8023
8336
|
*
|
|
@@ -8040,7 +8353,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
8040
8353
|
// t = Math.max(0, Math.min(1, t));
|
|
8041
8354
|
return t;
|
|
8042
8355
|
};
|
|
8043
|
-
;
|
|
8044
8356
|
/**
|
|
8045
8357
|
* Check if the given point is located on this line. Optionally also check if
|
|
8046
8358
|
* that point is located between point `a` and `b`.
|
|
@@ -8076,7 +8388,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
8076
8388
|
var t = this.getClosestT(p);
|
|
8077
8389
|
return this.vertAt(t);
|
|
8078
8390
|
};
|
|
8079
|
-
;
|
|
8080
8391
|
/**
|
|
8081
8392
|
* The the minimal distance between this line and the specified point.
|
|
8082
8393
|
*
|
|
@@ -8091,7 +8402,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
8091
8402
|
// https://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment
|
|
8092
8403
|
return Math.sqrt(VertTuple.vtutils.dist2(p, this.vertAt(this.getClosestT(p))));
|
|
8093
8404
|
};
|
|
8094
|
-
;
|
|
8095
8405
|
/**
|
|
8096
8406
|
* Create a deep clone of this instance.
|
|
8097
8407
|
*
|
|
@@ -8103,7 +8413,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
8103
8413
|
VertTuple.prototype.clone = function () {
|
|
8104
8414
|
return this.factory(this.a.clone(), this.b.clone());
|
|
8105
8415
|
};
|
|
8106
|
-
;
|
|
8107
8416
|
/**
|
|
8108
8417
|
* Create a string representation of this line.
|
|
8109
8418
|
*
|
|
@@ -8115,7 +8424,16 @@ var VertTuple = /** @class */ (function () {
|
|
|
8115
8424
|
VertTuple.prototype.toString = function () {
|
|
8116
8425
|
return "{ a : " + this.a.toString() + ", b : " + this.b.toString() + " }";
|
|
8117
8426
|
};
|
|
8118
|
-
|
|
8427
|
+
/**
|
|
8428
|
+
* This function should invalidate any installed listeners and invalidate this object.
|
|
8429
|
+
* After calling this function the object might not hold valid data any more and
|
|
8430
|
+
* should not be used.
|
|
8431
|
+
*/
|
|
8432
|
+
VertTuple.prototype.destroy = function () {
|
|
8433
|
+
this.a.destroy();
|
|
8434
|
+
this.b.destroy();
|
|
8435
|
+
this.isDestroyed = true;
|
|
8436
|
+
};
|
|
8119
8437
|
/**
|
|
8120
8438
|
* @private
|
|
8121
8439
|
**/
|
|
@@ -8159,7 +8477,13 @@ exports.VertTuple = VertTuple;
|
|
|
8159
8477
|
* @modified 2020-05-26 Added functions addX(number) and addY(number).
|
|
8160
8478
|
* @modified 2020-10-30 Changed the warnings in `sub(...)` and `add(...)` into real errors.
|
|
8161
8479
|
* @modified 2021-03-01 Changed the second param `center` in the `rotate` function from Vertex to XYCoords.
|
|
8162
|
-
* @
|
|
8480
|
+
* @modified 2021-12-01 Changed the type of param of `scale` to XYCoords.
|
|
8481
|
+
* @modified 2021-12-01 Added function `scaleXY` for non uniform scaling.
|
|
8482
|
+
* @modified 2021-12-17 Added the functions `lerp` and `lerpAbs` for linear interpolations.
|
|
8483
|
+
* @modified 2022-01-31 Added `Vertex.utils.arrayToJSON`.
|
|
8484
|
+
* @modified 2022-02-02 Added the `destroy` method.
|
|
8485
|
+
* @modified 2022-02-02 Cleared the `Vertex.toSVGString` function (deprecated). Use `drawutilssvg` instead.
|
|
8486
|
+
* @version 2.7.0
|
|
8163
8487
|
*
|
|
8164
8488
|
* @file Vertex
|
|
8165
8489
|
* @public
|
|
@@ -8505,20 +8829,72 @@ var Vertex = /** @class */ (function () {
|
|
|
8505
8829
|
};
|
|
8506
8830
|
/**
|
|
8507
8831
|
* This is a vector-like behavior and 'scales' this vertex
|
|
8508
|
-
* towards/from a given center.
|
|
8832
|
+
* towards/from a given center by one uniform scale factor.
|
|
8509
8833
|
*
|
|
8510
8834
|
* @method scale
|
|
8511
8835
|
* @param {number} factor - The factor to 'scale' this vertex; 1.0 means no change.
|
|
8512
|
-
* @param {
|
|
8836
|
+
* @param {XYCoords=} center - The origin of scaling; default is (0,0).
|
|
8513
8837
|
* @return {Vertex} this
|
|
8514
8838
|
* @instance
|
|
8515
8839
|
* @memberof Vertex
|
|
8516
8840
|
**/
|
|
8517
8841
|
Vertex.prototype.scale = function (factor, center) {
|
|
8518
|
-
|
|
8519
|
-
|
|
8520
|
-
|
|
8521
|
-
|
|
8842
|
+
return this.scaleXY({ x: factor, y: factor }, center);
|
|
8843
|
+
};
|
|
8844
|
+
/**
|
|
8845
|
+
* Perform a linear interpolation towards the given target vertex.
|
|
8846
|
+
* The amount value `t` is relative, `t=0.0` means no change, `t=1.0`
|
|
8847
|
+
* means this point will be moved to the exact target position.
|
|
8848
|
+
*
|
|
8849
|
+
* `t=0.5` will move this point to the middle of the connecting
|
|
8850
|
+
* linear segment.
|
|
8851
|
+
*
|
|
8852
|
+
* @param {XYCoords} target - The target position to lerp this vertex to.
|
|
8853
|
+
* @param {number} t - The relative amount, usually in [0..1], but other values will work, too.
|
|
8854
|
+
* @returns
|
|
8855
|
+
*/
|
|
8856
|
+
Vertex.prototype.lerp = function (target, t) {
|
|
8857
|
+
var diff = this.difference(target);
|
|
8858
|
+
// return new Vertex(this.x + diff.x * t, this.y + diff.y * t);
|
|
8859
|
+
this.x += diff.x * t;
|
|
8860
|
+
this.y += diff.y * t;
|
|
8861
|
+
return this;
|
|
8862
|
+
};
|
|
8863
|
+
/**
|
|
8864
|
+
* Perform a linear interpolation towards the given target vertex (absolute variant).
|
|
8865
|
+
* The amount value `t` is absolute, which means the lerp amount is a direct distance
|
|
8866
|
+
* value. This point will have move the amount of the passed distance `u`.
|
|
8867
|
+
*
|
|
8868
|
+
* @param {XYCoords} target - The target position to lerp this vertex to.
|
|
8869
|
+
* @param {number} t - The absolute move amount to use to lerping.
|
|
8870
|
+
* @returns
|
|
8871
|
+
*/
|
|
8872
|
+
Vertex.prototype.lerpAbs = function (target, u) {
|
|
8873
|
+
var dist = this.distance(target);
|
|
8874
|
+
var diff = this.difference(target);
|
|
8875
|
+
var step = { x: diff.x / dist, y: diff.y / dist };
|
|
8876
|
+
// return new Vertex(this.x + step.x * u, this.y + step.y * u);
|
|
8877
|
+
this.x += step.x * u;
|
|
8878
|
+
this.y += step.y * u;
|
|
8879
|
+
return this;
|
|
8880
|
+
};
|
|
8881
|
+
/**
|
|
8882
|
+
* This is a vector-like behavior and 'scales' this vertex
|
|
8883
|
+
* towards/from a given center by two independent x- and y- scale factors.
|
|
8884
|
+
*
|
|
8885
|
+
* @method scale
|
|
8886
|
+
* @param {number} factor - The factor to 'scale' this vertex; 1.0 means no change.
|
|
8887
|
+
* @param {XYCoords=} center - The origin of scaling; default is (0,0).
|
|
8888
|
+
* @return {Vertex} this
|
|
8889
|
+
* @instance
|
|
8890
|
+
* @memberof Vertex
|
|
8891
|
+
**/
|
|
8892
|
+
Vertex.prototype.scaleXY = function (factors, center) {
|
|
8893
|
+
if (!center || typeof center === "undefined") {
|
|
8894
|
+
center = { x: 0, y: 0 };
|
|
8895
|
+
}
|
|
8896
|
+
this.x = center.x + (this.x - center.x) * factors.x;
|
|
8897
|
+
this.y = center.y + (this.y - center.y) * factors.y;
|
|
8522
8898
|
return this;
|
|
8523
8899
|
};
|
|
8524
8900
|
/**
|
|
@@ -8607,20 +8983,31 @@ var Vertex = /** @class */ (function () {
|
|
|
8607
8983
|
* @return {string} A string representing the SVG code for this vertex.
|
|
8608
8984
|
* @instance
|
|
8609
8985
|
* @memberof Vertex
|
|
8986
|
+
* @deprecated
|
|
8610
8987
|
**/
|
|
8611
8988
|
Vertex.prototype.toSVGString = function (options) {
|
|
8612
|
-
options = options || {};
|
|
8613
|
-
var buffer = [];
|
|
8614
|
-
buffer.push("<circle");
|
|
8615
|
-
if (options.className)
|
|
8616
|
-
|
|
8617
|
-
buffer.push('
|
|
8618
|
-
buffer.push('
|
|
8619
|
-
buffer.push(
|
|
8620
|
-
buffer.
|
|
8621
|
-
return
|
|
8989
|
+
// options = options || {};
|
|
8990
|
+
// var buffer = [];
|
|
8991
|
+
// buffer.push("<circle");
|
|
8992
|
+
// if (options.className) buffer.push(' class="' + options.className + '"');
|
|
8993
|
+
// buffer.push(' cx="' + this.x + '"');
|
|
8994
|
+
// buffer.push(' cy="' + this.y + '"');
|
|
8995
|
+
// buffer.push(' r="2"');
|
|
8996
|
+
// buffer.push(" />");
|
|
8997
|
+
// return buffer.join("");
|
|
8998
|
+
console.warn("[Deprecation] Warning: the Vertex.toSVGString method is deprecated and does not return and valid SVG data any more. Please use `drawutilssvg` instead.");
|
|
8999
|
+
return "";
|
|
8622
9000
|
};
|
|
8623
9001
|
// END Vertex
|
|
9002
|
+
/**
|
|
9003
|
+
* This function should invalidate any installed listeners and invalidate this object.
|
|
9004
|
+
* After calling this function the object might not hold valid data any more and
|
|
9005
|
+
* should not be used.
|
|
9006
|
+
*/
|
|
9007
|
+
Vertex.prototype.destroy = function () {
|
|
9008
|
+
this.listeners.removeAllListeners();
|
|
9009
|
+
this.isDestroyed = true;
|
|
9010
|
+
};
|
|
8624
9011
|
/**
|
|
8625
9012
|
* Create a new random vertex inside the given viewport.
|
|
8626
9013
|
*
|
|
@@ -8674,6 +9061,19 @@ var Vertex = /** @class */ (function () {
|
|
|
8674
9061
|
vertices.push(new Vertex(zB.x * scaleX, zB.y * scaleY));
|
|
8675
9062
|
vertices.push(new Vertex(zB.x * scaleX - headlen * 1.35 * Math.cos(angle + Math.PI / 8), zB.y * scaleY - headlen * 1.35 * Math.sin(angle + Math.PI / 8)));
|
|
8676
9063
|
return vertices;
|
|
9064
|
+
},
|
|
9065
|
+
/**
|
|
9066
|
+
* Convert the given vertices (array) to a JSON string.
|
|
9067
|
+
*
|
|
9068
|
+
* @param {number?} precision - (optional) The numeric precision to be used (number of precision digits).
|
|
9069
|
+
* @returns {string}
|
|
9070
|
+
*/
|
|
9071
|
+
arrayToJSON: function (vertices, precision) {
|
|
9072
|
+
return JSON.stringify(vertices.map(function (vert) {
|
|
9073
|
+
return typeof precision === undefined
|
|
9074
|
+
? { x: vert.x, y: vert.y }
|
|
9075
|
+
: { x: Number(vert.x.toFixed(precision)), y: Number(vert.y.toFixed(precision)) };
|
|
9076
|
+
}));
|
|
8677
9077
|
}
|
|
8678
9078
|
};
|
|
8679
9079
|
return Vertex;
|
|
@@ -8787,7 +9187,6 @@ var VertexListeners = /** @class */ (function () {
|
|
|
8787
9187
|
this.dragEnd = [];
|
|
8788
9188
|
this.vertex = vertex;
|
|
8789
9189
|
}
|
|
8790
|
-
;
|
|
8791
9190
|
/**
|
|
8792
9191
|
* Add a click listener.
|
|
8793
9192
|
*
|
|
@@ -8801,7 +9200,6 @@ var VertexListeners = /** @class */ (function () {
|
|
|
8801
9200
|
VertexListeners._addListener(this.click, listener);
|
|
8802
9201
|
return this;
|
|
8803
9202
|
};
|
|
8804
|
-
;
|
|
8805
9203
|
/**
|
|
8806
9204
|
* The click listener is a function with a single drag event param.
|
|
8807
9205
|
* @callback VertexListeners~clickListener
|
|
@@ -8820,7 +9218,6 @@ var VertexListeners = /** @class */ (function () {
|
|
|
8820
9218
|
this.click = VertexListeners._removeListener(this.click, listener);
|
|
8821
9219
|
return this;
|
|
8822
9220
|
};
|
|
8823
|
-
;
|
|
8824
9221
|
/**
|
|
8825
9222
|
* The click listener is a function with a single drag event param.
|
|
8826
9223
|
* @callback VertexListeners~clickListener
|
|
@@ -8839,7 +9236,6 @@ var VertexListeners = /** @class */ (function () {
|
|
|
8839
9236
|
VertexListeners._addListener(this.drag, listener);
|
|
8840
9237
|
return this;
|
|
8841
9238
|
};
|
|
8842
|
-
;
|
|
8843
9239
|
/**
|
|
8844
9240
|
* The drag listener is a function with a single drag event param.
|
|
8845
9241
|
* @callback VertexListeners~dragListener
|
|
@@ -8858,7 +9254,6 @@ var VertexListeners = /** @class */ (function () {
|
|
|
8858
9254
|
this.drag = VertexListeners._removeListener(this.drag, listener);
|
|
8859
9255
|
return this;
|
|
8860
9256
|
};
|
|
8861
|
-
;
|
|
8862
9257
|
/**
|
|
8863
9258
|
* Add a dragStart listener.
|
|
8864
9259
|
*
|
|
@@ -8872,7 +9267,6 @@ var VertexListeners = /** @class */ (function () {
|
|
|
8872
9267
|
VertexListeners._addListener(this.dragStart, listener);
|
|
8873
9268
|
return this;
|
|
8874
9269
|
};
|
|
8875
|
-
;
|
|
8876
9270
|
/**
|
|
8877
9271
|
* The drag-start listener is a function with a single drag event param.
|
|
8878
9272
|
* @callback VertexListeners~dragStartListener
|
|
@@ -8891,7 +9285,6 @@ var VertexListeners = /** @class */ (function () {
|
|
|
8891
9285
|
this.dragStart = VertexListeners._removeListener(this.dragStart, listener);
|
|
8892
9286
|
return this;
|
|
8893
9287
|
};
|
|
8894
|
-
;
|
|
8895
9288
|
/**
|
|
8896
9289
|
* Add a dragEnd listener.
|
|
8897
9290
|
*
|
|
@@ -8906,27 +9299,25 @@ var VertexListeners = /** @class */ (function () {
|
|
|
8906
9299
|
VertexListeners._addListener(this.dragEnd, listener);
|
|
8907
9300
|
return this;
|
|
8908
9301
|
};
|
|
8909
|
-
;
|
|
8910
9302
|
/**
|
|
8911
9303
|
* The drag-end listener is a function with a single drag event param.
|
|
8912
9304
|
* @callback VertexListeners~dragEndListener
|
|
8913
9305
|
* @param {Event} e - The (extended) drag event.
|
|
8914
9306
|
*/
|
|
8915
9307
|
/**
|
|
8916
|
-
|
|
8917
|
-
|
|
8918
|
-
|
|
8919
|
-
|
|
8920
|
-
|
|
8921
|
-
|
|
8922
|
-
|
|
8923
|
-
|
|
9308
|
+
* Remove a drag listener.
|
|
9309
|
+
*
|
|
9310
|
+
* @method removeDragEndListener
|
|
9311
|
+
* @param {VertexListeners~clickListener} listener - The drag listener to remove (a callback).
|
|
9312
|
+
* @return {VertexListeners} this (for chaining)
|
|
9313
|
+
* @instance
|
|
9314
|
+
* @memberof VertexListeners
|
|
9315
|
+
**/
|
|
8924
9316
|
VertexListeners.prototype.removeDragEndListener = function (listener) {
|
|
8925
9317
|
// this.drag.push( listener );
|
|
8926
9318
|
this.dragEnd = VertexListeners._removeListener(this.dragEnd, listener);
|
|
8927
9319
|
return this;
|
|
8928
9320
|
};
|
|
8929
|
-
;
|
|
8930
9321
|
/**
|
|
8931
9322
|
* Fire a click event with the given event instance to all
|
|
8932
9323
|
* installed click listeners.
|
|
@@ -8940,7 +9331,6 @@ var VertexListeners = /** @class */ (function () {
|
|
|
8940
9331
|
VertexListeners.prototype.fireClickEvent = function (e) {
|
|
8941
9332
|
VertexListeners._fireEvent(this, this.click, e);
|
|
8942
9333
|
};
|
|
8943
|
-
;
|
|
8944
9334
|
/**
|
|
8945
9335
|
* Fire a drag event with the given event instance to all
|
|
8946
9336
|
* installed drag listeners.
|
|
@@ -8954,7 +9344,6 @@ var VertexListeners = /** @class */ (function () {
|
|
|
8954
9344
|
VertexListeners.prototype.fireDragEvent = function (e) {
|
|
8955
9345
|
VertexListeners._fireEvent(this, this.drag, e);
|
|
8956
9346
|
};
|
|
8957
|
-
;
|
|
8958
9347
|
/**
|
|
8959
9348
|
* Fire a dragStart event with the given event instance to all
|
|
8960
9349
|
* installed drag-start listeners.
|
|
@@ -8968,7 +9357,6 @@ var VertexListeners = /** @class */ (function () {
|
|
|
8968
9357
|
VertexListeners.prototype.fireDragStartEvent = function (e) {
|
|
8969
9358
|
VertexListeners._fireEvent(this, this.dragStart, e);
|
|
8970
9359
|
};
|
|
8971
|
-
;
|
|
8972
9360
|
/**
|
|
8973
9361
|
* Fire a dragEnd event with the given event instance to all
|
|
8974
9362
|
* installed drag-end listeners.
|
|
@@ -8982,13 +9370,21 @@ var VertexListeners = /** @class */ (function () {
|
|
|
8982
9370
|
VertexListeners.prototype.fireDragEndEvent = function (e) {
|
|
8983
9371
|
VertexListeners._fireEvent(this, this.dragEnd, e);
|
|
8984
9372
|
};
|
|
8985
|
-
|
|
9373
|
+
/**
|
|
9374
|
+
* Removes all listeners from this listeners object.
|
|
9375
|
+
*/
|
|
9376
|
+
VertexListeners.prototype.removeAllListeners = function () {
|
|
9377
|
+
this.click = [];
|
|
9378
|
+
this.drag = [];
|
|
9379
|
+
this.dragStart = [];
|
|
9380
|
+
this.dragEnd = [];
|
|
9381
|
+
};
|
|
8986
9382
|
/**
|
|
8987
9383
|
* @private
|
|
8988
9384
|
**/
|
|
8989
9385
|
VertexListeners._fireEvent = function (_self, listeners, e) {
|
|
8990
9386
|
var ve = e;
|
|
8991
|
-
if (typeof ve.params ==
|
|
9387
|
+
if (typeof ve.params == "undefined")
|
|
8992
9388
|
ve.params = { vertex: _self.vertex };
|
|
8993
9389
|
else
|
|
8994
9390
|
ve.params.vertex = _self.vertex;
|
|
@@ -8996,7 +9392,6 @@ var VertexListeners = /** @class */ (function () {
|
|
|
8996
9392
|
listeners[i](ve);
|
|
8997
9393
|
}
|
|
8998
9394
|
};
|
|
8999
|
-
;
|
|
9000
9395
|
/**
|
|
9001
9396
|
* @private
|
|
9002
9397
|
*/
|
|
@@ -9008,7 +9403,6 @@ var VertexListeners = /** @class */ (function () {
|
|
|
9008
9403
|
listeners.push(newListener);
|
|
9009
9404
|
return true;
|
|
9010
9405
|
};
|
|
9011
|
-
;
|
|
9012
9406
|
/**
|
|
9013
9407
|
* @private
|
|
9014
9408
|
*/
|
|
@@ -9019,7 +9413,6 @@ var VertexListeners = /** @class */ (function () {
|
|
|
9019
9413
|
}
|
|
9020
9414
|
return listeners;
|
|
9021
9415
|
};
|
|
9022
|
-
;
|
|
9023
9416
|
return VertexListeners;
|
|
9024
9417
|
}());
|
|
9025
9418
|
exports.VertexListeners = VertexListeners;
|
|
@@ -9070,7 +9463,9 @@ exports.VertexListeners = VertexListeners;
|
|
|
9070
9463
|
* @modified 2021-02-22 Added the `path` drawing function to draw SVG path data.
|
|
9071
9464
|
* @modified 2021-03-31 Added the `endDrawCycle` function from `DrawLib`.
|
|
9072
9465
|
* @modified 2021-05-31 Added the `setConfiguration` function from `DrawLib`.
|
|
9073
|
-
* @
|
|
9466
|
+
* @modified 2021-11-12 Adding more parameters tot the `text()` function: fontSize, textAlign, fontFamily, lineHeight.
|
|
9467
|
+
* @modified 2021-11-19 Added the `color` param to the `label(...)` function.
|
|
9468
|
+
* @version 1.10.0
|
|
9074
9469
|
**/
|
|
9075
9470
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
9076
9471
|
exports.drawutils = void 0;
|
|
@@ -9730,20 +10125,62 @@ var drawutils = /** @class */ (function () {
|
|
|
9730
10125
|
this.ctx.setLineDash([]);
|
|
9731
10126
|
this.ctx.restore();
|
|
9732
10127
|
};
|
|
10128
|
+
/**
|
|
10129
|
+
* Draw a text at the given relative position.
|
|
10130
|
+
*
|
|
10131
|
+
* @method text
|
|
10132
|
+
* @param {string} text - The text to draw.
|
|
10133
|
+
* @param {number} x - The x-position to draw the text at.
|
|
10134
|
+
* @param {number} y - The y-position to draw the text at.
|
|
10135
|
+
* @param {string=} options.color - The Color to use.
|
|
10136
|
+
* @param {string=} options.fontFamily - The font family to use.
|
|
10137
|
+
* @param {number=} options.fontSize - The font size (in pixels) to use.
|
|
10138
|
+
* @param {FontStyle=} options.fontStyle - The font style to use.
|
|
10139
|
+
* @param {FontWeight=} options.fontWeight - The font weight to use.
|
|
10140
|
+
* @param {number=} options.lineHeight - The line height (in pixels) to use.
|
|
10141
|
+
* @param {number=} options.rotation - The (optional) rotation in radians.
|
|
10142
|
+
* @param {string=} options.textAlign - The text align to use. According to the specifiactions (https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign) valid values are `"left" || "right" || "center" || "start" || "end"`.
|
|
10143
|
+
* @return {void}
|
|
10144
|
+
* @instance
|
|
10145
|
+
* @memberof drawutils
|
|
10146
|
+
*/
|
|
9733
10147
|
drawutils.prototype.text = function (text, x, y, options) {
|
|
10148
|
+
// See https://stackoverflow.com/a/23523697
|
|
10149
|
+
var _a, _b, _c;
|
|
9734
10150
|
options = options || {};
|
|
9735
10151
|
this.ctx.save();
|
|
9736
|
-
|
|
9737
|
-
|
|
10152
|
+
var relX = this.offset.x + x * this.scale.x;
|
|
10153
|
+
var relY = this.offset.y + y * this.scale.y;
|
|
9738
10154
|
var color = options.color || "black";
|
|
10155
|
+
if (options.fontSize || options.fontFamily) {
|
|
10156
|
+
// Scaling of text only works in uniform mode
|
|
10157
|
+
this.ctx.font =
|
|
10158
|
+
(options.fontWeight ? options.fontWeight + " " : "") +
|
|
10159
|
+
(options.fontStyle ? options.fontStyle + " " : "") +
|
|
10160
|
+
(options.fontSize ? options.fontSize * this.scale.x + "px " : " ") +
|
|
10161
|
+
(options.fontFamily
|
|
10162
|
+
? options.fontFamily.indexOf(" ") === -1
|
|
10163
|
+
? options.fontFamily
|
|
10164
|
+
: "\"" + options.fontFamily + "\""
|
|
10165
|
+
: "Arial");
|
|
10166
|
+
}
|
|
10167
|
+
if (options.textAlign) {
|
|
10168
|
+
this.ctx.textAlign = options.textAlign;
|
|
10169
|
+
}
|
|
10170
|
+
var rotation = (_a = options.rotation) !== null && _a !== void 0 ? _a : 0.0;
|
|
10171
|
+
var lineHeight = ((_c = (_b = options.lineHeight) !== null && _b !== void 0 ? _b : options.fontSize) !== null && _c !== void 0 ? _c : 0) * this.scale.x;
|
|
10172
|
+
this.ctx.translate(relX, relY);
|
|
10173
|
+
this.ctx.rotate(rotation);
|
|
9739
10174
|
if (this.fillShapes) {
|
|
9740
10175
|
this.ctx.fillStyle = color;
|
|
9741
|
-
this.ctx.fillText(text,
|
|
10176
|
+
this.ctx.fillText(text, 0, lineHeight / 2);
|
|
9742
10177
|
}
|
|
9743
10178
|
else {
|
|
9744
10179
|
this.ctx.strokeStyle = color;
|
|
9745
|
-
this.ctx.strokeText(text,
|
|
10180
|
+
this.ctx.strokeText(text, 0, lineHeight / 2);
|
|
9746
10181
|
}
|
|
10182
|
+
// this.ctx.translate(-relX, -relY);
|
|
10183
|
+
// this.ctx.rotate(-rotation); // is this necessary before 'restore()'?
|
|
9747
10184
|
this.ctx.restore();
|
|
9748
10185
|
};
|
|
9749
10186
|
/**
|
|
@@ -9763,8 +10200,9 @@ var drawutils = /** @class */ (function () {
|
|
|
9763
10200
|
*/
|
|
9764
10201
|
drawutils.prototype.label = function (text, x, y, rotation, color) {
|
|
9765
10202
|
this.ctx.save();
|
|
10203
|
+
this.ctx.font = "lighter 9pt Arial";
|
|
9766
10204
|
this.ctx.translate(x, y);
|
|
9767
|
-
if (typeof rotation
|
|
10205
|
+
if (typeof rotation !== "undefined")
|
|
9768
10206
|
this.ctx.rotate(rotation);
|
|
9769
10207
|
this.ctx.fillStyle = color || "black";
|
|
9770
10208
|
if (this.fillShapes) {
|
|
@@ -10385,6 +10823,25 @@ var drawutilsgl = /** @class */ (function () {
|
|
|
10385
10823
|
drawutilsgl.prototype.polyline = function (vertices, isOpen, color, lineWidth) {
|
|
10386
10824
|
// NOT YET IMPLEMENTED
|
|
10387
10825
|
};
|
|
10826
|
+
/**
|
|
10827
|
+
* Draw a text at the given relative position.
|
|
10828
|
+
*
|
|
10829
|
+
* @method text
|
|
10830
|
+
* @param {string} text - The text to draw.
|
|
10831
|
+
* @param {number} x - The x-position to draw the text at.
|
|
10832
|
+
* @param {number} y - The y-position to draw the text at.
|
|
10833
|
+
* @param {string=} options.color - The Color to use.
|
|
10834
|
+
* @param {string=} options.fontFamily - The font family to use.
|
|
10835
|
+
* @param {number=} options.fontSize - The font size (in pixels) to use.
|
|
10836
|
+
* @param {FontStyle=} options.fontStyle - The font style to use.
|
|
10837
|
+
* @param {FontWeight=} options.fontWeight - The font weight to use.
|
|
10838
|
+
* @param {number=} options.lineHeight - The line height (in pixels) to use.
|
|
10839
|
+
* @param {number=} options.rotation - The (optional) rotation in radians.
|
|
10840
|
+
* @param {string=} options.textAlign - The text align to use. According to the specifiactions (https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign) valid values are `"left" || "right" || "center" || "start" || "end"`.
|
|
10841
|
+
* @return {void}
|
|
10842
|
+
* @instance
|
|
10843
|
+
* @memberof drawutils
|
|
10844
|
+
*/
|
|
10388
10845
|
drawutilsgl.prototype.text = function (text, x, y, options) {
|
|
10389
10846
|
// NOT YET IMPLEMENTED
|
|
10390
10847
|
};
|
|
@@ -10396,14 +10853,12 @@ var drawutilsgl = /** @class */ (function () {
|
|
|
10396
10853
|
* @param {number} x - The x-position to draw the text at.
|
|
10397
10854
|
* @param {number} y - The y-position to draw the text at.
|
|
10398
10855
|
* @param {number=} rotation - The (aoptional) rotation in radians.
|
|
10856
|
+
* @param {string="black"} color - The color to use (default is black).
|
|
10399
10857
|
* @return {void}
|
|
10400
10858
|
* @instance
|
|
10401
10859
|
* @memberof drawutils
|
|
10402
10860
|
*/
|
|
10403
|
-
|
|
10404
|
-
// | Draw a non-scaling text label at the given position.
|
|
10405
|
-
// +-------------------------------
|
|
10406
|
-
drawutilsgl.prototype.label = function (text, x, y, rotation) {
|
|
10861
|
+
drawutilsgl.prototype.label = function (text, x, y, rotation, color) {
|
|
10407
10862
|
// NOT YET IMPLEMENTED
|
|
10408
10863
|
};
|
|
10409
10864
|
/**
|
|
@@ -10538,13 +10993,17 @@ var GLU = /** @class */ (function () {
|
|
|
10538
10993
|
* @modified 2021-03-31 Added 'ellipseSector' the the class names.
|
|
10539
10994
|
* @modified 2021-03-31 Implemented buffering using a buffer <g> node and the beginDrawCycle and endDrawCycle methods.
|
|
10540
10995
|
* @modified 2021-05-31 Added the `setConfiguration` function from `DrawLib`.
|
|
10541
|
-
* @
|
|
10996
|
+
* @modified 2021-11-15 Adding more parameters tot the `text()` function: fontSize, textAlign, fontFamily, lineHeight.
|
|
10997
|
+
* @modified 2021-11-19 Fixing the `label(text,x,y)` position.
|
|
10998
|
+
* @modified 2021-11-19 Added the `color` param to the `label(...)` function.
|
|
10999
|
+
* @version 1.4.0
|
|
10542
11000
|
**/
|
|
10543
11001
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
10544
11002
|
exports.drawutilssvg = void 0;
|
|
10545
11003
|
var CircleSector_1 = __webpack_require__(946);
|
|
10546
11004
|
var CubicBezierCurve_1 = __webpack_require__(510);
|
|
10547
11005
|
var Vertex_1 = __webpack_require__(421);
|
|
11006
|
+
var RAD_TO_DEG = 180 / Math.PI;
|
|
10548
11007
|
/**
|
|
10549
11008
|
* @classdesc A helper class for basic SVG drawing operations. This class should
|
|
10550
11009
|
* be compatible to the default 'draw' class.
|
|
@@ -10604,7 +11063,8 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
10604
11063
|
"vertex": "Vertex",
|
|
10605
11064
|
"line": "Line",
|
|
10606
11065
|
"vector": "Vector",
|
|
10607
|
-
"image": "Image"
|
|
11066
|
+
"image": "Image",
|
|
11067
|
+
"text": "Text"
|
|
10608
11068
|
};
|
|
10609
11069
|
// Question: why isn't this working if the svgNode is created dynamically? (nodeStyle.sheet is null)
|
|
10610
11070
|
var rules = [];
|
|
@@ -11385,27 +11845,65 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
11385
11845
|
if (!isOpen)
|
|
11386
11846
|
d.push("Z");
|
|
11387
11847
|
node.setAttribute("d", d.join(" "));
|
|
11388
|
-
return this._bindFillDraw(node, "
|
|
11848
|
+
return this._bindFillDraw(node, "polygon", color, lineWidth || 1);
|
|
11389
11849
|
};
|
|
11390
11850
|
/**
|
|
11391
|
-
* Draw a text
|
|
11851
|
+
* Draw a text at the given relative position.
|
|
11392
11852
|
*
|
|
11393
|
-
* @method
|
|
11853
|
+
* @method text
|
|
11394
11854
|
* @param {string} text - The text to draw.
|
|
11395
11855
|
* @param {number} x - The x-position to draw the text at.
|
|
11396
11856
|
* @param {number} y - The y-position to draw the text at.
|
|
11397
|
-
* @param {
|
|
11857
|
+
* @param {string=} options.color - The Color to use.
|
|
11858
|
+
* @param {string=} options.fontFamily - The font family to use.
|
|
11859
|
+
* @param {number=} options.fontSize - The font size (in pixels) to use.
|
|
11860
|
+
* @param {FontStyle=} options.fontStyle - The font style to use.
|
|
11861
|
+
* @param {FontWeight=} options.fontWeight - The font weight to use.
|
|
11862
|
+
* @param {number=} options.lineHeight - The line height (in pixels) to use.
|
|
11863
|
+
* @param {number=} options.rotation - The (optional) rotation in radians.
|
|
11864
|
+
* @param {string=} options.textAlign - The text align to use. According to the specifiactions (https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign) valid values are `"left" || "right" || "center" || "start" || "end"`.
|
|
11398
11865
|
* @return {void}
|
|
11399
11866
|
* @instance
|
|
11400
|
-
* @memberof
|
|
11867
|
+
* @memberof drawutils
|
|
11401
11868
|
*/
|
|
11402
11869
|
drawutilssvg.prototype.text = function (text, x, y, options) {
|
|
11870
|
+
var _a, _b;
|
|
11403
11871
|
options = options || {};
|
|
11404
11872
|
var color = options.color || "black";
|
|
11405
|
-
var
|
|
11406
|
-
|
|
11407
|
-
|
|
11408
|
-
|
|
11873
|
+
var lineHeight = ((_b = (_a = options.lineHeight) !== null && _a !== void 0 ? _a : options.fontSize) !== null && _b !== void 0 ? _b : 0) * this.scale.x;
|
|
11874
|
+
// https://www.w3.org/TR/SVG/text.html#TextAnchorProperty
|
|
11875
|
+
// start | middle | end
|
|
11876
|
+
var textAlign = options.textAlign === "left" || options.textAlign === "start"
|
|
11877
|
+
? "start"
|
|
11878
|
+
: options.textAlign === "center"
|
|
11879
|
+
? "middle"
|
|
11880
|
+
: options.textAlign === "right" || options.textAlign === "end"
|
|
11881
|
+
? "end"
|
|
11882
|
+
: "start";
|
|
11883
|
+
var transformOrigin = this._x(x) + "px " + this._y(y) + "px";
|
|
11884
|
+
var translate = "translate(" + this._x(x) + " " + (this._y(y) + lineHeight / 2) + ")";
|
|
11885
|
+
// Safari has a transform-origin/rotation bug.
|
|
11886
|
+
// It's essential to use rotate(r,x,y) here. "rotate(r)"" with transform-origin(x,y) won't do the job.
|
|
11887
|
+
// And rotate and translate cannot be used is combination on a text object.
|
|
11888
|
+
// So wrap the text inside a <g>, translate the <g>, and rotate the text inside.
|
|
11889
|
+
var rotate = options.rotation ? "rotate(" + options.rotation * RAD_TO_DEG + " 0 0)" : "";
|
|
11890
|
+
var node = this.makeNode("g");
|
|
11891
|
+
var curId = this.curId;
|
|
11892
|
+
this.curId = curId + "_text";
|
|
11893
|
+
var textNode = this.makeNode("text");
|
|
11894
|
+
node.appendChild(textNode);
|
|
11895
|
+
textNode.setAttribute("font-family", options.fontFamily); // May be undefined
|
|
11896
|
+
textNode.setAttribute("font-size", options.fontSize ? "" + options.fontSize * this.scale.x : null);
|
|
11897
|
+
textNode.setAttribute("font-style", options.fontStyle ? "" + options.fontStyle : null);
|
|
11898
|
+
textNode.setAttribute("font-weight", options.fontWeight ? "" + options.fontWeight : null);
|
|
11899
|
+
textNode.setAttribute("text-anchor", textAlign);
|
|
11900
|
+
textNode.setAttribute("transform-origin", "0 0");
|
|
11901
|
+
textNode.setAttribute("transform", rotate);
|
|
11902
|
+
node.setAttribute("transform-origin", transformOrigin);
|
|
11903
|
+
node.setAttribute("transform", translate);
|
|
11904
|
+
textNode.innerHTML = text;
|
|
11905
|
+
// Restore old ID
|
|
11906
|
+
this.curId = curId;
|
|
11409
11907
|
return this._bindFillDraw(node, "text", color, 1);
|
|
11410
11908
|
};
|
|
11411
11909
|
/**
|
|
@@ -11416,16 +11914,21 @@ var drawutilssvg = /** @class */ (function () {
|
|
|
11416
11914
|
* @param {number} x - The x-position to draw the text at.
|
|
11417
11915
|
* @param {number} y - The y-position to draw the text at.
|
|
11418
11916
|
* @param {number=} rotation - The (optional) rotation in radians.
|
|
11917
|
+
* @param {string="black"} color - The color to use (default is black).
|
|
11419
11918
|
* @return {void}
|
|
11420
11919
|
* @instance
|
|
11421
11920
|
* @memberof drawutilssvg
|
|
11422
11921
|
*/
|
|
11423
|
-
drawutilssvg.prototype.label = function (text, x, y, rotation) {
|
|
11922
|
+
drawutilssvg.prototype.label = function (text, x, y, rotation, color) {
|
|
11424
11923
|
var node = this.makeNode("text");
|
|
11425
11924
|
// For some strange reason SVG rotation transforms use degrees instead of radians
|
|
11426
|
-
node.setAttribute("transform", "translate(" +
|
|
11925
|
+
node.setAttribute("transform", "translate(" + x + "," + y + "), rotate(" + ((rotation || 0) / Math.PI) * 180 + ")");
|
|
11926
|
+
node.setAttribute("font-family", "Arial");
|
|
11927
|
+
node.setAttribute("font-size", "9pt");
|
|
11928
|
+
node.setAttribute("font-style", "normal");
|
|
11929
|
+
node.setAttribute("font-weight", "lighter");
|
|
11427
11930
|
node.innerHTML = text;
|
|
11428
|
-
return this._bindFillDraw(node, "label", "black", null);
|
|
11931
|
+
return this._bindFillDraw(node, "label", color || "black", null);
|
|
11429
11932
|
};
|
|
11430
11933
|
/**
|
|
11431
11934
|
* Draw an SVG-like path given by the specified path data.
|
|
@@ -11876,6 +12379,7 @@ globalThis.VEllipse = __webpack_require__(112).VEllipse;
|
|
|
11876
12379
|
globalThis.Circle = __webpack_require__(913).Circle;
|
|
11877
12380
|
globalThis.CircleSector = __webpack_require__(946).CircleSector;
|
|
11878
12381
|
globalThis.PBImage = __webpack_require__(699).PBImage;
|
|
12382
|
+
globalThis.PBText = __webpack_require__(196).PBText;
|
|
11879
12383
|
globalThis.MouseHandler = __webpack_require__(293).MouseHandler;
|
|
11880
12384
|
globalThis.KeyHandler = __webpack_require__(909).KeyHandler;
|
|
11881
12385
|
globalThis.drawutils = __webpack_require__(149).drawutils;
|