plotboilerplate 1.15.0 → 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/changelog.md +24 -0
- package/dist/index.esm.js +574 -428
- 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 +574 -428
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +1 -1
- package/src/cjs/BezierPath.d.ts +33 -1
- package/src/cjs/BezierPath.js +80 -13
- 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 +15 -1
- package/src/cjs/PBText.js +11 -1
- package/src/cjs/PBText.js.map +1 -1
- package/src/cjs/PlotBoilerplate.js +1 -1
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/Polygon.d.ts +16 -1
- package/src/cjs/Polygon.js +37 -23
- 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 +25 -1
- package/src/cjs/Vertex.js +38 -11
- 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/utils/creategui.js +1 -1
- 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 +33 -1
- package/src/esm/BezierPath.js +80 -13
- 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 +15 -1
- package/src/esm/PBText.js +11 -1
- package/src/esm/PBText.js.map +1 -1
- package/src/esm/PlotBoilerplate.js +1 -1
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/Polygon.d.ts +16 -1
- package/src/esm/Polygon.js +37 -23
- 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 +25 -1
- package/src/esm/Vertex.js +38 -11
- 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/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 +96 -11
- 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 +20 -1
- package/src/ts/PlotBoilerplate.ts +1 -1
- package/src/ts/Polygon.ts +48 -22
- 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 +52 -10
- package/src/ts/VertexListeners.ts +248 -266
- package/src/ts/utils/helpers/BezierPathInteractionHelper.ts +61 -30
- package/src/ts/utils/io/FileDrop.ts +178 -0
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
|
|
@@ -1342,6 +1345,59 @@ var BezierPath = /** @class */ (function () {
|
|
|
1342
1345
|
}
|
|
1343
1346
|
return new Bounds_1.Bounds(min, max);
|
|
1344
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
|
+
};
|
|
1345
1401
|
/**
|
|
1346
1402
|
* Clone this BezierPath (deep clone).
|
|
1347
1403
|
*
|
|
@@ -1399,19 +1455,30 @@ var BezierPath = /** @class */ (function () {
|
|
|
1399
1455
|
* @return {string} The SVG string.
|
|
1400
1456
|
**/
|
|
1401
1457
|
BezierPath.prototype.toSVGString = function (options) {
|
|
1402
|
-
options = options || {};
|
|
1403
|
-
var buffer = [];
|
|
1404
|
-
buffer.push("<path");
|
|
1405
|
-
if (options.className)
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
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();
|
|
1412
1480
|
}
|
|
1413
|
-
|
|
1414
|
-
return buffer.join("");
|
|
1481
|
+
this.isDestroyed = true;
|
|
1415
1482
|
};
|
|
1416
1483
|
/**
|
|
1417
1484
|
* Create a JSON string representation of this bézier curve.
|
|
@@ -1730,7 +1797,9 @@ exports.Bounds = Bounds;
|
|
|
1730
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.
|
|
1731
1798
|
* @modified 2020-10-16 Added the containsCircle(...) function.
|
|
1732
1799
|
* @modified 2021-01-20 Added UID.
|
|
1733
|
-
* @
|
|
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
|
|
1734
1803
|
**/
|
|
1735
1804
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1736
1805
|
exports.Circle = void 0;
|
|
@@ -1767,7 +1836,6 @@ var Circle = /** @class */ (function () {
|
|
|
1767
1836
|
this.center = center;
|
|
1768
1837
|
this.radius = radius;
|
|
1769
1838
|
}
|
|
1770
|
-
;
|
|
1771
1839
|
/**
|
|
1772
1840
|
* Check if the given circle is fully contained inside this circle.
|
|
1773
1841
|
*
|
|
@@ -1780,7 +1848,6 @@ var Circle = /** @class */ (function () {
|
|
|
1780
1848
|
Circle.prototype.containsCircle = function (circle) {
|
|
1781
1849
|
return this.center.distance(circle.center) + circle.radius < this.radius;
|
|
1782
1850
|
};
|
|
1783
|
-
;
|
|
1784
1851
|
/**
|
|
1785
1852
|
* Calculate the distance from this circle to the given line.
|
|
1786
1853
|
*
|
|
@@ -1799,7 +1866,6 @@ var Circle = /** @class */ (function () {
|
|
|
1799
1866
|
var closestPointOnLine = line.getClosestPoint(this.center);
|
|
1800
1867
|
return closestPointOnLine.distance(this.center) - this.radius;
|
|
1801
1868
|
};
|
|
1802
|
-
;
|
|
1803
1869
|
/**
|
|
1804
1870
|
* Get the vertex on the this circle for the given angle.
|
|
1805
1871
|
*
|
|
@@ -1813,7 +1879,6 @@ var Circle = /** @class */ (function () {
|
|
|
1813
1879
|
// Find the point on the circle respective the angle. Then move relative to center.
|
|
1814
1880
|
return Circle.circleUtils.vertAt(angle, this.radius).add(this.center);
|
|
1815
1881
|
};
|
|
1816
|
-
;
|
|
1817
1882
|
/**
|
|
1818
1883
|
* Get a tangent line of this circle for a given angle.
|
|
1819
1884
|
*
|
|
@@ -1830,7 +1895,6 @@ var Circle = /** @class */ (function () {
|
|
|
1830
1895
|
// Construct the perpendicular of the line in point a. Then move relative to center.
|
|
1831
1896
|
return new Vector_1.Vector(pointA, new Vertex_1.Vertex(0, 0)).add(this.center).perp();
|
|
1832
1897
|
};
|
|
1833
|
-
;
|
|
1834
1898
|
/**
|
|
1835
1899
|
* Calculate the intersection points (if exists) with the given circle.
|
|
1836
1900
|
*
|
|
@@ -1870,47 +1934,55 @@ var Circle = /** @class */ (function () {
|
|
|
1870
1934
|
// x4 = P2.x - h*(P1.y - P0.y)/d;
|
|
1871
1935
|
// y4 = P2.y + h*(P1.x - P0.x)/d;
|
|
1872
1936
|
// return pair<Point, Point>(Point(x3, y3), Point(x4, y4));
|
|
1873
|
-
// }
|
|
1937
|
+
// }
|
|
1874
1938
|
var p0 = this.center;
|
|
1875
1939
|
var p1 = circle.center;
|
|
1876
1940
|
var d = p0.distance(p1);
|
|
1877
1941
|
var a = (this.radius * this.radius - circle.radius * circle.radius + d * d) / (2 * d);
|
|
1878
1942
|
var h = Math.sqrt(this.radius * this.radius - a * a);
|
|
1879
1943
|
var p2 = p1.clone().scale(a / d, p0);
|
|
1880
|
-
var x3 = p2.x + h * (p1.y - p0.y) / d;
|
|
1881
|
-
var y3 = p2.y - h * (p1.x - p0.x) / d;
|
|
1882
|
-
var x4 = p2.x - h * (p1.y - p0.y) / d;
|
|
1883
|
-
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;
|
|
1884
1948
|
return new Line_1.Line(new Vertex_1.Vertex(x3, y3), new Vertex_1.Vertex(x4, y4));
|
|
1885
1949
|
};
|
|
1886
|
-
;
|
|
1887
1950
|
/**
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
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
|
+
*/
|
|
1897
1960
|
Circle.prototype.toSVGString = function (options) {
|
|
1898
|
-
options = options || {};
|
|
1899
|
-
var buffer = [];
|
|
1900
|
-
buffer.push(
|
|
1901
|
-
if (options.className)
|
|
1902
|
-
|
|
1903
|
-
buffer.push('
|
|
1904
|
-
buffer.push('
|
|
1905
|
-
buffer.push(
|
|
1906
|
-
buffer.
|
|
1907
|
-
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;
|
|
1908
1981
|
};
|
|
1909
|
-
;
|
|
1910
1982
|
Circle.circleUtils = {
|
|
1911
1983
|
vertAt: function (angle, radius) {
|
|
1912
1984
|
/* return new Vertex( Math.sin(angle) * radius,
|
|
1913
|
-
|
|
1985
|
+
Math.cos(angle) * radius ); */
|
|
1914
1986
|
return new Vertex_1.Vertex(Math.cos(angle) * radius, Math.sin(angle) * radius);
|
|
1915
1987
|
}
|
|
1916
1988
|
};
|
|
@@ -1964,27 +2036,42 @@ var CircleSector = /** @class */ (function () {
|
|
|
1964
2036
|
this.startAngle = startAngle;
|
|
1965
2037
|
this.endAngle = endAngle;
|
|
1966
2038
|
}
|
|
1967
|
-
;
|
|
1968
2039
|
/**
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
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
|
+
*/
|
|
1977
2049
|
CircleSector.prototype.toSVGString = function (options) {
|
|
1978
|
-
options = options || {};
|
|
1979
|
-
var buffer = [];
|
|
1980
|
-
buffer.push(
|
|
1981
|
-
if (options.className)
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
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;
|
|
1986
2074
|
};
|
|
1987
|
-
;
|
|
1988
2075
|
CircleSector.circleSectorUtils = {
|
|
1989
2076
|
/**
|
|
1990
2077
|
* Helper function to convert polar circle coordinates to cartesian coordinates.
|
|
@@ -1992,11 +2079,11 @@ var CircleSector = /** @class */ (function () {
|
|
|
1992
2079
|
* TODO: generalize for ellipses (two radii).
|
|
1993
2080
|
*
|
|
1994
2081
|
* @param {number} angle - The angle in radians.
|
|
1995
|
-
|
|
2082
|
+
*/
|
|
1996
2083
|
polarToCartesian: function (centerX, centerY, radius, angle) {
|
|
1997
2084
|
return {
|
|
1998
|
-
x: centerX +
|
|
1999
|
-
y: centerY +
|
|
2085
|
+
x: centerX + radius * Math.cos(angle),
|
|
2086
|
+
y: centerY + radius * Math.sin(angle)
|
|
2000
2087
|
};
|
|
2001
2088
|
},
|
|
2002
2089
|
/**
|
|
@@ -2009,7 +2096,7 @@ var CircleSector = /** @class */ (function () {
|
|
|
2009
2096
|
* @return [ 'A', radiusx, radiusy, rotation=0, largeArcFlag=1|0, sweepFlag=0, endx, endy ]
|
|
2010
2097
|
*/
|
|
2011
2098
|
describeSVGArc: function (x, y, radius, startAngle, endAngle, options) {
|
|
2012
|
-
if (typeof options ===
|
|
2099
|
+
if (typeof options === "undefined")
|
|
2013
2100
|
options = { moveToStart: true };
|
|
2014
2101
|
var end = CircleSector.circleSectorUtils.polarToCartesian(x, y, radius, endAngle);
|
|
2015
2102
|
var start = CircleSector.circleSectorUtils.polarToCartesian(x, y, radius, startAngle);
|
|
@@ -2034,7 +2121,7 @@ var CircleSector = /** @class */ (function () {
|
|
|
2034
2121
|
}
|
|
2035
2122
|
var pathData = [];
|
|
2036
2123
|
if (options.moveToStart) {
|
|
2037
|
-
pathData.push(
|
|
2124
|
+
pathData.push("M", start.x, start.y);
|
|
2038
2125
|
}
|
|
2039
2126
|
pathData.push("A", radius, radius, 0, largeArcFlag, sweepFlag, end.x, end.y);
|
|
2040
2127
|
return pathData;
|
|
@@ -2071,7 +2158,9 @@ exports.CircleSector = CircleSector;
|
|
|
2071
2158
|
* @modified 2020-07-14 Changed the moveCurvePoint(...,Vertex) to moveCurvePoint(...,XYCoords), which is more generic.
|
|
2072
2159
|
* @modified 2020-07-24 Added the getClosestT function and the helper function locateIntervalByDistance(...).
|
|
2073
2160
|
* @modified 2021-01-20 Added UID.
|
|
2074
|
-
* @
|
|
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
|
|
2075
2164
|
*
|
|
2076
2165
|
* @file CubicBezierCurve
|
|
2077
2166
|
* @public
|
|
@@ -2126,7 +2215,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2126
2215
|
this.arcLength = null;
|
|
2127
2216
|
this.updateArcLengths();
|
|
2128
2217
|
}
|
|
2129
|
-
;
|
|
2130
2218
|
/**
|
|
2131
2219
|
* Move the given curve point (the start point, end point or one of the two
|
|
2132
2220
|
* control points).
|
|
@@ -2163,7 +2251,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2163
2251
|
if (updateArcLengths)
|
|
2164
2252
|
this.updateArcLengths();
|
|
2165
2253
|
};
|
|
2166
|
-
;
|
|
2167
2254
|
/**
|
|
2168
2255
|
* Translate the whole curve by the given {x,y} amount: moves all four points.
|
|
2169
2256
|
*
|
|
@@ -2180,7 +2267,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2180
2267
|
this.endPoint.add(amount);
|
|
2181
2268
|
return this;
|
|
2182
2269
|
};
|
|
2183
|
-
;
|
|
2184
2270
|
/**
|
|
2185
2271
|
* Reverse this curve, means swapping start- and end-point and swapping
|
|
2186
2272
|
* start-control- and end-control-point.
|
|
@@ -2199,7 +2285,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2199
2285
|
this.endControlPoint = tmp;
|
|
2200
2286
|
return this;
|
|
2201
2287
|
};
|
|
2202
|
-
;
|
|
2203
2288
|
/**
|
|
2204
2289
|
* Get the total curve length.<br>
|
|
2205
2290
|
* <br>
|
|
@@ -2218,7 +2303,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2218
2303
|
CubicBezierCurve.prototype.getLength = function () {
|
|
2219
2304
|
return this.arcLength;
|
|
2220
2305
|
};
|
|
2221
|
-
;
|
|
2222
2306
|
/**
|
|
2223
2307
|
* Uptate the internal arc segment buffer and their lengths.<br>
|
|
2224
2308
|
* <br>
|
|
@@ -2256,7 +2340,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2256
2340
|
}
|
|
2257
2341
|
this.arcLength = newLength;
|
|
2258
2342
|
};
|
|
2259
|
-
;
|
|
2260
2343
|
/**
|
|
2261
2344
|
* Get a 't' (relative position on curve) with the closest distance to point 'p'.
|
|
2262
2345
|
*
|
|
@@ -2279,7 +2362,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2279
2362
|
} while (iteration < 4 && this.getPointAt(result.tPrev).distance(this.getPointAt(result.tNext)) > desiredEpsilon);
|
|
2280
2363
|
return result.t;
|
|
2281
2364
|
};
|
|
2282
|
-
;
|
|
2283
2365
|
/**
|
|
2284
2366
|
* This helper function locates the 't' on a fixed step interval with the minimal distance
|
|
2285
2367
|
* between the curve (at 't') and the given point.
|
|
@@ -2308,12 +2390,12 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2308
2390
|
minDist = dist;
|
|
2309
2391
|
}
|
|
2310
2392
|
}
|
|
2311
|
-
return {
|
|
2393
|
+
return {
|
|
2394
|
+
t: tStart + tDiff * (minIndex / stepCount),
|
|
2312
2395
|
tPrev: tStart + tDiff * (Math.max(0, minIndex - 1) / stepCount),
|
|
2313
2396
|
tNext: tStart + tDiff * (Math.min(stepCount, minIndex + 1) / stepCount)
|
|
2314
2397
|
};
|
|
2315
2398
|
};
|
|
2316
|
-
;
|
|
2317
2399
|
/**
|
|
2318
2400
|
* Get the bounds of this bezier curve.
|
|
2319
2401
|
*
|
|
@@ -2335,7 +2417,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2335
2417
|
}
|
|
2336
2418
|
return new Bounds_1.Bounds(min, max);
|
|
2337
2419
|
};
|
|
2338
|
-
;
|
|
2339
2420
|
/**
|
|
2340
2421
|
* Get the start point of the curve.<br>
|
|
2341
2422
|
* <br>
|
|
@@ -2349,7 +2430,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2349
2430
|
CubicBezierCurve.prototype.getStartPoint = function () {
|
|
2350
2431
|
return this.startPoint;
|
|
2351
2432
|
};
|
|
2352
|
-
;
|
|
2353
2433
|
/**
|
|
2354
2434
|
* Get the end point of the curve.<br>
|
|
2355
2435
|
* <br>
|
|
@@ -2363,7 +2443,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2363
2443
|
CubicBezierCurve.prototype.getEndPoint = function () {
|
|
2364
2444
|
return this.endPoint;
|
|
2365
2445
|
};
|
|
2366
|
-
;
|
|
2367
2446
|
/**
|
|
2368
2447
|
* Get the start control point of the curve.<br>
|
|
2369
2448
|
* <br>
|
|
@@ -2377,7 +2456,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2377
2456
|
CubicBezierCurve.prototype.getStartControlPoint = function () {
|
|
2378
2457
|
return this.startControlPoint;
|
|
2379
2458
|
};
|
|
2380
|
-
;
|
|
2381
2459
|
/**
|
|
2382
2460
|
* Get the end control point of the curve.<br>
|
|
2383
2461
|
* <br>
|
|
@@ -2391,7 +2469,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2391
2469
|
CubicBezierCurve.prototype.getEndControlPoint = function () {
|
|
2392
2470
|
return this.endControlPoint;
|
|
2393
2471
|
};
|
|
2394
|
-
;
|
|
2395
2472
|
/**
|
|
2396
2473
|
* Get one of the four curve points specified by the passt point ID.
|
|
2397
2474
|
*
|
|
@@ -2412,7 +2489,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2412
2489
|
return this.endControlPoint;
|
|
2413
2490
|
throw new Error("Invalid point ID '" + id + "'.");
|
|
2414
2491
|
};
|
|
2415
|
-
;
|
|
2416
2492
|
/**
|
|
2417
2493
|
* Get the curve point at a given position t, where t is in [0,1].<br>
|
|
2418
2494
|
* <br>
|
|
@@ -2427,13 +2503,16 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2427
2503
|
**/
|
|
2428
2504
|
CubicBezierCurve.prototype.getPointAt = function (t) {
|
|
2429
2505
|
// Perform some powerful math magic
|
|
2430
|
-
var x = this.startPoint.x * Math.pow(1.0 - t, 3) +
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
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);
|
|
2434
2514
|
return new Vertex_1.Vertex(x, y);
|
|
2435
2515
|
};
|
|
2436
|
-
;
|
|
2437
2516
|
/**
|
|
2438
2517
|
* Get the curve point at a given position u, where u is in [0,arcLength].<br>
|
|
2439
2518
|
* <br>
|
|
@@ -2449,7 +2528,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2449
2528
|
CubicBezierCurve.prototype.getPoint = function (u) {
|
|
2450
2529
|
return this.getPointAt(u / this.arcLength);
|
|
2451
2530
|
};
|
|
2452
|
-
;
|
|
2453
2531
|
/**
|
|
2454
2532
|
* Get the curve tangent vector at a given absolute curve position t in [0,1].<br>
|
|
2455
2533
|
* <br>
|
|
@@ -2470,18 +2548,11 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2470
2548
|
var t2 = t * t;
|
|
2471
2549
|
// (1 - t)^2 = (1-t)*(1-t) = 1 - t - t + t^2 = 1 - 2*t + t^2
|
|
2472
2550
|
var nt2 = 1 - 2 * t + t2;
|
|
2473
|
-
var tX = -3 * a.x * nt2 +
|
|
2474
|
-
|
|
2475
|
-
c.x * (6 * (t - t2) - 3 * t2) +
|
|
2476
|
-
3 * d.x * t2;
|
|
2477
|
-
var tY = -3 * a.y * nt2 +
|
|
2478
|
-
b.y * (3 * nt2 - 6 * (t - t2)) +
|
|
2479
|
-
c.y * (6 * (t - t2) - 3 * t2) +
|
|
2480
|
-
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;
|
|
2481
2553
|
// Note: my implementation does NOT normalize tangent vectors!
|
|
2482
2554
|
return new Vertex_1.Vertex(tX, tY);
|
|
2483
2555
|
};
|
|
2484
|
-
;
|
|
2485
2556
|
/**
|
|
2486
2557
|
* Get a sub curve at the given start end end offsets (values between 0.0 and 1.0).
|
|
2487
2558
|
*
|
|
@@ -2507,7 +2578,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2507
2578
|
// pb.draw.cubicBezier( startVec.a, endVec.a, startVec.b, endVec.b, '#8800ff', 2 );
|
|
2508
2579
|
return new CubicBezierCurve(startVec.a, endVec.a, startVec.b, endVec.b);
|
|
2509
2580
|
};
|
|
2510
|
-
;
|
|
2511
2581
|
/**
|
|
2512
2582
|
* Convert a relative curve position u to the absolute curve position t.
|
|
2513
2583
|
*
|
|
@@ -2518,9 +2588,8 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2518
2588
|
* @return {number}
|
|
2519
2589
|
**/
|
|
2520
2590
|
CubicBezierCurve.prototype.convertU2T = function (u) {
|
|
2521
|
-
return Math.max(0.0, Math.min(1.0,
|
|
2591
|
+
return Math.max(0.0, Math.min(1.0, u / this.arcLength));
|
|
2522
2592
|
};
|
|
2523
|
-
;
|
|
2524
2593
|
/**
|
|
2525
2594
|
* Get the curve tangent vector at a given relative position u in [0,arcLength].<br>
|
|
2526
2595
|
* <br>
|
|
@@ -2535,7 +2604,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2535
2604
|
CubicBezierCurve.prototype.getTangent = function (u) {
|
|
2536
2605
|
return this.getTangentAt(this.convertU2T(u));
|
|
2537
2606
|
};
|
|
2538
|
-
;
|
|
2539
2607
|
/**
|
|
2540
2608
|
* Get the curve perpendicular at a given relative position u in [0,arcLength] as a vector.<br>
|
|
2541
2609
|
* <br>
|
|
@@ -2550,7 +2618,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2550
2618
|
CubicBezierCurve.prototype.getPerpendicular = function (u) {
|
|
2551
2619
|
return this.getPerpendicularAt(this.convertU2T(u));
|
|
2552
2620
|
};
|
|
2553
|
-
;
|
|
2554
2621
|
/**
|
|
2555
2622
|
* Get the curve perpendicular at a given absolute position t in [0,1] as a vector.<br>
|
|
2556
2623
|
* <br>
|
|
@@ -2566,7 +2633,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2566
2633
|
var tangentVector = this.getTangentAt(t);
|
|
2567
2634
|
return new Vertex_1.Vertex(tangentVector.y, -tangentVector.x);
|
|
2568
2635
|
};
|
|
2569
|
-
;
|
|
2570
2636
|
/**
|
|
2571
2637
|
* Clone this Bézier curve (deep clone).
|
|
2572
2638
|
*
|
|
@@ -2578,7 +2644,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2578
2644
|
CubicBezierCurve.prototype.clone = function () {
|
|
2579
2645
|
return new CubicBezierCurve(this.getStartPoint().clone(), this.getEndPoint().clone(), this.getStartControlPoint().clone(), this.getEndControlPoint().clone());
|
|
2580
2646
|
};
|
|
2581
|
-
;
|
|
2582
2647
|
/**
|
|
2583
2648
|
* Check if this and the specified curve are equal.<br>
|
|
2584
2649
|
* <br>
|
|
@@ -2597,17 +2662,25 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2597
2662
|
// Let's see if this restricted version works out.
|
|
2598
2663
|
if (!curve)
|
|
2599
2664
|
return false;
|
|
2600
|
-
if (!curve.startPoint ||
|
|
2601
|
-
!curve.endPoint ||
|
|
2602
|
-
!curve.startControlPoint ||
|
|
2603
|
-
!curve.endControlPoint)
|
|
2665
|
+
if (!curve.startPoint || !curve.endPoint || !curve.startControlPoint || !curve.endControlPoint)
|
|
2604
2666
|
return false;
|
|
2605
|
-
return this.startPoint.equals(curve.startPoint)
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
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;
|
|
2609
2683
|
};
|
|
2610
|
-
;
|
|
2611
2684
|
/**
|
|
2612
2685
|
* Quick check for class instance.
|
|
2613
2686
|
* Is there a better way?
|
|
@@ -2633,7 +2706,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2633
2706
|
*/
|
|
2634
2707
|
return obj instanceof CubicBezierCurve;
|
|
2635
2708
|
};
|
|
2636
|
-
;
|
|
2637
2709
|
/**
|
|
2638
2710
|
* Create an SVG path data representation of this bézier curve.
|
|
2639
2711
|
*
|
|
@@ -2642,32 +2714,34 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2642
2714
|
* or in other words<br>
|
|
2643
2715
|
* <pre>'M startoint.x startPoint.y C startControlPoint.x startControlPoint.y endControlPoint.x endControlPoint.y endPoint.x endPoint.y'</pre>
|
|
2644
2716
|
*
|
|
2717
|
+
* @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
|
|
2645
2718
|
* @method toSVGPathData
|
|
2646
2719
|
* @instance
|
|
2647
2720
|
* @memberof CubicBezierCurve
|
|
2648
2721
|
* @return {string} The SVG path data string.
|
|
2649
2722
|
**/
|
|
2650
2723
|
CubicBezierCurve.prototype.toSVGPathData = function () {
|
|
2651
|
-
var buffer = [];
|
|
2652
|
-
buffer.push(
|
|
2653
|
-
buffer.push(this.startPoint.x.toString());
|
|
2654
|
-
buffer.push(
|
|
2655
|
-
buffer.push(this.startPoint.y.toString());
|
|
2656
|
-
buffer.push(
|
|
2657
|
-
buffer.push(this.startControlPoint.x.toString());
|
|
2658
|
-
buffer.push(
|
|
2659
|
-
buffer.push(this.startControlPoint.y.toString());
|
|
2660
|
-
buffer.push(
|
|
2661
|
-
buffer.push(this.endControlPoint.x.toString());
|
|
2662
|
-
buffer.push(
|
|
2663
|
-
buffer.push(this.endControlPoint.y.toString());
|
|
2664
|
-
buffer.push(
|
|
2665
|
-
buffer.push(this.endPoint.x.toString());
|
|
2666
|
-
buffer.push(
|
|
2667
|
-
buffer.push(this.endPoint.y.toString());
|
|
2668
|
-
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 "";
|
|
2669
2744
|
};
|
|
2670
|
-
;
|
|
2671
2745
|
/**
|
|
2672
2746
|
* Convert this curve to a JSON string.
|
|
2673
2747
|
*
|
|
@@ -2680,18 +2754,33 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2680
2754
|
CubicBezierCurve.prototype.toJSON = function (prettyFormat) {
|
|
2681
2755
|
var jsonString = "{ " + // begin object
|
|
2682
2756
|
(prettyFormat ? "\n\t" : "") +
|
|
2683
|
-
"
|
|
2757
|
+
'"startPoint" : [' +
|
|
2758
|
+
this.getStartPoint().x +
|
|
2759
|
+
"," +
|
|
2760
|
+
this.getStartPoint().y +
|
|
2761
|
+
"], " +
|
|
2684
2762
|
(prettyFormat ? "\n\t" : "") +
|
|
2685
|
-
"
|
|
2763
|
+
'"endPoint" : [' +
|
|
2764
|
+
this.getEndPoint().x +
|
|
2765
|
+
"," +
|
|
2766
|
+
this.getEndPoint().y +
|
|
2767
|
+
"], " +
|
|
2686
2768
|
(prettyFormat ? "\n\t" : "") +
|
|
2687
|
-
"
|
|
2769
|
+
'"startControlPoint": [' +
|
|
2770
|
+
this.getStartControlPoint().x +
|
|
2771
|
+
"," +
|
|
2772
|
+
this.getStartControlPoint().y +
|
|
2773
|
+
"], " +
|
|
2688
2774
|
(prettyFormat ? "\n\t" : "") +
|
|
2689
|
-
"
|
|
2775
|
+
'"endControlPoint" : [' +
|
|
2776
|
+
this.getEndControlPoint().x +
|
|
2777
|
+
"," +
|
|
2778
|
+
this.getEndControlPoint().y +
|
|
2779
|
+
"]" +
|
|
2690
2780
|
(prettyFormat ? "\n\t" : "") +
|
|
2691
2781
|
" }"; // end object
|
|
2692
2782
|
return jsonString;
|
|
2693
2783
|
};
|
|
2694
|
-
;
|
|
2695
2784
|
/**
|
|
2696
2785
|
* Parse a Bézier curve from the given JSON string.
|
|
2697
2786
|
*
|
|
@@ -2706,7 +2795,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2706
2795
|
var obj = JSON.parse(jsonString);
|
|
2707
2796
|
return CubicBezierCurve.fromObject(obj);
|
|
2708
2797
|
};
|
|
2709
|
-
;
|
|
2710
2798
|
/**
|
|
2711
2799
|
* Try to convert the passed object to a CubicBezierCurve.
|
|
2712
2800
|
*
|
|
@@ -2721,16 +2809,15 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2721
2809
|
if (typeof obj !== "object")
|
|
2722
2810
|
throw "Can only build from object.";
|
|
2723
2811
|
if (!obj.startPoint)
|
|
2724
|
-
throw
|
|
2812
|
+
throw 'Object member "startPoint" missing.';
|
|
2725
2813
|
if (!obj.endPoint)
|
|
2726
|
-
throw
|
|
2814
|
+
throw 'Object member "endPoint" missing.';
|
|
2727
2815
|
if (!obj.startControlPoint)
|
|
2728
|
-
throw
|
|
2816
|
+
throw 'Object member "startControlPoint" missing.';
|
|
2729
2817
|
if (!obj.endControlPoint)
|
|
2730
|
-
throw
|
|
2818
|
+
throw 'Object member "endControlPoint" missing.';
|
|
2731
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]));
|
|
2732
2820
|
};
|
|
2733
|
-
;
|
|
2734
2821
|
/**
|
|
2735
2822
|
* Convert a 4-element array of vertices to a cubic bézier curve.
|
|
2736
2823
|
*
|
|
@@ -2747,7 +2834,6 @@ var CubicBezierCurve = /** @class */ (function () {
|
|
|
2747
2834
|
throw "Can only build from array with four elements.";
|
|
2748
2835
|
return new CubicBezierCurve(arr[0], arr[1], arr[2], arr[3]);
|
|
2749
2836
|
};
|
|
2750
|
-
;
|
|
2751
2837
|
/** @constant {number} */
|
|
2752
2838
|
CubicBezierCurve.START_POINT = 0;
|
|
2753
2839
|
/** @constant {number} */
|
|
@@ -2870,7 +2956,8 @@ exports.Grid = Grid;
|
|
|
2870
2956
|
* @modified 2020-07-28 Changed the `delete` key code from 8 to 46.
|
|
2871
2957
|
* @modified 2020-10-04 Changed `window` to `globalThis`.
|
|
2872
2958
|
* @modified 2020-10-04 Added extended JSDoc.
|
|
2873
|
-
* @
|
|
2959
|
+
* @modified 2022-02-02 Added the `destroy` method.
|
|
2960
|
+
* @version 1.1.0
|
|
2874
2961
|
*
|
|
2875
2962
|
* @file KeyHandler
|
|
2876
2963
|
* @public
|
|
@@ -2903,7 +2990,7 @@ var KeyHandler = /** @class */ (function () {
|
|
|
2903
2990
|
* @memberof KeyHandler
|
|
2904
2991
|
* @param {HTMLElement} options.element (optional) The HTML element to listen on; if null then 'window' will be used.
|
|
2905
2992
|
* @param {boolean} options.trackAll (optional) Set to true if you want to keep track of _all_ keys (keyStatus).
|
|
2906
|
-
|
|
2993
|
+
**/
|
|
2907
2994
|
function KeyHandler(options) {
|
|
2908
2995
|
this.downListeners = [];
|
|
2909
2996
|
this.pressListeners = [];
|
|
@@ -2922,7 +3009,6 @@ var KeyHandler = /** @class */ (function () {
|
|
|
2922
3009
|
// Install the listeners
|
|
2923
3010
|
this.installListeners();
|
|
2924
3011
|
}
|
|
2925
|
-
;
|
|
2926
3012
|
/**
|
|
2927
3013
|
* A helper function to fire key events from this KeyHandler.
|
|
2928
3014
|
*
|
|
@@ -2940,7 +3026,6 @@ var KeyHandler = /** @class */ (function () {
|
|
|
2940
3026
|
}
|
|
2941
3027
|
return hasListener;
|
|
2942
3028
|
};
|
|
2943
|
-
;
|
|
2944
3029
|
/**
|
|
2945
3030
|
* Internal function to fire a new keydown event to all listeners.
|
|
2946
3031
|
* You should not call this function on your own unless you know what you do.
|
|
@@ -2956,10 +3041,9 @@ var KeyHandler = /** @class */ (function () {
|
|
|
2956
3041
|
KeyHandler.prototype.fireDownEvent = function (e, handler) {
|
|
2957
3042
|
if (handler.fireEvent(e, handler.downListeners) || handler.trackAllKeys) {
|
|
2958
3043
|
// Down event has listeners. Update key state.
|
|
2959
|
-
handler.keyStates[e.keyCode] =
|
|
3044
|
+
handler.keyStates[e.keyCode] = "down";
|
|
2960
3045
|
}
|
|
2961
3046
|
};
|
|
2962
|
-
;
|
|
2963
3047
|
/**
|
|
2964
3048
|
* Internal function to fire a new keypress event to all listeners.
|
|
2965
3049
|
* You should not call this function on your own unless you know what you do.
|
|
@@ -2975,7 +3059,6 @@ var KeyHandler = /** @class */ (function () {
|
|
|
2975
3059
|
KeyHandler.prototype.firePressEvent = function (e, handler) {
|
|
2976
3060
|
handler.fireEvent(e, handler.pressListeners);
|
|
2977
3061
|
};
|
|
2978
|
-
;
|
|
2979
3062
|
/**
|
|
2980
3063
|
* Internal function to fire a new keyup event to all listeners.
|
|
2981
3064
|
* You should not call this function on your own unless you know what you do.
|
|
@@ -2994,20 +3077,18 @@ var KeyHandler = /** @class */ (function () {
|
|
|
2994
3077
|
delete handler.keyStates[e.keyCode];
|
|
2995
3078
|
}
|
|
2996
3079
|
};
|
|
2997
|
-
;
|
|
2998
3080
|
/**
|
|
2999
3081
|
* Resolve the key/name code.
|
|
3000
3082
|
*/
|
|
3001
3083
|
KeyHandler.key2code = function (key) {
|
|
3002
|
-
if (typeof key ==
|
|
3084
|
+
if (typeof key == "number")
|
|
3003
3085
|
return key;
|
|
3004
|
-
if (typeof key !=
|
|
3086
|
+
if (typeof key != "string")
|
|
3005
3087
|
throw "Unknown key name or key type (should be a string or integer): " + key;
|
|
3006
3088
|
if (KeyHandler.KEY_CODES[key])
|
|
3007
3089
|
return KeyHandler.KEY_CODES[key];
|
|
3008
3090
|
throw "Unknown key (cannot resolve key code): " + key;
|
|
3009
3091
|
};
|
|
3010
|
-
;
|
|
3011
3092
|
/**
|
|
3012
3093
|
* Install the required listeners into the initially passed element.
|
|
3013
3094
|
*
|
|
@@ -3016,20 +3097,24 @@ var KeyHandler = /** @class */ (function () {
|
|
|
3016
3097
|
*/
|
|
3017
3098
|
KeyHandler.prototype.installListeners = function () {
|
|
3018
3099
|
var _self = this;
|
|
3019
|
-
this.element.addEventListener(
|
|
3020
|
-
|
|
3021
|
-
|
|
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
|
+
}));
|
|
3022
3109
|
};
|
|
3023
|
-
;
|
|
3024
3110
|
/**
|
|
3025
3111
|
* Remove all installed event listeners from the underlying element.
|
|
3026
3112
|
*/
|
|
3027
3113
|
KeyHandler.prototype.releaseListeners = function () {
|
|
3028
|
-
this.element.removeEventListener(
|
|
3029
|
-
this.element.removeEventListener(
|
|
3030
|
-
this.element.removeEventListener(
|
|
3114
|
+
this.element.removeEventListener("keydown", this._keyDownListener);
|
|
3115
|
+
this.element.removeEventListener("keypress", this._keyPressListener);
|
|
3116
|
+
this.element.removeEventListener("keyup", this._keyUpListener);
|
|
3031
3117
|
};
|
|
3032
|
-
;
|
|
3033
3118
|
/**
|
|
3034
3119
|
* Listen for key down. This function allows chaining.
|
|
3035
3120
|
*
|
|
@@ -3046,7 +3131,6 @@ var KeyHandler = /** @class */ (function () {
|
|
|
3046
3131
|
this.downListeners.push({ key: key, keyCode: KeyHandler.key2code(key), listener: listener });
|
|
3047
3132
|
return this;
|
|
3048
3133
|
};
|
|
3049
|
-
;
|
|
3050
3134
|
/**
|
|
3051
3135
|
* Listen for key press.
|
|
3052
3136
|
*
|
|
@@ -3063,7 +3147,6 @@ var KeyHandler = /** @class */ (function () {
|
|
|
3063
3147
|
this.pressListeners.push({ key: key, keyCode: KeyHandler.key2code(key), listener: listener });
|
|
3064
3148
|
return this;
|
|
3065
3149
|
};
|
|
3066
|
-
;
|
|
3067
3150
|
/**
|
|
3068
3151
|
* Listen for key up.
|
|
3069
3152
|
*
|
|
@@ -3080,22 +3163,30 @@ var KeyHandler = /** @class */ (function () {
|
|
|
3080
3163
|
this.upListeners.push({ key: key, keyCode: KeyHandler.key2code(key), listener: listener });
|
|
3081
3164
|
return this;
|
|
3082
3165
|
};
|
|
3083
|
-
;
|
|
3084
3166
|
/**
|
|
3085
3167
|
* Check if a specific key is currently held pressed.
|
|
3086
3168
|
*
|
|
3087
3169
|
* @param {string|number} key - Any key identifier, key code or one from the KEY_CODES list.
|
|
3088
3170
|
*/
|
|
3089
3171
|
KeyHandler.prototype.isDown = function (key) {
|
|
3090
|
-
if (typeof key ==
|
|
3172
|
+
if (typeof key == "number")
|
|
3091
3173
|
return this.keyStates[key] ? true : false;
|
|
3092
3174
|
else
|
|
3093
3175
|
return this.keyStates[KeyHandler.key2code(key)] ? true : false;
|
|
3094
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
|
+
};
|
|
3095
3185
|
/**
|
|
3096
3186
|
* Source:
|
|
3097
3187
|
* https://keycode.info/
|
|
3098
3188
|
*/
|
|
3189
|
+
// prettier-ignore
|
|
3099
3190
|
KeyHandler.KEY_CODES = {
|
|
3100
3191
|
'break': 3,
|
|
3101
3192
|
'backspace': 8,
|
|
@@ -3313,7 +3404,8 @@ exports.KeyHandler = KeyHandler;
|
|
|
3313
3404
|
* @modified 2020-03-16 The Line.angle(Line) parameter is now optional. The baseline (x-axis) will be used if not defined.
|
|
3314
3405
|
* @modified 2020-03-23 Ported to Typescript from JS.
|
|
3315
3406
|
* @modified 2020-12-04 The `intersection` function returns undefined if both lines are parallel.
|
|
3316
|
-
* @
|
|
3407
|
+
* @modified 2022-02-02 Added the `destroy` method.
|
|
3408
|
+
* @version 2.2.0
|
|
3317
3409
|
*
|
|
3318
3410
|
* @file Line
|
|
3319
3411
|
* @public
|
|
@@ -3377,20 +3469,19 @@ var Line = /** @class */ (function (_super) {
|
|
|
3377
3469
|
return null;
|
|
3378
3470
|
var a = this.a.y - line.a.y;
|
|
3379
3471
|
var b = this.a.x - line.a.x;
|
|
3380
|
-
var numerator1 = (
|
|
3381
|
-
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;
|
|
3382
3474
|
a = numerator1 / denominator; // NaN if parallel lines
|
|
3383
3475
|
b = numerator2 / denominator;
|
|
3384
3476
|
// Catch NaN?
|
|
3385
|
-
var x = this.a.x +
|
|
3386
|
-
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);
|
|
3387
3479
|
if (isNaN(a) || isNaN(x) || isNaN(y)) {
|
|
3388
3480
|
return undefined;
|
|
3389
3481
|
}
|
|
3390
3482
|
// if we cast these lines infinitely in both directions, they intersect here:
|
|
3391
3483
|
return new Vertex_1.Vertex(x, y);
|
|
3392
3484
|
};
|
|
3393
|
-
;
|
|
3394
3485
|
/**
|
|
3395
3486
|
* Create an SVG representation of this line.
|
|
3396
3487
|
*
|
|
@@ -3403,19 +3494,20 @@ var Line = /** @class */ (function (_super) {
|
|
|
3403
3494
|
* @memberof Line
|
|
3404
3495
|
**/
|
|
3405
3496
|
Line.prototype.toSVGString = function (options) {
|
|
3406
|
-
options = options || {};
|
|
3407
|
-
var buffer = [];
|
|
3408
|
-
buffer.push('<line');
|
|
3409
|
-
if
|
|
3410
|
-
|
|
3411
|
-
buffer.push(' x1="' + this.a.x + '"');
|
|
3412
|
-
buffer.push(' y1="' + this.a.y + '"');
|
|
3413
|
-
buffer.push(' x2="' + this.b.x + '"');
|
|
3414
|
-
buffer.push(' y2="' + this.b.y + '"');
|
|
3415
|
-
buffer.push(' />');
|
|
3416
|
-
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 "";
|
|
3417
3510
|
};
|
|
3418
|
-
;
|
|
3419
3511
|
return Line;
|
|
3420
3512
|
}(VertTuple_1.VertTuple));
|
|
3421
3513
|
exports.Line = Line;
|
|
@@ -3577,41 +3669,41 @@ var MouseHandler = /** @class */ (function () {
|
|
|
3577
3669
|
// | drag offset, ...) to the callbacks.
|
|
3578
3670
|
// +-------------------------------------------------
|
|
3579
3671
|
var _self = this;
|
|
3580
|
-
this.handlers[
|
|
3672
|
+
this.handlers["mousemove"] = function (e) {
|
|
3581
3673
|
if (_self.listeners.mousemove)
|
|
3582
|
-
_self.listeners.mousemove(_self.mkParams(e,
|
|
3674
|
+
_self.listeners.mousemove(_self.mkParams(e, "mousemove"));
|
|
3583
3675
|
if (_self.mouseDragPos && _self.listeners.drag)
|
|
3584
|
-
_self.listeners.drag(_self.mkParams(e,
|
|
3676
|
+
_self.listeners.drag(_self.mkParams(e, "drag"));
|
|
3585
3677
|
if (_self.mouseDownPos)
|
|
3586
3678
|
_self.mouseDragPos = _self.relPos(e);
|
|
3587
3679
|
};
|
|
3588
|
-
this.handlers[
|
|
3680
|
+
this.handlers["mouseup"] = function (e) {
|
|
3589
3681
|
if (_self.listeners.mouseup)
|
|
3590
|
-
_self.listeners.mouseup(_self.mkParams(e,
|
|
3682
|
+
_self.listeners.mouseup(_self.mkParams(e, "mouseup"));
|
|
3591
3683
|
_self.mouseDragPos = undefined;
|
|
3592
3684
|
_self.mouseDownPos = undefined;
|
|
3593
3685
|
_self.mouseButton = -1;
|
|
3594
3686
|
};
|
|
3595
|
-
this.handlers[
|
|
3687
|
+
this.handlers["mousedown"] = function (e) {
|
|
3596
3688
|
_self.mouseDragPos = _self.relPos(e);
|
|
3597
3689
|
_self.mouseDownPos = _self.relPos(e);
|
|
3598
3690
|
_self.mouseButton = e.button;
|
|
3599
3691
|
if (_self.listeners.mousedown)
|
|
3600
|
-
_self.listeners.mousedown(_self.mkParams(e,
|
|
3692
|
+
_self.listeners.mousedown(_self.mkParams(e, "mousedown"));
|
|
3601
3693
|
};
|
|
3602
|
-
this.handlers[
|
|
3694
|
+
this.handlers["click"] = function (e) {
|
|
3603
3695
|
if (_self.listeners.click)
|
|
3604
|
-
_self.listeners.click(_self.mkParams(e,
|
|
3696
|
+
_self.listeners.click(_self.mkParams(e, "click"));
|
|
3605
3697
|
};
|
|
3606
|
-
this.handlers[
|
|
3698
|
+
this.handlers["wheel"] = function (e) {
|
|
3607
3699
|
if (_self.listeners.wheel)
|
|
3608
|
-
_self.listeners.wheel(_self.mkParams(e,
|
|
3700
|
+
_self.listeners.wheel(_self.mkParams(e, "wheel"));
|
|
3609
3701
|
};
|
|
3610
|
-
this.element.addEventListener(
|
|
3611
|
-
this.element.addEventListener(
|
|
3612
|
-
this.element.addEventListener(
|
|
3613
|
-
this.element.addEventListener(
|
|
3614
|
-
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"]);
|
|
3615
3707
|
}
|
|
3616
3708
|
/**
|
|
3617
3709
|
* Get relative position from the given MouseEvent.
|
|
@@ -3624,11 +3716,8 @@ var MouseHandler = /** @class */ (function () {
|
|
|
3624
3716
|
* @return {XYCoords} The relative mouse coordinates.
|
|
3625
3717
|
*/
|
|
3626
3718
|
MouseHandler.prototype.relPos = function (e) {
|
|
3627
|
-
return { x: e.offsetX,
|
|
3628
|
-
y: e.offsetY
|
|
3629
|
-
};
|
|
3719
|
+
return { x: e.offsetX, y: e.offsetY };
|
|
3630
3720
|
};
|
|
3631
|
-
;
|
|
3632
3721
|
/**
|
|
3633
3722
|
* Build the extended event params.
|
|
3634
3723
|
*
|
|
@@ -3654,8 +3743,8 @@ var MouseHandler = /** @class */ (function () {
|
|
|
3654
3743
|
rightButton: this.mouseButton == 2,
|
|
3655
3744
|
mouseDownPos: this.mouseDownPos,
|
|
3656
3745
|
draggedFrom: this.mouseDragPos,
|
|
3657
|
-
wasDragged:
|
|
3658
|
-
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 }
|
|
3659
3748
|
};
|
|
3660
3749
|
return xEvent;
|
|
3661
3750
|
};
|
|
@@ -3706,14 +3795,13 @@ var MouseHandler = /** @class */ (function () {
|
|
|
3706
3795
|
*/
|
|
3707
3796
|
MouseHandler.prototype.drag = function (callback) {
|
|
3708
3797
|
if (this.listeners.drag)
|
|
3709
|
-
this.throwAlreadyInstalled(
|
|
3798
|
+
this.throwAlreadyInstalled("drag");
|
|
3710
3799
|
this.listeners.drag = callback;
|
|
3711
|
-
this.listenFor(
|
|
3712
|
-
this.listenFor(
|
|
3713
|
-
this.listenFor(
|
|
3800
|
+
this.listenFor("mousedown");
|
|
3801
|
+
this.listenFor("mousemove");
|
|
3802
|
+
this.listenFor("mouseup");
|
|
3714
3803
|
return this;
|
|
3715
3804
|
};
|
|
3716
|
-
;
|
|
3717
3805
|
/**
|
|
3718
3806
|
* Installer function to listen for a specific event: mouse-move.
|
|
3719
3807
|
* Pass your callbacks here.
|
|
@@ -3728,12 +3816,11 @@ var MouseHandler = /** @class */ (function () {
|
|
|
3728
3816
|
*/
|
|
3729
3817
|
MouseHandler.prototype.move = function (callback) {
|
|
3730
3818
|
if (this.listeners.mousemove)
|
|
3731
|
-
this.throwAlreadyInstalled(
|
|
3732
|
-
this.listenFor(
|
|
3819
|
+
this.throwAlreadyInstalled("mousemove");
|
|
3820
|
+
this.listenFor("mousemove");
|
|
3733
3821
|
this.listeners.mousemove = callback;
|
|
3734
3822
|
return this;
|
|
3735
3823
|
};
|
|
3736
|
-
;
|
|
3737
3824
|
/**
|
|
3738
3825
|
* Installer function to listen for a specific event: mouse-up.
|
|
3739
3826
|
* Pass your callbacks here.
|
|
@@ -3748,12 +3835,11 @@ var MouseHandler = /** @class */ (function () {
|
|
|
3748
3835
|
*/
|
|
3749
3836
|
MouseHandler.prototype.up = function (callback) {
|
|
3750
3837
|
if (this.listeners.mouseup)
|
|
3751
|
-
this.throwAlreadyInstalled(
|
|
3752
|
-
this.listenFor(
|
|
3838
|
+
this.throwAlreadyInstalled("mouseup");
|
|
3839
|
+
this.listenFor("mouseup");
|
|
3753
3840
|
this.listeners.mouseup = callback;
|
|
3754
3841
|
return this;
|
|
3755
3842
|
};
|
|
3756
|
-
;
|
|
3757
3843
|
/**
|
|
3758
3844
|
* Installer function to listen for a specific event: mouse-down.
|
|
3759
3845
|
* Pass your callbacks here.
|
|
@@ -3768,12 +3854,11 @@ var MouseHandler = /** @class */ (function () {
|
|
|
3768
3854
|
*/
|
|
3769
3855
|
MouseHandler.prototype.down = function (callback) {
|
|
3770
3856
|
if (this.listeners.mousedown)
|
|
3771
|
-
this.throwAlreadyInstalled(
|
|
3772
|
-
this.listenFor(
|
|
3857
|
+
this.throwAlreadyInstalled("mousedown");
|
|
3858
|
+
this.listenFor("mousedown");
|
|
3773
3859
|
this.listeners.mousedown = callback;
|
|
3774
3860
|
return this;
|
|
3775
3861
|
};
|
|
3776
|
-
;
|
|
3777
3862
|
/**
|
|
3778
3863
|
* Installer function to listen for a specific event: mouse-click.
|
|
3779
3864
|
* Pass your callbacks here.
|
|
@@ -3788,12 +3873,11 @@ var MouseHandler = /** @class */ (function () {
|
|
|
3788
3873
|
*/
|
|
3789
3874
|
MouseHandler.prototype.click = function (callback) {
|
|
3790
3875
|
if (this.listeners.click)
|
|
3791
|
-
this.throwAlreadyInstalled(
|
|
3792
|
-
this.listenFor(
|
|
3876
|
+
this.throwAlreadyInstalled("click");
|
|
3877
|
+
this.listenFor("click");
|
|
3793
3878
|
this.listeners.click = callback;
|
|
3794
3879
|
return this;
|
|
3795
3880
|
};
|
|
3796
|
-
;
|
|
3797
3881
|
/**
|
|
3798
3882
|
* Installer function to listen for a specific event: mouse-wheel.
|
|
3799
3883
|
* Pass your callbacks here.
|
|
@@ -3808,12 +3892,11 @@ var MouseHandler = /** @class */ (function () {
|
|
|
3808
3892
|
*/
|
|
3809
3893
|
MouseHandler.prototype.wheel = function (callback) {
|
|
3810
3894
|
if (this.listeners.wheel)
|
|
3811
|
-
this.throwAlreadyInstalled(
|
|
3812
|
-
this.listenFor(
|
|
3895
|
+
this.throwAlreadyInstalled("wheel");
|
|
3896
|
+
this.listenFor("wheel");
|
|
3813
3897
|
this.listeners.wheel = callback;
|
|
3814
3898
|
return this;
|
|
3815
3899
|
};
|
|
3816
|
-
;
|
|
3817
3900
|
/**
|
|
3818
3901
|
* An internal function to throw events.
|
|
3819
3902
|
*
|
|
@@ -3827,7 +3910,6 @@ var MouseHandler = /** @class */ (function () {
|
|
|
3827
3910
|
MouseHandler.prototype.throwAlreadyInstalled = function (name) {
|
|
3828
3911
|
throw "This MouseHandler already has a '" + name + "' callback. To keep the code simple there is only room for one.";
|
|
3829
3912
|
};
|
|
3830
|
-
;
|
|
3831
3913
|
/**
|
|
3832
3914
|
* Call this when your work is done.
|
|
3833
3915
|
*
|
|
@@ -3840,16 +3922,16 @@ var MouseHandler = /** @class */ (function () {
|
|
|
3840
3922
|
* @return {void}
|
|
3841
3923
|
*/
|
|
3842
3924
|
MouseHandler.prototype.destroy = function () {
|
|
3843
|
-
this.unlistenFor(
|
|
3844
|
-
this.unlistenFor(
|
|
3845
|
-
this.unlistenFor(
|
|
3846
|
-
this.unlistenFor(
|
|
3847
|
-
this.unlistenFor(
|
|
3848
|
-
this.element.removeEventListener(
|
|
3849
|
-
this.element.removeEventListener(
|
|
3850
|
-
this.element.removeEventListener(
|
|
3851
|
-
this.element.removeEventListener(
|
|
3852
|
-
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"]);
|
|
3853
3935
|
};
|
|
3854
3936
|
return MouseHandler;
|
|
3855
3937
|
}());
|
|
@@ -3868,7 +3950,9 @@ exports.MouseHandler = MouseHandler;
|
|
|
3868
3950
|
* @modified 2019-03-23 Added JSDoc tags.
|
|
3869
3951
|
* @modified 2020-03-25 Ported this class from vanilla-JS to Typescript.
|
|
3870
3952
|
* @modified 2021-01-20 Added UID.
|
|
3871
|
-
* @
|
|
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
|
|
3872
3956
|
*
|
|
3873
3957
|
* @file PBImage
|
|
3874
3958
|
* @fileoverview As native Image objects have only a position and with
|
|
@@ -3906,7 +3990,6 @@ var PBImage = /** @class */ (function () {
|
|
|
3906
3990
|
this.upperLeft = upperLeft;
|
|
3907
3991
|
this.lowerRight = lowerRight;
|
|
3908
3992
|
}
|
|
3909
|
-
;
|
|
3910
3993
|
/**
|
|
3911
3994
|
* Convert this vertex to SVG code.
|
|
3912
3995
|
*
|
|
@@ -3921,7 +4004,16 @@ var PBImage = /** @class */ (function () {
|
|
|
3921
4004
|
console.warn("PBImage is not yet SVG serializable. Returning empty SVG string.");
|
|
3922
4005
|
return "";
|
|
3923
4006
|
};
|
|
3924
|
-
|
|
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
|
+
};
|
|
3925
4017
|
return PBImage;
|
|
3926
4018
|
}());
|
|
3927
4019
|
exports.PBImage = PBImage;
|
|
@@ -3936,7 +4028,8 @@ exports.PBImage = PBImage;
|
|
|
3936
4028
|
/**
|
|
3937
4029
|
* @author Ikaros Kappler
|
|
3938
4030
|
* @date 2021-11-16
|
|
3939
|
-
* @
|
|
4031
|
+
* @modified 2022-02-02 Added the `destroy` method.
|
|
4032
|
+
* @version 1.1.0
|
|
3940
4033
|
**/
|
|
3941
4034
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
3942
4035
|
exports.PBText = void 0;
|
|
@@ -3994,6 +4087,15 @@ var PBText = /** @class */ (function () {
|
|
|
3994
4087
|
console.warn("[PBText.toSVGString()] This function is not implemented as it defines a deprecated method. Use the 'drawutilssvg.text()' method instead.");
|
|
3995
4088
|
return "";
|
|
3996
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
|
+
};
|
|
3997
4099
|
return PBText;
|
|
3998
4100
|
}()); // END class
|
|
3999
4101
|
exports.PBText = PBText;
|
|
@@ -4714,7 +4816,7 @@ var PlotBoilerplate = /** @class */ (function () {
|
|
|
4714
4816
|
}
|
|
4715
4817
|
}
|
|
4716
4818
|
for (var i = 0; i < this.drawables.length; i++) {
|
|
4717
|
-
if (this.drawables[i] === drawable) {
|
|
4819
|
+
if (this.drawables[i] === drawable || this.drawables[i].uid === drawable.uid) {
|
|
4718
4820
|
this.drawables.splice(i, 1);
|
|
4719
4821
|
if (removeWithVertices) {
|
|
4720
4822
|
// Check if some listeners need to be removed
|
|
@@ -6130,7 +6232,9 @@ __webpack_unused_export__ = PlotBoilerplate;
|
|
|
6130
6232
|
* @modified 2021-01-29 Changed the param type for `containsVert` from Vertex to XYCoords.
|
|
6131
6233
|
* @modified 2021-12-14 Added the `perimeter()` function.
|
|
6132
6234
|
* @modified 2021-12-16 Added the `getEvenDistributionPolygon()` function.
|
|
6133
|
-
* @
|
|
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
|
|
6134
6238
|
*
|
|
6135
6239
|
* @file Polygon
|
|
6136
6240
|
* @public
|
|
@@ -6542,29 +6646,41 @@ var Polygon = /** @class */ (function () {
|
|
|
6542
6646
|
* @memberof Polygon
|
|
6543
6647
|
**/
|
|
6544
6648
|
Polygon.prototype.toSVGString = function (options) {
|
|
6545
|
-
options = options || {};
|
|
6546
|
-
var buffer = [];
|
|
6547
|
-
buffer.push("<path");
|
|
6548
|
-
if (options.className)
|
|
6549
|
-
|
|
6550
|
-
|
|
6551
|
-
|
|
6552
|
-
|
|
6553
|
-
|
|
6554
|
-
|
|
6555
|
-
|
|
6556
|
-
|
|
6557
|
-
|
|
6558
|
-
|
|
6559
|
-
|
|
6560
|
-
|
|
6561
|
-
|
|
6562
|
-
|
|
6563
|
-
|
|
6564
|
-
|
|
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();
|
|
6565
6682
|
}
|
|
6566
|
-
|
|
6567
|
-
return buffer.join("");
|
|
6683
|
+
this.isDestroyed = true;
|
|
6568
6684
|
};
|
|
6569
6685
|
Polygon.utils = {
|
|
6570
6686
|
/**
|
|
@@ -6638,7 +6754,9 @@ exports.Polygon = Polygon;
|
|
|
6638
6754
|
* @modified 2020-12-28 Added the `getArea` function.
|
|
6639
6755
|
* @modified 2021-01-20 Added UID.
|
|
6640
6756
|
* @modified 2021-01-22 Always updating circumcircle when retieving it.
|
|
6641
|
-
* @
|
|
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
|
|
6642
6760
|
*
|
|
6643
6761
|
* @file Triangle
|
|
6644
6762
|
* @fileoverview A simple triangle class: three vertices.
|
|
@@ -6708,7 +6826,6 @@ var Triangle = /** @class */ (function () {
|
|
|
6708
6826
|
throw "Cannot create triangle from array with less than three vertices (" + arr.length + ")";
|
|
6709
6827
|
return new Triangle(arr[0], arr[1], arr[2]);
|
|
6710
6828
|
};
|
|
6711
|
-
;
|
|
6712
6829
|
/**
|
|
6713
6830
|
* Get the area of this triangle. The returned area is never negative.
|
|
6714
6831
|
*
|
|
@@ -6724,7 +6841,6 @@ var Triangle = /** @class */ (function () {
|
|
|
6724
6841
|
Triangle.prototype.getArea = function () {
|
|
6725
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));
|
|
6726
6843
|
};
|
|
6727
|
-
;
|
|
6728
6844
|
/**
|
|
6729
6845
|
* Get the centroid of this triangle.
|
|
6730
6846
|
*
|
|
@@ -6738,7 +6854,6 @@ var Triangle = /** @class */ (function () {
|
|
|
6738
6854
|
Triangle.prototype.getCentroid = function () {
|
|
6739
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);
|
|
6740
6856
|
};
|
|
6741
|
-
;
|
|
6742
6857
|
/**
|
|
6743
6858
|
* Scale the triangle towards its centroid.
|
|
6744
6859
|
*
|
|
@@ -6755,7 +6870,6 @@ var Triangle = /** @class */ (function () {
|
|
|
6755
6870
|
this.c.scale(factor, centroid);
|
|
6756
6871
|
return this;
|
|
6757
6872
|
};
|
|
6758
|
-
;
|
|
6759
6873
|
/**
|
|
6760
6874
|
* Get the circumcircle of this triangle.
|
|
6761
6875
|
*
|
|
@@ -6772,11 +6886,10 @@ var Triangle = /** @class */ (function () {
|
|
|
6772
6886
|
* @memberof Triangle
|
|
6773
6887
|
*/
|
|
6774
6888
|
Triangle.prototype.getCircumcircle = function () {
|
|
6775
|
-
// if( !this.center || !this.radius )
|
|
6889
|
+
// if( !this.center || !this.radius )
|
|
6776
6890
|
this.calcCircumcircle();
|
|
6777
6891
|
return new Circle_1.Circle(this.center.clone(), this.radius);
|
|
6778
6892
|
};
|
|
6779
|
-
;
|
|
6780
6893
|
/**
|
|
6781
6894
|
* Check if this triangle and the passed triangle share an
|
|
6782
6895
|
* adjacent edge.
|
|
@@ -6796,7 +6909,6 @@ var Triangle = /** @class */ (function () {
|
|
|
6796
6909
|
var c = this.c.equals(tri.a) || this.c.equals(tri.b) || this.c.equals(tri.c);
|
|
6797
6910
|
return (a && b) || (a && c) || (b && c);
|
|
6798
6911
|
};
|
|
6799
|
-
;
|
|
6800
6912
|
/**
|
|
6801
6913
|
* Get that vertex of this triangle (a,b,c) that is not vert1 nor vert2 of
|
|
6802
6914
|
* the passed two.
|
|
@@ -6809,14 +6921,13 @@ var Triangle = /** @class */ (function () {
|
|
|
6809
6921
|
* @memberof Triangle
|
|
6810
6922
|
*/
|
|
6811
6923
|
Triangle.prototype.getThirdVertex = function (vert1, vert2) {
|
|
6812
|
-
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)))
|
|
6813
6925
|
return this.c;
|
|
6814
|
-
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)))
|
|
6815
6927
|
return this.a;
|
|
6816
6928
|
//if( this.c.equals(vert1) && this.a.equals(vert2) || this.c.equals(vert2) && this.a.equals(vert1) )
|
|
6817
6929
|
return this.b;
|
|
6818
6930
|
};
|
|
6819
|
-
;
|
|
6820
6931
|
/**
|
|
6821
6932
|
* Re-compute the circumcircle of this triangle (if the vertices
|
|
6822
6933
|
* have changed).
|
|
@@ -6856,8 +6967,7 @@ var Triangle = /** @class */ (function () {
|
|
|
6856
6967
|
}
|
|
6857
6968
|
this.radius_squared = dx * dx + dy * dy;
|
|
6858
6969
|
this.radius = Math.sqrt(this.radius_squared);
|
|
6859
|
-
};
|
|
6860
|
-
; // END calcCircumcircle
|
|
6970
|
+
}; // END calcCircumcircle
|
|
6861
6971
|
/**
|
|
6862
6972
|
* Check if the passed vertex is inside this triangle's
|
|
6863
6973
|
* circumcircle.
|
|
@@ -6872,9 +6982,8 @@ var Triangle = /** @class */ (function () {
|
|
|
6872
6982
|
var dx = this.center.x - v.x;
|
|
6873
6983
|
var dy = this.center.y - v.y;
|
|
6874
6984
|
var dist_squared = dx * dx + dy * dy;
|
|
6875
|
-
return
|
|
6985
|
+
return dist_squared <= this.radius_squared;
|
|
6876
6986
|
};
|
|
6877
|
-
;
|
|
6878
6987
|
/**
|
|
6879
6988
|
* Get the rectangular bounds for this triangle.
|
|
6880
6989
|
*
|
|
@@ -6886,7 +6995,6 @@ var Triangle = /** @class */ (function () {
|
|
|
6886
6995
|
Triangle.prototype.bounds = function () {
|
|
6887
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)));
|
|
6888
6997
|
};
|
|
6889
|
-
;
|
|
6890
6998
|
/**
|
|
6891
6999
|
* Convert this triangle to a polygon instance.
|
|
6892
7000
|
*
|
|
@@ -6900,7 +7008,6 @@ var Triangle = /** @class */ (function () {
|
|
|
6900
7008
|
Triangle.prototype.toPolygon = function () {
|
|
6901
7009
|
return new Polygon_1.Polygon([this.a, this.b, this.c]);
|
|
6902
7010
|
};
|
|
6903
|
-
;
|
|
6904
7011
|
/**
|
|
6905
7012
|
* Get the determinant of this triangle.
|
|
6906
7013
|
*
|
|
@@ -6913,7 +7020,6 @@ var Triangle = /** @class */ (function () {
|
|
|
6913
7020
|
// (b.y - a.y)*(c.x - b.x) - (c.y - b.y)*(b.x - a.x);
|
|
6914
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);
|
|
6915
7022
|
};
|
|
6916
|
-
;
|
|
6917
7023
|
/**
|
|
6918
7024
|
* Checks if the passed vertex (p) is inside this triangle.
|
|
6919
7025
|
*
|
|
@@ -6928,7 +7034,6 @@ var Triangle = /** @class */ (function () {
|
|
|
6928
7034
|
Triangle.prototype.containsPoint = function (p) {
|
|
6929
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);
|
|
6930
7036
|
};
|
|
6931
|
-
;
|
|
6932
7037
|
/**
|
|
6933
7038
|
* Get that inner triangle which defines the maximal incircle.
|
|
6934
7039
|
*
|
|
@@ -6947,7 +7052,6 @@ var Triangle = /** @class */ (function () {
|
|
|
6947
7052
|
var circleIntersC = lineC.getClosestPoint(intersection);
|
|
6948
7053
|
return new Triangle(circleIntersA, circleIntersB, circleIntersC);
|
|
6949
7054
|
};
|
|
6950
|
-
;
|
|
6951
7055
|
/**
|
|
6952
7056
|
* Get the incircle of this triangle. That is the circle that touches each side
|
|
6953
7057
|
* of this triangle in exactly one point.
|
|
@@ -6959,7 +7063,6 @@ var Triangle = /** @class */ (function () {
|
|
|
6959
7063
|
Triangle.prototype.getIncircle = function () {
|
|
6960
7064
|
return this.getIncircularTriangle().getCircumcircle();
|
|
6961
7065
|
};
|
|
6962
|
-
;
|
|
6963
7066
|
/**
|
|
6964
7067
|
* Get the incenter of this triangle (which is the center of the circumcircle).
|
|
6965
7068
|
*
|
|
@@ -6973,7 +7076,6 @@ var Triangle = /** @class */ (function () {
|
|
|
6973
7076
|
this.calcCircumcircle();
|
|
6974
7077
|
return this.center.clone();
|
|
6975
7078
|
};
|
|
6976
|
-
;
|
|
6977
7079
|
/**
|
|
6978
7080
|
* Converts this triangle into a human-readable string.
|
|
6979
7081
|
*
|
|
@@ -6983,9 +7085,8 @@ var Triangle = /** @class */ (function () {
|
|
|
6983
7085
|
* @memberof Triangle
|
|
6984
7086
|
*/
|
|
6985
7087
|
Triangle.prototype.toString = function () {
|
|
6986
|
-
return
|
|
7088
|
+
return "{ a : " + this.a.toString() + ", b : " + this.b.toString() + ", c : " + this.c.toString() + "}";
|
|
6987
7089
|
};
|
|
6988
|
-
;
|
|
6989
7090
|
/**
|
|
6990
7091
|
* Create an SVG representation of this triangle.
|
|
6991
7092
|
*
|
|
@@ -6997,32 +7098,43 @@ var Triangle = /** @class */ (function () {
|
|
|
6997
7098
|
* @memberof Triangle
|
|
6998
7099
|
**/
|
|
6999
7100
|
Triangle.prototype.toSVGString = function (options) {
|
|
7000
|
-
options = options || {};
|
|
7001
|
-
var buffer = [];
|
|
7002
|
-
buffer.push(
|
|
7003
|
-
if (options.className)
|
|
7004
|
-
|
|
7005
|
-
|
|
7006
|
-
|
|
7007
|
-
|
|
7008
|
-
|
|
7009
|
-
|
|
7010
|
-
|
|
7011
|
-
|
|
7012
|
-
|
|
7013
|
-
|
|
7014
|
-
|
|
7015
|
-
|
|
7016
|
-
|
|
7017
|
-
|
|
7018
|
-
|
|
7019
|
-
|
|
7020
|
-
|
|
7021
|
-
|
|
7022
|
-
buffer.
|
|
7023
|
-
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;
|
|
7024
7137
|
};
|
|
7025
|
-
;
|
|
7026
7138
|
/**
|
|
7027
7139
|
* An epsilon for comparison.
|
|
7028
7140
|
* This should be the same epsilon as in Vertex.
|
|
@@ -7033,10 +7145,10 @@ var Triangle = /** @class */ (function () {
|
|
|
7033
7145
|
Triangle.utils = {
|
|
7034
7146
|
// Used in the bounds() function.
|
|
7035
7147
|
max3: function (a, b, c) {
|
|
7036
|
-
return
|
|
7148
|
+
return a >= b && a >= c ? a : b >= a && b >= c ? b : c;
|
|
7037
7149
|
},
|
|
7038
7150
|
min3: function (a, b, c) {
|
|
7039
|
-
return
|
|
7151
|
+
return a <= b && a <= c ? a : b <= a && b <= c ? b : c;
|
|
7040
7152
|
},
|
|
7041
7153
|
signedArea: function (p0x, p0y, p1x, p1y, p2x, p2y) {
|
|
7042
7154
|
return 0.5 * (-p1y * p2x + p0y * (-p1x + p2x) + p0x * (p1y - p2y) + p1x * p2y);
|
|
@@ -7052,9 +7164,9 @@ var Triangle = /** @class */ (function () {
|
|
|
7052
7164
|
// http://stackoverflow.com/questions/2049582/how-to-determine-a-point-in-a-2d-triangle
|
|
7053
7165
|
// var area : number = 1/2*(-p1y*p2x + p0y*(-p1x + p2x) + p0x*(p1y - p2y) + p1x*p2y);
|
|
7054
7166
|
var area = Triangle.utils.signedArea(p0x, p0y, p1x, p1y, p2x, p2y);
|
|
7055
|
-
var s = 1 / (2 * area) * (p0y * p2x - p0x * p2y + (p2y - p0y) * px + (p0x - p2x) * py);
|
|
7056
|
-
var t = 1 / (2 * area) * (p0x * p1y - p0y * p1x + (p0y - p1y) * px + (p1x - p0x) * py);
|
|
7057
|
-
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;
|
|
7058
7170
|
}
|
|
7059
7171
|
};
|
|
7060
7172
|
return Triangle;
|
|
@@ -7110,7 +7222,9 @@ exports.UIDGenerator = UIDGenerator;
|
|
|
7110
7222
|
* @modified 2021-03-10 Added the `toCubicBezier` method.
|
|
7111
7223
|
* @modified 2021-03-15 Added `VEllipse.quarterSegmentCount` and `VEllipse.scale` functions.
|
|
7112
7224
|
* @modified 2021-03-19 Added the `VEllipse.rotate` function.
|
|
7113
|
-
* @
|
|
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
|
|
7114
7228
|
*
|
|
7115
7229
|
* @file VEllipse
|
|
7116
7230
|
* @fileoverview Ellipses with a center and an x- and a y-axis (stored as a vertex).
|
|
@@ -7443,17 +7557,28 @@ var VEllipse = /** @class */ (function () {
|
|
|
7443
7557
|
* @return string The SVG string
|
|
7444
7558
|
*/
|
|
7445
7559
|
VEllipse.prototype.toSVGString = function (options) {
|
|
7446
|
-
options = options || {};
|
|
7447
|
-
var buffer = [];
|
|
7448
|
-
buffer.push("<ellipse");
|
|
7449
|
-
if (options.className)
|
|
7450
|
-
|
|
7451
|
-
buffer.push('
|
|
7452
|
-
buffer.push('
|
|
7453
|
-
buffer.push('
|
|
7454
|
-
buffer.push(
|
|
7455
|
-
buffer.
|
|
7456
|
-
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;
|
|
7457
7582
|
};
|
|
7458
7583
|
/**
|
|
7459
7584
|
* A static collection of ellipse-related helper functions.
|
|
@@ -7529,7 +7654,8 @@ exports.VEllipse = VEllipse;
|
|
|
7529
7654
|
*
|
|
7530
7655
|
* @author Ikaros Kappler
|
|
7531
7656
|
* @date 2021-02-26
|
|
7532
|
-
* @
|
|
7657
|
+
* @modified 2022-02-02 Added the `destroy` method.
|
|
7658
|
+
* @version 1.1.0
|
|
7533
7659
|
*/
|
|
7534
7660
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
7535
7661
|
exports.VEllipseSector = void 0;
|
|
@@ -7623,6 +7749,15 @@ var VEllipseSector = /** @class */ (function () {
|
|
|
7623
7749
|
}
|
|
7624
7750
|
return curves;
|
|
7625
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
|
+
};
|
|
7626
7761
|
VEllipseSector.ellipseSectorUtils = {
|
|
7627
7762
|
/**
|
|
7628
7763
|
* Helper function to convert an elliptic section to SVG arc params (for the `d` attribute).
|
|
@@ -7807,7 +7942,9 @@ exports.VEllipseSector = VEllipseSector;
|
|
|
7807
7942
|
* @modified 2019-12-04 Added the Vector.inv() function.
|
|
7808
7943
|
* @modified 2020-03-23 Ported to Typescript from JS.
|
|
7809
7944
|
* @modified 2021-01-20 Added UID.
|
|
7810
|
-
* @
|
|
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
|
|
7811
7948
|
*
|
|
7812
7949
|
* @file Vector
|
|
7813
7950
|
* @public
|
|
@@ -7857,7 +7994,6 @@ var Vector = /** @class */ (function (_super) {
|
|
|
7857
7994
|
_this.className = "Vector";
|
|
7858
7995
|
return _this;
|
|
7859
7996
|
}
|
|
7860
|
-
;
|
|
7861
7997
|
/**
|
|
7862
7998
|
* Get the perpendicular of this vector which is located at a.
|
|
7863
7999
|
*
|
|
@@ -7872,7 +8008,6 @@ var Vector = /** @class */ (function (_super) {
|
|
|
7872
8008
|
v.b.add(this.a);
|
|
7873
8009
|
return v;
|
|
7874
8010
|
};
|
|
7875
|
-
;
|
|
7876
8011
|
/**
|
|
7877
8012
|
* The inverse of a vector is a vector witht the same magnitude but oppose direction.
|
|
7878
8013
|
*
|
|
@@ -7886,7 +8021,6 @@ var Vector = /** @class */ (function (_super) {
|
|
|
7886
8021
|
this.b = tmp;
|
|
7887
8022
|
return this;
|
|
7888
8023
|
};
|
|
7889
|
-
;
|
|
7890
8024
|
/**
|
|
7891
8025
|
* This function computes the inverse of the vector, which means 'a' stays untouched.
|
|
7892
8026
|
*
|
|
@@ -7897,7 +8031,6 @@ var Vector = /** @class */ (function (_super) {
|
|
|
7897
8031
|
this.b.y = this.a.y - (this.b.y - this.a.y);
|
|
7898
8032
|
return this;
|
|
7899
8033
|
};
|
|
7900
|
-
;
|
|
7901
8034
|
/**
|
|
7902
8035
|
* Get the intersection if this vector and the specified vector.
|
|
7903
8036
|
*
|
|
@@ -7913,16 +8046,15 @@ var Vector = /** @class */ (function (_super) {
|
|
|
7913
8046
|
return null;
|
|
7914
8047
|
var a = this.a.y - line.a.y;
|
|
7915
8048
|
var b = this.a.x - line.a.x;
|
|
7916
|
-
var numerator1 = (
|
|
7917
|
-
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;
|
|
7918
8051
|
a = numerator1 / denominator; // NaN if parallel lines
|
|
7919
8052
|
b = numerator2 / denominator;
|
|
7920
8053
|
// TODO:
|
|
7921
8054
|
// FOR A VECTOR THE LINE-INTERSECTION MUST BE ON BOTH VECTORS
|
|
7922
8055
|
// if we cast these lines infinitely in both directions, they intersect here:
|
|
7923
|
-
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));
|
|
7924
8057
|
};
|
|
7925
|
-
;
|
|
7926
8058
|
/**
|
|
7927
8059
|
* Create an SVG representation of this line.
|
|
7928
8060
|
*
|
|
@@ -7935,31 +8067,30 @@ var Vector = /** @class */ (function (_super) {
|
|
|
7935
8067
|
* @memberof Vector
|
|
7936
8068
|
**/
|
|
7937
8069
|
Vector.prototype.toSVGString = function (options) {
|
|
7938
|
-
options = options || {};
|
|
7939
|
-
var buffer = [];
|
|
7940
|
-
var vertices = Vector.utils.buildArrowHead(this.a, this.b, 8, 1.0, 1.0);
|
|
7941
|
-
buffer.push(
|
|
7942
|
-
if (options.className)
|
|
7943
|
-
|
|
7944
|
-
buffer.push(
|
|
7945
|
-
buffer.push('
|
|
7946
|
-
buffer.push('
|
|
7947
|
-
buffer.push('
|
|
7948
|
-
buffer.push('
|
|
7949
|
-
buffer.push(
|
|
7950
|
-
|
|
7951
|
-
//
|
|
7952
|
-
|
|
7953
|
-
|
|
7954
|
-
|
|
7955
|
-
|
|
7956
|
-
|
|
7957
|
-
|
|
7958
|
-
buffer.
|
|
7959
|
-
|
|
7960
|
-
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 "";
|
|
7961
8093
|
};
|
|
7962
|
-
;
|
|
7963
8094
|
Vector.utils = {
|
|
7964
8095
|
/**
|
|
7965
8096
|
* Generate a four-point arrow head, starting at the vector end minus the
|
|
@@ -7989,10 +8120,10 @@ var Vector = /** @class */ (function (_super) {
|
|
|
7989
8120
|
buildArrowHead: function (zA, zB, headlen, scaleX, scaleY) {
|
|
7990
8121
|
var angle = Math.atan2((zB.y - zA.y) * scaleY, (zB.x - zA.x) * scaleX);
|
|
7991
8122
|
var vertices = [];
|
|
7992
|
-
vertices.push(new Vertex_1.Vertex(zB.x * scaleX -
|
|
7993
|
-
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)));
|
|
7994
8125
|
vertices.push(new Vertex_1.Vertex(zB.x * scaleX, zB.y * scaleY));
|
|
7995
|
-
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)));
|
|
7996
8127
|
return vertices;
|
|
7997
8128
|
}
|
|
7998
8129
|
};
|
|
@@ -8017,7 +8148,8 @@ exports.Vector = Vector;
|
|
|
8017
8148
|
* @modified 2020-12-04 Changed `getClosestT` param from `Vertex` to `XYCoords` (generalized).
|
|
8018
8149
|
* @modified 2020-12-04 Added the `hasPoint(XYCoords)` function.
|
|
8019
8150
|
* @modified 2021-01-20 Added UID.
|
|
8020
|
-
* @
|
|
8151
|
+
* @modified 2022-02-02 Added the `destroy` method.
|
|
8152
|
+
* @version 1.2.0
|
|
8021
8153
|
*/
|
|
8022
8154
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
8023
8155
|
exports.VertTuple = void 0;
|
|
@@ -8055,7 +8187,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
8055
8187
|
VertTuple.prototype.length = function () {
|
|
8056
8188
|
return Math.sqrt(Math.pow(this.b.x - this.a.x, 2) + Math.pow(this.b.y - this.a.y, 2));
|
|
8057
8189
|
};
|
|
8058
|
-
;
|
|
8059
8190
|
/**
|
|
8060
8191
|
* Set the length of this vector to the given amount. This only works if this
|
|
8061
8192
|
* vector is not a null vector.
|
|
@@ -8068,7 +8199,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
8068
8199
|
VertTuple.prototype.setLength = function (length) {
|
|
8069
8200
|
return this.scale(length / this.length());
|
|
8070
8201
|
};
|
|
8071
|
-
;
|
|
8072
8202
|
/**
|
|
8073
8203
|
* Substract the given vertex from this line's end points.
|
|
8074
8204
|
*
|
|
@@ -8083,7 +8213,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
8083
8213
|
this.b.sub(amount);
|
|
8084
8214
|
return this;
|
|
8085
8215
|
};
|
|
8086
|
-
;
|
|
8087
8216
|
/**
|
|
8088
8217
|
* Add the given vertex to this line's end points.
|
|
8089
8218
|
*
|
|
@@ -8098,7 +8227,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
8098
8227
|
this.b.add(amount);
|
|
8099
8228
|
return this;
|
|
8100
8229
|
};
|
|
8101
|
-
;
|
|
8102
8230
|
/**
|
|
8103
8231
|
* Normalize this line (set to length 1).
|
|
8104
8232
|
*
|
|
@@ -8111,7 +8239,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
8111
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());
|
|
8112
8240
|
return this;
|
|
8113
8241
|
};
|
|
8114
|
-
;
|
|
8115
8242
|
/**
|
|
8116
8243
|
* Scale this line by the given factor.
|
|
8117
8244
|
*
|
|
@@ -8125,7 +8252,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
8125
8252
|
this.b.set(this.a.x + (this.b.x - this.a.x) * factor, this.a.y + (this.b.y - this.a.y) * factor);
|
|
8126
8253
|
return this;
|
|
8127
8254
|
};
|
|
8128
|
-
;
|
|
8129
8255
|
/**
|
|
8130
8256
|
* Move this line to a new location.
|
|
8131
8257
|
*
|
|
@@ -8141,7 +8267,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
8141
8267
|
this.b.add(diff);
|
|
8142
8268
|
return this;
|
|
8143
8269
|
};
|
|
8144
|
-
;
|
|
8145
8270
|
/**
|
|
8146
8271
|
* Get the angle between this and the passed line (in radians).
|
|
8147
8272
|
*
|
|
@@ -8152,7 +8277,7 @@ var VertTuple = /** @class */ (function () {
|
|
|
8152
8277
|
* @memberof VertTuple
|
|
8153
8278
|
**/
|
|
8154
8279
|
VertTuple.prototype.angle = function (line) {
|
|
8155
|
-
if (line == null || typeof line ==
|
|
8280
|
+
if (line == null || typeof line == "undefined") {
|
|
8156
8281
|
line = this.factory(new Vertex_1.Vertex(0, 0), new Vertex_1.Vertex(100, 0));
|
|
8157
8282
|
}
|
|
8158
8283
|
// Compute the angle from x axis and the return the difference :)
|
|
@@ -8162,7 +8287,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
8162
8287
|
// The result might be negative, but isn't it usually nicer to determine angles in positive values only?
|
|
8163
8288
|
return Math.atan2(v1.x, v1.y) - Math.atan2(v0.x, v0.y);
|
|
8164
8289
|
};
|
|
8165
|
-
;
|
|
8166
8290
|
/**
|
|
8167
8291
|
* Get line point at position t in [0 ... 1]:<br>
|
|
8168
8292
|
* <pre>[P(0)]=[A]--------------------[P(t)]------[B]=[P(1)]</pre><br>
|
|
@@ -8178,7 +8302,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
8178
8302
|
VertTuple.prototype.vertAt = function (t) {
|
|
8179
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);
|
|
8180
8304
|
};
|
|
8181
|
-
;
|
|
8182
8305
|
/**
|
|
8183
8306
|
* Get the denominator of this and the given line.
|
|
8184
8307
|
*
|
|
@@ -8192,9 +8315,8 @@ var VertTuple = /** @class */ (function () {
|
|
|
8192
8315
|
**/
|
|
8193
8316
|
VertTuple.prototype.denominator = function (line) {
|
|
8194
8317
|
// http://jsfiddle.net/justin_c_rounds/Gd2S2/
|
|
8195
|
-
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);
|
|
8196
8319
|
};
|
|
8197
|
-
;
|
|
8198
8320
|
/**
|
|
8199
8321
|
* Checks if this and the given line are co-linear.
|
|
8200
8322
|
*
|
|
@@ -8209,7 +8331,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
8209
8331
|
VertTuple.prototype.colinear = function (line) {
|
|
8210
8332
|
return Math.abs(this.denominator(line)) < Vertex_1.Vertex.EPSILON;
|
|
8211
8333
|
};
|
|
8212
|
-
;
|
|
8213
8334
|
/**
|
|
8214
8335
|
* Get the closest position T from this line to the specified point.
|
|
8215
8336
|
*
|
|
@@ -8232,7 +8353,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
8232
8353
|
// t = Math.max(0, Math.min(1, t));
|
|
8233
8354
|
return t;
|
|
8234
8355
|
};
|
|
8235
|
-
;
|
|
8236
8356
|
/**
|
|
8237
8357
|
* Check if the given point is located on this line. Optionally also check if
|
|
8238
8358
|
* that point is located between point `a` and `b`.
|
|
@@ -8268,7 +8388,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
8268
8388
|
var t = this.getClosestT(p);
|
|
8269
8389
|
return this.vertAt(t);
|
|
8270
8390
|
};
|
|
8271
|
-
;
|
|
8272
8391
|
/**
|
|
8273
8392
|
* The the minimal distance between this line and the specified point.
|
|
8274
8393
|
*
|
|
@@ -8283,7 +8402,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
8283
8402
|
// https://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment
|
|
8284
8403
|
return Math.sqrt(VertTuple.vtutils.dist2(p, this.vertAt(this.getClosestT(p))));
|
|
8285
8404
|
};
|
|
8286
|
-
;
|
|
8287
8405
|
/**
|
|
8288
8406
|
* Create a deep clone of this instance.
|
|
8289
8407
|
*
|
|
@@ -8295,7 +8413,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
8295
8413
|
VertTuple.prototype.clone = function () {
|
|
8296
8414
|
return this.factory(this.a.clone(), this.b.clone());
|
|
8297
8415
|
};
|
|
8298
|
-
;
|
|
8299
8416
|
/**
|
|
8300
8417
|
* Create a string representation of this line.
|
|
8301
8418
|
*
|
|
@@ -8307,7 +8424,16 @@ var VertTuple = /** @class */ (function () {
|
|
|
8307
8424
|
VertTuple.prototype.toString = function () {
|
|
8308
8425
|
return "{ a : " + this.a.toString() + ", b : " + this.b.toString() + " }";
|
|
8309
8426
|
};
|
|
8310
|
-
|
|
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
|
+
};
|
|
8311
8437
|
/**
|
|
8312
8438
|
* @private
|
|
8313
8439
|
**/
|
|
@@ -8354,7 +8480,10 @@ exports.VertTuple = VertTuple;
|
|
|
8354
8480
|
* @modified 2021-12-01 Changed the type of param of `scale` to XYCoords.
|
|
8355
8481
|
* @modified 2021-12-01 Added function `scaleXY` for non uniform scaling.
|
|
8356
8482
|
* @modified 2021-12-17 Added the functions `lerp` and `lerpAbs` for linear interpolations.
|
|
8357
|
-
* @
|
|
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
|
|
8358
8487
|
*
|
|
8359
8488
|
* @file Vertex
|
|
8360
8489
|
* @public
|
|
@@ -8854,20 +8983,31 @@ var Vertex = /** @class */ (function () {
|
|
|
8854
8983
|
* @return {string} A string representing the SVG code for this vertex.
|
|
8855
8984
|
* @instance
|
|
8856
8985
|
* @memberof Vertex
|
|
8986
|
+
* @deprecated
|
|
8857
8987
|
**/
|
|
8858
8988
|
Vertex.prototype.toSVGString = function (options) {
|
|
8859
|
-
options = options || {};
|
|
8860
|
-
var buffer = [];
|
|
8861
|
-
buffer.push("<circle");
|
|
8862
|
-
if (options.className)
|
|
8863
|
-
|
|
8864
|
-
buffer.push('
|
|
8865
|
-
buffer.push('
|
|
8866
|
-
buffer.push(
|
|
8867
|
-
buffer.
|
|
8868
|
-
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 "";
|
|
8869
9000
|
};
|
|
8870
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
|
+
};
|
|
8871
9011
|
/**
|
|
8872
9012
|
* Create a new random vertex inside the given viewport.
|
|
8873
9013
|
*
|
|
@@ -8921,6 +9061,19 @@ var Vertex = /** @class */ (function () {
|
|
|
8921
9061
|
vertices.push(new Vertex(zB.x * scaleX, zB.y * scaleY));
|
|
8922
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)));
|
|
8923
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
|
+
}));
|
|
8924
9077
|
}
|
|
8925
9078
|
};
|
|
8926
9079
|
return Vertex;
|
|
@@ -9034,7 +9187,6 @@ var VertexListeners = /** @class */ (function () {
|
|
|
9034
9187
|
this.dragEnd = [];
|
|
9035
9188
|
this.vertex = vertex;
|
|
9036
9189
|
}
|
|
9037
|
-
;
|
|
9038
9190
|
/**
|
|
9039
9191
|
* Add a click listener.
|
|
9040
9192
|
*
|
|
@@ -9048,7 +9200,6 @@ var VertexListeners = /** @class */ (function () {
|
|
|
9048
9200
|
VertexListeners._addListener(this.click, listener);
|
|
9049
9201
|
return this;
|
|
9050
9202
|
};
|
|
9051
|
-
;
|
|
9052
9203
|
/**
|
|
9053
9204
|
* The click listener is a function with a single drag event param.
|
|
9054
9205
|
* @callback VertexListeners~clickListener
|
|
@@ -9067,7 +9218,6 @@ var VertexListeners = /** @class */ (function () {
|
|
|
9067
9218
|
this.click = VertexListeners._removeListener(this.click, listener);
|
|
9068
9219
|
return this;
|
|
9069
9220
|
};
|
|
9070
|
-
;
|
|
9071
9221
|
/**
|
|
9072
9222
|
* The click listener is a function with a single drag event param.
|
|
9073
9223
|
* @callback VertexListeners~clickListener
|
|
@@ -9086,7 +9236,6 @@ var VertexListeners = /** @class */ (function () {
|
|
|
9086
9236
|
VertexListeners._addListener(this.drag, listener);
|
|
9087
9237
|
return this;
|
|
9088
9238
|
};
|
|
9089
|
-
;
|
|
9090
9239
|
/**
|
|
9091
9240
|
* The drag listener is a function with a single drag event param.
|
|
9092
9241
|
* @callback VertexListeners~dragListener
|
|
@@ -9105,7 +9254,6 @@ var VertexListeners = /** @class */ (function () {
|
|
|
9105
9254
|
this.drag = VertexListeners._removeListener(this.drag, listener);
|
|
9106
9255
|
return this;
|
|
9107
9256
|
};
|
|
9108
|
-
;
|
|
9109
9257
|
/**
|
|
9110
9258
|
* Add a dragStart listener.
|
|
9111
9259
|
*
|
|
@@ -9119,7 +9267,6 @@ var VertexListeners = /** @class */ (function () {
|
|
|
9119
9267
|
VertexListeners._addListener(this.dragStart, listener);
|
|
9120
9268
|
return this;
|
|
9121
9269
|
};
|
|
9122
|
-
;
|
|
9123
9270
|
/**
|
|
9124
9271
|
* The drag-start listener is a function with a single drag event param.
|
|
9125
9272
|
* @callback VertexListeners~dragStartListener
|
|
@@ -9138,7 +9285,6 @@ var VertexListeners = /** @class */ (function () {
|
|
|
9138
9285
|
this.dragStart = VertexListeners._removeListener(this.dragStart, listener);
|
|
9139
9286
|
return this;
|
|
9140
9287
|
};
|
|
9141
|
-
;
|
|
9142
9288
|
/**
|
|
9143
9289
|
* Add a dragEnd listener.
|
|
9144
9290
|
*
|
|
@@ -9153,27 +9299,25 @@ var VertexListeners = /** @class */ (function () {
|
|
|
9153
9299
|
VertexListeners._addListener(this.dragEnd, listener);
|
|
9154
9300
|
return this;
|
|
9155
9301
|
};
|
|
9156
|
-
;
|
|
9157
9302
|
/**
|
|
9158
9303
|
* The drag-end listener is a function with a single drag event param.
|
|
9159
9304
|
* @callback VertexListeners~dragEndListener
|
|
9160
9305
|
* @param {Event} e - The (extended) drag event.
|
|
9161
9306
|
*/
|
|
9162
9307
|
/**
|
|
9163
|
-
|
|
9164
|
-
|
|
9165
|
-
|
|
9166
|
-
|
|
9167
|
-
|
|
9168
|
-
|
|
9169
|
-
|
|
9170
|
-
|
|
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
|
+
**/
|
|
9171
9316
|
VertexListeners.prototype.removeDragEndListener = function (listener) {
|
|
9172
9317
|
// this.drag.push( listener );
|
|
9173
9318
|
this.dragEnd = VertexListeners._removeListener(this.dragEnd, listener);
|
|
9174
9319
|
return this;
|
|
9175
9320
|
};
|
|
9176
|
-
;
|
|
9177
9321
|
/**
|
|
9178
9322
|
* Fire a click event with the given event instance to all
|
|
9179
9323
|
* installed click listeners.
|
|
@@ -9187,7 +9331,6 @@ var VertexListeners = /** @class */ (function () {
|
|
|
9187
9331
|
VertexListeners.prototype.fireClickEvent = function (e) {
|
|
9188
9332
|
VertexListeners._fireEvent(this, this.click, e);
|
|
9189
9333
|
};
|
|
9190
|
-
;
|
|
9191
9334
|
/**
|
|
9192
9335
|
* Fire a drag event with the given event instance to all
|
|
9193
9336
|
* installed drag listeners.
|
|
@@ -9201,7 +9344,6 @@ var VertexListeners = /** @class */ (function () {
|
|
|
9201
9344
|
VertexListeners.prototype.fireDragEvent = function (e) {
|
|
9202
9345
|
VertexListeners._fireEvent(this, this.drag, e);
|
|
9203
9346
|
};
|
|
9204
|
-
;
|
|
9205
9347
|
/**
|
|
9206
9348
|
* Fire a dragStart event with the given event instance to all
|
|
9207
9349
|
* installed drag-start listeners.
|
|
@@ -9215,7 +9357,6 @@ var VertexListeners = /** @class */ (function () {
|
|
|
9215
9357
|
VertexListeners.prototype.fireDragStartEvent = function (e) {
|
|
9216
9358
|
VertexListeners._fireEvent(this, this.dragStart, e);
|
|
9217
9359
|
};
|
|
9218
|
-
;
|
|
9219
9360
|
/**
|
|
9220
9361
|
* Fire a dragEnd event with the given event instance to all
|
|
9221
9362
|
* installed drag-end listeners.
|
|
@@ -9229,13 +9370,21 @@ var VertexListeners = /** @class */ (function () {
|
|
|
9229
9370
|
VertexListeners.prototype.fireDragEndEvent = function (e) {
|
|
9230
9371
|
VertexListeners._fireEvent(this, this.dragEnd, e);
|
|
9231
9372
|
};
|
|
9232
|
-
|
|
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
|
+
};
|
|
9233
9382
|
/**
|
|
9234
9383
|
* @private
|
|
9235
9384
|
**/
|
|
9236
9385
|
VertexListeners._fireEvent = function (_self, listeners, e) {
|
|
9237
9386
|
var ve = e;
|
|
9238
|
-
if (typeof ve.params ==
|
|
9387
|
+
if (typeof ve.params == "undefined")
|
|
9239
9388
|
ve.params = { vertex: _self.vertex };
|
|
9240
9389
|
else
|
|
9241
9390
|
ve.params.vertex = _self.vertex;
|
|
@@ -9243,7 +9392,6 @@ var VertexListeners = /** @class */ (function () {
|
|
|
9243
9392
|
listeners[i](ve);
|
|
9244
9393
|
}
|
|
9245
9394
|
};
|
|
9246
|
-
;
|
|
9247
9395
|
/**
|
|
9248
9396
|
* @private
|
|
9249
9397
|
*/
|
|
@@ -9255,7 +9403,6 @@ var VertexListeners = /** @class */ (function () {
|
|
|
9255
9403
|
listeners.push(newListener);
|
|
9256
9404
|
return true;
|
|
9257
9405
|
};
|
|
9258
|
-
;
|
|
9259
9406
|
/**
|
|
9260
9407
|
* @private
|
|
9261
9408
|
*/
|
|
@@ -9266,7 +9413,6 @@ var VertexListeners = /** @class */ (function () {
|
|
|
9266
9413
|
}
|
|
9267
9414
|
return listeners;
|
|
9268
9415
|
};
|
|
9269
|
-
;
|
|
9270
9416
|
return VertexListeners;
|
|
9271
9417
|
}());
|
|
9272
9418
|
exports.VertexListeners = VertexListeners;
|