plotboilerplate 1.23.3 → 1.25.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 +19 -1
- package/dist/index.esm.js +1684 -394
- 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 +12450 -11120
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +9 -5
- 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 +37 -6
- package/src/cjs/PlotBoilerplate.js +224 -125
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/Polygon.d.ts +68 -5
- package/src/cjs/Polygon.js +143 -22
- package/src/cjs/Polygon.js.map +1 -1
- package/src/cjs/Triangle.d.ts +52 -3
- package/src/cjs/Triangle.js +80 -1
- 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 +28 -4
- package/src/cjs/VertTuple.js +36 -3
- package/src/cjs/VertTuple.js.map +1 -1
- package/src/cjs/Vertex.d.ts +31 -4
- package/src/cjs/Vertex.js +35 -1
- package/src/cjs/Vertex.js.map +1 -1
- package/src/cjs/interfaces/core.d.ts +67 -0
- package/src/cjs/interfaces/core.js +4 -0
- package/src/cjs/interfaces/core.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/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/datastructures/Color.d.ts +147 -1
- package/src/cjs/utils/datastructures/Color.js +385 -41
- package/src/cjs/utils/datastructures/Color.js.map +1 -1
- package/src/cjs/utils/datastructures/ColorGradient.d.ts +79 -0
- package/src/cjs/utils/datastructures/ColorGradient.js +171 -0
- package/src/cjs/utils/datastructures/ColorGradient.js.map +1 -0
- package/src/cjs/utils/dom/components/ColorGradientPicker.d.ts +245 -0
- package/src/cjs/utils/dom/components/ColorGradientPicker.js +667 -0
- package/src/cjs/utils/dom/components/ColorGradientPicker.js.map +1 -0
- package/src/cjs/utils/dom/components/ColorGradientPickerJSX.d.ts +129 -0
- package/src/cjs/utils/dom/components/ColorGradientPickerJSX.js +520 -0
- package/src/cjs/utils/dom/components/ColorGradientPickerJSX.js.map +1 -0
- package/src/cjs/utils/dom/components/ColorGradientSelector.d.ts +117 -0
- package/src/cjs/utils/dom/components/ColorGradientSelector.js +325 -0
- package/src/cjs/utils/dom/components/ColorGradientSelector.js.map +1 -0
- package/src/cjs/utils/dom/components/Test.d.ts +7 -0
- package/src/cjs/utils/dom/components/Test.js +30 -0
- package/src/cjs/utils/dom/components/Test.js.map +1 -0
- package/src/cjs/utils/dom/guiSizeToggler.js +1 -1
- package/src/cjs/utils/dom/guiSizeToggler.js.map +1 -1
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.d.ts +16 -8
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.js +49 -28
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
- package/src/cjs/utils/helpers/CircleHelper.d.ts +10 -1
- package/src/cjs/utils/helpers/CircleHelper.js +13 -2
- package/src/cjs/utils/helpers/CircleHelper.js.map +1 -1
- package/src/cjs/utils/helpers/CircleSectorHelper.d.ts +11 -2
- package/src/cjs/utils/helpers/CircleSectorHelper.js +20 -20
- package/src/cjs/utils/helpers/CircleSectorHelper.js.map +1 -1
- package/src/cjs/utils/helpers/TriangleHelper.d.ts +57 -0
- package/src/cjs/utils/helpers/TriangleHelper.js +83 -0
- package/src/cjs/utils/helpers/TriangleHelper.js.map +1 -0
- package/src/cjs/utils/helpers/VEllipseHelper.d.ts +32 -0
- package/src/cjs/utils/helpers/VEllipseHelper.js +88 -0
- package/src/cjs/utils/helpers/VEllipseHelper.js.map +1 -0
- package/src/cjs/utils/helpers/VEllipseSectorHelper.d.ts +44 -4
- package/src/cjs/utils/helpers/VEllipseSectorHelper.js +108 -25
- package/src/cjs/utils/helpers/VEllipseSectorHelper.js.map +1 -1
- package/src/cjs/utils/parsers/LinearColorGradientParser.d.ts +78 -0
- package/src/cjs/utils/parsers/LinearColorGradientParser.js +224 -0
- package/src/cjs/utils/parsers/LinearColorGradientParser.js.map +1 -0
- package/src/createDemoDrawables.js +4 -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 +37 -6
- package/src/esm/PlotBoilerplate.js +224 -125
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/Polygon.d.ts +68 -5
- package/src/esm/Polygon.js +138 -22
- package/src/esm/Polygon.js.map +1 -1
- package/src/esm/Triangle.d.ts +52 -3
- package/src/esm/Triangle.js +77 -1
- 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 +28 -4
- package/src/esm/VertTuple.js +36 -3
- package/src/esm/VertTuple.js.map +1 -1
- package/src/esm/Vertex.d.ts +31 -4
- package/src/esm/Vertex.js +35 -1
- package/src/esm/Vertex.js.map +1 -1
- package/src/esm/interfaces/core.d.ts +67 -0
- package/src/esm/interfaces/core.js +4 -0
- package/src/esm/interfaces/core.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/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/datastructures/Color.d.ts +147 -1
- package/src/esm/utils/datastructures/Color.js +386 -42
- package/src/esm/utils/datastructures/Color.js.map +1 -1
- package/src/esm/utils/datastructures/ColorGradient.d.ts +79 -0
- package/src/esm/utils/datastructures/ColorGradient.js +166 -0
- package/src/esm/utils/datastructures/ColorGradient.js.map +1 -0
- package/src/esm/utils/dom/components/ColorGradientPicker.d.ts +245 -0
- package/src/esm/utils/dom/components/ColorGradientPicker.js +732 -0
- package/src/esm/utils/dom/components/ColorGradientPicker.js.map +1 -0
- package/src/esm/utils/dom/components/ColorGradientPickerJSX.d.ts +129 -0
- package/src/esm/utils/dom/components/ColorGradientPickerJSX.js +582 -0
- package/src/esm/utils/dom/components/ColorGradientPickerJSX.js.map +1 -0
- package/src/esm/utils/dom/components/ColorGradientSelector.d.ts +117 -0
- package/src/esm/utils/dom/components/ColorGradientSelector.js +332 -0
- package/src/esm/utils/dom/components/ColorGradientSelector.js.map +1 -0
- package/src/esm/utils/dom/components/Test.d.ts +7 -0
- package/src/esm/utils/dom/components/Test.js +26 -0
- package/src/esm/utils/dom/components/Test.js.map +1 -0
- package/src/esm/utils/dom/guiSizeToggler.js +1 -1
- package/src/esm/utils/dom/guiSizeToggler.js.map +1 -1
- package/src/esm/utils/helpers/BezierPathInteractionHelper.d.ts +16 -8
- package/src/esm/utils/helpers/BezierPathInteractionHelper.js +47 -27
- package/src/esm/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
- package/src/esm/utils/helpers/CircleHelper.d.ts +10 -1
- package/src/esm/utils/helpers/CircleHelper.js +13 -2
- package/src/esm/utils/helpers/CircleHelper.js.map +1 -1
- package/src/esm/utils/helpers/CircleSectorHelper.d.ts +11 -2
- package/src/esm/utils/helpers/CircleSectorHelper.js +20 -20
- package/src/esm/utils/helpers/CircleSectorHelper.js.map +1 -1
- package/src/esm/utils/helpers/TriangleHelper.d.ts +57 -0
- package/src/esm/utils/helpers/TriangleHelper.js +78 -0
- package/src/esm/utils/helpers/TriangleHelper.js.map +1 -0
- package/src/esm/utils/helpers/VEllipseHelper.d.ts +32 -0
- package/src/esm/utils/helpers/VEllipseHelper.js +83 -0
- package/src/esm/utils/helpers/VEllipseHelper.js.map +1 -0
- package/src/esm/utils/helpers/VEllipseSectorHelper.d.ts +44 -4
- package/src/esm/utils/helpers/VEllipseSectorHelper.js +107 -24
- package/src/esm/utils/helpers/VEllipseSectorHelper.js.map +1 -1
- package/src/esm/utils/parsers/LinearColorGradientParser.d.ts +78 -0
- package/src/esm/utils/parsers/LinearColorGradientParser.js +217 -0
- package/src/esm/utils/parsers/LinearColorGradientParser.js.map +1 -0
- package/src/external.d.ts +9 -0
- 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 +236 -114
- package/src/ts/Polygon.ts +164 -29
- package/src/ts/Triangle.ts +85 -3
- 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 +39 -4
- package/src/ts/Vertex.ts +40 -4
- package/src/ts/interfaces/core.ts +73 -0
- package/src/ts/utils/algorithms/convexPolygonIncircle.ts +82 -78
- package/src/ts/utils/createRandomizedPolygon.ts +31 -0
- package/src/ts/utils/datastructures/Color.ts +423 -44
- package/src/ts/utils/datastructures/ColorGradient.ts +196 -0
- package/src/ts/utils/dom/components/ColorGradientPicker.tsx +877 -0
- package/src/ts/utils/dom/components/ColorGradientSelector.tsx +445 -0
- package/src/ts/utils/dom/components/Test.tsx +44 -0
- package/src/ts/utils/dom/components/_ColorGradientPicker_raw.ts_ +392 -0
- package/src/ts/utils/dom/guiSizeToggler.ts +1 -1
- package/src/ts/utils/helpers/BezierPathInteractionHelper.ts +61 -35
- package/src/ts/utils/helpers/CircleHelper.ts +17 -3
- package/src/ts/utils/helpers/CircleSectorHelper.ts +118 -126
- package/src/ts/utils/helpers/TriangleHelper.ts +102 -0
- package/src/ts/utils/helpers/VEllipseHelper.ts +115 -0
- package/src/ts/utils/helpers/VEllipseSectorHelper.ts +144 -26
- package/src/ts/utils/parsers/LinearColorGradientParser.ts +297 -0
package/src/ts/Vertex.ts
CHANGED
|
@@ -33,7 +33,10 @@
|
|
|
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
|
-
* @
|
|
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
|
+
* @modified 2025-05-07 Class `Vertex` is now implementing interface `IBounded` (to meet convention).
|
|
39
|
+
* @version 2.11.0
|
|
37
40
|
*
|
|
38
41
|
* @file Vertex
|
|
39
42
|
* @public
|
|
@@ -42,8 +45,9 @@
|
|
|
42
45
|
import { IVertexAttr, VertexAttr } from "./VertexAttr";
|
|
43
46
|
import { UIDGenerator } from "./UIDGenerator";
|
|
44
47
|
import { VertexListeners } from "./VertexListeners";
|
|
45
|
-
import { XYCoords, SVGSerializable, UID } from "./interfaces";
|
|
48
|
+
import { XYCoords, SVGSerializable, UID, IBounded } from "./interfaces";
|
|
46
49
|
import { geomutils } from "./geomutils";
|
|
50
|
+
import { Bounds } from "./Bounds";
|
|
47
51
|
|
|
48
52
|
/**
|
|
49
53
|
* @classdesc A vertex is a pair of two numbers.<br>
|
|
@@ -59,7 +63,7 @@ import { geomutils } from "./geomutils";
|
|
|
59
63
|
* @requires XYCoords
|
|
60
64
|
*
|
|
61
65
|
*/
|
|
62
|
-
export class Vertex implements XYCoords, SVGSerializable {
|
|
66
|
+
export class Vertex implements IBounded, XYCoords, SVGSerializable {
|
|
63
67
|
private static readonly ZERO = new Vertex(0, 0);
|
|
64
68
|
|
|
65
69
|
/**
|
|
@@ -272,6 +276,22 @@ export class Vertex implements XYCoords, SVGSerializable {
|
|
|
272
276
|
return this;
|
|
273
277
|
}
|
|
274
278
|
|
|
279
|
+
/**
|
|
280
|
+
* Move this point by the given amount.
|
|
281
|
+
*
|
|
282
|
+
* This method just calls `add(amount).
|
|
283
|
+
*
|
|
284
|
+
*
|
|
285
|
+
* @method move
|
|
286
|
+
* @param {Vertex} amount - The amount to move this vertex.
|
|
287
|
+
* @return {Vertex} this - For chaining.
|
|
288
|
+
* @instance
|
|
289
|
+
* @memberof Vertex
|
|
290
|
+
*/
|
|
291
|
+
move(amount: XYCoords): Vertex {
|
|
292
|
+
return this.add(amount);
|
|
293
|
+
}
|
|
294
|
+
|
|
275
295
|
/**
|
|
276
296
|
* Add the passed amounts to the x- and y- components of this vertex.
|
|
277
297
|
*
|
|
@@ -554,7 +574,7 @@ export class Vertex implements XYCoords, SVGSerializable {
|
|
|
554
574
|
* @instance
|
|
555
575
|
* @memberof Vertex
|
|
556
576
|
**/
|
|
557
|
-
rotate(angle: number, center
|
|
577
|
+
rotate(angle: number, center?: XYCoords | undefined): Vertex {
|
|
558
578
|
if (!center || typeof center === "undefined") {
|
|
559
579
|
center = { x: 0, y: 0 };
|
|
560
580
|
}
|
|
@@ -627,6 +647,22 @@ export class Vertex implements XYCoords, SVGSerializable {
|
|
|
627
647
|
return this;
|
|
628
648
|
}
|
|
629
649
|
|
|
650
|
+
//--- BEGIN --- Implement interface `IBounded`
|
|
651
|
+
/**
|
|
652
|
+
* Get the bounding box (bounds) of this Vertex.
|
|
653
|
+
* This is just by convention – any vertex is just a position without any useful with or height (0).
|
|
654
|
+
*
|
|
655
|
+
* @method getBounds
|
|
656
|
+
* @instance
|
|
657
|
+
* @memberof Vertex
|
|
658
|
+
* @return {Bounds} The rectangular bounds of this Vertex (width and height are zero).
|
|
659
|
+
**/
|
|
660
|
+
getBounds(): Bounds {
|
|
661
|
+
// return Bounds.computeFromVertices([this.a, this.b, this.c]);
|
|
662
|
+
return Bounds.computeFromVertices([this]);
|
|
663
|
+
}
|
|
664
|
+
//--- END --- Implement interface `IBounded`
|
|
665
|
+
|
|
630
666
|
/**
|
|
631
667
|
* Get a string representation of this vertex.
|
|
632
668
|
*
|
|
@@ -20,6 +20,10 @@
|
|
|
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`.
|
|
25
|
+
* @modified 2025-05-07 Added callback `onContentChanged` to PB to track if the drawable content changed.
|
|
26
|
+
* @modified 2025-06-07 Adding helper type `PolygonIntersectionTuple` for re-usability.
|
|
23
27
|
**/
|
|
24
28
|
|
|
25
29
|
import { Vertex } from "../Vertex";
|
|
@@ -37,6 +41,7 @@ import { PlotBoilerplate } from "../PlotBoilerplate";
|
|
|
37
41
|
import { DrawLib } from "./DrawLib";
|
|
38
42
|
import { PBText } from "../PBText";
|
|
39
43
|
import { CSSBackdropFilterParams } from "./externals";
|
|
44
|
+
import { VertTuple } from "../VertTuple";
|
|
40
45
|
|
|
41
46
|
/**
|
|
42
47
|
* @classdesc Coordinates (x,y) on the plane.
|
|
@@ -111,6 +116,18 @@ export interface CanvasWrapper {
|
|
|
111
116
|
setSize: (width: number, height: number) => void;
|
|
112
117
|
element: HTMLCanvasElement | SVGElement;
|
|
113
118
|
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The interface for PB change events.
|
|
122
|
+
*/
|
|
123
|
+
export interface IPBChangeEvent {
|
|
124
|
+
type: "DRAWABLES_ADDED" | "DRAWABLES_REMOVED";
|
|
125
|
+
addedDrawables: Array<Drawable>;
|
|
126
|
+
removedDrawables: Array<Drawable>;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export type PBContentChangeListener = (event: IPBChangeEvent) => void; // A callback function that will be triggered after content changed.
|
|
130
|
+
|
|
114
131
|
/**
|
|
115
132
|
* The config that's used by PB.
|
|
116
133
|
*/
|
|
@@ -261,3 +278,59 @@ export interface IDraggable {
|
|
|
261
278
|
isVertex(): boolean;
|
|
262
279
|
setVIndex(vindex: number): IDraggable;
|
|
263
280
|
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Shapes should implement this interface if they support intersection calculation.
|
|
284
|
+
*/
|
|
285
|
+
export interface Intersectable {
|
|
286
|
+
/**
|
|
287
|
+
* Get all line intersections with this polygon.
|
|
288
|
+
*
|
|
289
|
+
* This method returns all intersections (as vertices) with this shape. The returned array of vertices is in no specific order.
|
|
290
|
+
*
|
|
291
|
+
* See demo `47-closest-vector-projection-on-polygon` for how it works.
|
|
292
|
+
*
|
|
293
|
+
* @param {VertTuple} line - The line to find intersections with.
|
|
294
|
+
* @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).
|
|
295
|
+
* @returns {Array<Vertex>} - An array of all intersections within this shape's bounds.
|
|
296
|
+
*/
|
|
297
|
+
lineIntersections(line: VertTuple<any>, inVectorBoundsOnly?: boolean): Array<Vertex>;
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Get all line intersections of this polygon and their tangents along the shape.
|
|
301
|
+
*
|
|
302
|
+
* This method returns all intersection tangents (as vectors) with this shape. The returned array of vectors is in no specific order.
|
|
303
|
+
*
|
|
304
|
+
* @param {VertTuple} line - The line to find intersections with.
|
|
305
|
+
* @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).
|
|
306
|
+
* @returns {Array<Vector>} - An array of all intersection tangents within this shape's bounds.
|
|
307
|
+
*/
|
|
308
|
+
lineIntersectionTangents(line: VertTuple<any>, inVectorBoundsOnly?: boolean): Array<Vector>;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export interface IBounded {
|
|
312
|
+
/**
|
|
313
|
+
* Get the bounding box (bounds) of this shape.
|
|
314
|
+
*
|
|
315
|
+
* @method getBounds
|
|
316
|
+
* @return {Bounds} The rectangular bounds of this shape.
|
|
317
|
+
**/
|
|
318
|
+
getBounds(): IBounds;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export interface IShapeInteractionHelper {
|
|
322
|
+
/**
|
|
323
|
+
* Let this shape helper draw it's handle lines. It's up to the helper what they look like.
|
|
324
|
+
* @param {DrawLib<any>} draw - The draw library to use.
|
|
325
|
+
* @param {DrawLib<any>} fill - The fill library to use.
|
|
326
|
+
*/
|
|
327
|
+
drawHandleLines(draw: DrawLib<any>, fill: DrawLib<any>): void;
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Destroys this helper. This means that all listeners get released and this helper
|
|
331
|
+
* will not receive or handle any events.
|
|
332
|
+
*/
|
|
333
|
+
destroy(): void;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export type PolygonIntersectionTuple<T> = { edgeIndex: number; intersection: T };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
2
|
* @author mbostock, extended and ported to TypeScript by Ikaros Kappler
|
|
3
3
|
* @date 2020-05-19
|
|
4
4
|
* @modified 2021-02-08 Fixed a lot of es2015 compatibility issues.
|
|
5
|
-
* @
|
|
5
|
+
* @modified 2024-03-24 Fixing some unstrict types to match with the new Typescript settings.
|
|
6
|
+
* @version 1.0.3
|
|
6
7
|
* @file contextPolygonIncircle
|
|
7
8
|
* @public
|
|
8
9
|
*/
|
|
@@ -14,17 +15,16 @@ import { Polygon } from "../../Polygon";
|
|
|
14
15
|
import { Triangle } from "../../Triangle";
|
|
15
16
|
import { Vertex } from "../../Vertex";
|
|
16
17
|
|
|
17
|
-
|
|
18
18
|
/**
|
|
19
19
|
* For circle-polygon-intersection-count detection we need an epsilon to
|
|
20
20
|
* eliminate smaller precision errors.
|
|
21
21
|
*/
|
|
22
|
-
const EPS
|
|
22
|
+
const EPS: number = 0.000001;
|
|
23
23
|
|
|
24
24
|
export interface PolygonIncircle {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
25
|
+
circle: Circle;
|
|
26
|
+
triangle: Triangle;
|
|
27
|
+
}
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Compute the max sized inlying circle in the given convex (!) polygon - also called the
|
|
@@ -50,54 +50,60 @@ export interface PolygonIncircle {
|
|
|
50
50
|
* @param {Polygon} convexHull - The actual convex polygon.
|
|
51
51
|
* @return {PolygonIncircle} A pair of a circle (the incircle) and a triangle (the three points where the circle is touching the polygon).
|
|
52
52
|
*/
|
|
53
|
-
export const convexPolygonIncircle = (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
53
|
+
export const convexPolygonIncircle = (convexHull: Polygon): PolygonIncircle => {
|
|
54
|
+
var n: number = convexHull.vertices.length;
|
|
55
|
+
var bestCircle: Circle | null = null;
|
|
56
|
+
var bestTriangle: Triangle | null = null;
|
|
57
|
+
for (var a = 0; a < n; a++) {
|
|
58
|
+
for (var b = a + 1; b < n; b++) {
|
|
59
|
+
for (var c = b + 1; c < n; c++) {
|
|
60
|
+
// As these lines are part of the convex hull, we know that
|
|
61
|
+
// * line a preceeds line b and
|
|
62
|
+
// * line b preceeds line c :)
|
|
63
|
+
let lineA: Line = new Line(convexHull.vertices[a], convexHull.vertices[(a + 1) % n]);
|
|
64
|
+
let lineB: Line = new Line(convexHull.vertices[b], convexHull.vertices[(b + 1) % n]);
|
|
65
|
+
let lineC: Line = new Line(convexHull.vertices[c], convexHull.vertices[(c + 1) % n]);
|
|
66
|
+
|
|
67
|
+
// Find intersections by expanding the lines
|
|
68
|
+
let vertB: Vertex | null = lineA.intersection(lineB);
|
|
69
|
+
let vertC: Vertex | null = lineB.intersection(lineC);
|
|
70
|
+
|
|
71
|
+
if (!vertB || !vertC) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// An object: { center: Vertex, radius: number }
|
|
76
|
+
let triangle: Triangle | null = getTangentTriangle4(lineA.a, vertB, vertC, lineC.b);
|
|
77
|
+
if (!triangle) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Workaround. There will be a future version where the 'getCircumCircle()' functions
|
|
82
|
+
// returns a real Circle instance.
|
|
83
|
+
let _circle: Circle = triangle.getCircumcircle();
|
|
84
|
+
let circle: Circle = new Circle(_circle.center, _circle.radius);
|
|
85
|
+
|
|
86
|
+
// Count the number of intersections with the convex hull:
|
|
87
|
+
// If there are exactly three, we have found an in-lying circle.
|
|
88
|
+
// * Check if this one is better (bigger) than the old one.
|
|
89
|
+
// * Also check if the circle is located inside the polygon;
|
|
90
|
+
// The construction can, in some cases, produce an out-lying circle.
|
|
91
|
+
if (!convexHull.containsVert(circle.center)) {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
var circleIntersections: Array<number> = findCircleIntersections(convexHull, circle);
|
|
95
|
+
if (circleIntersections.length == 3 && (bestCircle == undefined || bestCircle.radius < circle.radius)) {
|
|
96
|
+
bestCircle = circle;
|
|
97
|
+
bestTriangle = triangle;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
93
100
|
}
|
|
94
|
-
|
|
95
|
-
|
|
101
|
+
}
|
|
102
|
+
return { circle: bestCircle as Circle, triangle: bestTriangle as Triangle };
|
|
96
103
|
};
|
|
97
104
|
|
|
98
|
-
|
|
99
105
|
/**
|
|
100
|
-
* This function computes the three points for the inner maximum circle
|
|
106
|
+
* This function computes the three points for the inner maximum circle
|
|
101
107
|
* lying tangential to the three subsequential lines (given by four points).
|
|
102
108
|
*
|
|
103
109
|
* Compute the circle from that triangle by using Triangle.getCircumcircle().
|
|
@@ -114,26 +120,26 @@ export const convexPolygonIncircle = ( convexHull:Polygon ) : PolygonIncircle =>
|
|
|
114
120
|
* @param {Vertex} vertD - The fourth point of the three connected lines.
|
|
115
121
|
* @return {Triangle} The triangle of the circular tangential points with the given lines (3 or 4 of them).
|
|
116
122
|
*/
|
|
117
|
-
const getTangentTriangle4 = (
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const lineA : Line = new Line(vertA,vertB);
|
|
122
|
-
const lineB : Line = new Line(vertB,vertC);
|
|
123
|
-
const lineC : Line = new Line(vertC,vertD);
|
|
123
|
+
const getTangentTriangle4 = (vertA: Vertex, vertB: Vertex, vertC: Vertex, vertD: Vertex): Triangle | null => {
|
|
124
|
+
const lineA: Line = new Line(vertA, vertB);
|
|
125
|
+
const lineB: Line = new Line(vertB, vertC);
|
|
126
|
+
const lineC: Line = new Line(vertC, vertD);
|
|
124
127
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
+
const bisector1: Line = geomutils.nsectAngle(vertB, vertA, vertC, 2)[0]; // bisector of first triangle
|
|
129
|
+
const bisector2: Line = geomutils.nsectAngle(vertC, vertB, vertD, 2)[0]; // bisector of second triangle
|
|
130
|
+
const intersection: Vertex | null = bisector1.intersection(bisector2);
|
|
128
131
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const circleIntersC : Vertex = lineC.getClosestPoint( intersection );
|
|
132
|
+
if (!intersection) {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
133
135
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
+
// Find the closest points on one of the polygon lines (all have same distance by construction)
|
|
137
|
+
const circleIntersA: Vertex = lineA.getClosestPoint(intersection);
|
|
138
|
+
const circleIntersB: Vertex = lineB.getClosestPoint(intersection);
|
|
139
|
+
const circleIntersC: Vertex = lineC.getClosestPoint(intersection);
|
|
136
140
|
|
|
141
|
+
return new Triangle(circleIntersA, circleIntersB, circleIntersC);
|
|
142
|
+
};
|
|
137
143
|
|
|
138
144
|
/**
|
|
139
145
|
* Find all intersecting lines (indices) on the polyon that intersect the circle.
|
|
@@ -142,16 +148,14 @@ const getTangentTriangle4 = ( vertA : Vertex,
|
|
|
142
148
|
* @param {Circle} circle - The circle to detect the intersections with.
|
|
143
149
|
* @return {Array<number>} The indices of those lines that intersect (or touch) the circle.
|
|
144
150
|
**/
|
|
145
|
-
const findCircleIntersections = (
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
151
|
+
const findCircleIntersections = (convexHull: Polygon, circle: Circle): Array<number> => {
|
|
152
|
+
const result: Array<number> = [];
|
|
153
|
+
for (var i = 0; i < convexHull.vertices.length; i++) {
|
|
154
|
+
var line: Line = new Line(convexHull.vertices[i], convexHull.vertices[(i + 1) % convexHull.vertices.length]);
|
|
155
|
+
// Use an epsilon here because circle coordinates can be kind of unprecise in the detail.
|
|
156
|
+
if (circle.lineDistance(line) < EPS) {
|
|
157
|
+
result.push(i);
|
|
153
158
|
}
|
|
154
|
-
|
|
159
|
+
}
|
|
160
|
+
return result;
|
|
155
161
|
};
|
|
156
|
-
|
|
157
|
-
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A helper function to generate randmoized non-intersecting polygons.
|
|
3
|
+
*
|
|
4
|
+
* @author Ikaros Kappler
|
|
5
|
+
* @date 2025-03-23 (ported to Typescript from a helper script from 2024)
|
|
6
|
+
* @version 1.0.0
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { Bounds } from "../Bounds";
|
|
10
|
+
import { Polygon } from "../Polygon";
|
|
11
|
+
import { Vertex } from "../Vertex";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param numVertices
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export const createRandomizedPolygon = (numVertices: number, viewport: Bounds, createClockwise?: boolean) => {
|
|
19
|
+
const polygon = new Polygon();
|
|
20
|
+
for (var i = 0; i < numVertices; i++) {
|
|
21
|
+
const vert = new Vertex(viewport.getMinDimension() * 0.33, 0.0);
|
|
22
|
+
vert.rotate(((Math.PI * 2) / numVertices) * i);
|
|
23
|
+
vert.addXY(viewport.width * 0.1 * (1.0 - Math.random() * 2), viewport.height * 0.1 * (1.0 - Math.random() * 2));
|
|
24
|
+
polygon.addVertex(vert);
|
|
25
|
+
}
|
|
26
|
+
if (createClockwise && !polygon.isClockwise()) {
|
|
27
|
+
// Reverse
|
|
28
|
+
polygon.vertices = polygon.vertices.reverse();
|
|
29
|
+
}
|
|
30
|
+
return polygon;
|
|
31
|
+
};
|