plotboilerplate 1.23.2 → 1.23.3
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/dist/index.esm.js +7052 -6754
- 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 +329 -27
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +4 -2
- package/src/cjs/PlotBoilerplate.d.ts +4 -2
- package/src/cjs/PlotBoilerplate.js +7 -3
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/Polygon.d.ts +107 -4
- package/src/cjs/Polygon.js +215 -9
- package/src/cjs/Polygon.js.map +1 -1
- package/src/cjs/Triangle.d.ts +23 -3
- package/src/cjs/Triangle.js +15 -2
- package/src/cjs/Triangle.js.map +1 -1
- package/src/cjs/VertTuple.d.ts +12 -7
- package/src/cjs/VertTuple.js +14 -9
- package/src/cjs/VertTuple.js.map +1 -1
- package/src/cjs/Vertex.d.ts +2 -1
- package/src/cjs/Vertex.js +5 -2
- package/src/cjs/Vertex.js.map +1 -1
- package/src/cjs/draw.d.ts +1 -0
- package/src/cjs/draw.js +2 -1
- package/src/cjs/draw.js.map +1 -1
- package/src/cjs/drawutilssvg.js +24 -0
- package/src/cjs/drawutilssvg.js.map +1 -1
- package/src/cjs/geomutils.d.ts +32 -1
- package/src/cjs/geomutils.js +47 -1
- package/src/cjs/geomutils.js.map +1 -1
- package/src/cjs/utils/algorithms/PolygonInset.d.ts +184 -0
- package/src/cjs/utils/algorithms/PolygonInset.js +431 -0
- package/src/cjs/utils/algorithms/PolygonInset.js.map +1 -0
- package/src/cjs/utils/algorithms/clearDuplicateVertices.d.ts +5 -4
- package/src/cjs/utils/algorithms/clearDuplicateVertices.js +6 -3
- package/src/cjs/utils/algorithms/clearDuplicateVertices.js.map +1 -1
- package/src/cjs/utils/algorithms/findPolygonSelfIntersections.d.ts +2 -1
- package/src/cjs/utils/algorithms/findPolygonSelfIntersections.js +3 -3
- package/src/cjs/utils/algorithms/findPolygonSelfIntersections.js.map +1 -1
- package/src/cjs/utils/algorithms/splitPolygonToNonIntersecting.d.ts +3 -2
- package/src/cjs/utils/algorithms/splitPolygonToNonIntersecting.js +11 -9
- package/src/cjs/utils/algorithms/splitPolygonToNonIntersecting.js.map +1 -1
- package/src/cjs/utils/detectDarkMode.js.map +1 -1
- package/src/cjs/utils/dom/guiSizeToggler.d.ts +2 -1
- package/src/cjs/utils/dom/guiSizeToggler.js +5 -3
- package/src/cjs/utils/dom/guiSizeToggler.js.map +1 -1
- package/src/esm/PlotBoilerplate.d.ts +4 -2
- package/src/esm/PlotBoilerplate.js +7 -3
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/Polygon.d.ts +107 -4
- package/src/esm/Polygon.js +214 -9
- package/src/esm/Polygon.js.map +1 -1
- package/src/esm/Triangle.d.ts +23 -3
- package/src/esm/Triangle.js +15 -2
- package/src/esm/Triangle.js.map +1 -1
- package/src/esm/VertTuple.d.ts +12 -7
- package/src/esm/VertTuple.js +14 -9
- package/src/esm/VertTuple.js.map +1 -1
- package/src/esm/Vertex.d.ts +2 -1
- package/src/esm/Vertex.js +5 -2
- package/src/esm/Vertex.js.map +1 -1
- package/src/esm/draw.d.ts +1 -0
- package/src/esm/draw.js +2 -1
- package/src/esm/draw.js.map +1 -1
- package/src/esm/drawutilssvg.js +24 -0
- package/src/esm/drawutilssvg.js.map +1 -1
- package/src/esm/geomutils.d.ts +32 -1
- package/src/esm/geomutils.js +47 -1
- package/src/esm/geomutils.js.map +1 -1
- package/src/esm/utils/algorithms/PolygonInset.d.ts +184 -0
- package/src/esm/utils/algorithms/PolygonInset.js +424 -0
- package/src/esm/utils/algorithms/PolygonInset.js.map +1 -0
- package/src/esm/utils/algorithms/clearDuplicateVertices.d.ts +5 -4
- package/src/esm/utils/algorithms/clearDuplicateVertices.js +6 -3
- package/src/esm/utils/algorithms/clearDuplicateVertices.js.map +1 -1
- package/src/esm/utils/algorithms/findPolygonSelfIntersections.d.ts +2 -1
- package/src/esm/utils/algorithms/findPolygonSelfIntersections.js +3 -3
- package/src/esm/utils/algorithms/findPolygonSelfIntersections.js.map +1 -1
- package/src/esm/utils/algorithms/splitPolygonToNonIntersecting.d.ts +3 -2
- package/src/esm/utils/algorithms/splitPolygonToNonIntersecting.js +11 -9
- package/src/esm/utils/algorithms/splitPolygonToNonIntersecting.js.map +1 -1
- package/src/esm/utils/detectDarkMode.js.map +1 -1
- package/src/esm/utils/dom/guiSizeToggler.d.ts +2 -1
- package/src/esm/utils/dom/guiSizeToggler.js +4 -2
- package/src/esm/utils/dom/guiSizeToggler.js.map +1 -1
- package/src/ts/PlotBoilerplate.ts +7 -3
- package/src/ts/Polygon.ts +230 -9
- package/src/ts/Triangle.ts +18 -4
- package/src/ts/VertTuple.ts +15 -10
- package/src/ts/Vertex.ts +5 -2
- package/src/ts/draw.ts +2 -1
- package/src/ts/drawutilssvg.ts +29 -0
- package/src/ts/geomutils.ts +49 -1
- package/src/ts/utils/algorithms/PolygonInset.ts +529 -0
- package/src/ts/utils/algorithms/clearDuplicateVertices.ts +11 -8
- package/src/ts/utils/algorithms/findPolygonSelfIntersections.ts +25 -26
- package/src/ts/utils/algorithms/splitPolygonToNonIntersecting.ts +92 -99
- package/src/ts/utils/detectDarkMode.ts +1 -3
- package/src/ts/utils/dom/guiSizeToggler.ts +4 -2
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* @author Ikaros Kappler
|
|
6
6
|
* @date 2020-12-04
|
|
7
7
|
* @modified 2020-12-09 Ported from vanilla JS to Typescript.
|
|
8
|
+
* @modified 2024-11-22 Fixed a type error in line 41.
|
|
8
9
|
*/
|
|
9
10
|
|
|
10
11
|
import { Line } from "../../Line";
|
|
@@ -18,34 +19,32 @@ import { XYCoords } from "../../interfaces";
|
|
|
18
19
|
*
|
|
19
20
|
* @name findPolygonSelfIntersections
|
|
20
21
|
* @param {Array<Vertex>} vertices - The vertices that form the polygon.
|
|
21
|
-
* @return Array<Vertex>
|
|
22
|
+
* @return {Array<Vertex>}
|
|
22
23
|
*/
|
|
23
|
-
export const findPolygonSelfIntersections = (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
lineB.b.set( vertices[(b+1)%n] );
|
|
24
|
+
export const findPolygonSelfIntersections = (vertices: Array<XYCoords>): Array<Vertex> => {
|
|
25
|
+
const pointList: Array<Vertex> = [];
|
|
26
|
+
const lineA: Line = new Line(new Vertex(), new Vertex());
|
|
27
|
+
const lineB: Line = new Line(new Vertex(), new Vertex());
|
|
28
|
+
const n: number = vertices.length;
|
|
29
|
+
for (var a = 0; a < n; a++) {
|
|
30
|
+
lineA.a.set(vertices[a]);
|
|
31
|
+
lineA.b.set(vertices[(a + 1) % n]);
|
|
32
|
+
for (var b = 0; b < n; b++) {
|
|
33
|
+
// Same edge or neighbour edges intersect by definition.
|
|
34
|
+
// Skip them.
|
|
35
|
+
if (a == b || a + 1 == b || a == b + 1 || (a == 0 && b + 1 == n) || (b == 0 && a + 1 == n)) continue;
|
|
36
|
+
lineB.a.set(vertices[b]);
|
|
37
|
+
lineB.b.set(vertices[(b + 1) % n]);
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
// Commpute the intersection point of the (infinite) lines.
|
|
40
|
+
// The point is undefined if and only if both line are parallel (co-linear).
|
|
41
|
+
const intersectionPoint: Vertex | null = lineA.intersection(lineB);
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
}
|
|
43
|
+
// Check if the intersection point is on both (finite) edges of the polygon.
|
|
44
|
+
if (intersectionPoint && lineA.hasPoint(intersectionPoint) && lineB.hasPoint(intersectionPoint)) {
|
|
45
|
+
pointList.push(intersectionPoint);
|
|
46
|
+
}
|
|
49
47
|
}
|
|
50
|
-
|
|
48
|
+
}
|
|
49
|
+
return pointList;
|
|
51
50
|
};
|
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @requires Line
|
|
3
3
|
* @requires Vertex
|
|
4
|
-
*
|
|
4
|
+
*
|
|
5
5
|
* @author Ikaros Kappler
|
|
6
6
|
* @date 2020-12-04
|
|
7
7
|
* @modified 2020-12-07 Ported from vanilla JS to typescript.
|
|
8
|
-
* @
|
|
8
|
+
* @modified 2024-11-22 Added the `insideBoundsOnly` param to the `splitPolygonToNonIntersecting` algorithm.
|
|
9
|
+
* @version 1.1.0
|
|
9
10
|
*/
|
|
10
11
|
|
|
11
12
|
import { Line } from "../../Line";
|
|
12
13
|
import { Vertex } from "../../Vertex";
|
|
13
14
|
|
|
14
|
-
|
|
15
15
|
/**
|
|
16
16
|
* Splitting a polygon at a self intersection results in two new polygons.
|
|
17
17
|
*/
|
|
18
|
-
type ISplit = [
|
|
19
|
-
|
|
18
|
+
type ISplit = [Array<Vertex>, Array<Vertex>];
|
|
20
19
|
|
|
21
20
|
/**
|
|
22
|
-
* This function cuts a given self-intersecting polygon into non-self-intersecting
|
|
21
|
+
* This function cuts a given self-intersecting polygon into non-self-intersecting
|
|
23
22
|
* sub polygons.
|
|
24
23
|
*
|
|
25
24
|
* The algorithm only works for non-self-overlapping polygons:
|
|
@@ -35,97 +34,91 @@ type ISplit = [ Array<Vertex>, Array<Vertex> ];
|
|
|
35
34
|
* @return {Array<Array<Vertex>>} A sequence of non-self-intersecting sub polygons.
|
|
36
35
|
*/
|
|
37
36
|
export const splitPolygonToNonIntersecting = (() => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return [ first, second ];
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
return splitPolygonToNonIntersecting;
|
|
37
|
+
/**
|
|
38
|
+
* @param {Array<Vertex>} vertices
|
|
39
|
+
* @param {number=10} maxDepth
|
|
40
|
+
*/
|
|
41
|
+
const splitPolygonToNonIntersecting = (
|
|
42
|
+
vertices: Array<Vertex>,
|
|
43
|
+
maxDepth?: number,
|
|
44
|
+
insideBoundsOnly?: boolean
|
|
45
|
+
): Array<Array<Vertex>> => {
|
|
46
|
+
if (typeof maxDepth === "undefined") maxDepth = 10;
|
|
47
|
+
return _splitPolygonToNonIntersecting(vertices, maxDepth, insideBoundsOnly);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const _splitPolygonToNonIntersecting = (
|
|
51
|
+
vertices: Array<Vertex>,
|
|
52
|
+
maxDepth: number,
|
|
53
|
+
insideBoundsOnly?: boolean
|
|
54
|
+
): Array<Array<Vertex>> => {
|
|
55
|
+
if (maxDepth <= 0) {
|
|
56
|
+
// aborting at max depth
|
|
57
|
+
return [vertices];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (vertices.length <= 3) {
|
|
61
|
+
// No intersections possible
|
|
62
|
+
return [vertices];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const n: number = vertices.length;
|
|
66
|
+
const lineA: Line = new Line(new Vertex(), new Vertex());
|
|
67
|
+
const lineB: Line = new Line(new Vertex(), new Vertex());
|
|
68
|
+
for (var a = 0; a < vertices.length; a++) {
|
|
69
|
+
lineA.a.set(vertices[a]);
|
|
70
|
+
lineA.b.set(vertices[(a + 1) % n]);
|
|
71
|
+
for (var b = 0; b < vertices.length; b++) {
|
|
72
|
+
// Equal edges or neighbour edges intersect by definition.
|
|
73
|
+
// We ignore them.
|
|
74
|
+
if (a == b || a + 1 == b || a == b + 1 || (a == 0 && b + 1 == vertices.length) || (b == 0 && a + 1 == vertices.length))
|
|
75
|
+
continue;
|
|
76
|
+
lineB.a.set(vertices[b]);
|
|
77
|
+
lineB.b.set(vertices[(b + 1) % n]);
|
|
78
|
+
|
|
79
|
+
const intersectionPoint: Vertex | null = lineA.intersection(lineB);
|
|
80
|
+
if (
|
|
81
|
+
intersectionPoint &&
|
|
82
|
+
lineA.hasPoint(intersectionPoint, insideBoundsOnly) &&
|
|
83
|
+
lineB.hasPoint(intersectionPoint, insideBoundsOnly)
|
|
84
|
+
) {
|
|
85
|
+
// Cut polygon into two here
|
|
86
|
+
const split: ISplit = splitPolygonAt(vertices, a, b, intersectionPoint);
|
|
87
|
+
|
|
88
|
+
// Split has 2 elements.
|
|
89
|
+
const leftCleaned: Array<Array<Vertex>> = _splitPolygonToNonIntersecting(split[0], maxDepth - 1, insideBoundsOnly);
|
|
90
|
+
const rightCleaned: Array<Array<Vertex>> = _splitPolygonToNonIntersecting(split[1], maxDepth - 1, insideBoundsOnly);
|
|
91
|
+
|
|
92
|
+
return leftCleaned.concat(rightCleaned);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// No intersection found:
|
|
98
|
+
// just return a list with the original
|
|
99
|
+
// polygon as its only element.
|
|
100
|
+
return [vertices];
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// Pre: edgeIndexA < edgeIndexB && vertices.length >= 4
|
|
104
|
+
const splitPolygonAt = (vertices: Array<Vertex>, edgeIndexA: number, edgeIndexB: number, intersectionPoint: Vertex): ISplit => {
|
|
105
|
+
const first: Array<Vertex> = [];
|
|
106
|
+
var second: Array<Vertex> = [];
|
|
107
|
+
for (var i = 0; i < vertices.length; i++) {
|
|
108
|
+
if (i <= edgeIndexA) first.push(vertices[i]);
|
|
109
|
+
|
|
110
|
+
if (i == edgeIndexA) {
|
|
111
|
+
first.push(intersectionPoint);
|
|
112
|
+
second.push(intersectionPoint); // clone???
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (i > edgeIndexA && i <= edgeIndexB) second.push(vertices[i]);
|
|
116
|
+
|
|
117
|
+
if (i > edgeIndexB) first.push(vertices[i]);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return [first, second];
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
return splitPolygonToNonIntersecting;
|
|
130
124
|
})();
|
|
131
|
-
|
|
@@ -8,9 +8,7 @@
|
|
|
8
8
|
* @returns {boolean}
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export const detectDarkMode = (GUP?: Record<string, string>) => {
|
|
11
|
+
export const detectDarkMode = (GUP?: Record<string, string>): boolean => {
|
|
14
12
|
// Respect overrides
|
|
15
13
|
if (typeof GUP !== "undefined" && GUP.hasOwnProperty("darkmode") && GUP["darkmode"]) {
|
|
16
14
|
// const overrideValue = PlotBoilerplate.utils.fetch.bool(GUP, "darkmode", null);
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* @date 2021-12-13
|
|
6
6
|
* @modified 2022-01-10
|
|
7
7
|
* @modified 2024-06-25 Ported to typescript and moved to utils/dom (was located inside demos before).
|
|
8
|
-
* @
|
|
8
|
+
* @modified 2024-10-02 Added a transition time.
|
|
9
|
+
* @version 1.1.1
|
|
9
10
|
*/
|
|
10
11
|
|
|
11
12
|
import { GUI } from "../../interfaces/externals";
|
|
@@ -36,7 +37,8 @@ const applyGuiSize = (gui: GUI, guiDoubleSize: boolean, cssProps: Record<string,
|
|
|
36
37
|
}
|
|
37
38
|
};
|
|
38
39
|
|
|
39
|
-
export const guiSizeToggler
|
|
40
|
+
export const guiSizeToggler = (gui: GUI, config: ITogglerConfig, cssProps: Record<string, string>) => {
|
|
41
|
+
gui.domElement.style["transition"] = "transform 0.5s";
|
|
40
42
|
return {
|
|
41
43
|
update: function () {
|
|
42
44
|
applyGuiSize(gui, Boolean(config.guiDoubleSize), cssProps);
|