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,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* A mutable point set datastructure for holding a finite but variable set of vertices.
|
|
4
|
+
*
|
|
5
|
+
* @date 2026-09-12
|
|
6
|
+
* @author Ikaros Kappler
|
|
7
|
+
* @version 1.0.0
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.PointSet = void 0;
|
|
11
|
+
var PointSet = /** @class */ (function () {
|
|
12
|
+
function PointSet(pb) {
|
|
13
|
+
this.dragListeners = [];
|
|
14
|
+
this.pb = pb;
|
|
15
|
+
this.points = [];
|
|
16
|
+
}
|
|
17
|
+
PointSet.prototype.fireDragEvent = function () {
|
|
18
|
+
this.dragListeners.forEach(function (listener) {
|
|
19
|
+
listener();
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Adds a random point to the point list.
|
|
24
|
+
*
|
|
25
|
+
* @name addRandomPoint
|
|
26
|
+
* @instance
|
|
27
|
+
* @override
|
|
28
|
+
* @memberof PointSet
|
|
29
|
+
* @return {void}
|
|
30
|
+
*/
|
|
31
|
+
PointSet.prototype.addRandomPoint = function (horizontalSafeArea, verticalSafeArea) {
|
|
32
|
+
if (horizontalSafeArea === void 0) { horizontalSafeArea = 0; }
|
|
33
|
+
if (verticalSafeArea === void 0) { verticalSafeArea = 0; }
|
|
34
|
+
// this.addVertex(Vertex.randomVertex(this.pb.viewport()).scale(0.5));
|
|
35
|
+
this.addVertex(this.pb.viewport().randomPoint(horizontalSafeArea, verticalSafeArea));
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Adds the given point/vertex to the point list.
|
|
39
|
+
*
|
|
40
|
+
* @name addVertex
|
|
41
|
+
* @instance
|
|
42
|
+
* @override
|
|
43
|
+
* @memberof PointSet
|
|
44
|
+
* @param {Vertex} vert - The vertex to add.
|
|
45
|
+
* @return {void}
|
|
46
|
+
*/
|
|
47
|
+
PointSet.prototype.addVertex = function (vert) {
|
|
48
|
+
this.points.push(vert);
|
|
49
|
+
this.pb.add(vert, false); // redraw=false
|
|
50
|
+
var _self = this;
|
|
51
|
+
vert.listeners.addDragListener(function () {
|
|
52
|
+
_self.fireDragEvent();
|
|
53
|
+
});
|
|
54
|
+
// vert.listeners.addDragListener(_self.fireDragEvent);
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Remove all vertices from this set and from the plotboilerplate instance.
|
|
58
|
+
*
|
|
59
|
+
* @name clear
|
|
60
|
+
* @instance
|
|
61
|
+
* @override
|
|
62
|
+
* @memberof PointSet
|
|
63
|
+
* @return {void}
|
|
64
|
+
*/
|
|
65
|
+
PointSet.prototype.clear = function () {
|
|
66
|
+
for (var i = 0; i < this.points.length; i++) {
|
|
67
|
+
this.pb.remove(this.points[i], false);
|
|
68
|
+
// TODO: How to remove drag listener?
|
|
69
|
+
// this.points[i].listeners.removeDragListener(this.fireDragEvent);
|
|
70
|
+
}
|
|
71
|
+
this.points = [];
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Add or remove n random points; depends on the config settings.
|
|
75
|
+
*
|
|
76
|
+
* I have no idea how tired I was when I wrote this function but it seems working pretty well.
|
|
77
|
+
*/
|
|
78
|
+
PointSet.prototype.randomPoints = function (pointCount, horizontalSafeArea, verticalSafeArea) {
|
|
79
|
+
if (horizontalSafeArea === void 0) { horizontalSafeArea = 0; }
|
|
80
|
+
if (verticalSafeArea === void 0) { verticalSafeArea = 0; }
|
|
81
|
+
// Generate random points.
|
|
82
|
+
for (var i = this.points.length; i < pointCount; i++) {
|
|
83
|
+
this.addRandomPoint(horizontalSafeArea, verticalSafeArea);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Add random points and be sure they cover the whole viewport.
|
|
88
|
+
*
|
|
89
|
+
* I have no idea how tired I was when I wrote this function but it seems working pretty well.
|
|
90
|
+
*/
|
|
91
|
+
PointSet.prototype.randomFullCover = function (pointCount) {
|
|
92
|
+
this.clear();
|
|
93
|
+
this.randomPoints(pointCount - 4, 0.0, 0.0); //, true, true);
|
|
94
|
+
// Add 4 more points in the corners.
|
|
95
|
+
var viewport = this.pb.viewport();
|
|
96
|
+
this.addVertex(viewport.getNorthWestPoint());
|
|
97
|
+
this.addVertex(viewport.getNorthEastPoint());
|
|
98
|
+
this.addVertex(viewport.getSouthWestPoint());
|
|
99
|
+
this.addVertex(viewport.getSouthEastPoint());
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Call when the desired number of points changes.
|
|
103
|
+
**/
|
|
104
|
+
PointSet.prototype.updatePointCount = function (newPointCount, horizontalSafeArea, verticalSafeArea) {
|
|
105
|
+
if (horizontalSafeArea === void 0) { horizontalSafeArea = 0; }
|
|
106
|
+
if (verticalSafeArea === void 0) { verticalSafeArea = 0; }
|
|
107
|
+
if (newPointCount > this.points.length) {
|
|
108
|
+
this.randomPoints(newPointCount, horizontalSafeArea, verticalSafeArea);
|
|
109
|
+
}
|
|
110
|
+
// Do not clear ; no full cover ; do rebuild
|
|
111
|
+
else if (newPointCount < this.points.length) {
|
|
112
|
+
// Remove n-m points
|
|
113
|
+
for (var i = newPointCount; i < this.points.length; i++) {
|
|
114
|
+
this.pb.remove(this.points[i]);
|
|
115
|
+
}
|
|
116
|
+
// TODO: MOVE THIS TO THE PointSet class.
|
|
117
|
+
this.points = this.points.slice(0, newPointCount);
|
|
118
|
+
// TODO: also remove listeners?
|
|
119
|
+
// updateAnimator();
|
|
120
|
+
// rebuild();
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
return PointSet;
|
|
124
|
+
}());
|
|
125
|
+
exports.PointSet = PointSet;
|
|
126
|
+
//# 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;IAKE,kBAAY,EAAmB;QAFtB,kBAAa,GAAoB,EAAE,CAAC;QAG3C,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IACnB,CAAC;IAEO,gCAAa,GAArB;QACE,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,UAAA,QAAQ;YACjC,QAAQ,EAAE,CAAC;QACb,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;OAQG;IACH,iCAAc,GAAd,UAAe,kBAA8B,EAAE,gBAA4B;QAA5D,mCAAA,EAAA,sBAA8B;QAAE,iCAAA,EAAA,oBAA4B;QACzE,sEAAsE;QACtE,IAAI,CAAC,SAAS,CAAC,IA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B;YACtB,eAAe;QACjB,CAAC;IACH,CAAC;IAQH,eAAC;AAAD,CAAC,AA3HD,IA2HC;AA3HY,4BAAQ"}
|
|
@@ -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
|
*
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
* @modified 2020-08-12 Ported this class from vanilla JS to TypeScript.
|
|
18
18
|
* @modified 2020-08-17 Added some missing type declarations.
|
|
19
19
|
* @modified 2021-01-20 Members `triangles` and `sharedVertex` are now public.
|
|
20
|
-
* @
|
|
20
|
+
* @modified 2026-09-15 Added the `VoronoiCell.sharedVertexIndex` attribute.
|
|
21
|
+
* @version 1.2.0
|
|
21
22
|
*
|
|
22
23
|
* @file VoronoiCell
|
|
23
24
|
* @public
|
|
@@ -26,6 +27,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
27
|
exports.VoronoiCell = void 0;
|
|
27
28
|
var Line_1 = require("../../Line");
|
|
28
29
|
var Polygon_1 = require("../../Polygon");
|
|
30
|
+
var Triangle_1 = require("../../Triangle");
|
|
29
31
|
var Vertex_1 = require("../../Vertex");
|
|
30
32
|
var VoronoiCell = /** @class */ (function () {
|
|
31
33
|
/**
|
|
@@ -38,15 +40,15 @@ var VoronoiCell = /** @class */ (function () {
|
|
|
38
40
|
* @param {Vertex} sharedVertex This is the 'center' of the voronoi cell; all triangles must share
|
|
39
41
|
* that vertex.
|
|
40
42
|
**/
|
|
41
|
-
function VoronoiCell(triangles, sharedVertex) {
|
|
42
|
-
if (typeof triangles ===
|
|
43
|
+
function VoronoiCell(triangles, sharedVertex, sharedVertexIndex) {
|
|
44
|
+
if (typeof triangles === "undefined")
|
|
43
45
|
triangles = [];
|
|
44
|
-
if (typeof sharedVertex ===
|
|
46
|
+
if (typeof sharedVertex === "undefined")
|
|
45
47
|
sharedVertex = new Vertex_1.Vertex(0, 0);
|
|
46
48
|
this.triangles = triangles;
|
|
47
49
|
this.sharedVertex = sharedVertex;
|
|
50
|
+
this.sharedVertexIndex = sharedVertexIndex;
|
|
48
51
|
}
|
|
49
|
-
;
|
|
50
52
|
/**
|
|
51
53
|
* Check if the first and the last triangle in the path are NOT connected.
|
|
52
54
|
*
|
|
@@ -59,7 +61,6 @@ var VoronoiCell = /** @class */ (function () {
|
|
|
59
61
|
// There must be at least three triangles
|
|
60
62
|
return this.triangles.length < 3 || !this.triangles[0].isAdjacent(this.triangles[this.triangles.length - 1]);
|
|
61
63
|
};
|
|
62
|
-
;
|
|
63
64
|
/**
|
|
64
65
|
* Convert this Voronoi cell to a path polygon, consisting of all Voronoi cell corner points.
|
|
65
66
|
*
|
|
@@ -74,7 +75,32 @@ var VoronoiCell = /** @class */ (function () {
|
|
|
74
75
|
VoronoiCell.prototype.toPolygon = function () {
|
|
75
76
|
return new Polygon_1.Polygon(this.toPathArray(), this.isOpen());
|
|
76
77
|
};
|
|
77
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Get all 'umbrella' triangles for this Voronoi cell.
|
|
80
|
+
*
|
|
81
|
+
* The 'umbrella' is that sequence of triangles that covers the whole Voronoi cell and
|
|
82
|
+
* meet in the cell's centroid.
|
|
83
|
+
*
|
|
84
|
+
* @method getUmbrellaTriangles
|
|
85
|
+
* @instance
|
|
86
|
+
* @memberof VoronoiCell
|
|
87
|
+
* @return {Array<Triangle>}
|
|
88
|
+
**/
|
|
89
|
+
VoronoiCell.prototype.getUmbrellaTriangles = function () {
|
|
90
|
+
var tris = [];
|
|
91
|
+
// for (var i = 0; i < this.triangles.length; i++) {
|
|
92
|
+
// var delaunayTri = this.triangles[i];
|
|
93
|
+
// var tri = new Triangle(this.sharedVertex, delaunayTri.b, delaunayTri.c);
|
|
94
|
+
// tris.push(tri);
|
|
95
|
+
// }
|
|
96
|
+
var vertices = this.toPathArray();
|
|
97
|
+
var n = vertices.length;
|
|
98
|
+
for (var i = 0; i < n; i++) {
|
|
99
|
+
var tri = new Triangle_1.Triangle(this.sharedVertex, vertices[i], vertices[(i + 1) % n]);
|
|
100
|
+
tris.push(tri);
|
|
101
|
+
}
|
|
102
|
+
return tris;
|
|
103
|
+
};
|
|
78
104
|
/**
|
|
79
105
|
* Convert the voronoi cell path data to an SVG polygon data string.
|
|
80
106
|
*
|
|
@@ -89,9 +115,12 @@ var VoronoiCell = /** @class */ (function () {
|
|
|
89
115
|
if (this.triangles.length == 0)
|
|
90
116
|
return "";
|
|
91
117
|
var arr = this.toPathArray();
|
|
92
|
-
return arr
|
|
118
|
+
return arr
|
|
119
|
+
.map(function (vert) {
|
|
120
|
+
return "" + vert.x + "," + vert.y;
|
|
121
|
+
})
|
|
122
|
+
.join(" ");
|
|
93
123
|
};
|
|
94
|
-
;
|
|
95
124
|
/**
|
|
96
125
|
* Convert the voronoi cell path data to an array.
|
|
97
126
|
*
|
|
@@ -146,7 +175,6 @@ var VoronoiCell = /** @class */ (function () {
|
|
|
146
175
|
var openEdgePoint = new Vertex_1.Vertex(perpendicular.x + (center.x - perpendicular.x) * 1000, perpendicular.y + (center.y - perpendicular.y) * 1000);
|
|
147
176
|
return openEdgePoint;
|
|
148
177
|
};
|
|
149
|
-
;
|
|
150
178
|
/**
|
|
151
179
|
* A helper function.
|
|
152
180
|
*
|
|
@@ -170,13 +198,12 @@ var VoronoiCell = /** @class */ (function () {
|
|
|
170
198
|
return tri.a;
|
|
171
199
|
}
|
|
172
200
|
// Here:
|
|
173
|
-
// tri.c.equals(sharedVertex)
|
|
201
|
+
// tri.c.equals(sharedVertex)
|
|
174
202
|
if (neighbour.a.equals(tri.a) || neighbour.b.equals(tri.a) || neighbour.c.equals(tri.a))
|
|
175
203
|
return tri.b;
|
|
176
204
|
else
|
|
177
205
|
return tri.a;
|
|
178
206
|
};
|
|
179
|
-
;
|
|
180
207
|
return VoronoiCell;
|
|
181
208
|
}());
|
|
182
209
|
exports.VoronoiCell = VoronoiCell;
|
|
@@ -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,mCAAkC;AAClC,yCAAwC;AACxC,2CAA0C;AAC1C,uCAAsC;AAEtC;IAsBE;;;;;;;;;QASI;IACJ,qBAAY,SAA0B,EAAE,YAAoB,EAAE,iBAAyB;QACrF,IAAI,OAAO,SAAS,KAAK,WAAW;YAAE,SAAS,GAAG,EAAE,CAAC;QACrD,IAAI,OAAO,YAAY,KAAK,WAAW;YAAE,YAAY,GAAG,IAAI,eAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACzE,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC7C,CAAC;IAED;;;;;;;QAOI;IACJ,4BAAM,GAAN;QACE,yCAAyC;QACzC,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IAC/G,CAAC;IAED;;;;;;;;;;QAUI;IACJ,+BAAS,GAAT;QACE,OAAO,IAAI,iBAAO,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACxD,CAAC;IAED;;;;;;;;;;QAUI;IACJ,0CAAoB,GAApB;QACE,IAAI,IAAI,GAAoB,EAAE,CAAC;QAC/B,oDAAoD;QACpD,yCAAy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
|
|
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,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Refactored all Voronoi helper functions for drawing the diagram (demo 07) into this class.
|
|
4
|
+
*
|
|
5
|
+
* @author Ikaros Kappler
|
|
6
|
+
* @date 2026-09-13
|
|
7
|
+
* @modified 2026-09-15 Ported to Typescript.
|
|
8
|
+
* @version 1.0.1
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.VoronoiRenderer = void 0;
|
|
12
|
+
var Bounds_1 = require("../../Bounds");
|
|
13
|
+
var Polygon_1 = require("../../Polygon");
|
|
14
|
+
var convexPolygonIncircle_1 = require("../algorithms/convexPolygonIncircle");
|
|
15
|
+
var sutherlandHodgman_1 = require("../algorithms/sutherlandHodgman");
|
|
16
|
+
var cloneVertexArray_1 = require("../cloneVertexArray");
|
|
17
|
+
var VoronoiRenderer = /** @class */ (function () {
|
|
18
|
+
function VoronoiRenderer(voronoiContext) {
|
|
19
|
+
this.voronoiContext = voronoiContext;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Draw the given triangle with the specified (CSS-) color.
|
|
23
|
+
*
|
|
24
|
+
* @name draw
|
|
25
|
+
* @instance
|
|
26
|
+
* @memberof VoronoiRenderer
|
|
27
|
+
* @param {DrawLib} draw
|
|
28
|
+
* @param {Triangle} t
|
|
29
|
+
* @param {string} color
|
|
30
|
+
* @return {void}
|
|
31
|
+
*/
|
|
32
|
+
VoronoiRenderer.prototype.draw = function (draw, fill) {
|
|
33
|
+
// Draw circumcircles
|
|
34
|
+
if (this.voronoiContext.config.drawCircumCircles) {
|
|
35
|
+
VoronoiRenderer.drawCircumCircles(draw, this.voronoiContext.triangles);
|
|
36
|
+
}
|
|
37
|
+
// An array of VoronoiCells.
|
|
38
|
+
var clipBoxPolygon = Bounds_1.Bounds.computeFromVertices(this.voronoiContext.pointSet.points).toPolygon();
|
|
39
|
+
if (this.voronoiContext.config.drawClipBox) {
|
|
40
|
+
draw.polygon(clipBoxPolygon, "rgba(192,192,192,0.25)");
|
|
41
|
+
}
|
|
42
|
+
for (var v in this.voronoiContext.voronoiCells) {
|
|
43
|
+
var cell = this.voronoiContext.voronoiCells[v];
|
|
44
|
+
this._drawCell(draw, fill, clipBoxPolygon, cell);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Draw the given triangle with the specified (CSS-) color.
|
|
49
|
+
*
|
|
50
|
+
* @name _drawCell
|
|
51
|
+
* @instance
|
|
52
|
+
* @private
|
|
53
|
+
* @memberof VoronoiRenderer
|
|
54
|
+
* @param {DrawLib} draw
|
|
55
|
+
* @param {Polygon} clipBoxPolygon
|
|
56
|
+
* @param {VoronoiCell} cell
|
|
57
|
+
* @return {void}
|
|
58
|
+
*/
|
|
59
|
+
VoronoiRenderer.prototype._drawCell = function (draw, fill, clipBoxPolygon, cell) {
|
|
60
|
+
var _a, _b;
|
|
61
|
+
var cellPolygon = cell.toPolygon();
|
|
62
|
+
cellPolygon.scale(this.voronoiContext.config.voronoiCellScale, cell.sharedVertex);
|
|
63
|
+
// Draw large (unclipped) Voronoi cell
|
|
64
|
+
if (this.voronoiContext.config.drawVoronoiOutlines &&
|
|
65
|
+
(!this.voronoiContext.config.clipVoronoiCells || this.voronoiContext.config.drawUnclippedVoronoiCells)) {
|
|
66
|
+
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);
|
|
67
|
+
}
|
|
68
|
+
// Apply clipping?
|
|
69
|
+
if (this.voronoiContext.config.clipVoronoiCells) {
|
|
70
|
+
// Clone the array here: convert Array<XYCoords> to Array<Vertex>
|
|
71
|
+
// polygon = new Polygon(cloneVertexArray(sutherlandHodgman(polygon.vertices, clipBoxPolygon.vertices)), false);
|
|
72
|
+
cellPolygon = VoronoiRenderer.clipVoronoiPolygon(cellPolygon, clipBoxPolygon);
|
|
73
|
+
}
|
|
74
|
+
if (this.voronoiContext.config.drawVoronoiOutlines && this.voronoiContext.config.clipVoronoiCells) {
|
|
75
|
+
draw.polygon(cellPolygon, this.voronoiContext.config.voronoiOutlineColor, (_b = this.voronoiContext.config.voronoiCellLineWidth) !== null && _b !== void 0 ? _b : 2.0);
|
|
76
|
+
}
|
|
77
|
+
if ((!cell.isOpen() || this.voronoiContext.config.clipVoronoiCells) && cell.triangles.length >= 3) {
|
|
78
|
+
if (this.voronoiContext.config.drawCubicCurves) {
|
|
79
|
+
var cbezier = cellPolygon.toCubicBezierData(this.voronoiContext.config.voronoiCubicThreshold);
|
|
80
|
+
if (this.voronoiContext.config.fillVoronoiCells) {
|
|
81
|
+
fill.cubicBezierPath(cbezier, this.voronoiContext.config.voronoiCellColor);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
draw.cubicBezierPath(cbezier, this.voronoiContext.config.voronoiCellColor);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (this.voronoiContext.config.drawVoronoiIncircles) {
|
|
88
|
+
var result = (0, convexPolygonIncircle_1.convexPolygonIncircle)(cellPolygon);
|
|
89
|
+
var circle = result.circle;
|
|
90
|
+
// var triangle = result.triangle;
|
|
91
|
+
// Here we should have found the best inlying circle (and the corresponding triangle)
|
|
92
|
+
// inside the Voronoi cell.
|
|
93
|
+
draw.circle(circle.center, circle.radius, "rgba(255,192,0,1.0)", 2);
|
|
94
|
+
}
|
|
95
|
+
} // END cell is not open
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* A function for drawing the triangles.
|
|
99
|
+
*
|
|
100
|
+
* @static
|
|
101
|
+
*/
|
|
102
|
+
VoronoiRenderer.prototype.drawTriangles = function (draw) {
|
|
103
|
+
for (var i in this.voronoiContext.triangles) {
|
|
104
|
+
var t = this.voronoiContext.triangles[i];
|
|
105
|
+
VoronoiRenderer.drawTriangle(draw, t, this.voronoiContext.config.makeVoronoiDiagram ? "rgba(0,128,224,0.33)" : "#0088d8");
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Draw the given triangle with the specified (CSS-) color.
|
|
110
|
+
*
|
|
111
|
+
* @static
|
|
112
|
+
* @name drawTriangle
|
|
113
|
+
* @memberof VoronoiRenderer
|
|
114
|
+
* @param {DrawLib} draw
|
|
115
|
+
* @param {Triangle} tri
|
|
116
|
+
* @param {string} color
|
|
117
|
+
* @return {void}
|
|
118
|
+
*/
|
|
119
|
+
VoronoiRenderer.drawTriangle = function (draw, tri, color) {
|
|
120
|
+
// draw.line(t.a, t.b, color);
|
|
121
|
+
// draw.line(t.b, t.c, color);
|
|
122
|
+
// draw.line(t.c, t.a, color);
|
|
123
|
+
draw.polyline([tri.a, tri.b, tri.c], false, color);
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Draw the circumcircles of all triangles.
|
|
127
|
+
*/
|
|
128
|
+
VoronoiRenderer.drawCircumCircles = function (draw, triangles) {
|
|
129
|
+
for (var t in triangles) {
|
|
130
|
+
var cc = triangles[t].getCircumcircle();
|
|
131
|
+
draw.circle(cc.center, cc.radius, "#e86800");
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Clip the convex (!) cell polygon by the convex (!) clipping polygon.
|
|
136
|
+
*
|
|
137
|
+
* @param cellPolygon
|
|
138
|
+
* @param clipBoxPolygon
|
|
139
|
+
* @returns
|
|
140
|
+
*/
|
|
141
|
+
VoronoiRenderer.clipVoronoiPolygon = function (cellPolygon, clipBoxPolygon) {
|
|
142
|
+
return new Polygon_1.Polygon((0, cloneVertexArray_1.cloneVertexArray)((0, sutherlandHodgman_1.sutherlandHodgman)(cellPolygon.vertices, clipBoxPolygon.vertices)), false);
|
|
143
|
+
};
|
|
144
|
+
return VoronoiRenderer;
|
|
145
|
+
}());
|
|
146
|
+
exports.VoronoiRenderer = VoronoiRenderer;
|
|
147
|
+
//# 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,uCAAsC;AACtC,yCAAwC;AAGxC,6EAA4E;AAC5E,qEAAoE;AACpE,wDAAuD;AAkCvD;IAGE,yBAAY,cAA+B;QACzC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACvC,CAAC;IAED;;;;;;;;;;OAUG;IACH,8BAAI,GAAJ,UAAK,IAAkB,EAAE,IAAkB;QACzC,qBAAqB;QACrB,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC;YACjD,eAAe,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;QACzE,CAAC;QAED,4BAA4B;QAC5B,IAAI,cAAc,GAAG,eAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,CAAC;QACjG,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;YAC3C,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,wBAAwB,CAAC,CAAC;QACzD,CAAC;QAED,KAAK,IAAI,CAAC,IAAI,IAAI,CAAC,cAAc,CAAC,YAAY,EAAE,CAAC;YAC/C,IAAI,IAAI,GAAG,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YAC/C,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE,IA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ded`.
|
|
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
|
|
@@ -261,6 +263,16 @@ export declare class Polygon implements IBounded, Intersectable, SVGSerializable
|
|
|
261
263
|
* @return {boolean}
|
|
262
264
|
*/
|
|
263
265
|
isClockwise(): boolean;
|
|
266
|
+
/**
|
|
267
|
+
* Revert the order of this polygon's vertices to change the winding order.
|
|
268
|
+
* This operation is in-place.
|
|
269
|
+
*
|
|
270
|
+
* @method revert
|
|
271
|
+
* @instance
|
|
272
|
+
* @memberof Polygon
|
|
273
|
+
* @return {Polygon} This for chaining.
|
|
274
|
+
*/
|
|
275
|
+
revert(): Polygon;
|
|
264
276
|
/**
|
|
265
277
|
* Get the perimeter of this polygon.
|
|
266
278
|
* The perimeter is the absolute length of the outline.
|
|
@@ -309,18 +321,19 @@ export declare class Polygon implements IBounded, Intersectable, SVGSerializable
|
|
|
309
321
|
getMeanCenter(): Vertex | null;
|
|
310
322
|
/**
|
|
311
323
|
* Get centroid.
|
|
312
|
-
* Centroids define the barycenter of any non self-intersecting convex polygon.
|
|
324
|
+
* Centroids define the barycenter of any non self-intersecting convex clockwise polygon.
|
|
313
325
|
*
|
|
314
|
-
* If the polygon is self intersecting or non
|
|
326
|
+
* If the polygon is self intersecting or non convex or not clockwise then the barycenter is not well defined.
|
|
315
327
|
*
|
|
316
328
|
* https://mathworld.wolfram.com/PolygonCentroid.html
|
|
317
329
|
*
|
|
318
330
|
* @method getCentroid
|
|
319
331
|
* @instance
|
|
332
|
+
* @param {boolean} forceClockwise - [optiona] If set to true then the centroid will be calculated for the clockwise polygon.
|
|
320
333
|
* @memberof Polygon
|
|
321
334
|
* @returns {Vertex|null}
|
|
322
335
|
*/
|
|
323
|
-
getCentroid(): Vertex | null;
|
|
336
|
+
getCentroid(forceClockwise?: boolean): Vertex | null;
|
|
324
337
|
/**
|
|
325
338
|
* Get all line intersections with this polygon.
|
|
326
339
|
*
|
|
@@ -498,6 +511,7 @@ export declare class Polygon implements IBounded, Intersectable, SVGSerializable
|
|
|
498
511
|
*/
|
|
499
512
|
area(vertices: Array<XYCoords>): number;
|
|
500
513
|
isClockwise(vertices: Array<XYCoords>): boolean;
|
|
514
|
+
calculateCentroid(vertices: XYCoords[], forceClockwise?: boolean): Vertex;
|
|
501
515
|
/**
|
|
502
516
|
* Calulate the signed polyon area by interpreting the polygon as a matrix
|
|
503
517
|
* and calculating its determinant.
|