plotboilerplate 1.20.1 → 1.21.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 +17 -1
- package/dist/index.esm.js +2065 -1397
- 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 +1265 -584
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +2 -1
- package/src/cjs/BezierPath.d.ts +27 -49
- package/src/cjs/BezierPath.js +69 -237
- package/src/cjs/BezierPath.js.map +1 -1
- package/src/cjs/Bounds.d.ts +14 -1
- package/src/cjs/Bounds.js +21 -1
- package/src/cjs/Bounds.js.map +1 -1
- package/src/cjs/CubicBezierCurve.d.ts +70 -1
- package/src/cjs/CubicBezierCurve.js +130 -12
- package/src/cjs/CubicBezierCurve.js.map +1 -1
- package/src/cjs/Line.d.ts +2 -1
- package/src/cjs/Line.js +1 -0
- package/src/cjs/Line.js.map +1 -1
- package/src/cjs/PBText.d.ts +2 -1
- package/src/cjs/PBText.js +10 -9
- package/src/cjs/PBText.js.map +1 -1
- package/src/cjs/PlotBoilerplate.d.ts +10 -13
- package/src/cjs/PlotBoilerplate.js +136 -47
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/Polygon.d.ts +35 -1
- package/src/cjs/Polygon.js +87 -1
- package/src/cjs/Polygon.js.map +1 -1
- package/src/cjs/Triangle.js +1 -0
- package/src/cjs/Triangle.js.map +1 -1
- package/src/cjs/VEllipse.js +1 -1
- package/src/cjs/VEllipse.js.map +1 -1
- package/src/cjs/Vector.d.ts +4 -4
- package/src/cjs/Vector.js +2 -2
- package/src/cjs/Vector.js.map +1 -1
- package/src/cjs/VertTuple.d.ts +2 -1
- package/src/cjs/VertTuple.js +4 -3
- package/src/cjs/VertTuple.js.map +1 -1
- package/src/cjs/Vertex.d.ts +14 -3
- package/src/cjs/Vertex.js +18 -3
- package/src/cjs/Vertex.js.map +1 -1
- package/src/cjs/draw.d.ts +159 -79
- package/src/cjs/draw.js +311 -139
- package/src/cjs/draw.js.map +1 -1
- package/src/cjs/drawgl.d.ts +93 -55
- package/src/cjs/drawgl.js +90 -34
- package/src/cjs/drawgl.js.map +1 -1
- package/src/cjs/drawutilssvg.d.ts +233 -58
- package/src/cjs/drawutilssvg.js +384 -95
- package/src/cjs/drawutilssvg.js.map +1 -1
- package/src/cjs/interfaces/DrawLib.d.ts +161 -82
- package/src/cjs/interfaces/DrawLib.js +7 -0
- package/src/cjs/interfaces/DrawLib.js.map +1 -1
- package/src/cjs/interfaces/core.d.ts +46 -32
- package/src/cjs/interfaces/core.js +2 -0
- package/src/cjs/interfaces/core.js.map +1 -1
- package/src/cjs/utils/creategui.js +16 -10
- package/src/cjs/utils/datastructures/Color.d.ts +3 -1
- package/src/cjs/utils/datastructures/Color.js +12 -1
- package/src/cjs/utils/datastructures/Color.js.map +1 -1
- package/src/cjs/utils/detectDarkMode.d.ts +10 -0
- package/src/cjs/utils/detectDarkMode.js +32 -0
- package/src/cjs/utils/detectDarkMode.js.map +1 -0
- package/src/cjs/utils/module.js +4 -2
- package/src/esm/BezierPath.d.ts +27 -49
- package/src/esm/BezierPath.js +69 -237
- package/src/esm/BezierPath.js.map +1 -1
- package/src/esm/Bounds.d.ts +14 -1
- package/src/esm/Bounds.js +19 -1
- package/src/esm/Bounds.js.map +1 -1
- package/src/esm/CubicBezierCurve.d.ts +70 -1
- package/src/esm/CubicBezierCurve.js +130 -12
- package/src/esm/CubicBezierCurve.js.map +1 -1
- package/src/esm/Line.d.ts +2 -1
- package/src/esm/Line.js +1 -0
- package/src/esm/Line.js.map +1 -1
- package/src/esm/PBText.d.ts +2 -1
- package/src/esm/PBText.js +10 -9
- package/src/esm/PBText.js.map +1 -1
- package/src/esm/PlotBoilerplate.d.ts +10 -13
- package/src/esm/PlotBoilerplate.js +136 -48
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/Polygon.d.ts +35 -1
- package/src/esm/Polygon.js +85 -1
- package/src/esm/Polygon.js.map +1 -1
- package/src/esm/Triangle.js +1 -0
- package/src/esm/Triangle.js.map +1 -1
- package/src/esm/VEllipse.js +1 -1
- package/src/esm/VEllipse.js.map +1 -1
- package/src/esm/Vector.d.ts +4 -4
- package/src/esm/Vector.js +2 -2
- package/src/esm/Vector.js.map +1 -1
- package/src/esm/VertTuple.d.ts +2 -1
- package/src/esm/VertTuple.js +4 -3
- package/src/esm/VertTuple.js.map +1 -1
- package/src/esm/Vertex.d.ts +14 -3
- package/src/esm/Vertex.js +18 -3
- package/src/esm/Vertex.js.map +1 -1
- package/src/esm/draw.d.ts +159 -79
- package/src/esm/draw.js +307 -137
- package/src/esm/draw.js.map +1 -1
- package/src/esm/drawgl.d.ts +93 -55
- package/src/esm/drawgl.js +90 -34
- package/src/esm/drawgl.js.map +1 -1
- package/src/esm/drawutilssvg.d.ts +233 -58
- package/src/esm/drawutilssvg.js +379 -95
- package/src/esm/drawutilssvg.js.map +1 -1
- package/src/esm/interfaces/DrawLib.d.ts +161 -82
- package/src/esm/interfaces/DrawLib.js +7 -0
- package/src/esm/interfaces/DrawLib.js.map +1 -1
- package/src/esm/interfaces/core.d.ts +46 -32
- package/src/esm/interfaces/core.js +2 -0
- package/src/esm/interfaces/core.js.map +1 -1
- package/src/esm/utils/datastructures/Color.d.ts +3 -1
- package/src/esm/utils/datastructures/Color.js +12 -1
- package/src/esm/utils/datastructures/Color.js.map +1 -1
- package/src/esm/utils/detectDarkMode.d.ts +10 -0
- package/src/esm/utils/detectDarkMode.js +28 -0
- package/src/esm/utils/detectDarkMode.js.map +1 -0
- package/src/ts/BezierPath.ts +74 -244
- package/src/ts/Bounds.ts +25 -1
- package/src/ts/CubicBezierCurve.ts +139 -12
- package/src/ts/Line.ts +2 -1
- package/src/ts/PBText.ts +10 -9
- package/src/ts/PlotBoilerplate.ts +130 -50
- package/src/ts/Polygon.ts +91 -1
- package/src/ts/Triangle.ts +2 -1
- package/src/ts/VEllipse.ts +2 -2
- package/src/ts/Vector.ts +4 -4
- package/src/ts/VertTuple.ts +4 -3
- package/src/ts/Vertex.ts +20 -4
- package/src/ts/draw.ts +316 -119
- package/src/ts/drawgl.ts +141 -78
- package/src/ts/drawutilssvg.ts +562 -133
- package/src/ts/interfaces/DrawLib.ts +223 -86
- package/src/ts/interfaces/core.ts +47 -32
- package/src/ts/utils/datastructures/Color.ts +13 -1
- package/src/ts/utils/detectDarkMode.ts +30 -0
package/src/ts/Polygon.ts
CHANGED
|
@@ -24,7 +24,10 @@
|
|
|
24
24
|
* @modified 2022-02-02 Added the `destroy` method.
|
|
25
25
|
* @modified 2022-02-02 Cleared the `Polygon.toSVGString` function (deprecated). Use `drawutilssvg` instead.
|
|
26
26
|
* @modified 2022-03-08 Added the `Polygon.clone()` function.
|
|
27
|
-
* @
|
|
27
|
+
* @modified 2023-09-25 Added the `Polygon.getInterpolationPolygon(number)` function.
|
|
28
|
+
* @modified 2023-09-25 Added the `Polygon.lineIntersections(Line,boolean)` function.
|
|
29
|
+
* @modified 2023-09-29 Added the `Polygon.closestLineIntersection(Line,boolean)` function.
|
|
30
|
+
* @version 1.11.0
|
|
28
31
|
*
|
|
29
32
|
* @file Polygon
|
|
30
33
|
* @public
|
|
@@ -32,7 +35,9 @@
|
|
|
32
35
|
|
|
33
36
|
import { BezierPath } from "./BezierPath";
|
|
34
37
|
import { Bounds } from "./Bounds";
|
|
38
|
+
import { Line } from "./Line";
|
|
35
39
|
import { UIDGenerator } from "./UIDGenerator";
|
|
40
|
+
import { VertTuple } from "./VertTuple";
|
|
36
41
|
import { Vertex } from "./Vertex";
|
|
37
42
|
import { XYCoords, SVGSerializable, UID } from "./interfaces";
|
|
38
43
|
|
|
@@ -276,6 +281,91 @@ export class Polygon implements SVGSerializable {
|
|
|
276
281
|
return this;
|
|
277
282
|
}
|
|
278
283
|
|
|
284
|
+
/**
|
|
285
|
+
* Get all line intersections with this polygon.
|
|
286
|
+
*
|
|
287
|
+
* See demo `47-closest-vector-projection-on-polygon` for how it works.
|
|
288
|
+
*
|
|
289
|
+
* @param {VertTuple} line - The line to find intersections with.
|
|
290
|
+
* @param {boolean} inVectorBoundsOnly - If set to true only intersecion points on the passed vector are returned (located strictly between start and end vertex).
|
|
291
|
+
* @returns {Array<Vertex>} - An array of all intersections within the polygon bounds.
|
|
292
|
+
*/
|
|
293
|
+
lineIntersections(line: VertTuple<any>, inVectorBoundsOnly: boolean = false): Array<Vertex> {
|
|
294
|
+
// Find the intersections of all lines inside the edge bounds
|
|
295
|
+
const intersectionPoints: Array<Vertex> = [];
|
|
296
|
+
for (var i = 0; i < this.vertices.length; i++) {
|
|
297
|
+
const polyLine = new Line(this.vertices[i], this.vertices[(i + 1) % this.vertices.length]);
|
|
298
|
+
const intersection = polyLine.intersection(line);
|
|
299
|
+
// true => only inside bounds
|
|
300
|
+
// ignore last edge if open
|
|
301
|
+
if (
|
|
302
|
+
(!this.isOpen || i + 1 !== this.vertices.length) &&
|
|
303
|
+
intersection !== null &&
|
|
304
|
+
polyLine.hasPoint(intersection, true) &&
|
|
305
|
+
(!inVectorBoundsOnly || line.hasPoint(intersection, inVectorBoundsOnly))
|
|
306
|
+
) {
|
|
307
|
+
intersectionPoints.push(intersection);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return intersectionPoints;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Get the closest line-polygon-intersection point (closest the line point A).
|
|
315
|
+
*
|
|
316
|
+
* See demo `47-closest-vector-projection-on-polygon` for how it works.
|
|
317
|
+
*
|
|
318
|
+
* @param {VertTuple} line - The line to find intersections with.
|
|
319
|
+
* @param {boolean} inVectorBoundsOnly - If set to true only intersecion points on the passed vector are considered (located strictly between start and end vertex).
|
|
320
|
+
* @returns {Array<Vertex>} - An array of all intersections within the polygon bounds.
|
|
321
|
+
*/
|
|
322
|
+
closestLineIntersection(line: VertTuple<any>, inVectorBoundsOnly: boolean = false): Vertex | null {
|
|
323
|
+
const allIntersections = this.lineIntersections(line, inVectorBoundsOnly);
|
|
324
|
+
if (allIntersections.length <= 0) {
|
|
325
|
+
// Empty polygon -> no intersections
|
|
326
|
+
return null;
|
|
327
|
+
}
|
|
328
|
+
// Find the closest intersection
|
|
329
|
+
let closestIntersection = new Vertex(Number.MAX_VALUE, Number.MAX_VALUE);
|
|
330
|
+
let curDist = Number.MAX_VALUE;
|
|
331
|
+
for (var i in allIntersections) {
|
|
332
|
+
const curVert = allIntersections[i];
|
|
333
|
+
const dist = curVert.distance(line.a);
|
|
334
|
+
if (dist < curDist) {
|
|
335
|
+
// && line.hasPoint(curVert)) {
|
|
336
|
+
curDist = dist;
|
|
337
|
+
closestIntersection = curVert;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return closestIntersection;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Construct a new polygon from this polygon with more vertices on each edge. The
|
|
345
|
+
* interpolation count determines the number of additional vertices on each edge.
|
|
346
|
+
* An interpolation count of `0` will return a polygon that equals the source
|
|
347
|
+
* polygon.
|
|
348
|
+
*
|
|
349
|
+
* @param {number} interpolationCount
|
|
350
|
+
* @returns {Polygon} A polygon with `interpolationCount` more vertices (as as factor).
|
|
351
|
+
*/
|
|
352
|
+
getInterpolationPolygon(interpolationCount: number): Polygon {
|
|
353
|
+
const verts: Array<Vertex> = [];
|
|
354
|
+
for (var i = 0; i < this.vertices.length; i++) {
|
|
355
|
+
const curVert = this.vertices[i];
|
|
356
|
+
const nextVert = this.vertices[(i + 1) % this.vertices.length];
|
|
357
|
+
verts.push(curVert.clone());
|
|
358
|
+
// Add interpolation points
|
|
359
|
+
if (!this.isOpen || i + 1 !== this.vertices.length) {
|
|
360
|
+
const lerpAmount = 1.0 / (interpolationCount + 1);
|
|
361
|
+
for (var j = 1; j <= interpolationCount; j++) {
|
|
362
|
+
verts.push(curVert.clone().lerp(nextVert, lerpAmount * j));
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return new Polygon(verts, this.isOpen);
|
|
367
|
+
}
|
|
368
|
+
|
|
279
369
|
/**
|
|
280
370
|
* Convert this polygon into a new polygon with n evenly distributed vertices.
|
|
281
371
|
*
|
package/src/ts/Triangle.ts
CHANGED
|
@@ -404,7 +404,8 @@ export class Triangle implements SVGSerializable {
|
|
|
404
404
|
|
|
405
405
|
const bisector1 = geomutils.nsectAngle(this.b, this.a, this.c, 2)[0]; // bisector of first angle (in b)
|
|
406
406
|
const bisector2 = geomutils.nsectAngle(this.c, this.b, this.a, 2)[0]; // bisector of second angle (in c)
|
|
407
|
-
|
|
407
|
+
// Cast to non-null here because we know there _is_ an intersection
|
|
408
|
+
const intersection = bisector1.intersection(bisector2) as Vertex;
|
|
408
409
|
|
|
409
410
|
// Find the closest points on one of the polygon lines (all have same distance by construction)
|
|
410
411
|
const circleIntersA = lineA.getClosestPoint(intersection);
|
package/src/ts/VEllipse.ts
CHANGED
|
@@ -392,8 +392,8 @@ export class VEllipse implements SVGSerializable {
|
|
|
392
392
|
let startTangent: Vector = this.tangentAt(curAngle);
|
|
393
393
|
let endTangent: Vector = this.tangentAt(nextAngle);
|
|
394
394
|
|
|
395
|
-
// Find intersection
|
|
396
|
-
let intersection: Vertex
|
|
395
|
+
// Find intersection (ignore that the result might be null in some extreme cases)
|
|
396
|
+
let intersection: Vertex = startTangent.intersection(endTangent) as Vertex;
|
|
397
397
|
// What if intersection is undefined?
|
|
398
398
|
// --> This *can* not happen if segmentCount > 2 and height and width of the ellipse are not zero.
|
|
399
399
|
|
package/src/ts/Vector.ts
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
import { VertTuple } from "./VertTuple";
|
|
22
22
|
import { Vertex } from "./Vertex";
|
|
23
|
-
import { SVGSerializable } from "./interfaces";
|
|
23
|
+
import { SVGSerializable, XYCoords } from "./interfaces";
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* @classdesc A vector (Vertex,Vertex) is a line with a visible direction.<br>
|
|
@@ -156,13 +156,13 @@ export class Vector extends VertTuple<Vector> implements SVGSerializable {
|
|
|
156
156
|
* Example:
|
|
157
157
|
* buildArrowHead( new Vertex(0,0), new Vertex(50,100), 8, 1.0, 1.0 )
|
|
158
158
|
*
|
|
159
|
-
* @param {
|
|
160
|
-
* @param {
|
|
159
|
+
* @param {XYCoords} zA - The start vertex of the vector to calculate the arrow head for.
|
|
160
|
+
* @param {XYCoords} zB - The end vertex of the vector.
|
|
161
161
|
* @param {number} headlen - The length of the arrow head (along the vector direction. A good value is 12).
|
|
162
162
|
* @param {number} scaleX - The horizontal scaling during draw.
|
|
163
163
|
* @param {number} scaleY - the vertical scaling during draw.
|
|
164
164
|
**/
|
|
165
|
-
buildArrowHead: (zA:
|
|
165
|
+
buildArrowHead: (zA: XYCoords, zB: XYCoords, headlen: number, scaleX: number, scaleY: number): Array<Vertex> => {
|
|
166
166
|
const angle = Math.atan2((zB.y - zA.y) * scaleY, (zB.x - zA.x) * scaleX);
|
|
167
167
|
const vertices: Array<Vertex> = [];
|
|
168
168
|
vertices.push(new Vertex(zB.x * scaleX - headlen * Math.cos(angle), zB.y * scaleY - headlen * Math.sin(angle)));
|
package/src/ts/VertTuple.ts
CHANGED
|
@@ -9,7 +9,8 @@
|
|
|
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
|
-
* @
|
|
12
|
+
* @modified 2023-09-29 Fixed a calculation error in the VertTuple.hasPoint() function; distance measure was broken!
|
|
13
|
+
* @version 1.2.1
|
|
13
14
|
*/
|
|
14
15
|
|
|
15
16
|
import { Vertex } from "./Vertex";
|
|
@@ -277,11 +278,11 @@ export class VertTuple<T extends VertTuple<T>> {
|
|
|
277
278
|
hasPoint(point: XYCoords, insideBoundsOnly?: boolean): boolean {
|
|
278
279
|
const t: number = this.getClosestT(point);
|
|
279
280
|
// Compare to pointDistance?
|
|
281
|
+
const distance: number = Math.sqrt(VertTuple.vtutils.dist2(point, this.vertAt(t)));
|
|
280
282
|
if (typeof insideBoundsOnly !== "undefined" && insideBoundsOnly) {
|
|
281
|
-
const distance: number = Math.sqrt(VertTuple.vtutils.dist2(point, this.vertAt(t)));
|
|
282
283
|
return distance < Vertex.EPSILON && t >= 0 && t <= 1;
|
|
283
284
|
} else {
|
|
284
|
-
return t >= 0 && t <= 1;
|
|
285
|
+
return distance < Vertex.EPSILON; // t >= 0 && t <= 1;
|
|
285
286
|
}
|
|
286
287
|
}
|
|
287
288
|
|
package/src/ts/Vertex.ts
CHANGED
|
@@ -29,6 +29,8 @@
|
|
|
29
29
|
* @modified 2022-02-02 Added the `destroy` method.
|
|
30
30
|
* @modified 2022-02-02 Cleared the `Vertex.toSVGString` function (deprecated). Use `drawutilssvg` instead.
|
|
31
31
|
* @modified 2022-11-28 Added the `subXY`, `subX` and `subY` methods to the `Vertex` class.
|
|
32
|
+
* @modified 2023-09-29 Downgraded types for the `Vertex.utils.buildArrowHead` function (replacing Vertex params by more generic XYCoords type).
|
|
33
|
+
* @modified 2023-09-29 Added the `Vertex.abs()` method as it seems useful.
|
|
32
34
|
* @version 2.8.0
|
|
33
35
|
*
|
|
34
36
|
* @file Vertex
|
|
@@ -607,6 +609,20 @@ export class Vertex implements XYCoords, SVGSerializable {
|
|
|
607
609
|
return this;
|
|
608
610
|
}
|
|
609
611
|
|
|
612
|
+
/**
|
|
613
|
+
* Set both coordinates of this vertex to their absolute value (abs(x), abs(y)).
|
|
614
|
+
*
|
|
615
|
+
* @method abs
|
|
616
|
+
* @return {Vertex} this
|
|
617
|
+
* @instance
|
|
618
|
+
* @memberof Vertex
|
|
619
|
+
*/
|
|
620
|
+
abs(): Vertex {
|
|
621
|
+
this.x = Math.abs(this.x);
|
|
622
|
+
this.y = Math.abs(this.y);
|
|
623
|
+
return this;
|
|
624
|
+
}
|
|
625
|
+
|
|
610
626
|
/**
|
|
611
627
|
* Get a string representation of this vertex.
|
|
612
628
|
*
|
|
@@ -662,15 +678,15 @@ export class Vertex implements XYCoords, SVGSerializable {
|
|
|
662
678
|
* Example:
|
|
663
679
|
* buildArrowHead( new Vertex(0,0), new Vertex(50,100), 8, 1.0, 1.0 )
|
|
664
680
|
*
|
|
665
|
-
* @param {
|
|
666
|
-
* @param {
|
|
681
|
+
* @param {XYCoords} zA - The start vertex of the vector to calculate the arrow head for.
|
|
682
|
+
* @param {XYCoords} zB - The end vertex of the vector.
|
|
667
683
|
* @param {number} headlen - The length of the arrow head (along the vector direction. A good value is 12).
|
|
668
684
|
* @param {number} scaleX - The horizontal scaling during draw.
|
|
669
685
|
* @param {number} scaleY - the vertical scaling during draw.
|
|
670
686
|
**/
|
|
671
687
|
// @DEPRECATED: use Vector.utils.buildArrowHead instead!!!
|
|
672
|
-
buildArrowHead: (zA:
|
|
673
|
-
|
|
688
|
+
buildArrowHead: (zA: XYCoords, zB: XYCoords, headlen: number, scaleX: number, scaleY: number): Array<Vertex> => {
|
|
689
|
+
console.warn("[DEPRECATION] Vertex.utils.buildArrowHead is deprecated. Please use Vector.utils.buildArrowHead instead.");
|
|
674
690
|
var angle: number = Math.atan2((zB.y - zA.y) * scaleY, (zB.x - zA.x) * scaleX);
|
|
675
691
|
|
|
676
692
|
var vertices: Array<Vertex> = [];
|