plotboilerplate 1.30.0 → 1.31.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 +26 -13
- package/dist/index.esm.js +120 -45
- 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 +75 -24
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +1 -1
- package/src/cjs/Polygon.d.ts +18 -4
- package/src/cjs/Polygon.js +56 -18
- package/src/cjs/Polygon.js.map +1 -1
- package/src/cjs/VertTuple.d.ts +15 -4
- package/src/cjs/VertTuple.js +17 -4
- package/src/cjs/VertTuple.js.map +1 -1
- package/src/cjs/Vertex.d.ts +2 -2
- package/src/cjs/Vertex.js +2 -2
- package/src/cjs/utils/algorithms/delaunay2voronoi.d.ts +2 -1
- package/src/cjs/utils/algorithms/delaunay2voronoi.js +8 -10
- package/src/cjs/utils/algorithms/delaunay2voronoi.js.map +1 -1
- package/src/cjs/utils/datastructures/PointSet.d.ts +63 -0
- package/src/cjs/utils/datastructures/PointSet.js +126 -0
- package/src/cjs/utils/datastructures/PointSet.js.map +1 -0
- package/src/cjs/utils/datastructures/VoronoiCell.d.ts +19 -2
- package/src/cjs/utils/datastructures/VoronoiCell.js +39 -12
- package/src/cjs/utils/datastructures/VoronoiCell.js.map +1 -1
- package/src/cjs/utils/renderers/VoronoiRenderer.d.ts +99 -0
- package/src/cjs/utils/renderers/VoronoiRenderer.js +147 -0
- package/src/cjs/utils/renderers/VoronoiRenderer.js.map +1 -0
- package/src/esm/Polygon.d.ts +18 -4
- package/src/esm/Polygon.js +56 -18
- package/src/esm/Polygon.js.map +1 -1
- package/src/esm/VertTuple.d.ts +15 -4
- package/src/esm/VertTuple.js +17 -4
- package/src/esm/VertTuple.js.map +1 -1
- package/src/esm/Vertex.d.ts +2 -2
- package/src/esm/Vertex.js +2 -2
- package/src/esm/utils/algorithms/delaunay2voronoi.d.ts +2 -1
- package/src/esm/utils/algorithms/delaunay2voronoi.js +8 -10
- package/src/esm/utils/algorithms/delaunay2voronoi.js.map +1 -1
- package/src/esm/utils/datastructures/PointSet.d.ts +63 -0
- package/src/esm/utils/datastructures/PointSet.js +115 -0
- package/src/esm/utils/datastructures/PointSet.js.map +1 -0
- package/src/esm/utils/datastructures/VoronoiCell.d.ts +19 -2
- package/src/esm/utils/datastructures/VoronoiCell.js +39 -12
- package/src/esm/utils/datastructures/VoronoiCell.js.map +1 -1
- package/src/esm/utils/renderers/VoronoiRenderer.d.ts +99 -0
- package/src/esm/utils/renderers/VoronoiRenderer.js +142 -0
- package/src/esm/utils/renderers/VoronoiRenderer.js.map +1 -0
- package/src/ts/Polygon.ts +58 -18
- package/src/ts/VertTuple.ts +18 -4
- package/src/ts/Vertex.ts +2 -2
- package/src/ts/utils/_AppContext.ts_ +22 -0
- package/src/ts/utils/algorithms/delaunay2voronoi.ts +81 -88
- package/src/ts/utils/datastructures/PointSet.ts +135 -0
- package/src/ts/utils/datastructures/VoronoiCell.ts +198 -169
- package/src/ts/utils/renderers/VoronoiRenderer.ts +200 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PointSet.js","sourceRoot":"","sources":["../../../ts/utils/datastructures/PointSet.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,MAAM,OAAO,QAAQ;IAKnB,YAAY,EAAmB;QAFtB,kBAAa,GAAoB,EAAE,CAAC;QAG3C,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IACnB,CAAC;IAEO,aAAa;QACnB,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;YACpC,QAAQ,EAAE,CAAC;QACb,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;OAQG;I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CAAC;CAQF"}
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
* @modified 2020-08-12 Ported this class from vanilla JS to TypeScript.
|
|
17
17
|
* @modified 2020-08-17 Added some missing type declarations.
|
|
18
18
|
* @modified 2021-01-20 Members `triangles` and `sharedVertex` are now public.
|
|
19
|
-
* @
|
|
19
|
+
* @modified 2026-09-15 Added the `VoronoiCell.sharedVertexIndex` attribute.
|
|
20
|
+
* @version 1.2.0
|
|
20
21
|
*
|
|
21
22
|
* @file VoronoiCell
|
|
22
23
|
* @public
|
|
@@ -39,6 +40,10 @@ export declare class VoronoiCell {
|
|
|
39
40
|
* @instance
|
|
40
41
|
*/
|
|
41
42
|
sharedVertex: Vertex;
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
*/
|
|
46
|
+
sharedVertexIndex: number;
|
|
42
47
|
/**
|
|
43
48
|
* The constructor.
|
|
44
49
|
*
|
|
@@ -49,7 +54,7 @@ export declare class VoronoiCell {
|
|
|
49
54
|
* @param {Vertex} sharedVertex This is the 'center' of the voronoi cell; all triangles must share
|
|
50
55
|
* that vertex.
|
|
51
56
|
**/
|
|
52
|
-
constructor(triangles: Array<Triangle>, sharedVertex: Vertex);
|
|
57
|
+
constructor(triangles: Array<Triangle>, sharedVertex: Vertex, sharedVertexIndex: number);
|
|
53
58
|
/**
|
|
54
59
|
* Check if the first and the last triangle in the path are NOT connected.
|
|
55
60
|
*
|
|
@@ -71,6 +76,18 @@ export declare class VoronoiCell {
|
|
|
71
76
|
* @return {Polygon}
|
|
72
77
|
**/
|
|
73
78
|
toPolygon(): Polygon;
|
|
79
|
+
/**
|
|
80
|
+
* Get all 'umbrella' triangles for this Voronoi cell.
|
|
81
|
+
*
|
|
82
|
+
* The 'umbrella' is that sequence of triangles that covers the whole Voronoi cell and
|
|
83
|
+
* meet in the cell's centroid.
|
|
84
|
+
*
|
|
85
|
+
* @method getUmbrellaTriangles
|
|
86
|
+
* @instance
|
|
87
|
+
* @memberof VoronoiCell
|
|
88
|
+
* @return {Array<Triangle>}
|
|
89
|
+
**/
|
|
90
|
+
getUmbrellaTriangles(): Array<Triangle>;
|
|
74
91
|
/**
|
|
75
92
|
* Convert the voronoi cell path data to an SVG polygon data string.
|
|
76
93
|
*
|
|
@@ -16,13 +16,15 @@
|
|
|
16
16
|
* @modified 2020-08-12 Ported this class from vanilla JS to TypeScript.
|
|
17
17
|
* @modified 2020-08-17 Added some missing type declarations.
|
|
18
18
|
* @modified 2021-01-20 Members `triangles` and `sharedVertex` are now public.
|
|
19
|
-
* @
|
|
19
|
+
* @modified 2026-09-15 Added the `VoronoiCell.sharedVertexIndex` attribute.
|
|
20
|
+
* @version 1.2.0
|
|
20
21
|
*
|
|
21
22
|
* @file VoronoiCell
|
|
22
23
|
* @public
|
|
23
24
|
**/
|
|
24
25
|
import { Line } from "../../Line";
|
|
25
26
|
import { Polygon } from "../../Polygon";
|
|
27
|
+
import { Triangle } from "../../Triangle";
|
|
26
28
|
import { Vertex } from "../../Vertex";
|
|
27
29
|
export class VoronoiCell {
|
|
28
30
|
/**
|
|
@@ -35,15 +37,15 @@ export class VoronoiCell {
|
|
|
35
37
|
* @param {Vertex} sharedVertex This is the 'center' of the voronoi cell; all triangles must share
|
|
36
38
|
* that vertex.
|
|
37
39
|
**/
|
|
38
|
-
constructor(triangles, sharedVertex) {
|
|
39
|
-
if (typeof triangles ===
|
|
40
|
+
constructor(triangles, sharedVertex, sharedVertexIndex) {
|
|
41
|
+
if (typeof triangles === "undefined")
|
|
40
42
|
triangles = [];
|
|
41
|
-
if (typeof sharedVertex ===
|
|
43
|
+
if (typeof sharedVertex === "undefined")
|
|
42
44
|
sharedVertex = new Vertex(0, 0);
|
|
43
45
|
this.triangles = triangles;
|
|
44
46
|
this.sharedVertex = sharedVertex;
|
|
47
|
+
this.sharedVertexIndex = sharedVertexIndex;
|
|
45
48
|
}
|
|
46
|
-
;
|
|
47
49
|
/**
|
|
48
50
|
* Check if the first and the last triangle in the path are NOT connected.
|
|
49
51
|
*
|
|
@@ -56,7 +58,6 @@ export class VoronoiCell {
|
|
|
56
58
|
// There must be at least three triangles
|
|
57
59
|
return this.triangles.length < 3 || !this.triangles[0].isAdjacent(this.triangles[this.triangles.length - 1]);
|
|
58
60
|
}
|
|
59
|
-
;
|
|
60
61
|
/**
|
|
61
62
|
* Convert this Voronoi cell to a path polygon, consisting of all Voronoi cell corner points.
|
|
62
63
|
*
|
|
@@ -71,7 +72,32 @@ export class VoronoiCell {
|
|
|
71
72
|
toPolygon() {
|
|
72
73
|
return new Polygon(this.toPathArray(), this.isOpen());
|
|
73
74
|
}
|
|
74
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Get all 'umbrella' triangles for this Voronoi cell.
|
|
77
|
+
*
|
|
78
|
+
* The 'umbrella' is that sequence of triangles that covers the whole Voronoi cell and
|
|
79
|
+
* meet in the cell's centroid.
|
|
80
|
+
*
|
|
81
|
+
* @method getUmbrellaTriangles
|
|
82
|
+
* @instance
|
|
83
|
+
* @memberof VoronoiCell
|
|
84
|
+
* @return {Array<Triangle>}
|
|
85
|
+
**/
|
|
86
|
+
getUmbrellaTriangles() {
|
|
87
|
+
var tris = [];
|
|
88
|
+
// for (var i = 0; i < this.triangles.length; i++) {
|
|
89
|
+
// var delaunayTri = this.triangles[i];
|
|
90
|
+
// var tri = new Triangle(this.sharedVertex, delaunayTri.b, delaunayTri.c);
|
|
91
|
+
// tris.push(tri);
|
|
92
|
+
// }
|
|
93
|
+
var vertices = this.toPathArray();
|
|
94
|
+
var n = vertices.length;
|
|
95
|
+
for (var i = 0; i < n; i++) {
|
|
96
|
+
var tri = new Triangle(this.sharedVertex, vertices[i], vertices[(i + 1) % n]);
|
|
97
|
+
tris.push(tri);
|
|
98
|
+
}
|
|
99
|
+
return tris;
|
|
100
|
+
}
|
|
75
101
|
/**
|
|
76
102
|
* Convert the voronoi cell path data to an SVG polygon data string.
|
|
77
103
|
*
|
|
@@ -86,9 +112,12 @@ export class VoronoiCell {
|
|
|
86
112
|
if (this.triangles.length == 0)
|
|
87
113
|
return "";
|
|
88
114
|
const arr = this.toPathArray();
|
|
89
|
-
return arr
|
|
115
|
+
return arr
|
|
116
|
+
.map((vert) => {
|
|
117
|
+
return "" + vert.x + "," + vert.y;
|
|
118
|
+
})
|
|
119
|
+
.join(" ");
|
|
90
120
|
}
|
|
91
|
-
;
|
|
92
121
|
/**
|
|
93
122
|
* Convert the voronoi cell path data to an array.
|
|
94
123
|
*
|
|
@@ -143,7 +172,6 @@ export class VoronoiCell {
|
|
|
143
172
|
const openEdgePoint = new Vertex(perpendicular.x + (center.x - perpendicular.x) * 1000, perpendicular.y + (center.y - perpendicular.y) * 1000);
|
|
144
173
|
return openEdgePoint;
|
|
145
174
|
}
|
|
146
|
-
;
|
|
147
175
|
/**
|
|
148
176
|
* A helper function.
|
|
149
177
|
*
|
|
@@ -167,12 +195,11 @@ export class VoronoiCell {
|
|
|
167
195
|
return tri.a;
|
|
168
196
|
}
|
|
169
197
|
// Here:
|
|
170
|
-
// tri.c.equals(sharedVertex)
|
|
198
|
+
// tri.c.equals(sharedVertex)
|
|
171
199
|
if (neighbour.a.equals(tri.a) || neighbour.b.equals(tri.a) || neighbour.c.equals(tri.a))
|
|
172
200
|
return tri.b;
|
|
173
201
|
else
|
|
174
202
|
return tri.a;
|
|
175
203
|
}
|
|
176
|
-
;
|
|
177
204
|
}
|
|
178
205
|
//# sourceMappingURL=VoronoiCell.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VoronoiCell.js","sourceRoot":"","sources":["../../../ts/utils/datastructures/VoronoiCell.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"VoronoiCell.js","sourceRoot":"","sources":["../../../ts/utils/datastructures/VoronoiCell.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;IAuBI;AAEJ,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAA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,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;gBAAE,OAAO,GAAG,CAAC,CAAC,CAAC;;gBACjG,OAAO,GAAG,CAAC,CAAC,CAAC;QACpB,CAAC;QACD,IAAI,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;YAC/B,IAAI,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;gBAAE,OAAO,GAAG,CAAC,CAAC,CAAC;;gBACjG,OAAO,GAAG,CAAC,CAAC,CAAC;QACpB,CAAC;QACD,QAAQ;QACR,gCAAgC;QAChC,IAAI,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YAAE,OAAO,GAAG,CAAC,CAAC,CAAC;;YACjG,OAAO,GAAG,CAAC,CAAC,CAAC;IACpB,CAAC;CACF"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Refactored all Voronoi helper functions for drawing the diagram (demo 07) into this class.
|
|
3
|
+
*
|
|
4
|
+
* @author Ikaros Kappler
|
|
5
|
+
* @date 2026-09-13
|
|
6
|
+
* @modified 2026-09-15 Ported to Typescript.
|
|
7
|
+
* @version 1.0.1
|
|
8
|
+
*/
|
|
9
|
+
import { Polygon } from "../../Polygon";
|
|
10
|
+
import { Triangle } from "../../Triangle";
|
|
11
|
+
import { DrawLib } from "../../interfaces";
|
|
12
|
+
import { PointSet } from "../datastructures/PointSet";
|
|
13
|
+
import { VoronoiCell } from "../datastructures/VoronoiCell";
|
|
14
|
+
export interface IVoronoiConfig {
|
|
15
|
+
makeVoronoiDiagram: boolean;
|
|
16
|
+
drawPoints: boolean;
|
|
17
|
+
drawTriangles: boolean;
|
|
18
|
+
drawCircumCircles: boolean;
|
|
19
|
+
drawCubicCurves: boolean;
|
|
20
|
+
fillVoronoiCells: boolean;
|
|
21
|
+
voronoiOutlineColor: string;
|
|
22
|
+
voronoiCellColor: string;
|
|
23
|
+
voronoiCubicThreshold: number;
|
|
24
|
+
voronoiCellScale: number;
|
|
25
|
+
clipVoronoiCells: boolean;
|
|
26
|
+
drawClipBox: boolean;
|
|
27
|
+
drawUnclippedVoronoiCells: boolean;
|
|
28
|
+
drawVoronoiIncircles: boolean;
|
|
29
|
+
drawVoronoiOutlines: boolean;
|
|
30
|
+
pointCount: number;
|
|
31
|
+
horizontalSafeArea: number;
|
|
32
|
+
verticalSafeArea: number;
|
|
33
|
+
voronoiCellLineWidth: number;
|
|
34
|
+
}
|
|
35
|
+
export interface IVoronoiContext {
|
|
36
|
+
pointSet: PointSet;
|
|
37
|
+
triangles: Array<Triangle>;
|
|
38
|
+
voronoiCells: Array<VoronoiCell>;
|
|
39
|
+
config: IVoronoiConfig;
|
|
40
|
+
}
|
|
41
|
+
export declare class VoronoiRenderer {
|
|
42
|
+
voronoiContext: IVoronoiContext;
|
|
43
|
+
constructor(voronoiContext: IVoronoiContext);
|
|
44
|
+
/**
|
|
45
|
+
* Draw the given triangle with the specified (CSS-) color.
|
|
46
|
+
*
|
|
47
|
+
* @name draw
|
|
48
|
+
* @instance
|
|
49
|
+
* @memberof VoronoiRenderer
|
|
50
|
+
* @param {DrawLib} draw
|
|
51
|
+
* @param {Triangle} t
|
|
52
|
+
* @param {string} color
|
|
53
|
+
* @return {void}
|
|
54
|
+
*/
|
|
55
|
+
draw(draw: DrawLib<any>, fill: DrawLib<any>): void;
|
|
56
|
+
/**
|
|
57
|
+
* Draw the given triangle with the specified (CSS-) color.
|
|
58
|
+
*
|
|
59
|
+
* @name _drawCell
|
|
60
|
+
* @instance
|
|
61
|
+
* @private
|
|
62
|
+
* @memberof VoronoiRenderer
|
|
63
|
+
* @param {DrawLib} draw
|
|
64
|
+
* @param {Polygon} clipBoxPolygon
|
|
65
|
+
* @param {VoronoiCell} cell
|
|
66
|
+
* @return {void}
|
|
67
|
+
*/
|
|
68
|
+
private _drawCell;
|
|
69
|
+
/**
|
|
70
|
+
* A function for drawing the triangles.
|
|
71
|
+
*
|
|
72
|
+
* @static
|
|
73
|
+
*/
|
|
74
|
+
drawTriangles(draw: DrawLib<any>): void;
|
|
75
|
+
/**
|
|
76
|
+
* Draw the given triangle with the specified (CSS-) color.
|
|
77
|
+
*
|
|
78
|
+
* @static
|
|
79
|
+
* @name drawTriangle
|
|
80
|
+
* @memberof VoronoiRenderer
|
|
81
|
+
* @param {DrawLib} draw
|
|
82
|
+
* @param {Triangle} tri
|
|
83
|
+
* @param {string} color
|
|
84
|
+
* @return {void}
|
|
85
|
+
*/
|
|
86
|
+
static drawTriangle(draw: DrawLib<any>, tri: Triangle, color: string): void;
|
|
87
|
+
/**
|
|
88
|
+
* Draw the circumcircles of all triangles.
|
|
89
|
+
*/
|
|
90
|
+
static drawCircumCircles(draw: DrawLib<any>, triangles: Array<Triangle>): void;
|
|
91
|
+
/**
|
|
92
|
+
* Clip the convex (!) cell polygon by the convex (!) clipping polygon.
|
|
93
|
+
*
|
|
94
|
+
* @param cellPolygon
|
|
95
|
+
* @param clipBoxPolygon
|
|
96
|
+
* @returns
|
|
97
|
+
*/
|
|
98
|
+
static clipVoronoiPolygon(cellPolygon: Polygon, clipBoxPolygon: Polygon): Polygon;
|
|
99
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Refactored all Voronoi helper functions for drawing the diagram (demo 07) into this class.
|
|
3
|
+
*
|
|
4
|
+
* @author Ikaros Kappler
|
|
5
|
+
* @date 2026-09-13
|
|
6
|
+
* @modified 2026-09-15 Ported to Typescript.
|
|
7
|
+
* @version 1.0.1
|
|
8
|
+
*/
|
|
9
|
+
import { Bounds } from "../../Bounds";
|
|
10
|
+
import { Polygon } from "../../Polygon";
|
|
11
|
+
import { convexPolygonIncircle } from "../algorithms/convexPolygonIncircle";
|
|
12
|
+
import { sutherlandHodgman } from "../algorithms/sutherlandHodgman";
|
|
13
|
+
import { cloneVertexArray } from "../cloneVertexArray";
|
|
14
|
+
export class VoronoiRenderer {
|
|
15
|
+
constructor(voronoiContext) {
|
|
16
|
+
this.voronoiContext = voronoiContext;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Draw the given triangle with the specified (CSS-) color.
|
|
20
|
+
*
|
|
21
|
+
* @name draw
|
|
22
|
+
* @instance
|
|
23
|
+
* @memberof VoronoiRenderer
|
|
24
|
+
* @param {DrawLib} draw
|
|
25
|
+
* @param {Triangle} t
|
|
26
|
+
* @param {string} color
|
|
27
|
+
* @return {void}
|
|
28
|
+
*/
|
|
29
|
+
draw(draw, fill) {
|
|
30
|
+
// Draw circumcircles
|
|
31
|
+
if (this.voronoiContext.config.drawCircumCircles) {
|
|
32
|
+
VoronoiRenderer.drawCircumCircles(draw, this.voronoiContext.triangles);
|
|
33
|
+
}
|
|
34
|
+
// An array of VoronoiCells.
|
|
35
|
+
var clipBoxPolygon = Bounds.computeFromVertices(this.voronoiContext.pointSet.points).toPolygon();
|
|
36
|
+
if (this.voronoiContext.config.drawClipBox) {
|
|
37
|
+
draw.polygon(clipBoxPolygon, "rgba(192,192,192,0.25)");
|
|
38
|
+
}
|
|
39
|
+
for (var v in this.voronoiContext.voronoiCells) {
|
|
40
|
+
var cell = this.voronoiContext.voronoiCells[v];
|
|
41
|
+
this._drawCell(draw, fill, clipBoxPolygon, cell);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Draw the given triangle with the specified (CSS-) color.
|
|
46
|
+
*
|
|
47
|
+
* @name _drawCell
|
|
48
|
+
* @instance
|
|
49
|
+
* @private
|
|
50
|
+
* @memberof VoronoiRenderer
|
|
51
|
+
* @param {DrawLib} draw
|
|
52
|
+
* @param {Polygon} clipBoxPolygon
|
|
53
|
+
* @param {VoronoiCell} cell
|
|
54
|
+
* @return {void}
|
|
55
|
+
*/
|
|
56
|
+
_drawCell(draw, fill, clipBoxPolygon, cell) {
|
|
57
|
+
var _a, _b;
|
|
58
|
+
var cellPolygon = cell.toPolygon();
|
|
59
|
+
cellPolygon.scale(this.voronoiContext.config.voronoiCellScale, cell.sharedVertex);
|
|
60
|
+
// Draw large (unclipped) Voronoi cell
|
|
61
|
+
if (this.voronoiContext.config.drawVoronoiOutlines &&
|
|
62
|
+
(!this.voronoiContext.config.clipVoronoiCells || this.voronoiContext.config.drawUnclippedVoronoiCells)) {
|
|
63
|
+
draw.polyline(cellPolygon.vertices, false, this.voronoiContext.config.clipVoronoiCells ? "rgba(128,128,128,0.333)" : this.voronoiContext.config.voronoiOutlineColor, (_a = this.voronoiContext.config.voronoiCellLineWidth) !== null && _a !== void 0 ? _a : 2.0);
|
|
64
|
+
}
|
|
65
|
+
// Apply clipping?
|
|
66
|
+
if (this.voronoiContext.config.clipVoronoiCells) {
|
|
67
|
+
// Clone the array here: convert Array<XYCoords> to Array<Vertex>
|
|
68
|
+
// polygon = new Polygon(cloneVertexArray(sutherlandHodgman(polygon.vertices, clipBoxPolygon.vertices)), false);
|
|
69
|
+
cellPolygon = VoronoiRenderer.clipVoronoiPolygon(cellPolygon, clipBoxPolygon);
|
|
70
|
+
}
|
|
71
|
+
if (this.voronoiContext.config.drawVoronoiOutlines && this.voronoiContext.config.clipVoronoiCells) {
|
|
72
|
+
draw.polygon(cellPolygon, this.voronoiContext.config.voronoiOutlineColor, (_b = this.voronoiContext.config.voronoiCellLineWidth) !== null && _b !== void 0 ? _b : 2.0);
|
|
73
|
+
}
|
|
74
|
+
if ((!cell.isOpen() || this.voronoiContext.config.clipVoronoiCells) && cell.triangles.length >= 3) {
|
|
75
|
+
if (this.voronoiContext.config.drawCubicCurves) {
|
|
76
|
+
var cbezier = cellPolygon.toCubicBezierData(this.voronoiContext.config.voronoiCubicThreshold);
|
|
77
|
+
if (this.voronoiContext.config.fillVoronoiCells) {
|
|
78
|
+
fill.cubicBezierPath(cbezier, this.voronoiContext.config.voronoiCellColor);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
draw.cubicBezierPath(cbezier, this.voronoiContext.config.voronoiCellColor);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (this.voronoiContext.config.drawVoronoiIncircles) {
|
|
85
|
+
var result = convexPolygonIncircle(cellPolygon);
|
|
86
|
+
var circle = result.circle;
|
|
87
|
+
// var triangle = result.triangle;
|
|
88
|
+
// Here we should have found the best inlying circle (and the corresponding triangle)
|
|
89
|
+
// inside the Voronoi cell.
|
|
90
|
+
draw.circle(circle.center, circle.radius, "rgba(255,192,0,1.0)", 2);
|
|
91
|
+
}
|
|
92
|
+
} // END cell is not open
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* A function for drawing the triangles.
|
|
96
|
+
*
|
|
97
|
+
* @static
|
|
98
|
+
*/
|
|
99
|
+
drawTriangles(draw) {
|
|
100
|
+
for (var i in this.voronoiContext.triangles) {
|
|
101
|
+
var t = this.voronoiContext.triangles[i];
|
|
102
|
+
VoronoiRenderer.drawTriangle(draw, t, this.voronoiContext.config.makeVoronoiDiagram ? "rgba(0,128,224,0.33)" : "#0088d8");
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Draw the given triangle with the specified (CSS-) color.
|
|
107
|
+
*
|
|
108
|
+
* @static
|
|
109
|
+
* @name drawTriangle
|
|
110
|
+
* @memberof VoronoiRenderer
|
|
111
|
+
* @param {DrawLib} draw
|
|
112
|
+
* @param {Triangle} tri
|
|
113
|
+
* @param {string} color
|
|
114
|
+
* @return {void}
|
|
115
|
+
*/
|
|
116
|
+
static drawTriangle(draw, tri, color) {
|
|
117
|
+
// draw.line(t.a, t.b, color);
|
|
118
|
+
// draw.line(t.b, t.c, color);
|
|
119
|
+
// draw.line(t.c, t.a, color);
|
|
120
|
+
draw.polyline([tri.a, tri.b, tri.c], false, color);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Draw the circumcircles of all triangles.
|
|
124
|
+
*/
|
|
125
|
+
static drawCircumCircles(draw, triangles) {
|
|
126
|
+
for (var t in triangles) {
|
|
127
|
+
var cc = triangles[t].getCircumcircle();
|
|
128
|
+
draw.circle(cc.center, cc.radius, "#e86800");
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Clip the convex (!) cell polygon by the convex (!) clipping polygon.
|
|
133
|
+
*
|
|
134
|
+
* @param cellPolygon
|
|
135
|
+
* @param clipBoxPolygon
|
|
136
|
+
* @returns
|
|
137
|
+
*/
|
|
138
|
+
static clipVoronoiPolygon(cellPolygon, clipBoxPolygon) {
|
|
139
|
+
return new Polygon(cloneVertexArray(sutherlandHodgman(cellPolygon.vertices, clipBoxPolygon.vertices)), false);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=VoronoiRenderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VoronoiRenderer.js","sourceRoot":"","sources":["../../../ts/utils/renderers/VoronoiRenderer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAGxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAkCvD,MAAM,OAAO,eAAe;IAG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AAC,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IACrD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,iBAAiB,CAAC,IAAkB,EAAE,SAA0B;QACrE,KAAK,IAAI,CAAC,IAAI,SAAS,EAAE,CAAC;YACxB,IAAI,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC;YACxC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,kBAAkB,CAAC,WAAoB,EAAE,cAAuB;QACrE,OAAO,IAAI,OAAO,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,WAAW,CAAC,QAAQ,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAChH,CAAC;CACF"}
|
package/src/ts/Polygon.ts
CHANGED
|
@@ -38,7 +38,9 @@
|
|
|
38
38
|
* @modified 2025-05-16 Class `Polygon` now implements `IBounded`.
|
|
39
39
|
* @modified 2025-05-20 Tweaking `Polygon.getInnerAngleAt` and `Polygo.isAngleAcute` to handle indices out of array bounds as well.
|
|
40
40
|
* @modified 2025-06-07 Adding `Polygon.closestLineIntersectionIndex` to determine line intersections plus detected edge index.
|
|
41
|
-
* @
|
|
41
|
+
* @modified 2026-09-16 Adding a `forceClockwise` parameter to the `Polygon.getCentroid()` method.
|
|
42
|
+
* @modified 2026-09-21 Adding `Polygon.revert` method to change the winding order.
|
|
43
|
+
* @version 1.17.0
|
|
42
44
|
*
|
|
43
45
|
* @file Polygon
|
|
44
46
|
* @public
|
|
@@ -400,6 +402,21 @@ export class Polygon implements IBounded, Intersectable, SVGSerializable {
|
|
|
400
402
|
return Polygon.utils.isClockwise(this.vertices);
|
|
401
403
|
}
|
|
402
404
|
|
|
405
|
+
/**
|
|
406
|
+
* Revert the order of this polygon's vertices to change the winding order.
|
|
407
|
+
* This operation is in-place.
|
|
408
|
+
*
|
|
409
|
+
* @method revert
|
|
410
|
+
* @instance
|
|
411
|
+
* @memberof Polygon
|
|
412
|
+
* @return {Polygon} This for chaining.
|
|
413
|
+
*/
|
|
414
|
+
revert(): Polygon {
|
|
415
|
+
// this.vertices.slice().reverse(); // Copy?
|
|
416
|
+
this.vertices.reverse();
|
|
417
|
+
return this;
|
|
418
|
+
}
|
|
419
|
+
|
|
403
420
|
/**
|
|
404
421
|
* Get the perimeter of this polygon.
|
|
405
422
|
* The perimeter is the absolute length of the outline.
|
|
@@ -483,35 +500,37 @@ export class Polygon implements IBounded, Intersectable, SVGSerializable {
|
|
|
483
500
|
|
|
484
501
|
/**
|
|
485
502
|
* Get centroid.
|
|
486
|
-
* Centroids define the barycenter of any non self-intersecting convex polygon.
|
|
503
|
+
* Centroids define the barycenter of any non self-intersecting convex clockwise polygon.
|
|
487
504
|
*
|
|
488
|
-
* If the polygon is self intersecting or non
|
|
505
|
+
* If the polygon is self intersecting or non convex or not clockwise then the barycenter is not well defined.
|
|
489
506
|
*
|
|
490
507
|
* https://mathworld.wolfram.com/PolygonCentroid.html
|
|
491
508
|
*
|
|
492
509
|
* @method getCentroid
|
|
493
510
|
* @instance
|
|
511
|
+
* @param {boolean} forceClockwise - [optiona] If set to true then the centroid will be calculated for the clockwise polygon.
|
|
494
512
|
* @memberof Polygon
|
|
495
513
|
* @returns {Vertex|null}
|
|
496
514
|
*/
|
|
497
|
-
getCentroid(): Vertex | null {
|
|
515
|
+
getCentroid(forceClockwise?: boolean): Vertex | null {
|
|
498
516
|
if (this.vertices.length === 0) {
|
|
499
517
|
return null;
|
|
500
518
|
}
|
|
501
|
-
const
|
|
502
|
-
const n = this.vertices.length;
|
|
503
|
-
for (var i = 0; i < n; i++) {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
}
|
|
511
|
-
const area = this.area();
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
return
|
|
519
|
+
// const centroid: Vertex = new Vertex(0.0, 0.0);
|
|
520
|
+
// const n = this.vertices.length;
|
|
521
|
+
// for (var i = 0; i < n; i++) {
|
|
522
|
+
// // center.add(this.vertices[i]);
|
|
523
|
+
// const cur: Vertex = this.vertices[i];
|
|
524
|
+
// const next: Vertex = this.vertices[(i + 1) % n];
|
|
525
|
+
// var factor: number = cur.x * next.y - next.x * cur.y;
|
|
526
|
+
// centroid.x += (cur.x + next.x) * factor;
|
|
527
|
+
// centroid.y += (cur.y + next.y) * factor;
|
|
528
|
+
// }
|
|
529
|
+
// const area = this.area();
|
|
530
|
+
// centroid.x *= 1 / (6 * area);
|
|
531
|
+
// centroid.y *= 1 / (6 * area);
|
|
532
|
+
// return centroid;
|
|
533
|
+
return Polygon.utils.calculateCentroid(this.vertices, forceClockwise);
|
|
515
534
|
}
|
|
516
535
|
|
|
517
536
|
//--- BEGIN --- Implement interface `Intersectable`
|
|
@@ -972,6 +991,27 @@ export class Polygon implements IBounded, Intersectable, SVGSerializable {
|
|
|
972
991
|
return Polygon.utils.signedArea(vertices) < 0;
|
|
973
992
|
},
|
|
974
993
|
|
|
994
|
+
calculateCentroid(vertices: XYCoords[], forceClockwise?: boolean): Vertex {
|
|
995
|
+
const centroid: Vertex = new Vertex(0.0, 0.0);
|
|
996
|
+
const n = vertices.length;
|
|
997
|
+
if (forceClockwise && !Polygon.utils.isClockwise(vertices)) {
|
|
998
|
+
return Polygon.utils.calculateCentroid(vertices.slice().reverse());
|
|
999
|
+
}
|
|
1000
|
+
for (var i = 0; i < n; i++) {
|
|
1001
|
+
// center.add(this.vertices[i]);
|
|
1002
|
+
const cur: XYCoords = vertices[i];
|
|
1003
|
+
const next: XYCoords = vertices[(i + 1) % n];
|
|
1004
|
+
var factor: number = cur.x * next.y - next.x * cur.y;
|
|
1005
|
+
centroid.x += (cur.x + next.x) * factor;
|
|
1006
|
+
centroid.y += (cur.y + next.y) * factor;
|
|
1007
|
+
}
|
|
1008
|
+
// const area = this.area();
|
|
1009
|
+
const area = Polygon.utils.area(vertices);
|
|
1010
|
+
centroid.x *= 1 / (6 * area);
|
|
1011
|
+
centroid.y *= 1 / (6 * area);
|
|
1012
|
+
return centroid;
|
|
1013
|
+
},
|
|
1014
|
+
|
|
975
1015
|
/**
|
|
976
1016
|
* Calulate the signed polyon area by interpreting the polygon as a matrix
|
|
977
1017
|
* and calculating its determinant.
|
package/src/ts/VertTuple.ts
CHANGED
|
@@ -17,8 +17,9 @@
|
|
|
17
17
|
* @modified 2025-04-15 Changed param of `VertTuple.moveTo` method from `Vertex` to `XYCoords`.
|
|
18
18
|
* @modified 2025-04-15 Added method `VertTuple.move` method.
|
|
19
19
|
* @modified 2026-06-10 Adding helper function `VertTuple.utils.calcCircumcircle`.
|
|
20
|
-
* @modified 2026-06-17 Adding method `VertTuple.asLine` for converting
|
|
21
|
-
* @
|
|
20
|
+
* @modified 2026-06-17 Adding method `VertTuple.asLine` for converting TertTuples to Line instances.
|
|
21
|
+
* @modified 2026-09-21 Adding method `VertTuple.asVector` for converting TertTuples to Vector instances.
|
|
22
|
+
* @version 1.7.0
|
|
22
23
|
*/
|
|
23
24
|
|
|
24
25
|
import { Vertex } from "./Vertex";
|
|
@@ -26,6 +27,7 @@ import { UIDGenerator } from "./UIDGenerator";
|
|
|
26
27
|
import { XYCoords, UID } from "./interfaces";
|
|
27
28
|
import { ICircle } from "./Circle";
|
|
28
29
|
import { Line } from "./Line";
|
|
30
|
+
import { Vector } from "./Vector";
|
|
29
31
|
|
|
30
32
|
/**
|
|
31
33
|
* @classdesc An abstract base classes for vertex tuple constructs, like Lines or Vectors.
|
|
@@ -372,10 +374,10 @@ export class VertTuple<T extends VertTuple<T>> {
|
|
|
372
374
|
}
|
|
373
375
|
|
|
374
376
|
/**
|
|
375
|
-
* Converts this `
|
|
377
|
+
* Converts this `VertTuple` to a `Line` (segment).
|
|
376
378
|
*
|
|
377
379
|
* @method asLine
|
|
378
|
-
* @return {
|
|
380
|
+
* @return {Line} This tuple as `Line` instance.
|
|
379
381
|
* @instance
|
|
380
382
|
* @memberof VertTuple
|
|
381
383
|
**/
|
|
@@ -383,6 +385,18 @@ export class VertTuple<T extends VertTuple<T>> {
|
|
|
383
385
|
return new Line(this.a, this.b);
|
|
384
386
|
}
|
|
385
387
|
|
|
388
|
+
/**
|
|
389
|
+
* Converts this `VertTuple` to a `Vector` (arrow).
|
|
390
|
+
*
|
|
391
|
+
* @method asVector
|
|
392
|
+
* @return {Line} This tuple as `Vector` instance.
|
|
393
|
+
* @instance
|
|
394
|
+
* @memberof VertTuple
|
|
395
|
+
**/
|
|
396
|
+
asVector(): Vector {
|
|
397
|
+
return new Vector(this.a, this.b);
|
|
398
|
+
}
|
|
399
|
+
|
|
386
400
|
/**
|
|
387
401
|
* Create a string representation of this line.
|
|
388
402
|
*
|
package/src/ts/Vertex.ts
CHANGED
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
* @modified 2025-04-13 Adding the `Vertex.move(amount: XYCoords)` method (does the same as `add`, added by naming convention).
|
|
38
38
|
* @modified 2025-05-07 Class `Vertex` is now implementing interface `IBounded` (to meet convention).
|
|
39
39
|
* @modified 2026-06-10 Adding methods `Vertex.findClosestPoint` and `Vertex.findFarestPoint`.
|
|
40
|
-
* @version 2.12.
|
|
40
|
+
* @version 2.12.1
|
|
41
41
|
*
|
|
42
42
|
* @file Vertex
|
|
43
43
|
* @public
|
|
@@ -569,7 +569,7 @@ export class Vertex implements IBounded, XYCoords, SVGSerializable {
|
|
|
569
569
|
* around given center.
|
|
570
570
|
*
|
|
571
571
|
* @method rotate
|
|
572
|
-
* @param {number} angle - The angle to 'rotate' this vertex; 0.0 means no change.
|
|
572
|
+
* @param {number} angle - The angle in radians to 'rotate' this vertex; 0.0 means no change.
|
|
573
573
|
* @param {XYCoords=} center - The center of rotation; default is (0,0).
|
|
574
574
|
* @return {Vertex} this
|
|
575
575
|
* @instance
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An experimental top class to wrap demo environments.
|
|
3
|
+
*
|
|
4
|
+
* @date 2026-04-13
|
|
5
|
+
* @modified 2026-09-15 Ported to Typescript.
|
|
6
|
+
* @author Ikaros Kappler
|
|
7
|
+
* @version 1.0.0
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import PlotBoilerplate from "../PlotBoilerplate";
|
|
11
|
+
|
|
12
|
+
export class AppContext<GlobalVars = Record<string, any>> {
|
|
13
|
+
pb: PlotBoilerplate;
|
|
14
|
+
config: any;
|
|
15
|
+
|
|
16
|
+
globals: Record<keyof GlobalVars, GlobalVars[keyof GlobalVars]>;
|
|
17
|
+
|
|
18
|
+
constructor(pb, config) {
|
|
19
|
+
this.pb = pb;
|
|
20
|
+
this.config = config;
|
|
21
|
+
}
|
|
22
|
+
}
|