plotboilerplate 1.12.10 → 1.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/changelog.md +50 -0
- package/dist/index.esm.js +999 -510
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/plotboilerplate.browser.min.js +1 -1
- package/dist/plotboilerplate.browser.min.js.map +1 -1
- package/dist/plotboilerplate.js +1013 -509
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +1 -1
- package/src/cjs/BezierPath.d.ts +45 -2
- package/src/cjs/BezierPath.js +114 -18
- package/src/cjs/BezierPath.js.map +1 -1
- package/src/cjs/Circle.d.ts +25 -10
- package/src/cjs/Circle.js +38 -33
- package/src/cjs/Circle.js.map +1 -1
- package/src/cjs/CircleSector.d.ts +27 -13
- package/src/cjs/CircleSector.js +38 -23
- package/src/cjs/CircleSector.js.map +1 -1
- package/src/cjs/CubicBezierCurve.d.ts +17 -1
- package/src/cjs/CubicBezierCurve.js +78 -79
- package/src/cjs/CubicBezierCurve.js.map +1 -1
- package/src/cjs/KeyHandler.d.ts +10 -3
- package/src/cjs/KeyHandler.js +28 -23
- package/src/cjs/KeyHandler.js.map +1 -1
- package/src/cjs/Line.d.ts +2 -1
- package/src/cjs/Line.js +19 -18
- package/src/cjs/Line.js.map +1 -1
- package/src/cjs/MouseHandler.js +43 -53
- package/src/cjs/MouseHandler.js.map +1 -1
- package/src/cjs/PBImage.d.ts +16 -1
- package/src/cjs/PBImage.js +13 -3
- package/src/cjs/PBImage.js.map +1 -1
- package/src/cjs/PBText.d.ts +130 -0
- package/src/cjs/PBText.js +76 -0
- package/src/cjs/PBText.js.map +1 -0
- package/src/cjs/PlotBoilerplate.d.ts +2 -1
- package/src/cjs/PlotBoilerplate.js +44 -16
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/Polygon.d.ts +37 -1
- package/src/cjs/Polygon.js +131 -54
- package/src/cjs/Polygon.js.map +1 -1
- package/src/cjs/Triangle.d.ts +16 -1
- package/src/cjs/Triangle.js +50 -54
- package/src/cjs/Triangle.js.map +1 -1
- package/src/cjs/VEllipse.d.ts +16 -1
- package/src/cjs/VEllipse.js +25 -12
- package/src/cjs/VEllipse.js.map +1 -1
- package/src/cjs/VEllipseSector.d.ts +15 -1
- package/src/cjs/VEllipseSector.js +11 -1
- package/src/cjs/VEllipseSector.js.map +1 -1
- package/src/cjs/Vector.d.ts +3 -1
- package/src/cjs/Vector.js +32 -36
- package/src/cjs/Vector.js.map +1 -1
- package/src/cjs/VertTuple.d.ts +15 -1
- package/src/cjs/VertTuple.js +14 -19
- package/src/cjs/VertTuple.js.map +1 -1
- package/src/cjs/Vertex.d.ts +66 -4
- package/src/cjs/Vertex.js +99 -17
- package/src/cjs/Vertex.js.map +1 -1
- package/src/cjs/VertexListeners.d.ts +12 -8
- package/src/cjs/VertexListeners.js +18 -25
- package/src/cjs/VertexListeners.js.map +1 -1
- package/src/cjs/draw.d.ts +30 -2
- package/src/cjs/draw.js +51 -6
- package/src/cjs/draw.js.map +1 -1
- package/src/cjs/drawgl.d.ts +29 -2
- package/src/cjs/drawgl.js +21 -4
- package/src/cjs/drawgl.js.map +1 -1
- package/src/cjs/drawutilssvg.d.ts +25 -7
- package/src/cjs/drawutilssvg.js +62 -14
- package/src/cjs/drawutilssvg.js.map +1 -1
- package/src/cjs/entry.js +1 -0
- package/src/cjs/index.d.ts +1 -0
- package/src/cjs/index.js +1 -0
- package/src/cjs/index.js.map +1 -1
- package/src/cjs/interfaces/DrawLib.d.ts +27 -6
- package/src/cjs/interfaces/DrawLib.js +3 -0
- package/src/cjs/interfaces/DrawLib.js.map +1 -1
- package/src/cjs/interfaces/core.d.ts +9 -1
- package/src/cjs/interfaces/core.js +1 -0
- package/src/cjs/interfaces/core.js.map +1 -1
- package/src/cjs/utils/creategui.js +1 -1
- package/src/cjs/utils/findInVertexArray.d.ts +19 -0
- package/src/cjs/utils/findInVertexArray.js +29 -0
- package/src/cjs/utils/findInVertexArray.js.map +1 -0
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.d.ts +15 -0
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.js +55 -28
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
- package/src/cjs/utils/io/DndFileHandler.d.ts +63 -0
- package/src/cjs/utils/io/DndFileHandler.js +112 -0
- package/src/cjs/utils/io/DndFileHandler.js.map +1 -0
- package/src/cjs/utils/io/FileDrop.d.ts +98 -0
- package/src/cjs/utils/io/FileDrop.js +142 -0
- package/src/cjs/utils/io/FileDrop.js.map +1 -0
- package/src/esm/BezierPath.d.ts +45 -2
- package/src/esm/BezierPath.js +114 -18
- package/src/esm/BezierPath.js.map +1 -1
- package/src/esm/Circle.d.ts +25 -10
- package/src/esm/Circle.js +38 -33
- package/src/esm/Circle.js.map +1 -1
- package/src/esm/CircleSector.d.ts +27 -13
- package/src/esm/CircleSector.js +38 -23
- package/src/esm/CircleSector.js.map +1 -1
- package/src/esm/CubicBezierCurve.d.ts +17 -1
- package/src/esm/CubicBezierCurve.js +78 -79
- package/src/esm/CubicBezierCurve.js.map +1 -1
- package/src/esm/KeyHandler.d.ts +10 -3
- package/src/esm/KeyHandler.js +28 -23
- package/src/esm/KeyHandler.js.map +1 -1
- package/src/esm/Line.d.ts +2 -1
- package/src/esm/Line.js +19 -18
- package/src/esm/Line.js.map +1 -1
- package/src/esm/MouseHandler.js +43 -53
- package/src/esm/MouseHandler.js.map +1 -1
- package/src/esm/PBImage.d.ts +16 -1
- package/src/esm/PBImage.js +13 -3
- package/src/esm/PBImage.js.map +1 -1
- package/src/esm/PBText.d.ts +130 -0
- package/src/esm/PBText.js +71 -0
- package/src/esm/PBText.js.map +1 -0
- package/src/esm/PlotBoilerplate.d.ts +2 -1
- package/src/esm/PlotBoilerplate.js +44 -16
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/Polygon.d.ts +37 -1
- package/src/esm/Polygon.js +131 -54
- package/src/esm/Polygon.js.map +1 -1
- package/src/esm/Triangle.d.ts +16 -1
- package/src/esm/Triangle.js +50 -54
- package/src/esm/Triangle.js.map +1 -1
- package/src/esm/VEllipse.d.ts +16 -1
- package/src/esm/VEllipse.js +25 -12
- package/src/esm/VEllipse.js.map +1 -1
- package/src/esm/VEllipseSector.d.ts +15 -1
- package/src/esm/VEllipseSector.js +11 -1
- package/src/esm/VEllipseSector.js.map +1 -1
- package/src/esm/Vector.d.ts +3 -1
- package/src/esm/Vector.js +32 -36
- package/src/esm/Vector.js.map +1 -1
- package/src/esm/VertTuple.d.ts +15 -1
- package/src/esm/VertTuple.js +14 -19
- package/src/esm/VertTuple.js.map +1 -1
- package/src/esm/Vertex.d.ts +66 -4
- package/src/esm/Vertex.js +99 -17
- package/src/esm/Vertex.js.map +1 -1
- package/src/esm/VertexListeners.d.ts +12 -8
- package/src/esm/VertexListeners.js +18 -25
- package/src/esm/VertexListeners.js.map +1 -1
- package/src/esm/draw.d.ts +30 -2
- package/src/esm/draw.js +51 -6
- package/src/esm/draw.js.map +1 -1
- package/src/esm/drawgl.d.ts +29 -2
- package/src/esm/drawgl.js +21 -4
- package/src/esm/drawgl.js.map +1 -1
- package/src/esm/drawutilssvg.d.ts +25 -7
- package/src/esm/drawutilssvg.js +62 -14
- package/src/esm/drawutilssvg.js.map +1 -1
- package/src/esm/entry.js +1 -0
- package/src/esm/index.d.ts +1 -0
- package/src/esm/index.js +1 -0
- package/src/esm/index.js.map +1 -1
- package/src/esm/interfaces/DrawLib.d.ts +27 -6
- package/src/esm/interfaces/DrawLib.js +3 -0
- package/src/esm/interfaces/DrawLib.js.map +1 -1
- package/src/esm/interfaces/core.d.ts +9 -1
- package/src/esm/interfaces/core.js +1 -0
- package/src/esm/interfaces/core.js.map +1 -1
- package/src/esm/utils/findInVertexArray.d.ts +19 -0
- package/src/esm/utils/findInVertexArray.js +25 -0
- package/src/esm/utils/findInVertexArray.js.map +1 -0
- package/src/esm/utils/helpers/BezierPathInteractionHelper.d.ts +15 -0
- package/src/esm/utils/helpers/BezierPathInteractionHelper.js +54 -28
- package/src/esm/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
- package/src/esm/utils/io/DndFileHandler.d.ts +63 -0
- package/src/esm/utils/io/DndFileHandler.js +106 -0
- package/src/esm/utils/io/DndFileHandler.js.map +1 -0
- package/src/esm/utils/io/FileDrop.d.ts +98 -0
- package/src/esm/utils/io/FileDrop.js +136 -0
- package/src/esm/utils/io/FileDrop.js.map +1 -0
- package/src/ts/BezierPath.ts +133 -16
- package/src/ts/Circle.ts +213 -200
- package/src/ts/CircleSector.ts +171 -141
- package/src/ts/CubicBezierCurve.ts +777 -810
- package/src/ts/KeyHandler.ts +221 -212
- package/src/ts/Line.ts +77 -80
- package/src/ts/MouseHandler.ts +356 -368
- package/src/ts/PBImage.ts +81 -68
- package/src/ts/PBText.ts +166 -0
- package/src/ts/PlotBoilerplate.ts +48 -20
- package/src/ts/Polygon.ts +519 -451
- package/src/ts/Triangle.ts +484 -489
- package/src/ts/VEllipse.ts +36 -11
- package/src/ts/VEllipseSector.ts +20 -1
- package/src/ts/Vector.ts +164 -160
- package/src/ts/VertTuple.ts +333 -338
- package/src/ts/Vertex.ts +117 -16
- package/src/ts/VertexListeners.ts +248 -266
- package/src/ts/draw.ts +71 -8
- package/src/ts/drawgl.ts +48 -8
- package/src/ts/drawutilssvg.ts +94 -17
- package/src/ts/index.ts +1 -0
- package/src/ts/interfaces/DrawLib.ts +30 -4
- package/src/ts/interfaces/core.ts +9 -0
- package/src/ts/utils/findInVertexArray.ts +28 -0
- package/src/ts/utils/helpers/BezierPathInteractionHelper.ts +61 -30
- package/src/ts/utils/io/FileDrop.ts +178 -0
- package/dist/plotboilerplate.browser.min.js.LICENSE.txt +0 -8
- package/src/ts/utils/algorithms/clearPolygonDuplicateVertices.ts~ +0 -5
- package/src/ts/utils/algorithms/findPolygonSelfIntersections.ts~ +0 -45
- package/src/ts/utils/algorithms/sh-tmp.ts~ +0 -59
- package/src/ts/utils/algorithms/splitPolygonToNonIntersecting.ts~ +0 -113
- package/src/ts/utils/algorithms/sutherlandHodgman.ts~ +0 -88
package/src/cjs/Vector.js
CHANGED
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
* @modified 2019-12-04 Added the Vector.inv() function.
|
|
11
11
|
* @modified 2020-03-23 Ported to Typescript from JS.
|
|
12
12
|
* @modified 2021-01-20 Added UID.
|
|
13
|
-
* @
|
|
13
|
+
* @modified 2022-02-02 Added the `destroy` method.
|
|
14
|
+
* @modified 2022-02-02 Cleared the `Vector.toSVGString` function (deprecated). Use `drawutilssvg` instead.
|
|
15
|
+
* @version 1.4.0
|
|
14
16
|
*
|
|
15
17
|
* @file Vector
|
|
16
18
|
* @public
|
|
@@ -60,7 +62,6 @@ var Vector = /** @class */ (function (_super) {
|
|
|
60
62
|
_this.className = "Vector";
|
|
61
63
|
return _this;
|
|
62
64
|
}
|
|
63
|
-
;
|
|
64
65
|
/**
|
|
65
66
|
* Get the perpendicular of this vector which is located at a.
|
|
66
67
|
*
|
|
@@ -75,7 +76,6 @@ var Vector = /** @class */ (function (_super) {
|
|
|
75
76
|
v.b.add(this.a);
|
|
76
77
|
return v;
|
|
77
78
|
};
|
|
78
|
-
;
|
|
79
79
|
/**
|
|
80
80
|
* The inverse of a vector is a vector witht the same magnitude but oppose direction.
|
|
81
81
|
*
|
|
@@ -89,7 +89,6 @@ var Vector = /** @class */ (function (_super) {
|
|
|
89
89
|
this.b = tmp;
|
|
90
90
|
return this;
|
|
91
91
|
};
|
|
92
|
-
;
|
|
93
92
|
/**
|
|
94
93
|
* This function computes the inverse of the vector, which means 'a' stays untouched.
|
|
95
94
|
*
|
|
@@ -100,7 +99,6 @@ var Vector = /** @class */ (function (_super) {
|
|
|
100
99
|
this.b.y = this.a.y - (this.b.y - this.a.y);
|
|
101
100
|
return this;
|
|
102
101
|
};
|
|
103
|
-
;
|
|
104
102
|
/**
|
|
105
103
|
* Get the intersection if this vector and the specified vector.
|
|
106
104
|
*
|
|
@@ -116,16 +114,15 @@ var Vector = /** @class */ (function (_super) {
|
|
|
116
114
|
return null;
|
|
117
115
|
var a = this.a.y - line.a.y;
|
|
118
116
|
var b = this.a.x - line.a.x;
|
|
119
|
-
var numerator1 = (
|
|
120
|
-
var numerator2 = (
|
|
117
|
+
var numerator1 = (line.b.x - line.a.x) * a - (line.b.y - line.a.y) * b;
|
|
118
|
+
var numerator2 = (this.b.x - this.a.x) * a - (this.b.y - this.a.y) * b;
|
|
121
119
|
a = numerator1 / denominator; // NaN if parallel lines
|
|
122
120
|
b = numerator2 / denominator;
|
|
123
121
|
// TODO:
|
|
124
122
|
// FOR A VECTOR THE LINE-INTERSECTION MUST BE ON BOTH VECTORS
|
|
125
123
|
// if we cast these lines infinitely in both directions, they intersect here:
|
|
126
|
-
return new Vertex_1.Vertex(this.a.x +
|
|
124
|
+
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));
|
|
127
125
|
};
|
|
128
|
-
;
|
|
129
126
|
/**
|
|
130
127
|
* Create an SVG representation of this line.
|
|
131
128
|
*
|
|
@@ -138,31 +135,30 @@ var Vector = /** @class */ (function (_super) {
|
|
|
138
135
|
* @memberof Vector
|
|
139
136
|
**/
|
|
140
137
|
Vector.prototype.toSVGString = function (options) {
|
|
141
|
-
options = options || {};
|
|
142
|
-
var buffer = [];
|
|
143
|
-
var vertices = Vector.utils.buildArrowHead(this.a, this.b, 8, 1.0, 1.0);
|
|
144
|
-
buffer.push(
|
|
145
|
-
if (options.className)
|
|
146
|
-
|
|
147
|
-
buffer.push(
|
|
148
|
-
buffer.push('
|
|
149
|
-
buffer.push('
|
|
150
|
-
buffer.push('
|
|
151
|
-
buffer.push('
|
|
152
|
-
buffer.push(
|
|
153
|
-
|
|
154
|
-
//
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
buffer.
|
|
162
|
-
|
|
163
|
-
return
|
|
138
|
+
// options = options || {};
|
|
139
|
+
// var buffer = [];
|
|
140
|
+
// var vertices = Vector.utils.buildArrowHead(this.a, this.b, 8, 1.0, 1.0);
|
|
141
|
+
// buffer.push("<g");
|
|
142
|
+
// if (options.className) buffer.push(' class="' + options.className + '"');
|
|
143
|
+
// buffer.push(">");
|
|
144
|
+
// buffer.push(" <line");
|
|
145
|
+
// buffer.push(' x1="' + this.a.x + '"');
|
|
146
|
+
// buffer.push(' y1="' + this.a.y + '"');
|
|
147
|
+
// buffer.push(' x2="' + vertices[0].x + '"');
|
|
148
|
+
// buffer.push(' y2="' + vertices[0].y + '"');
|
|
149
|
+
// buffer.push(" />");
|
|
150
|
+
// // Add arrow head
|
|
151
|
+
// buffer.push(' <polygon points="');
|
|
152
|
+
// for (var i = 0; i < vertices.length; i++) {
|
|
153
|
+
// if (i > 0) buffer.push(" ");
|
|
154
|
+
// buffer.push("" + vertices[i].x + "," + vertices[i].y);
|
|
155
|
+
// }
|
|
156
|
+
// buffer.push('"/>');
|
|
157
|
+
// buffer.push("</g>");
|
|
158
|
+
// return buffer.join("");
|
|
159
|
+
console.warn("[Deprecation] Warning: the Vector.toSVGString method is deprecated and does not return and valid SVG data any more. Please use `drawutilssvg` instead.");
|
|
160
|
+
return "";
|
|
164
161
|
};
|
|
165
|
-
;
|
|
166
162
|
Vector.utils = {
|
|
167
163
|
/**
|
|
168
164
|
* Generate a four-point arrow head, starting at the vector end minus the
|
|
@@ -192,10 +188,10 @@ var Vector = /** @class */ (function (_super) {
|
|
|
192
188
|
buildArrowHead: function (zA, zB, headlen, scaleX, scaleY) {
|
|
193
189
|
var angle = Math.atan2((zB.y - zA.y) * scaleY, (zB.x - zA.x) * scaleX);
|
|
194
190
|
var vertices = [];
|
|
195
|
-
vertices.push(new Vertex_1.Vertex(zB.x * scaleX -
|
|
196
|
-
vertices.push(new Vertex_1.Vertex(zB.x * scaleX -
|
|
191
|
+
vertices.push(new Vertex_1.Vertex(zB.x * scaleX - headlen * Math.cos(angle), zB.y * scaleY - headlen * Math.sin(angle)));
|
|
192
|
+
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)));
|
|
197
193
|
vertices.push(new Vertex_1.Vertex(zB.x * scaleX, zB.y * scaleY));
|
|
198
|
-
vertices.push(new Vertex_1.Vertex(zB.x * scaleX -
|
|
194
|
+
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)));
|
|
199
195
|
return vertices;
|
|
200
196
|
}
|
|
201
197
|
};
|
package/src/cjs/Vector.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Vector.js","sourceRoot":"","sources":["../ts/Vector.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"Vector.js","sourceRoot":"","sources":["../ts/Vector.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;IAiBI;;;;;;;;;;;;;;;;AAEJ,yCAAwC;AACxC,mCAAkC;AAGlC;;;;;;;;IAQI;AACJ;IAA4B,0BAAiB;IAM3C;;;;;;;;QAQI;IACJ,gBAAY,KAAa,EAAE,KAAa;QAAxC,YACE,kBAAM,KAAK,EAAE,KAAK,EAAE,UAAC,CAAS,EAAE,CAAS,IAAK,OAAA,IAAI,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAhB,CAAgB,CAAC,SAChE;QAhBD;;YAEI;QACK,eAAS,GAAW,QAAQ,CAAC;;IAatC,CAAC;IAED;;;;;QAKI;IACJ,qBAAI,GAAJ;QACE,IAAI,CAAC,GAAW,IAAI,CAAC,KAAK,EAAE,CAAC;QAC7B,CAAC,CAAC,GAAG,CAAC,IAAI,CA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AAC,GAAG,MAAM,EAAE,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;YACxD,QAAQ,CAAC,IAAI,CACX,IAAI,eAAM,CACR,EAAE,CAAC,CAAC,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,EAC9D,EAAE,CAAC,CAAC,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAC/D,CACF,CAAC;YAEF,OAAO,QAAQ,CAAC;QAClB,CAAC;KACF,CAAC;IACJ,aAAC;CAAA,AA7KD,CAA4B,qBAAS,GA6KpC;AA7KY,wBAAM"}
|
package/src/cjs/VertTuple.d.ts
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* @modified 2020-12-04 Changed `getClosestT` param from `Vertex` to `XYCoords` (generalized).
|
|
9
9
|
* @modified 2020-12-04 Added the `hasPoint(XYCoords)` function.
|
|
10
10
|
* @modified 2021-01-20 Added UID.
|
|
11
|
-
* @
|
|
11
|
+
* @modified 2022-02-02 Added the `destroy` method.
|
|
12
|
+
* @version 1.2.0
|
|
12
13
|
*/
|
|
13
14
|
import { Vertex } from "./Vertex";
|
|
14
15
|
import { XYCoords, UID } from "./interfaces";
|
|
@@ -41,6 +42,13 @@ export declare class VertTuple<T extends VertTuple<T>> {
|
|
|
41
42
|
* @instance
|
|
42
43
|
*/
|
|
43
44
|
b: Vertex;
|
|
45
|
+
/**
|
|
46
|
+
* @member isDestroyed
|
|
47
|
+
* @memberof VertTuple
|
|
48
|
+
* @type {boolean}
|
|
49
|
+
* @instance
|
|
50
|
+
*/
|
|
51
|
+
isDestroyed: boolean;
|
|
44
52
|
/**
|
|
45
53
|
* The factory is used by the `clone` method.
|
|
46
54
|
*/
|
|
@@ -231,6 +239,12 @@ export declare class VertTuple<T extends VertTuple<T>> {
|
|
|
231
239
|
* @memberof VertTuple
|
|
232
240
|
**/
|
|
233
241
|
toString(): string;
|
|
242
|
+
/**
|
|
243
|
+
* This function should invalidate any installed listeners and invalidate this object.
|
|
244
|
+
* After calling this function the object might not hold valid data any more and
|
|
245
|
+
* should not be used.
|
|
246
|
+
*/
|
|
247
|
+
destroy(): void;
|
|
234
248
|
/**
|
|
235
249
|
* @private
|
|
236
250
|
**/
|
package/src/cjs/VertTuple.js
CHANGED
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
* @modified 2020-12-04 Changed `getClosestT` param from `Vertex` to `XYCoords` (generalized).
|
|
10
10
|
* @modified 2020-12-04 Added the `hasPoint(XYCoords)` function.
|
|
11
11
|
* @modified 2021-01-20 Added UID.
|
|
12
|
-
* @
|
|
12
|
+
* @modified 2022-02-02 Added the `destroy` method.
|
|
13
|
+
* @version 1.2.0
|
|
13
14
|
*/
|
|
14
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
16
|
exports.VertTuple = void 0;
|
|
@@ -47,7 +48,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
47
48
|
VertTuple.prototype.length = function () {
|
|
48
49
|
return Math.sqrt(Math.pow(this.b.x - this.a.x, 2) + Math.pow(this.b.y - this.a.y, 2));
|
|
49
50
|
};
|
|
50
|
-
;
|
|
51
51
|
/**
|
|
52
52
|
* Set the length of this vector to the given amount. This only works if this
|
|
53
53
|
* vector is not a null vector.
|
|
@@ -60,7 +60,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
60
60
|
VertTuple.prototype.setLength = function (length) {
|
|
61
61
|
return this.scale(length / this.length());
|
|
62
62
|
};
|
|
63
|
-
;
|
|
64
63
|
/**
|
|
65
64
|
* Substract the given vertex from this line's end points.
|
|
66
65
|
*
|
|
@@ -75,7 +74,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
75
74
|
this.b.sub(amount);
|
|
76
75
|
return this;
|
|
77
76
|
};
|
|
78
|
-
;
|
|
79
77
|
/**
|
|
80
78
|
* Add the given vertex to this line's end points.
|
|
81
79
|
*
|
|
@@ -90,7 +88,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
90
88
|
this.b.add(amount);
|
|
91
89
|
return this;
|
|
92
90
|
};
|
|
93
|
-
;
|
|
94
91
|
/**
|
|
95
92
|
* Normalize this line (set to length 1).
|
|
96
93
|
*
|
|
@@ -103,7 +100,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
103
100
|
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());
|
|
104
101
|
return this;
|
|
105
102
|
};
|
|
106
|
-
;
|
|
107
103
|
/**
|
|
108
104
|
* Scale this line by the given factor.
|
|
109
105
|
*
|
|
@@ -117,7 +113,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
117
113
|
this.b.set(this.a.x + (this.b.x - this.a.x) * factor, this.a.y + (this.b.y - this.a.y) * factor);
|
|
118
114
|
return this;
|
|
119
115
|
};
|
|
120
|
-
;
|
|
121
116
|
/**
|
|
122
117
|
* Move this line to a new location.
|
|
123
118
|
*
|
|
@@ -133,7 +128,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
133
128
|
this.b.add(diff);
|
|
134
129
|
return this;
|
|
135
130
|
};
|
|
136
|
-
;
|
|
137
131
|
/**
|
|
138
132
|
* Get the angle between this and the passed line (in radians).
|
|
139
133
|
*
|
|
@@ -144,7 +138,7 @@ var VertTuple = /** @class */ (function () {
|
|
|
144
138
|
* @memberof VertTuple
|
|
145
139
|
**/
|
|
146
140
|
VertTuple.prototype.angle = function (line) {
|
|
147
|
-
if (line == null || typeof line ==
|
|
141
|
+
if (line == null || typeof line == "undefined") {
|
|
148
142
|
line = this.factory(new Vertex_1.Vertex(0, 0), new Vertex_1.Vertex(100, 0));
|
|
149
143
|
}
|
|
150
144
|
// Compute the angle from x axis and the return the difference :)
|
|
@@ -154,7 +148,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
154
148
|
// The result might be negative, but isn't it usually nicer to determine angles in positive values only?
|
|
155
149
|
return Math.atan2(v1.x, v1.y) - Math.atan2(v0.x, v0.y);
|
|
156
150
|
};
|
|
157
|
-
;
|
|
158
151
|
/**
|
|
159
152
|
* Get line point at position t in [0 ... 1]:<br>
|
|
160
153
|
* <pre>[P(0)]=[A]--------------------[P(t)]------[B]=[P(1)]</pre><br>
|
|
@@ -170,7 +163,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
170
163
|
VertTuple.prototype.vertAt = function (t) {
|
|
171
164
|
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);
|
|
172
165
|
};
|
|
173
|
-
;
|
|
174
166
|
/**
|
|
175
167
|
* Get the denominator of this and the given line.
|
|
176
168
|
*
|
|
@@ -184,9 +176,8 @@ var VertTuple = /** @class */ (function () {
|
|
|
184
176
|
**/
|
|
185
177
|
VertTuple.prototype.denominator = function (line) {
|
|
186
178
|
// http://jsfiddle.net/justin_c_rounds/Gd2S2/
|
|
187
|
-
return (
|
|
179
|
+
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);
|
|
188
180
|
};
|
|
189
|
-
;
|
|
190
181
|
/**
|
|
191
182
|
* Checks if this and the given line are co-linear.
|
|
192
183
|
*
|
|
@@ -201,7 +192,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
201
192
|
VertTuple.prototype.colinear = function (line) {
|
|
202
193
|
return Math.abs(this.denominator(line)) < Vertex_1.Vertex.EPSILON;
|
|
203
194
|
};
|
|
204
|
-
;
|
|
205
195
|
/**
|
|
206
196
|
* Get the closest position T from this line to the specified point.
|
|
207
197
|
*
|
|
@@ -224,7 +214,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
224
214
|
// t = Math.max(0, Math.min(1, t));
|
|
225
215
|
return t;
|
|
226
216
|
};
|
|
227
|
-
;
|
|
228
217
|
/**
|
|
229
218
|
* Check if the given point is located on this line. Optionally also check if
|
|
230
219
|
* that point is located between point `a` and `b`.
|
|
@@ -260,7 +249,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
260
249
|
var t = this.getClosestT(p);
|
|
261
250
|
return this.vertAt(t);
|
|
262
251
|
};
|
|
263
|
-
;
|
|
264
252
|
/**
|
|
265
253
|
* The the minimal distance between this line and the specified point.
|
|
266
254
|
*
|
|
@@ -275,7 +263,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
275
263
|
// https://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment
|
|
276
264
|
return Math.sqrt(VertTuple.vtutils.dist2(p, this.vertAt(this.getClosestT(p))));
|
|
277
265
|
};
|
|
278
|
-
;
|
|
279
266
|
/**
|
|
280
267
|
* Create a deep clone of this instance.
|
|
281
268
|
*
|
|
@@ -287,7 +274,6 @@ var VertTuple = /** @class */ (function () {
|
|
|
287
274
|
VertTuple.prototype.clone = function () {
|
|
288
275
|
return this.factory(this.a.clone(), this.b.clone());
|
|
289
276
|
};
|
|
290
|
-
;
|
|
291
277
|
/**
|
|
292
278
|
* Create a string representation of this line.
|
|
293
279
|
*
|
|
@@ -299,7 +285,16 @@ var VertTuple = /** @class */ (function () {
|
|
|
299
285
|
VertTuple.prototype.toString = function () {
|
|
300
286
|
return "{ a : " + this.a.toString() + ", b : " + this.b.toString() + " }";
|
|
301
287
|
};
|
|
302
|
-
|
|
288
|
+
/**
|
|
289
|
+
* This function should invalidate any installed listeners and invalidate this object.
|
|
290
|
+
* After calling this function the object might not hold valid data any more and
|
|
291
|
+
* should not be used.
|
|
292
|
+
*/
|
|
293
|
+
VertTuple.prototype.destroy = function () {
|
|
294
|
+
this.a.destroy();
|
|
295
|
+
this.b.destroy();
|
|
296
|
+
this.isDestroyed = true;
|
|
297
|
+
};
|
|
303
298
|
/**
|
|
304
299
|
* @private
|
|
305
300
|
**/
|
package/src/cjs/VertTuple.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VertTuple.js","sourceRoot":"","sources":["../ts/VertTuple.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"VertTuple.js","sourceRoot":"","sources":["../ts/VertTuple.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAEH,mCAAkC;AAClC,+CAA8C;AAG9C;;;;;;GAMG;AACH;IAsCE;;;;;;;QAOI;IACJ,mBAAY,CAAS,EAAE,CAAS,EAAE,OAAoC;QACpE,IAAI,CAAC,GAAG,GAAG,2BAAY,CAAC,IAAI,EAAE,CAAC;QAC/B,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QACX,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QACX,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;;;;;QAMI;IACJ,0BAAM,GAAN;QACE,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACxF,CAAC;IAED;;;;;;;;QAQI;IACJ,6BAAS,GAAT,UAAU,MAAc;QACtB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED;;;;;;;;QAQI;IACJ,uBAAG,GAAH,UAAI,MAAgB;QAClB,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACnB,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;QAQI;IACJ,uBAAG,GAAH,UAAI,MAAgB;Q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AG,IAAI,CAAC;IAC5E,CAAC;IAED;;;;OAIG;IACH,2BAAO,GAAP;QACE,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QACjB,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QACjB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;IAED;;QAEI;IACG,iBAAO,GAAG;QACf,KAAK,EAAE,UAAC,CAAW,EAAE,CAAW;YAC9B,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/D,CAAC;KACF,CAAC;IACJ,gBAAC;CAAA,AA9UD,IA8UC;AA9UY,8BAAS"}
|
package/src/cjs/Vertex.d.ts
CHANGED
|
@@ -22,7 +22,13 @@
|
|
|
22
22
|
* @modified 2020-05-26 Added functions addX(number) and addY(number).
|
|
23
23
|
* @modified 2020-10-30 Changed the warnings in `sub(...)` and `add(...)` into real errors.
|
|
24
24
|
* @modified 2021-03-01 Changed the second param `center` in the `rotate` function from Vertex to XYCoords.
|
|
25
|
-
* @
|
|
25
|
+
* @modified 2021-12-01 Changed the type of param of `scale` to XYCoords.
|
|
26
|
+
* @modified 2021-12-01 Added function `scaleXY` for non uniform scaling.
|
|
27
|
+
* @modified 2021-12-17 Added the functions `lerp` and `lerpAbs` for linear interpolations.
|
|
28
|
+
* @modified 2022-01-31 Added `Vertex.utils.arrayToJSON`.
|
|
29
|
+
* @modified 2022-02-02 Added the `destroy` method.
|
|
30
|
+
* @modified 2022-02-02 Cleared the `Vertex.toSVGString` function (deprecated). Use `drawutilssvg` instead.
|
|
31
|
+
* @version 2.7.0
|
|
26
32
|
*
|
|
27
33
|
* @file Vertex
|
|
28
34
|
* @public
|
|
@@ -90,6 +96,13 @@ export declare class Vertex implements XYCoords, SVGSerializable {
|
|
|
90
96
|
* @instance
|
|
91
97
|
**/
|
|
92
98
|
listeners: VertexListeners;
|
|
99
|
+
/**
|
|
100
|
+
* @member isDestroyed
|
|
101
|
+
* @memberof Vertex
|
|
102
|
+
* @type {boolean}
|
|
103
|
+
* @instance
|
|
104
|
+
*/
|
|
105
|
+
isDestroyed: boolean;
|
|
93
106
|
/**
|
|
94
107
|
* The constructor for the vertex class.
|
|
95
108
|
*
|
|
@@ -262,16 +275,51 @@ export declare class Vertex implements XYCoords, SVGSerializable {
|
|
|
262
275
|
difference(vert: XYCoords): Vertex;
|
|
263
276
|
/**
|
|
264
277
|
* This is a vector-like behavior and 'scales' this vertex
|
|
265
|
-
* towards/from a given center.
|
|
278
|
+
* towards/from a given center by one uniform scale factor.
|
|
279
|
+
*
|
|
280
|
+
* @method scale
|
|
281
|
+
* @param {number} factor - The factor to 'scale' this vertex; 1.0 means no change.
|
|
282
|
+
* @param {XYCoords=} center - The origin of scaling; default is (0,0).
|
|
283
|
+
* @return {Vertex} this
|
|
284
|
+
* @instance
|
|
285
|
+
* @memberof Vertex
|
|
286
|
+
**/
|
|
287
|
+
scale(factor: number, center?: XYCoords): Vertex;
|
|
288
|
+
/**
|
|
289
|
+
* Perform a linear interpolation towards the given target vertex.
|
|
290
|
+
* The amount value `t` is relative, `t=0.0` means no change, `t=1.0`
|
|
291
|
+
* means this point will be moved to the exact target position.
|
|
292
|
+
*
|
|
293
|
+
* `t=0.5` will move this point to the middle of the connecting
|
|
294
|
+
* linear segment.
|
|
295
|
+
*
|
|
296
|
+
* @param {XYCoords} target - The target position to lerp this vertex to.
|
|
297
|
+
* @param {number} t - The relative amount, usually in [0..1], but other values will work, too.
|
|
298
|
+
* @returns
|
|
299
|
+
*/
|
|
300
|
+
lerp(target: XYCoords, t: number): Vertex;
|
|
301
|
+
/**
|
|
302
|
+
* Perform a linear interpolation towards the given target vertex (absolute variant).
|
|
303
|
+
* The amount value `t` is absolute, which means the lerp amount is a direct distance
|
|
304
|
+
* value. This point will have move the amount of the passed distance `u`.
|
|
305
|
+
*
|
|
306
|
+
* @param {XYCoords} target - The target position to lerp this vertex to.
|
|
307
|
+
* @param {number} t - The absolute move amount to use to lerping.
|
|
308
|
+
* @returns
|
|
309
|
+
*/
|
|
310
|
+
lerpAbs(target: XYCoords, u: number): Vertex;
|
|
311
|
+
/**
|
|
312
|
+
* This is a vector-like behavior and 'scales' this vertex
|
|
313
|
+
* towards/from a given center by two independent x- and y- scale factors.
|
|
266
314
|
*
|
|
267
315
|
* @method scale
|
|
268
316
|
* @param {number} factor - The factor to 'scale' this vertex; 1.0 means no change.
|
|
269
|
-
* @param {
|
|
317
|
+
* @param {XYCoords=} center - The origin of scaling; default is (0,0).
|
|
270
318
|
* @return {Vertex} this
|
|
271
319
|
* @instance
|
|
272
320
|
* @memberof Vertex
|
|
273
321
|
**/
|
|
274
|
-
|
|
322
|
+
scaleXY(factors: XYCoords, center?: XYCoords): Vertex;
|
|
275
323
|
/**
|
|
276
324
|
* This is a vector-like behavior and 'rotates' this vertex
|
|
277
325
|
* around given center.
|
|
@@ -333,10 +381,17 @@ export declare class Vertex implements XYCoords, SVGSerializable {
|
|
|
333
381
|
* @return {string} A string representing the SVG code for this vertex.
|
|
334
382
|
* @instance
|
|
335
383
|
* @memberof Vertex
|
|
384
|
+
* @deprecated
|
|
336
385
|
**/
|
|
337
386
|
toSVGString(options: {
|
|
338
387
|
className?: string;
|
|
339
388
|
}): string;
|
|
389
|
+
/**
|
|
390
|
+
* This function should invalidate any installed listeners and invalidate this object.
|
|
391
|
+
* After calling this function the object might not hold valid data any more and
|
|
392
|
+
* should not be used.
|
|
393
|
+
*/
|
|
394
|
+
destroy(): void;
|
|
340
395
|
/**
|
|
341
396
|
* Create a new random vertex inside the given viewport.
|
|
342
397
|
*
|
|
@@ -374,5 +429,12 @@ export declare class Vertex implements XYCoords, SVGSerializable {
|
|
|
374
429
|
* @param {number} scaleY - the vertical scaling during draw.
|
|
375
430
|
**/
|
|
376
431
|
buildArrowHead: (zA: Vertex, zB: Vertex, headlen: number, scaleX: number, scaleY: number) => Array<Vertex>;
|
|
432
|
+
/**
|
|
433
|
+
* Convert the given vertices (array) to a JSON string.
|
|
434
|
+
*
|
|
435
|
+
* @param {number?} precision - (optional) The numeric precision to be used (number of precision digits).
|
|
436
|
+
* @returns {string}
|
|
437
|
+
*/
|
|
438
|
+
arrayToJSON(vertices: Array<XYCoords>, precision?: number): string;
|
|
377
439
|
};
|
|
378
440
|
}
|
package/src/cjs/Vertex.js
CHANGED
|
@@ -23,7 +23,13 @@
|
|
|
23
23
|
* @modified 2020-05-26 Added functions addX(number) and addY(number).
|
|
24
24
|
* @modified 2020-10-30 Changed the warnings in `sub(...)` and `add(...)` into real errors.
|
|
25
25
|
* @modified 2021-03-01 Changed the second param `center` in the `rotate` function from Vertex to XYCoords.
|
|
26
|
-
* @
|
|
26
|
+
* @modified 2021-12-01 Changed the type of param of `scale` to XYCoords.
|
|
27
|
+
* @modified 2021-12-01 Added function `scaleXY` for non uniform scaling.
|
|
28
|
+
* @modified 2021-12-17 Added the functions `lerp` and `lerpAbs` for linear interpolations.
|
|
29
|
+
* @modified 2022-01-31 Added `Vertex.utils.arrayToJSON`.
|
|
30
|
+
* @modified 2022-02-02 Added the `destroy` method.
|
|
31
|
+
* @modified 2022-02-02 Cleared the `Vertex.toSVGString` function (deprecated). Use `drawutilssvg` instead.
|
|
32
|
+
* @version 2.7.0
|
|
27
33
|
*
|
|
28
34
|
* @file Vertex
|
|
29
35
|
* @public
|
|
@@ -369,20 +375,72 @@ var Vertex = /** @class */ (function () {
|
|
|
369
375
|
};
|
|
370
376
|
/**
|
|
371
377
|
* This is a vector-like behavior and 'scales' this vertex
|
|
372
|
-
* towards/from a given center.
|
|
378
|
+
* towards/from a given center by one uniform scale factor.
|
|
373
379
|
*
|
|
374
380
|
* @method scale
|
|
375
381
|
* @param {number} factor - The factor to 'scale' this vertex; 1.0 means no change.
|
|
376
|
-
* @param {
|
|
382
|
+
* @param {XYCoords=} center - The origin of scaling; default is (0,0).
|
|
377
383
|
* @return {Vertex} this
|
|
378
384
|
* @instance
|
|
379
385
|
* @memberof Vertex
|
|
380
386
|
**/
|
|
381
387
|
Vertex.prototype.scale = function (factor, center) {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
388
|
+
return this.scaleXY({ x: factor, y: factor }, center);
|
|
389
|
+
};
|
|
390
|
+
/**
|
|
391
|
+
* Perform a linear interpolation towards the given target vertex.
|
|
392
|
+
* The amount value `t` is relative, `t=0.0` means no change, `t=1.0`
|
|
393
|
+
* means this point will be moved to the exact target position.
|
|
394
|
+
*
|
|
395
|
+
* `t=0.5` will move this point to the middle of the connecting
|
|
396
|
+
* linear segment.
|
|
397
|
+
*
|
|
398
|
+
* @param {XYCoords} target - The target position to lerp this vertex to.
|
|
399
|
+
* @param {number} t - The relative amount, usually in [0..1], but other values will work, too.
|
|
400
|
+
* @returns
|
|
401
|
+
*/
|
|
402
|
+
Vertex.prototype.lerp = function (target, t) {
|
|
403
|
+
var diff = this.difference(target);
|
|
404
|
+
// return new Vertex(this.x + diff.x * t, this.y + diff.y * t);
|
|
405
|
+
this.x += diff.x * t;
|
|
406
|
+
this.y += diff.y * t;
|
|
407
|
+
return this;
|
|
408
|
+
};
|
|
409
|
+
/**
|
|
410
|
+
* Perform a linear interpolation towards the given target vertex (absolute variant).
|
|
411
|
+
* The amount value `t` is absolute, which means the lerp amount is a direct distance
|
|
412
|
+
* value. This point will have move the amount of the passed distance `u`.
|
|
413
|
+
*
|
|
414
|
+
* @param {XYCoords} target - The target position to lerp this vertex to.
|
|
415
|
+
* @param {number} t - The absolute move amount to use to lerping.
|
|
416
|
+
* @returns
|
|
417
|
+
*/
|
|
418
|
+
Vertex.prototype.lerpAbs = function (target, u) {
|
|
419
|
+
var dist = this.distance(target);
|
|
420
|
+
var diff = this.difference(target);
|
|
421
|
+
var step = { x: diff.x / dist, y: diff.y / dist };
|
|
422
|
+
// return new Vertex(this.x + step.x * u, this.y + step.y * u);
|
|
423
|
+
this.x += step.x * u;
|
|
424
|
+
this.y += step.y * u;
|
|
425
|
+
return this;
|
|
426
|
+
};
|
|
427
|
+
/**
|
|
428
|
+
* This is a vector-like behavior and 'scales' this vertex
|
|
429
|
+
* towards/from a given center by two independent x- and y- scale factors.
|
|
430
|
+
*
|
|
431
|
+
* @method scale
|
|
432
|
+
* @param {number} factor - The factor to 'scale' this vertex; 1.0 means no change.
|
|
433
|
+
* @param {XYCoords=} center - The origin of scaling; default is (0,0).
|
|
434
|
+
* @return {Vertex} this
|
|
435
|
+
* @instance
|
|
436
|
+
* @memberof Vertex
|
|
437
|
+
**/
|
|
438
|
+
Vertex.prototype.scaleXY = function (factors, center) {
|
|
439
|
+
if (!center || typeof center === "undefined") {
|
|
440
|
+
center = { x: 0, y: 0 };
|
|
441
|
+
}
|
|
442
|
+
this.x = center.x + (this.x - center.x) * factors.x;
|
|
443
|
+
this.y = center.y + (this.y - center.y) * factors.y;
|
|
386
444
|
return this;
|
|
387
445
|
};
|
|
388
446
|
/**
|
|
@@ -471,20 +529,31 @@ var Vertex = /** @class */ (function () {
|
|
|
471
529
|
* @return {string} A string representing the SVG code for this vertex.
|
|
472
530
|
* @instance
|
|
473
531
|
* @memberof Vertex
|
|
532
|
+
* @deprecated
|
|
474
533
|
**/
|
|
475
534
|
Vertex.prototype.toSVGString = function (options) {
|
|
476
|
-
options = options || {};
|
|
477
|
-
var buffer = [];
|
|
478
|
-
buffer.push("<circle");
|
|
479
|
-
if (options.className)
|
|
480
|
-
|
|
481
|
-
buffer.push('
|
|
482
|
-
buffer.push('
|
|
483
|
-
buffer.push(
|
|
484
|
-
buffer.
|
|
485
|
-
return
|
|
535
|
+
// options = options || {};
|
|
536
|
+
// var buffer = [];
|
|
537
|
+
// buffer.push("<circle");
|
|
538
|
+
// if (options.className) buffer.push(' class="' + options.className + '"');
|
|
539
|
+
// buffer.push(' cx="' + this.x + '"');
|
|
540
|
+
// buffer.push(' cy="' + this.y + '"');
|
|
541
|
+
// buffer.push(' r="2"');
|
|
542
|
+
// buffer.push(" />");
|
|
543
|
+
// return buffer.join("");
|
|
544
|
+
console.warn("[Deprecation] Warning: the Vertex.toSVGString method is deprecated and does not return and valid SVG data any more. Please use `drawutilssvg` instead.");
|
|
545
|
+
return "";
|
|
486
546
|
};
|
|
487
547
|
// END Vertex
|
|
548
|
+
/**
|
|
549
|
+
* This function should invalidate any installed listeners and invalidate this object.
|
|
550
|
+
* After calling this function the object might not hold valid data any more and
|
|
551
|
+
* should not be used.
|
|
552
|
+
*/
|
|
553
|
+
Vertex.prototype.destroy = function () {
|
|
554
|
+
this.listeners.removeAllListeners();
|
|
555
|
+
this.isDestroyed = true;
|
|
556
|
+
};
|
|
488
557
|
/**
|
|
489
558
|
* Create a new random vertex inside the given viewport.
|
|
490
559
|
*
|
|
@@ -538,6 +607,19 @@ var Vertex = /** @class */ (function () {
|
|
|
538
607
|
vertices.push(new Vertex(zB.x * scaleX, zB.y * scaleY));
|
|
539
608
|
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)));
|
|
540
609
|
return vertices;
|
|
610
|
+
},
|
|
611
|
+
/**
|
|
612
|
+
* Convert the given vertices (array) to a JSON string.
|
|
613
|
+
*
|
|
614
|
+
* @param {number?} precision - (optional) The numeric precision to be used (number of precision digits).
|
|
615
|
+
* @returns {string}
|
|
616
|
+
*/
|
|
617
|
+
arrayToJSON: function (vertices, precision) {
|
|
618
|
+
return JSON.stringify(vertices.map(function (vert) {
|
|
619
|
+
return typeof precision === undefined
|
|
620
|
+
? { x: vert.x, y: vert.y }
|
|
621
|
+
: { x: Number(vert.x.toFixed(precision)), y: Number(vert.y.toFixed(precision)) };
|
|
622
|
+
}));
|
|
541
623
|
}
|
|
542
624
|
};
|
|
543
625
|
return Vertex;
|