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.
Files changed (101) hide show
  1. package/dist/index.esm.js +7052 -6754
  2. package/dist/index.esm.js.map +1 -1
  3. package/dist/index.esm.min.js +1 -1
  4. package/dist/index.esm.min.js.map +1 -1
  5. package/dist/plotboilerplate.browser.min.js +1 -1
  6. package/dist/plotboilerplate.browser.min.js.map +1 -1
  7. package/dist/plotboilerplate.js +329 -27
  8. package/dist/plotboilerplate.min.js +1 -1
  9. package/package.json +4 -2
  10. package/src/cjs/PlotBoilerplate.d.ts +4 -2
  11. package/src/cjs/PlotBoilerplate.js +7 -3
  12. package/src/cjs/PlotBoilerplate.js.map +1 -1
  13. package/src/cjs/Polygon.d.ts +107 -4
  14. package/src/cjs/Polygon.js +215 -9
  15. package/src/cjs/Polygon.js.map +1 -1
  16. package/src/cjs/Triangle.d.ts +23 -3
  17. package/src/cjs/Triangle.js +15 -2
  18. package/src/cjs/Triangle.js.map +1 -1
  19. package/src/cjs/VertTuple.d.ts +12 -7
  20. package/src/cjs/VertTuple.js +14 -9
  21. package/src/cjs/VertTuple.js.map +1 -1
  22. package/src/cjs/Vertex.d.ts +2 -1
  23. package/src/cjs/Vertex.js +5 -2
  24. package/src/cjs/Vertex.js.map +1 -1
  25. package/src/cjs/draw.d.ts +1 -0
  26. package/src/cjs/draw.js +2 -1
  27. package/src/cjs/draw.js.map +1 -1
  28. package/src/cjs/drawutilssvg.js +24 -0
  29. package/src/cjs/drawutilssvg.js.map +1 -1
  30. package/src/cjs/geomutils.d.ts +32 -1
  31. package/src/cjs/geomutils.js +47 -1
  32. package/src/cjs/geomutils.js.map +1 -1
  33. package/src/cjs/utils/algorithms/PolygonInset.d.ts +184 -0
  34. package/src/cjs/utils/algorithms/PolygonInset.js +431 -0
  35. package/src/cjs/utils/algorithms/PolygonInset.js.map +1 -0
  36. package/src/cjs/utils/algorithms/clearDuplicateVertices.d.ts +5 -4
  37. package/src/cjs/utils/algorithms/clearDuplicateVertices.js +6 -3
  38. package/src/cjs/utils/algorithms/clearDuplicateVertices.js.map +1 -1
  39. package/src/cjs/utils/algorithms/findPolygonSelfIntersections.d.ts +2 -1
  40. package/src/cjs/utils/algorithms/findPolygonSelfIntersections.js +3 -3
  41. package/src/cjs/utils/algorithms/findPolygonSelfIntersections.js.map +1 -1
  42. package/src/cjs/utils/algorithms/splitPolygonToNonIntersecting.d.ts +3 -2
  43. package/src/cjs/utils/algorithms/splitPolygonToNonIntersecting.js +11 -9
  44. package/src/cjs/utils/algorithms/splitPolygonToNonIntersecting.js.map +1 -1
  45. package/src/cjs/utils/detectDarkMode.js.map +1 -1
  46. package/src/cjs/utils/dom/guiSizeToggler.d.ts +2 -1
  47. package/src/cjs/utils/dom/guiSizeToggler.js +5 -3
  48. package/src/cjs/utils/dom/guiSizeToggler.js.map +1 -1
  49. package/src/esm/PlotBoilerplate.d.ts +4 -2
  50. package/src/esm/PlotBoilerplate.js +7 -3
  51. package/src/esm/PlotBoilerplate.js.map +1 -1
  52. package/src/esm/Polygon.d.ts +107 -4
  53. package/src/esm/Polygon.js +214 -9
  54. package/src/esm/Polygon.js.map +1 -1
  55. package/src/esm/Triangle.d.ts +23 -3
  56. package/src/esm/Triangle.js +15 -2
  57. package/src/esm/Triangle.js.map +1 -1
  58. package/src/esm/VertTuple.d.ts +12 -7
  59. package/src/esm/VertTuple.js +14 -9
  60. package/src/esm/VertTuple.js.map +1 -1
  61. package/src/esm/Vertex.d.ts +2 -1
  62. package/src/esm/Vertex.js +5 -2
  63. package/src/esm/Vertex.js.map +1 -1
  64. package/src/esm/draw.d.ts +1 -0
  65. package/src/esm/draw.js +2 -1
  66. package/src/esm/draw.js.map +1 -1
  67. package/src/esm/drawutilssvg.js +24 -0
  68. package/src/esm/drawutilssvg.js.map +1 -1
  69. package/src/esm/geomutils.d.ts +32 -1
  70. package/src/esm/geomutils.js +47 -1
  71. package/src/esm/geomutils.js.map +1 -1
  72. package/src/esm/utils/algorithms/PolygonInset.d.ts +184 -0
  73. package/src/esm/utils/algorithms/PolygonInset.js +424 -0
  74. package/src/esm/utils/algorithms/PolygonInset.js.map +1 -0
  75. package/src/esm/utils/algorithms/clearDuplicateVertices.d.ts +5 -4
  76. package/src/esm/utils/algorithms/clearDuplicateVertices.js +6 -3
  77. package/src/esm/utils/algorithms/clearDuplicateVertices.js.map +1 -1
  78. package/src/esm/utils/algorithms/findPolygonSelfIntersections.d.ts +2 -1
  79. package/src/esm/utils/algorithms/findPolygonSelfIntersections.js +3 -3
  80. package/src/esm/utils/algorithms/findPolygonSelfIntersections.js.map +1 -1
  81. package/src/esm/utils/algorithms/splitPolygonToNonIntersecting.d.ts +3 -2
  82. package/src/esm/utils/algorithms/splitPolygonToNonIntersecting.js +11 -9
  83. package/src/esm/utils/algorithms/splitPolygonToNonIntersecting.js.map +1 -1
  84. package/src/esm/utils/detectDarkMode.js.map +1 -1
  85. package/src/esm/utils/dom/guiSizeToggler.d.ts +2 -1
  86. package/src/esm/utils/dom/guiSizeToggler.js +4 -2
  87. package/src/esm/utils/dom/guiSizeToggler.js.map +1 -1
  88. package/src/ts/PlotBoilerplate.ts +7 -3
  89. package/src/ts/Polygon.ts +230 -9
  90. package/src/ts/Triangle.ts +18 -4
  91. package/src/ts/VertTuple.ts +15 -10
  92. package/src/ts/Vertex.ts +5 -2
  93. package/src/ts/draw.ts +2 -1
  94. package/src/ts/drawutilssvg.ts +29 -0
  95. package/src/ts/geomutils.ts +49 -1
  96. package/src/ts/utils/algorithms/PolygonInset.ts +529 -0
  97. package/src/ts/utils/algorithms/clearDuplicateVertices.ts +11 -8
  98. package/src/ts/utils/algorithms/findPolygonSelfIntersections.ts +25 -26
  99. package/src/ts/utils/algorithms/splitPolygonToNonIntersecting.ts +92 -99
  100. package/src/ts/utils/detectDarkMode.ts +1 -3
  101. 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 = ( vertices:Array<XYCoords> ) : Array<Vertex> => {
24
- const pointList : Array<Vertex> = [];
25
- const lineA : Line = new Line( new Vertex(), new Vertex() );
26
- const lineB : Line = new Line( new Vertex(), new Vertex() );
27
- const n : number = vertices.length;
28
- for( var a = 0; a < n; a++ ) {
29
- lineA.a.set( vertices[a] );
30
- lineA.b.set( vertices[(a+1)%n] );
31
- for( var b = 0; b < n; b++ ) {
32
- // Same edge or neighbour edges intersect by definition.
33
- // Skip them.
34
- if( a == b || a+1 == b || a == b+1 || (a==0&&b+1==n) || (b==0&&a+1==n) )
35
- continue;
36
- lineB.a.set( vertices[b] );
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
- // 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|undefined = lineA.intersection(lineB);
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
- // Check if the intersection point is on both (finite) edges of the polygon.
44
- if( intersectionPoint
45
- && lineA.hasPoint(intersectionPoint) && lineB.hasPoint(intersectionPoint) ) {
46
- pointList.push( intersectionPoint );
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
- return pointList;
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
- * @version 1.0.1
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 = [ Array<Vertex>, Array<Vertex> ];
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
- * @param {Array<Vertex>} vertices
41
- * @param {number=10} maxDepth
42
- */
43
- const splitPolygonToNonIntersecting = ( vertices:Array<Vertex>,
44
- maxDepth?:number ) : Array<Array<Vertex>> => {
45
- if( typeof maxDepth === "undefined" )
46
- maxDepth = 10;
47
- return _splitPolygonToNonIntersecting( vertices, maxDepth );
48
- };
49
-
50
-
51
- const _splitPolygonToNonIntersecting = ( vertices:Array<Vertex>,
52
- maxDepth:number ) : Array<Array<Vertex>> => {
53
- if( maxDepth <= 0 ) {
54
- // aborting at max depth
55
- return [ vertices ];
56
- }
57
-
58
- if( vertices.length <= 3 ) {
59
- // No intersections possible
60
- return [ vertices ];
61
- }
62
-
63
- const n : number= vertices.length;
64
- const lineA : Line = new Line( new Vertex(), new Vertex() );
65
- const lineB : Line = new Line( new Vertex(), new Vertex() );
66
- for( var a = 0; a < vertices.length; a++ ) {
67
- lineA.a.set( vertices[a] );
68
- lineA.b.set( vertices[(a+1) % n] );
69
- for( var b = 0; b < vertices.length; b++ ) {
70
- // Equal edges or neighbour edges intersect by definition.
71
- // We ignore them.
72
- if( a == b || a+1 == b || a == b+1
73
- || (a==0&&b+1==vertices.length) || (b==0&&a+1==vertices.length) )
74
- continue;
75
- lineB.a.set( vertices[b] );
76
- lineB.b.set( vertices[(b+1) % n] );
77
-
78
- const intersectionPoint : Vertex|undefined = lineA.intersection(lineB);
79
- if( intersectionPoint && lineA.hasPoint(intersectionPoint) && lineB.hasPoint(intersectionPoint) ) {
80
-
81
- // Cut polygon into two here
82
- const split : ISplit = splitPolygonAt( vertices, a, b, intersectionPoint );
83
-
84
- // Split has 2 elements.
85
- const leftCleaned : Array<Array<Vertex>> =
86
- _splitPolygonToNonIntersecting( split[0], maxDepth-1 );
87
- const rightCleaned : Array<Array<Vertex>> =
88
- _splitPolygonToNonIntersecting( split[1], maxDepth-1 );
89
-
90
- return leftCleaned.concat( rightCleaned );
91
- }
92
- }
93
- }
94
-
95
- // No intersection found:
96
- // just return a list with the original
97
- // polygon as its only element.
98
- return [ vertices ];
99
- };
100
-
101
-
102
- // Pre: edgeIndexA < edgeIndexB && vertices.length >= 4
103
- const splitPolygonAt = ( vertices:Array<Vertex>,
104
- edgeIndexA:number,
105
- edgeIndexB:number,
106
- intersectionPoint:Vertex ) : ISplit => {
107
- const first : Array<Vertex> = [];
108
- var second : Array<Vertex> = [];
109
- for( var i = 0; i < vertices.length; i++ ) {
110
- if( i <= edgeIndexA )
111
- first.push( vertices[i] );
112
-
113
- if( i == edgeIndexA ) {
114
- first.push( intersectionPoint );
115
- second.push( intersectionPoint ); // clone???
116
- }
117
-
118
- if( i > edgeIndexA && i <= edgeIndexB )
119
- second.push( vertices[i] );
120
-
121
- if( i > edgeIndexB )
122
- first.push( vertices[i] );
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
- import PlotBoilerplate from "../PlotBoilerplate";
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
- * @version 1.1.0
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 /* gst */ = (gui: GUI, config: ITogglerConfig, cssProps: Record<string, string>) => {
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);