plotboilerplate 1.23.2 → 1.24.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 +6 -0
- package/dist/index.esm.js +8351 -6928
- 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 +1590 -123
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +4 -2
- package/src/cjs/BezierPath.d.ts +41 -5
- package/src/cjs/BezierPath.js +52 -2
- package/src/cjs/BezierPath.js.map +1 -1
- package/src/cjs/Bounds.d.ts +67 -3
- package/src/cjs/Bounds.js +101 -3
- package/src/cjs/Bounds.js.map +1 -1
- package/src/cjs/Circle.d.ts +46 -4
- package/src/cjs/Circle.js +82 -3
- package/src/cjs/Circle.js.map +1 -1
- package/src/cjs/CircleSector.d.ts +51 -2
- package/src/cjs/CircleSector.js +112 -3
- package/src/cjs/CircleSector.js.map +1 -1
- package/src/cjs/CubicBezierCurve.d.ts +113 -7
- package/src/cjs/CubicBezierCurve.js +281 -33
- package/src/cjs/CubicBezierCurve.js.map +1 -1
- package/src/cjs/Line.d.ts +38 -3
- package/src/cjs/Line.js +64 -1
- package/src/cjs/Line.js.map +1 -1
- package/src/cjs/PlotBoilerplate.d.ts +4 -2
- package/src/cjs/PlotBoilerplate.js +9 -12
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/Polygon.d.ts +153 -6
- package/src/cjs/Polygon.js +304 -23
- package/src/cjs/Polygon.js.map +1 -1
- package/src/cjs/Triangle.d.ts +73 -4
- package/src/cjs/Triangle.js +94 -2
- package/src/cjs/Triangle.js.map +1 -1
- package/src/cjs/VEllipse.d.ts +62 -3
- package/src/cjs/VEllipse.js +181 -17
- package/src/cjs/VEllipse.js.map +1 -1
- package/src/cjs/VEllipseSector.d.ts +86 -2
- package/src/cjs/VEllipseSector.js +148 -4
- package/src/cjs/VEllipseSector.js.map +1 -1
- package/src/cjs/Vector.d.ts +12 -2
- package/src/cjs/Vector.js +15 -2
- package/src/cjs/Vector.js.map +1 -1
- package/src/cjs/VertTuple.d.ts +39 -10
- package/src/cjs/VertTuple.js +49 -11
- package/src/cjs/VertTuple.js.map +1 -1
- package/src/cjs/Vertex.d.ts +18 -2
- package/src/cjs/Vertex.js +22 -2
- package/src/cjs/Vertex.js.map +1 -1
- package/src/cjs/draw.d.ts +1 -0
- package/src/cjs/draw.js +2 -1
- package/src/cjs/draw.js.map +1 -1
- package/src/cjs/drawutilssvg.js +24 -0
- package/src/cjs/drawutilssvg.js.map +1 -1
- package/src/cjs/geomutils.d.ts +32 -1
- package/src/cjs/geomutils.js +47 -1
- package/src/cjs/geomutils.js.map +1 -1
- package/src/cjs/interfaces/core.d.ts +39 -0
- package/src/cjs/interfaces/core.js +2 -0
- package/src/cjs/interfaces/core.js.map +1 -1
- package/src/cjs/utils/algorithms/PolygonInset.d.ts +184 -0
- package/src/cjs/utils/algorithms/PolygonInset.js +431 -0
- package/src/cjs/utils/algorithms/PolygonInset.js.map +1 -0
- package/src/cjs/utils/algorithms/clearDuplicateVertices.d.ts +5 -4
- package/src/cjs/utils/algorithms/clearDuplicateVertices.js +6 -3
- package/src/cjs/utils/algorithms/clearDuplicateVertices.js.map +1 -1
- package/src/cjs/utils/algorithms/convexPolygonIncircle.d.ts +2 -1
- package/src/cjs/utils/algorithms/convexPolygonIncircle.js +14 -6
- package/src/cjs/utils/algorithms/convexPolygonIncircle.js.map +1 -1
- package/src/cjs/utils/algorithms/findPolygonSelfIntersections.d.ts +2 -1
- package/src/cjs/utils/algorithms/findPolygonSelfIntersections.js +3 -3
- package/src/cjs/utils/algorithms/findPolygonSelfIntersections.js.map +1 -1
- package/src/cjs/utils/algorithms/splitPolygonToNonIntersecting.d.ts +3 -2
- package/src/cjs/utils/algorithms/splitPolygonToNonIntersecting.js +11 -9
- package/src/cjs/utils/algorithms/splitPolygonToNonIntersecting.js.map +1 -1
- package/src/cjs/utils/createRandomizedPolygon.d.ts +14 -0
- package/src/cjs/utils/createRandomizedPolygon.js +32 -0
- package/src/cjs/utils/createRandomizedPolygon.js.map +1 -0
- package/src/cjs/utils/detectDarkMode.js.map +1 -1
- package/src/cjs/utils/dom/guiSizeToggler.d.ts +2 -1
- package/src/cjs/utils/dom/guiSizeToggler.js +5 -3
- package/src/cjs/utils/dom/guiSizeToggler.js.map +1 -1
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.d.ts +9 -7
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.js +37 -23
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
- package/src/cjs/utils/helpers/CircleSectorHelper.d.ts +10 -1
- package/src/cjs/utils/helpers/CircleSectorHelper.js +19 -20
- package/src/cjs/utils/helpers/CircleSectorHelper.js.map +1 -1
- package/src/cjs/utils/helpers/VEllipseHelper.d.ts +30 -0
- package/src/cjs/utils/helpers/VEllipseHelper.js +86 -0
- package/src/cjs/utils/helpers/VEllipseHelper.js.map +1 -0
- package/src/cjs/utils/helpers/VEllipseSectorHelper.d.ts +42 -3
- package/src/cjs/utils/helpers/VEllipseSectorHelper.js +107 -25
- package/src/cjs/utils/helpers/VEllipseSectorHelper.js.map +1 -1
- package/src/createDemoDrawables.js +3 -1
- package/src/esm/BezierPath.d.ts +41 -5
- package/src/esm/BezierPath.js +50 -2
- package/src/esm/BezierPath.js.map +1 -1
- package/src/esm/Bounds.d.ts +67 -3
- package/src/esm/Bounds.js +101 -3
- package/src/esm/Bounds.js.map +1 -1
- package/src/esm/Circle.d.ts +46 -4
- package/src/esm/Circle.js +79 -3
- package/src/esm/Circle.js.map +1 -1
- package/src/esm/CircleSector.d.ts +51 -2
- package/src/esm/CircleSector.js +108 -3
- package/src/esm/CircleSector.js.map +1 -1
- package/src/esm/CubicBezierCurve.d.ts +113 -7
- package/src/esm/CubicBezierCurve.js +277 -33
- package/src/esm/CubicBezierCurve.js.map +1 -1
- package/src/esm/Line.d.ts +38 -3
- package/src/esm/Line.js +62 -1
- package/src/esm/Line.js.map +1 -1
- package/src/esm/PlotBoilerplate.d.ts +4 -2
- package/src/esm/PlotBoilerplate.js +9 -12
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/Polygon.d.ts +153 -6
- package/src/esm/Polygon.js +301 -23
- package/src/esm/Polygon.js.map +1 -1
- package/src/esm/Triangle.d.ts +73 -4
- package/src/esm/Triangle.js +91 -2
- package/src/esm/Triangle.js.map +1 -1
- package/src/esm/VEllipse.d.ts +62 -3
- package/src/esm/VEllipse.js +178 -17
- package/src/esm/VEllipse.js.map +1 -1
- package/src/esm/VEllipseSector.d.ts +86 -2
- package/src/esm/VEllipseSector.js +146 -7
- package/src/esm/VEllipseSector.js.map +1 -1
- package/src/esm/Vector.d.ts +12 -2
- package/src/esm/Vector.js +15 -2
- package/src/esm/Vector.js.map +1 -1
- package/src/esm/VertTuple.d.ts +39 -10
- package/src/esm/VertTuple.js +49 -11
- package/src/esm/VertTuple.js.map +1 -1
- package/src/esm/Vertex.d.ts +18 -2
- package/src/esm/Vertex.js +22 -2
- package/src/esm/Vertex.js.map +1 -1
- package/src/esm/draw.d.ts +1 -0
- package/src/esm/draw.js +2 -1
- package/src/esm/draw.js.map +1 -1
- package/src/esm/drawutilssvg.js +24 -0
- package/src/esm/drawutilssvg.js.map +1 -1
- package/src/esm/geomutils.d.ts +32 -1
- package/src/esm/geomutils.js +47 -1
- package/src/esm/geomutils.js.map +1 -1
- package/src/esm/interfaces/core.d.ts +39 -0
- package/src/esm/interfaces/core.js +2 -0
- package/src/esm/interfaces/core.js.map +1 -1
- package/src/esm/utils/algorithms/PolygonInset.d.ts +184 -0
- package/src/esm/utils/algorithms/PolygonInset.js +424 -0
- package/src/esm/utils/algorithms/PolygonInset.js.map +1 -0
- package/src/esm/utils/algorithms/clearDuplicateVertices.d.ts +5 -4
- package/src/esm/utils/algorithms/clearDuplicateVertices.js +6 -3
- package/src/esm/utils/algorithms/clearDuplicateVertices.js.map +1 -1
- package/src/esm/utils/algorithms/convexPolygonIncircle.d.ts +2 -1
- package/src/esm/utils/algorithms/convexPolygonIncircle.js +15 -7
- package/src/esm/utils/algorithms/convexPolygonIncircle.js.map +1 -1
- package/src/esm/utils/algorithms/createRandomizedPolygon.d.ts +14 -0
- package/src/esm/utils/algorithms/createRandomizedPolygon.js +28 -0
- package/src/esm/utils/algorithms/createRandomizedPolygon.js.map +1 -0
- package/src/esm/utils/algorithms/findPolygonSelfIntersections.d.ts +2 -1
- package/src/esm/utils/algorithms/findPolygonSelfIntersections.js +3 -3
- package/src/esm/utils/algorithms/findPolygonSelfIntersections.js.map +1 -1
- package/src/esm/utils/algorithms/splitPolygonToNonIntersecting.d.ts +3 -2
- package/src/esm/utils/algorithms/splitPolygonToNonIntersecting.js +11 -9
- package/src/esm/utils/algorithms/splitPolygonToNonIntersecting.js.map +1 -1
- package/src/esm/utils/createRandomizedPolygon.d.ts +14 -0
- package/src/esm/utils/createRandomizedPolygon.js +28 -0
- package/src/esm/utils/createRandomizedPolygon.js.map +1 -0
- package/src/esm/utils/detectDarkMode.js.map +1 -1
- package/src/esm/utils/dom/guiSizeToggler.d.ts +2 -1
- package/src/esm/utils/dom/guiSizeToggler.js +4 -2
- package/src/esm/utils/dom/guiSizeToggler.js.map +1 -1
- package/src/esm/utils/helpers/BezierPathInteractionHelper.d.ts +9 -7
- package/src/esm/utils/helpers/BezierPathInteractionHelper.js +35 -22
- package/src/esm/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
- package/src/esm/utils/helpers/CircleSectorHelper.d.ts +10 -1
- package/src/esm/utils/helpers/CircleSectorHelper.js +19 -20
- package/src/esm/utils/helpers/CircleSectorHelper.js.map +1 -1
- package/src/esm/utils/helpers/VEllipseHelper.d.ts +30 -0
- package/src/esm/utils/helpers/VEllipseHelper.js +81 -0
- package/src/esm/utils/helpers/VEllipseHelper.js.map +1 -0
- package/src/esm/utils/helpers/VEllipseSectorHelper.d.ts +42 -3
- package/src/esm/utils/helpers/VEllipseSectorHelper.js +106 -24
- package/src/esm/utils/helpers/VEllipseSectorHelper.js.map +1 -1
- package/src/ts/BezierPath.ts +58 -5
- package/src/ts/Bounds.ts +110 -6
- package/src/ts/Circle.ts +87 -5
- package/src/ts/CircleSector.ts +115 -5
- package/src/ts/CubicBezierCurve.ts +332 -42
- package/src/ts/Line.ts +66 -3
- package/src/ts/PlotBoilerplate.ts +10 -12
- package/src/ts/Polygon.ts +329 -27
- package/src/ts/Triangle.ts +101 -5
- package/src/ts/VEllipse.ts +214 -19
- package/src/ts/VEllipseSector.ts +154 -8
- package/src/ts/Vector.ts +16 -2
- package/src/ts/VertTuple.ts +53 -13
- package/src/ts/Vertex.ts +24 -3
- package/src/ts/draw.ts +2 -1
- package/src/ts/drawutilssvg.ts +29 -0
- package/src/ts/geomutils.ts +49 -1
- package/src/ts/interfaces/core.ts +42 -0
- package/src/ts/utils/algorithms/PolygonInset.ts +529 -0
- package/src/ts/utils/algorithms/clearDuplicateVertices.ts +11 -8
- package/src/ts/utils/algorithms/convexPolygonIncircle.ts +82 -78
- package/src/ts/utils/algorithms/findPolygonSelfIntersections.ts +25 -26
- package/src/ts/utils/algorithms/splitPolygonToNonIntersecting.ts +92 -99
- package/src/ts/utils/createRandomizedPolygon.ts +31 -0
- package/src/ts/utils/detectDarkMode.ts +1 -3
- package/src/ts/utils/dom/guiSizeToggler.ts +4 -2
- package/src/ts/utils/helpers/BezierPathInteractionHelper.ts +45 -29
- package/src/ts/utils/helpers/CircleSectorHelper.ts +115 -125
- package/src/ts/utils/helpers/VEllipseHelper.ts +113 -0
- package/src/ts/utils/helpers/VEllipseSectorHelper.ts +142 -25
package/src/ts/VertTuple.ts
CHANGED
|
@@ -10,7 +10,13 @@
|
|
|
10
10
|
* @modified 2021-01-20 Added UID.
|
|
11
11
|
* @modified 2022-02-02 Added the `destroy` method.
|
|
12
12
|
* @modified 2023-09-29 Fixed a calculation error in the VertTuple.hasPoint() function; distance measure was broken!
|
|
13
|
-
* @
|
|
13
|
+
* @modified 2024-09-10 Chaging the first param of `pointDistance` from `Vertex` to less strict type `XYCoords`. This should not break anything.
|
|
14
|
+
* @modified 2024-09-10 Adding the optional `epsilon` param to the `hasPoint` method.
|
|
15
|
+
* @modified 2024-12-02 Added the `epsilon` param to the `colinear` method. Default is 1.0e-6.
|
|
16
|
+
* @modified 2025-03-31 Added the `VertTuple.revert` method.
|
|
17
|
+
* @modified 2025-04-15 Changed param of `VertTuple.moveTo` method from `Vertex` to `XYCoords`.
|
|
18
|
+
* @modified 2025-04-15 Added method `VertTuple.move` method.
|
|
19
|
+
* @version 1.4.0
|
|
14
20
|
*/
|
|
15
21
|
|
|
16
22
|
import { Vertex } from "./Vertex";
|
|
@@ -121,9 +127,9 @@ export class VertTuple<T extends VertTuple<T>> {
|
|
|
121
127
|
*
|
|
122
128
|
* @method add
|
|
123
129
|
* @param {XYCoords} amount The amount (x,y) to add.
|
|
124
|
-
* @return {Line} this
|
|
125
130
|
* @instance
|
|
126
131
|
* @memberof VertTuple
|
|
132
|
+
* @return {VertTuple<T>} this
|
|
127
133
|
**/
|
|
128
134
|
add(amount: XYCoords): VertTuple<T> {
|
|
129
135
|
this.a.add(amount);
|
|
@@ -131,6 +137,23 @@ export class VertTuple<T extends VertTuple<T>> {
|
|
|
131
137
|
return this;
|
|
132
138
|
}
|
|
133
139
|
|
|
140
|
+
/**
|
|
141
|
+
* Reverse this vertex tuple: a becomes b, and b becomes a.
|
|
142
|
+
* This operation is in-place.
|
|
143
|
+
*
|
|
144
|
+
* @method add
|
|
145
|
+
* @param {XYCoords} amount The amount (x,y) to add.
|
|
146
|
+
* @instance
|
|
147
|
+
* @memberof VertTuple
|
|
148
|
+
* @return {VertTuple<T>} this
|
|
149
|
+
*/
|
|
150
|
+
revert(): VertTuple<T> {
|
|
151
|
+
const tmp: Vertex = this.a;
|
|
152
|
+
this.a = this.b;
|
|
153
|
+
this.b = tmp;
|
|
154
|
+
return this;
|
|
155
|
+
}
|
|
156
|
+
|
|
134
157
|
/**
|
|
135
158
|
* Normalize this line (set to length 1).
|
|
136
159
|
*
|
|
@@ -162,18 +185,33 @@ export class VertTuple<T extends VertTuple<T>> {
|
|
|
162
185
|
* Move this line to a new location.
|
|
163
186
|
*
|
|
164
187
|
* @method moveTo
|
|
165
|
-
* @param {
|
|
188
|
+
* @param {XYCoords} newA - The new desired location of 'a'. Vertex 'b' will be moved, too.
|
|
166
189
|
* @return {VertTuple} this
|
|
167
190
|
* @instance
|
|
168
191
|
* @memberof VertTuple
|
|
169
192
|
**/
|
|
170
|
-
moveTo(newA:
|
|
193
|
+
moveTo(newA: XYCoords): VertTuple<T> {
|
|
171
194
|
let diff = this.a.difference(newA);
|
|
172
195
|
this.a.add(diff);
|
|
173
196
|
this.b.add(diff);
|
|
174
197
|
return this;
|
|
175
198
|
}
|
|
176
199
|
|
|
200
|
+
/**
|
|
201
|
+
* Move this line by the given amount
|
|
202
|
+
*
|
|
203
|
+
* @method move
|
|
204
|
+
* @param {XYCoords} amount - The amount to move both point of this tuple.
|
|
205
|
+
* @return {VertTuple} this
|
|
206
|
+
* @instance
|
|
207
|
+
* @memberof VertTuple
|
|
208
|
+
**/
|
|
209
|
+
move(amount: XYCoords): VertTuple<T> {
|
|
210
|
+
this.a.add(amount);
|
|
211
|
+
this.b.add(amount);
|
|
212
|
+
return this;
|
|
213
|
+
}
|
|
214
|
+
|
|
177
215
|
/**
|
|
178
216
|
* Get the angle between this and the passed line (in radians).
|
|
179
217
|
*
|
|
@@ -234,12 +272,13 @@ export class VertTuple<T extends VertTuple<T>> {
|
|
|
234
272
|
*
|
|
235
273
|
* @method colinear
|
|
236
274
|
* @param {VertTuple} line
|
|
275
|
+
* @param {epsilon?=1.0e-6} epsilon - The epsilon to use (default is 1.0e-6).
|
|
237
276
|
* @instance
|
|
238
277
|
* @memberof VertTuple
|
|
239
278
|
* @return true if both lines are co-linear.
|
|
240
279
|
*/
|
|
241
|
-
colinear(line: VertTuple<T
|
|
242
|
-
return Math.abs(this.denominator(line)) < Vertex.EPSILON;
|
|
280
|
+
colinear(line: VertTuple<T>, epsilon?: number): boolean {
|
|
281
|
+
return Math.abs(this.denominator(line)) < (typeof epsilon === "undefined" ? Vertex.EPSILON : epsilon);
|
|
243
282
|
}
|
|
244
283
|
|
|
245
284
|
/**
|
|
@@ -269,20 +308,21 @@ export class VertTuple<T extends VertTuple<T>> {
|
|
|
269
308
|
* that point is located between point `a` and `b`.
|
|
270
309
|
*
|
|
271
310
|
* @method hasPoint
|
|
272
|
-
* @param {Vertex} point The point to check.
|
|
273
|
-
* @param {boolean=} insideBoundsOnly If set to to true (default=false) the point must be between start and end point of the line.
|
|
311
|
+
* @param {Vertex} point - The point to check.
|
|
312
|
+
* @param {boolean=} insideBoundsOnly - [optional] If set to to true (default=false) the point must be between start and end point of the line.
|
|
313
|
+
* @param {number=Vertex.EPSILON} epsilon - [optional] A tolerance.
|
|
274
314
|
* @return {boolean} True if the given point is on this line.
|
|
275
315
|
* @instance
|
|
276
316
|
* @memberof VertTuple
|
|
277
317
|
*/
|
|
278
|
-
hasPoint(point: XYCoords, insideBoundsOnly?: boolean): boolean {
|
|
318
|
+
hasPoint(point: XYCoords, insideBoundsOnly?: boolean, epsilon?: number): boolean {
|
|
279
319
|
const t: number = this.getClosestT(point);
|
|
280
320
|
// Compare to pointDistance?
|
|
281
321
|
const distance: number = Math.sqrt(VertTuple.vtutils.dist2(point, this.vertAt(t)));
|
|
282
322
|
if (typeof insideBoundsOnly !== "undefined" && insideBoundsOnly) {
|
|
283
|
-
return distance < Vertex.EPSILON && t >= 0 && t <= 1;
|
|
323
|
+
return distance < (epsilon ?? Vertex.EPSILON) && t >= 0 && t <= 1;
|
|
284
324
|
} else {
|
|
285
|
-
return distance < Vertex.EPSILON; // t >= 0 && t <= 1;
|
|
325
|
+
return distance < (epsilon ?? Vertex.EPSILON); // t >= 0 && t <= 1;
|
|
286
326
|
}
|
|
287
327
|
}
|
|
288
328
|
|
|
@@ -304,12 +344,12 @@ export class VertTuple<T extends VertTuple<T>> {
|
|
|
304
344
|
* The the minimal distance between this line and the specified point.
|
|
305
345
|
*
|
|
306
346
|
* @method pointDistance
|
|
307
|
-
* @param {
|
|
347
|
+
* @param {XYCoords} p The point (vertex) to measre the distance to.
|
|
308
348
|
* @return {number} The absolute minimal distance.
|
|
309
349
|
* @instance
|
|
310
350
|
* @memberof VertTuple
|
|
311
351
|
**/
|
|
312
|
-
pointDistance(p:
|
|
352
|
+
pointDistance(p: XYCoords): number {
|
|
313
353
|
// Taken From:
|
|
314
354
|
// https://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment
|
|
315
355
|
return Math.sqrt(VertTuple.vtutils.dist2(p, this.vertAt(this.getClosestT(p))));
|
package/src/ts/Vertex.ts
CHANGED
|
@@ -32,7 +32,10 @@
|
|
|
32
32
|
* @modified 2023-09-29 Downgraded types for the `Vertex.utils.buildArrowHead` function (replacing Vertex params by more generic XYCoords type).
|
|
33
33
|
* @modified 2023-09-29 Added the `Vertex.abs()` method as it seems useful.
|
|
34
34
|
* @modified 2024-03-08 Added the optional `precision` param to the `toString` method.
|
|
35
|
-
* @
|
|
35
|
+
* @modified 2024-12-17 Outsourced the euclidean distance calculation of `Vertex.distance` to `geomutils.dist4`.
|
|
36
|
+
* @modified 2025-03-24 Making the second parameter `center` of the `Vertex.rotate` method optional.
|
|
37
|
+
* @modified 2025-04-13 Adding the `Vertex.move(amount: XYCoords)` method (does the same as `add`, added by naming convention).
|
|
38
|
+
* @version 2.10.0
|
|
36
39
|
*
|
|
37
40
|
* @file Vertex
|
|
38
41
|
* @public
|
|
@@ -42,6 +45,7 @@ import { IVertexAttr, VertexAttr } from "./VertexAttr";
|
|
|
42
45
|
import { UIDGenerator } from "./UIDGenerator";
|
|
43
46
|
import { VertexListeners } from "./VertexListeners";
|
|
44
47
|
import { XYCoords, SVGSerializable, UID } from "./interfaces";
|
|
48
|
+
import { geomutils } from "./geomutils";
|
|
45
49
|
|
|
46
50
|
/**
|
|
47
51
|
* @classdesc A vertex is a pair of two numbers.<br>
|
|
@@ -270,6 +274,22 @@ export class Vertex implements XYCoords, SVGSerializable {
|
|
|
270
274
|
return this;
|
|
271
275
|
}
|
|
272
276
|
|
|
277
|
+
/**
|
|
278
|
+
* Move this point by the given amount.
|
|
279
|
+
*
|
|
280
|
+
* This method just calls `add(amount).
|
|
281
|
+
*
|
|
282
|
+
*
|
|
283
|
+
* @method move
|
|
284
|
+
* @param {Vertex} amount - The amount to move this vertex.
|
|
285
|
+
* @return {Vertex} this - For chaining.
|
|
286
|
+
* @instance
|
|
287
|
+
* @memberof Vertex
|
|
288
|
+
*/
|
|
289
|
+
move(amount: XYCoords): Vertex {
|
|
290
|
+
return this.add(amount);
|
|
291
|
+
}
|
|
292
|
+
|
|
273
293
|
/**
|
|
274
294
|
* Add the passed amounts to the x- and y- components of this vertex.
|
|
275
295
|
*
|
|
@@ -430,7 +450,8 @@ export class Vertex implements XYCoords, SVGSerializable {
|
|
|
430
450
|
* @memberof Vertex
|
|
431
451
|
**/
|
|
432
452
|
distance(vert: XYCoords): number {
|
|
433
|
-
return Math.sqrt(Math.pow(vert.x - this.x, 2) + Math.pow(vert.y - this.y, 2));
|
|
453
|
+
// return Math.sqrt(Math.pow(vert.x - this.x, 2) + Math.pow(vert.y - this.y, 2));
|
|
454
|
+
return geomutils.dist4(this.x, this.y, vert.x, vert.y);
|
|
434
455
|
}
|
|
435
456
|
|
|
436
457
|
/**
|
|
@@ -551,7 +572,7 @@ export class Vertex implements XYCoords, SVGSerializable {
|
|
|
551
572
|
* @instance
|
|
552
573
|
* @memberof Vertex
|
|
553
574
|
**/
|
|
554
|
-
rotate(angle: number, center
|
|
575
|
+
rotate(angle: number, center?: XYCoords | undefined): Vertex {
|
|
555
576
|
if (!center || typeof center === "undefined") {
|
|
556
577
|
center = { x: 0, y: 0 };
|
|
557
578
|
}
|
package/src/ts/draw.ts
CHANGED
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
* @modified 2023-09-29 Added the `lineDashes` attribute.
|
|
57
57
|
* @modified 2023-09-30 Adding `strokeOptions` param to these draw function: line, arrow, cubicBezierArrow, cubicBezier, cubicBezierPath, circle, circleArc, ellipse, square, rect, polygon, polyline.
|
|
58
58
|
* @modified 2023-10-07 Adding the optional `arrowHeadBasePositionBuffer` param to the arrowHead(...) method.
|
|
59
|
+
* @modified 2024-09-13 Remoed the scaling of `lineWidth` in the `polygon` and `polyline` methods. This makes no sense here and doesn't match up with the behavior of other line functions.
|
|
59
60
|
* @version 1.13.0
|
|
60
61
|
**/
|
|
61
62
|
|
|
@@ -1209,7 +1210,7 @@ export class drawutils implements DrawLib<void> {
|
|
|
1209
1210
|
this.ctx.save();
|
|
1210
1211
|
this.applyStrokeOpts(strokeOptions);
|
|
1211
1212
|
this.ctx.beginPath();
|
|
1212
|
-
this.ctx.lineWidth =
|
|
1213
|
+
this.ctx.lineWidth = lineWidth || 1.0;
|
|
1213
1214
|
this.ctx.moveTo(this.offset.x + vertices[0].x * this.scale.x, this.offset.y + vertices[0].y * this.scale.y);
|
|
1214
1215
|
for (var i = 0; i < vertices.length; i++) {
|
|
1215
1216
|
this.ctx.lineTo(this.offset.x + vertices[i].x * this.scale.x, this.offset.y + vertices[i].y * this.scale.y);
|
package/src/ts/drawutilssvg.ts
CHANGED
|
@@ -1288,6 +1288,35 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
|
|
|
1288
1288
|
* @memberof drawutilssvg
|
|
1289
1289
|
*/
|
|
1290
1290
|
grid(center: XYCoords, width: number, height: number, sizeX: number, sizeY: number, color: string) {
|
|
1291
|
+
// console.log("grid");
|
|
1292
|
+
// const node: SVGElement = this.makeNode("pattern");
|
|
1293
|
+
// var patternId = "pattern_id_" + Math.floor(Math.random() * 65365);
|
|
1294
|
+
// node.setAttribute("id", patternId);
|
|
1295
|
+
// node.setAttribute("viewBox", `0,0,${sizeX},${sizeY}`);
|
|
1296
|
+
// node.setAttribute("width", `${sizeX}`);
|
|
1297
|
+
// node.setAttribute("height", `${sizeX}`);
|
|
1298
|
+
|
|
1299
|
+
// var pattern: SVGElement = this.makeNode("path");
|
|
1300
|
+
// const d: SVGPathParams = [];
|
|
1301
|
+
// d.push("M", sizeX / 2.0, 0);
|
|
1302
|
+
// d.push("L", sizeX / 2.0, sizeY);
|
|
1303
|
+
// d.push("M", 0, sizeY / 2.0);
|
|
1304
|
+
// d.push("L", sizeX, sizeY / 2.0);
|
|
1305
|
+
// node.setAttribute("d", d.join(" "));
|
|
1306
|
+
|
|
1307
|
+
// this.bufferedNodeDefs.append(pattern);
|
|
1308
|
+
|
|
1309
|
+
// const fillNode: SVGElement = this.makeNode("rect");
|
|
1310
|
+
// // For some strange reason SVG rotation transforms use degrees instead of radians
|
|
1311
|
+
// // Note that the background does not scale with the zoom level (always covers full element)
|
|
1312
|
+
// fillNode.setAttribute("x", "0");
|
|
1313
|
+
// fillNode.setAttribute("y", "0");
|
|
1314
|
+
// fillNode.setAttribute("width", `${this.canvasSize.width}`);
|
|
1315
|
+
// fillNode.setAttribute("height", `${this.canvasSize.height}`);
|
|
1316
|
+
// fillNode.setAttribute("fill", `url(#${patternId})`);
|
|
1317
|
+
|
|
1318
|
+
// return this._bindFillDraw(fillNode, "grid", "red", 1);
|
|
1319
|
+
|
|
1291
1320
|
const node: SVGElement = this.makeNode("path");
|
|
1292
1321
|
const d: SVGPathParams = [];
|
|
1293
1322
|
|
package/src/ts/geomutils.ts
CHANGED
|
@@ -2,12 +2,16 @@
|
|
|
2
2
|
* @author Ikaros Kappler
|
|
3
3
|
* @date 2019-02-03
|
|
4
4
|
* @modified 2021-03-01 Added `wrapMax` function.
|
|
5
|
-
* @
|
|
5
|
+
* @modified 2024-11-15 Adding helper function `geomutils.mapAngleTo2PI(number)` for mapping any value into the interval [0,2*PI).
|
|
6
|
+
* @modified 2024-11-22 Adding helper function `geomutils.dotProduct(number)` for calculating the dot product of two vertices (as vectors).
|
|
7
|
+
*
|
|
8
|
+
* @version 1.2.0
|
|
6
9
|
**/
|
|
7
10
|
|
|
8
11
|
import { Line } from "./Line";
|
|
9
12
|
import { Triangle } from "./Triangle";
|
|
10
13
|
import { Vertex } from "./Vertex";
|
|
14
|
+
import { XYCoords } from "./interfaces";
|
|
11
15
|
|
|
12
16
|
/**
|
|
13
17
|
* A collection of usefull geometry utilities.
|
|
@@ -15,6 +19,50 @@ import { Vertex } from "./Vertex";
|
|
|
15
19
|
* @global
|
|
16
20
|
**/
|
|
17
21
|
export const geomutils = {
|
|
22
|
+
/**
|
|
23
|
+
* Map any angle (any numeric value) to [0, Math.PI).
|
|
24
|
+
*
|
|
25
|
+
* @param {number} angle - The numeric value to map.
|
|
26
|
+
* @return {number} The mapped angle inside [0,PI*2].
|
|
27
|
+
**/
|
|
28
|
+
mapAngleTo2PI(angle: number): number {
|
|
29
|
+
// Source: https://forums.codeguru.com/showthread.php?384172-get-angle-into-range-0-2*pi
|
|
30
|
+
const new_angle: number = Math.asin(Math.sin(angle));
|
|
31
|
+
if (Math.cos(angle) < 0) {
|
|
32
|
+
return Math.PI - new_angle;
|
|
33
|
+
} else if (new_angle < 0) {
|
|
34
|
+
return new_angle + 2 * Math.PI;
|
|
35
|
+
} else {
|
|
36
|
+
return new_angle;
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Calculate the euclidean distance between two points given by four coordinates (two coordinates each).
|
|
42
|
+
*
|
|
43
|
+
* @param {number} x1
|
|
44
|
+
* @param {number} y1
|
|
45
|
+
* @param {number} x2
|
|
46
|
+
* @param {number} y2
|
|
47
|
+
* @returns {number}
|
|
48
|
+
*/
|
|
49
|
+
dist4(x1: number, y1: number, x2: number, y2: number): number {
|
|
50
|
+
return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y1 - y2, 2));
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Map any angle (any numeric value) to [0, Math.PI).
|
|
55
|
+
*
|
|
56
|
+
* A × B := (A.x * B.x) + (A.y * B.y)
|
|
57
|
+
*
|
|
58
|
+
* @param {XYCoords} vertA - The first vertex.
|
|
59
|
+
* @param {XYCoords} vertB - The second vertex.
|
|
60
|
+
* @return {number} The dot product of the two vertices.
|
|
61
|
+
**/
|
|
62
|
+
dotProduct(vertA: XYCoords, vertB: XYCoords): number {
|
|
63
|
+
return vertA.x * vertB.x + vertA.y * vertB.y;
|
|
64
|
+
},
|
|
65
|
+
|
|
18
66
|
/**
|
|
19
67
|
* Compute the n-section of the angle – described as a triangle (A,B,C) – in point A.
|
|
20
68
|
*
|
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
* @modified 2023-02-10 All non-function attributes of the `Config` interface are now mandatory.
|
|
21
21
|
* @modified 2023-09-29 Added the `randomPoint(...)` function declaration to the IBounds interface.
|
|
22
22
|
* @modified 2024-08-25 Added the `CSSBackdropFilterParams` params to the global params (all optional).
|
|
23
|
+
* @modified 2025-03-29 Added interface `Intersectable`.
|
|
24
|
+
* @modified 2025-04-16 Added interface `IBounded`.
|
|
23
25
|
**/
|
|
24
26
|
|
|
25
27
|
import { Vertex } from "../Vertex";
|
|
@@ -37,6 +39,7 @@ import { PlotBoilerplate } from "../PlotBoilerplate";
|
|
|
37
39
|
import { DrawLib } from "./DrawLib";
|
|
38
40
|
import { PBText } from "../PBText";
|
|
39
41
|
import { CSSBackdropFilterParams } from "./externals";
|
|
42
|
+
import { VertTuple } from "../VertTuple";
|
|
40
43
|
|
|
41
44
|
/**
|
|
42
45
|
* @classdesc Coordinates (x,y) on the plane.
|
|
@@ -261,3 +264,42 @@ export interface IDraggable {
|
|
|
261
264
|
isVertex(): boolean;
|
|
262
265
|
setVIndex(vindex: number): IDraggable;
|
|
263
266
|
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Shapes should implement this interface if they support intersection calculation.
|
|
270
|
+
*/
|
|
271
|
+
export interface Intersectable {
|
|
272
|
+
/**
|
|
273
|
+
* Get all line intersections with this polygon.
|
|
274
|
+
*
|
|
275
|
+
* This method returns all intersections (as vertices) with this shape. The returned array of vertices is in no specific order.
|
|
276
|
+
*
|
|
277
|
+
* See demo `47-closest-vector-projection-on-polygon` for how it works.
|
|
278
|
+
*
|
|
279
|
+
* @param {VertTuple} line - The line to find intersections with.
|
|
280
|
+
* @param {boolean} inVectorBoundsOnly - (default=false) If set to true only intersecion points on the passed vector are returned (located strictly between start and end vertex).
|
|
281
|
+
* @returns {Array<Vertex>} - An array of all intersections within this shape's bounds.
|
|
282
|
+
*/
|
|
283
|
+
lineIntersections(line: VertTuple<any>, inVectorBoundsOnly?: boolean): Array<Vertex>;
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Get all line intersections of this polygon and their tangents along the shape.
|
|
287
|
+
*
|
|
288
|
+
* This method returns all intersection tangents (as vectors) with this shape. The returned array of vectors is in no specific order.
|
|
289
|
+
*
|
|
290
|
+
* @param {VertTuple} line - The line to find intersections with.
|
|
291
|
+
* @param {boolean} inVectorBoundsOnly - (default=false) If set to true only intersecion points on the passed vector are returned (located strictly between start and end vertex).
|
|
292
|
+
* @returns {Array<Vector>} - An array of all intersection tangents within this shape's bounds.
|
|
293
|
+
*/
|
|
294
|
+
lineIntersectionTangents(line: VertTuple<any>, inVectorBoundsOnly?: boolean): Array<Vector>;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export interface IBounded {
|
|
298
|
+
/**
|
|
299
|
+
* Get the bounding box (bounds) of this shape.
|
|
300
|
+
*
|
|
301
|
+
* @method getBounds
|
|
302
|
+
* @return {Bounds} The rectangular bounds of this shape.
|
|
303
|
+
**/
|
|
304
|
+
getBounds(): IBounds;
|
|
305
|
+
}
|