plotboilerplate 1.29.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 +310 -57
- 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 +266 -36
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +1 -1
- package/src/cjs/Circle.d.ts +17 -1
- package/src/cjs/Circle.js +21 -1
- package/src/cjs/Circle.js.map +1 -1
- package/src/cjs/CubicBezierCurve.d.ts +34 -3
- package/src/cjs/CubicBezierCurve.js +79 -12
- package/src/cjs/CubicBezierCurve.js.map +1 -1
- package/src/cjs/Line.d.ts +46 -1
- package/src/cjs/Line.js +80 -1
- package/src/cjs/Line.js.map +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 +24 -2
- package/src/cjs/VertTuple.js +28 -2
- 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/Circle.d.ts +17 -1
- package/src/esm/Circle.js +21 -1
- package/src/esm/Circle.js.map +1 -1
- package/src/esm/CubicBezierCurve.d.ts +34 -3
- package/src/esm/CubicBezierCurve.js +79 -12
- package/src/esm/CubicBezierCurve.js.map +1 -1
- package/src/esm/Line.d.ts +46 -1
- package/src/esm/Line.js +80 -1
- package/src/esm/Line.js.map +1 -1
- 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 +24 -2
- package/src/esm/VertTuple.js +28 -2
- 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/index-gl.js +1 -2
- package/src/ts/Circle.ts +23 -1
- package/src/ts/CubicBezierCurve.ts +133 -48
- package/src/ts/Line.ts +84 -1
- package/src/ts/Polygon.ts +58 -18
- package/src/ts/VertTuple.ts +30 -2
- 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,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A mutable point set datastructure for holding a finite but variable set of vertices.
|
|
3
|
+
*
|
|
4
|
+
* @date 2026-09-12
|
|
5
|
+
* @author Ikaros Kappler
|
|
6
|
+
* @version 1.0.0
|
|
7
|
+
*/
|
|
8
|
+
export class PointSet {
|
|
9
|
+
constructor(pb) {
|
|
10
|
+
this.dragListeners = [];
|
|
11
|
+
this.pb = pb;
|
|
12
|
+
this.points = [];
|
|
13
|
+
}
|
|
14
|
+
fireDragEvent() {
|
|
15
|
+
this.dragListeners.forEach(listener => {
|
|
16
|
+
listener();
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Adds a random point to the point list.
|
|
21
|
+
*
|
|
22
|
+
* @name addRandomPoint
|
|
23
|
+
* @instance
|
|
24
|
+
* @override
|
|
25
|
+
* @memberof PointSet
|
|
26
|
+
* @return {void}
|
|
27
|
+
*/
|
|
28
|
+
addRandomPoint(horizontalSafeArea = 0, verticalSafeArea = 0) {
|
|
29
|
+
// this.addVertex(Vertex.randomVertex(this.pb.viewport()).scale(0.5));
|
|
30
|
+
this.addVertex(this.pb.viewport().randomPoint(horizontalSafeArea, verticalSafeArea));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Adds the given point/vertex to the point list.
|
|
34
|
+
*
|
|
35
|
+
* @name addVertex
|
|
36
|
+
* @instance
|
|
37
|
+
* @override
|
|
38
|
+
* @memberof PointSet
|
|
39
|
+
* @param {Vertex} vert - The vertex to add.
|
|
40
|
+
* @return {void}
|
|
41
|
+
*/
|
|
42
|
+
addVertex(vert) {
|
|
43
|
+
this.points.push(vert);
|
|
44
|
+
this.pb.add(vert, false); // redraw=false
|
|
45
|
+
var _self = this;
|
|
46
|
+
vert.listeners.addDragListener(function () {
|
|
47
|
+
_self.fireDragEvent();
|
|
48
|
+
});
|
|
49
|
+
// vert.listeners.addDragListener(_self.fireDragEvent);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Remove all vertices from this set and from the plotboilerplate instance.
|
|
53
|
+
*
|
|
54
|
+
* @name clear
|
|
55
|
+
* @instance
|
|
56
|
+
* @override
|
|
57
|
+
* @memberof PointSet
|
|
58
|
+
* @return {void}
|
|
59
|
+
*/
|
|
60
|
+
clear() {
|
|
61
|
+
for (var i = 0; i < this.points.length; i++) {
|
|
62
|
+
this.pb.remove(this.points[i], false);
|
|
63
|
+
// TODO: How to remove drag listener?
|
|
64
|
+
// this.points[i].listeners.removeDragListener(this.fireDragEvent);
|
|
65
|
+
}
|
|
66
|
+
this.points = [];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Add or remove n random points; depends on the config settings.
|
|
70
|
+
*
|
|
71
|
+
* I have no idea how tired I was when I wrote this function but it seems working pretty well.
|
|
72
|
+
*/
|
|
73
|
+
randomPoints(pointCount, horizontalSafeArea = 0, verticalSafeArea = 0) {
|
|
74
|
+
// Generate random points.
|
|
75
|
+
for (var i = this.points.length; i < pointCount; i++) {
|
|
76
|
+
this.addRandomPoint(horizontalSafeArea, verticalSafeArea);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Add random points and be sure they cover the whole viewport.
|
|
81
|
+
*
|
|
82
|
+
* I have no idea how tired I was when I wrote this function but it seems working pretty well.
|
|
83
|
+
*/
|
|
84
|
+
randomFullCover(pointCount) {
|
|
85
|
+
this.clear();
|
|
86
|
+
this.randomPoints(pointCount - 4, 0.0, 0.0); //, true, true);
|
|
87
|
+
// Add 4 more points in the corners.
|
|
88
|
+
var viewport = this.pb.viewport();
|
|
89
|
+
this.addVertex(viewport.getNorthWestPoint());
|
|
90
|
+
this.addVertex(viewport.getNorthEastPoint());
|
|
91
|
+
this.addVertex(viewport.getSouthWestPoint());
|
|
92
|
+
this.addVertex(viewport.getSouthEastPoint());
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Call when the desired number of points changes.
|
|
96
|
+
**/
|
|
97
|
+
updatePointCount(newPointCount, horizontalSafeArea = 0, verticalSafeArea = 0) {
|
|
98
|
+
if (newPointCount > this.points.length) {
|
|
99
|
+
this.randomPoints(newPointCount, horizontalSafeArea, verticalSafeArea);
|
|
100
|
+
}
|
|
101
|
+
// Do not clear ; no full cover ; do rebuild
|
|
102
|
+
else if (newPointCount < this.points.length) {
|
|
103
|
+
// Remove n-m points
|
|
104
|
+
for (var i = newPointCount; i < this.points.length; i++) {
|
|
105
|
+
this.pb.remove(this.points[i]);
|
|
106
|
+
}
|
|
107
|
+
// TODO: MOVE THIS TO THE PointSet class.
|
|
108
|
+
this.points = this.points.slice(0, newPointCount);
|
|
109
|
+
// TODO: also remove listeners?
|
|
110
|
+
// updateAnimator();
|
|
111
|
+
// rebuild();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=PointSet.js.map
|
|
@@ -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;IACH,cAAc,CAAC,qBAA6B,CAAC,EAAE,mBAA2B,CAAC;QACzE,sEA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020-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,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,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,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;IAG1B,YAAY,cAA+B;QACzC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;I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AAE,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/index-gl.js
CHANGED
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
// Fetch the GET params
|
|
17
17
|
let GUP = gup();
|
|
18
18
|
var isDarkmode = detectDarkMode(GUP);
|
|
19
|
-
var isDarkmode = detectDarkMode(GUP);
|
|
20
19
|
|
|
21
20
|
window.addEventListener("load", function () {
|
|
22
21
|
// All config params are optional.
|
|
@@ -91,7 +90,7 @@
|
|
|
91
90
|
});
|
|
92
91
|
|
|
93
92
|
// Use a helper function to build all demo-drawables.
|
|
94
|
-
var drawables = createDemoDrawables(pb
|
|
93
|
+
var drawables = createDemoDrawables(pb, "example-image.png", function () {
|
|
95
94
|
pb.redraw();
|
|
96
95
|
});
|
|
97
96
|
pb.add(drawables);
|
package/src/ts/Circle.ts
CHANGED
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
* @modified 2026-07-08 Adding the `Circle.setRadius` method (for chaining).
|
|
23
23
|
* @mofified 2026-07-31 Adding the `radicalAxis(Circle)` method. Added the `Circle.circleUtils.createRadicalAxisHelperCircle` and `.circleDistance` helper methods.
|
|
24
24
|
* @modified 2026-08-03 Adding `Circle.tangentsFromPoint`.
|
|
25
|
-
* @
|
|
25
|
+
* @modified 2026-08-16 Adding the `Circle.sectorAngleByArcLength` method and the `Circle.circleUtils.sectorAngleByArcLength` helper method.
|
|
26
|
+
* @version 1.8.0
|
|
26
27
|
**/
|
|
27
28
|
|
|
28
29
|
import { Bounds } from "./Bounds";
|
|
@@ -474,6 +475,16 @@ export class Circle implements IBounded, ICircle, Intersectable, SVGSerializable
|
|
|
474
475
|
return [new Vector(intersection.a, vert), new Vector(intersection.b, vert)];
|
|
475
476
|
}
|
|
476
477
|
|
|
478
|
+
/**
|
|
479
|
+
* Calculate inner sector angle for this circle and a given circle arc length.
|
|
480
|
+
*
|
|
481
|
+
* @param {number} sectorArcLength - The desired arc length (in units).
|
|
482
|
+
* @returns The sector's inner angle (in radians).
|
|
483
|
+
*/
|
|
484
|
+
sectorAngleByArcLength(sectorArcLength: number) {
|
|
485
|
+
return Circle.circleUtils.sectorAngleByArcLength(sectorArcLength, this.radius);
|
|
486
|
+
}
|
|
487
|
+
|
|
477
488
|
/**
|
|
478
489
|
* Create a deep copy of this circle.
|
|
479
490
|
*
|
|
@@ -558,6 +569,17 @@ export class Circle implements IBounded, ICircle, Intersectable, SVGSerializable
|
|
|
558
569
|
*/
|
|
559
570
|
circleDistance: (circleA: Circle, circleB: Circle): number => {
|
|
560
571
|
return circleA.center.distance(circleB.center) - circleA.radius - circleB.radius;
|
|
572
|
+
},
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* Calculate the inner sector angle for a given circle arc length and radius.
|
|
576
|
+
*
|
|
577
|
+
* @param {number} sectorArcLength - The desired arc length.
|
|
578
|
+
* @param {number} circleRadius - The circle's radius.
|
|
579
|
+
* @returns The sector angle in radians.
|
|
580
|
+
*/
|
|
581
|
+
sectorAngleByArcLength: (sectorArcLength: number, circleRadius: number) => {
|
|
582
|
+
return sectorArcLength / circleRadius;
|
|
561
583
|
}
|
|
562
584
|
};
|
|
563
585
|
} // END class
|