plotboilerplate 1.25.0 → 1.26.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.
Files changed (105) hide show
  1. package/README.md +1 -0
  2. package/dist/index.esm.js +139 -33
  3. package/dist/index.esm.js.map +1 -1
  4. package/dist/index.esm.min.js +1 -1
  5. package/dist/index.esm.min.js.map +1 -1
  6. package/dist/plotboilerplate.browser.min.js +1 -1
  7. package/dist/plotboilerplate.browser.min.js.map +1 -1
  8. package/dist/plotboilerplate.js +139 -33
  9. package/dist/plotboilerplate.min.js +1 -1
  10. package/package.json +1 -1
  11. package/src/cjs/Bounds.d.ts +79 -25
  12. package/src/cjs/Bounds.js +102 -29
  13. package/src/cjs/Bounds.js.map +1 -1
  14. package/src/cjs/CircleSector.d.ts +3 -0
  15. package/src/cjs/CircleSector.js +28 -1
  16. package/src/cjs/CircleSector.js.map +1 -1
  17. package/src/cjs/drawutilssvg.d.ts +2 -1
  18. package/src/cjs/drawutilssvg.js +9 -3
  19. package/src/cjs/drawutilssvg.js.map +1 -1
  20. package/src/cjs/utils/LissajousFigure.d.ts +34 -0
  21. package/src/cjs/utils/LissajousFigure.js +100 -0
  22. package/src/cjs/utils/LissajousFigure.js.map +1 -0
  23. package/src/cjs/utils/PerlinNoise.d.ts +19 -0
  24. package/src/cjs/utils/PerlinNoise.js +352 -0
  25. package/src/cjs/utils/PerlinNoise.js.map +1 -0
  26. package/src/cjs/utils/SVGPathUtils.d.ts +22 -0
  27. package/src/cjs/utils/SVGPathUtils.js +45 -0
  28. package/src/cjs/utils/SVGPathUtils.js.map +1 -0
  29. package/src/cjs/utils/algorithms/pixelCornersToRoundPaths.d.ts +23 -0
  30. package/src/cjs/utils/algorithms/pixelCornersToRoundPaths.js +270 -0
  31. package/src/cjs/utils/algorithms/pixelCornersToRoundPaths.js.map +1 -0
  32. package/src/cjs/utils/datastructures/DataGrid2d.d.ts +6 -0
  33. package/src/cjs/utils/datastructures/DataGrid2dArrayMatrix.d.ts +88 -0
  34. package/src/cjs/utils/datastructures/DataGrid2dArrayMatrix.js +155 -0
  35. package/src/cjs/utils/datastructures/DataGrid2dArrayMatrix.js.map +1 -0
  36. package/src/cjs/utils/datastructures/DataGrid2dListAdapter.d.ts +1 -7
  37. package/src/cjs/utils/datastructures/DataGrid2dListAdapter.js +3 -3
  38. package/src/cjs/utils/datastructures/DataGrid2dListAdapter.js.map +1 -1
  39. package/src/cjs/utils/datastructures/GeometryMesh.d.ts +49 -0
  40. package/src/cjs/utils/datastructures/GeometryMesh.js +58 -0
  41. package/src/cjs/utils/datastructures/GeometryMesh.js.map +1 -0
  42. package/src/cjs/utils/detectDarkMode.js +16 -7
  43. package/src/cjs/utils/detectDarkMode.js.map +1 -1
  44. package/src/cjs/utils/dom/components/ColorGradientPicker.d.ts +4 -3
  45. package/src/cjs/utils/dom/components/ColorGradientPicker.js +8 -8
  46. package/src/cjs/utils/dom/components/ColorGradientPicker.js.map +1 -1
  47. package/src/cjs/utils/dom/components/ColorGradientSelector.d.ts +1 -0
  48. package/src/cjs/utils/dom/components/ColorGradientSelector.js +4 -2
  49. package/src/cjs/utils/dom/components/ColorGradientSelector.js.map +1 -1
  50. package/src/cjs/utils/parsers/svg/types.d.ts +8 -8
  51. package/src/esm/Bounds.d.ts +79 -25
  52. package/src/esm/Bounds.js +102 -29
  53. package/src/esm/Bounds.js.map +1 -1
  54. package/src/esm/CircleSector.d.ts +3 -0
  55. package/src/esm/CircleSector.js +28 -1
  56. package/src/esm/CircleSector.js.map +1 -1
  57. package/src/esm/drawutilssvg.d.ts +2 -1
  58. package/src/esm/drawutilssvg.js +9 -3
  59. package/src/esm/drawutilssvg.js.map +1 -1
  60. package/src/esm/utils/LissajousFigure.d.ts +34 -0
  61. package/src/esm/utils/LissajousFigure.js +95 -0
  62. package/src/esm/utils/LissajousFigure.js.map +1 -0
  63. package/src/esm/utils/PerlinNoise.d.ts +19 -0
  64. package/src/esm/utils/PerlinNoise.js +346 -0
  65. package/src/esm/utils/PerlinNoise.js.map +1 -0
  66. package/src/esm/utils/SVGPathUtils.d.ts +22 -0
  67. package/src/esm/utils/SVGPathUtils.js +42 -0
  68. package/src/esm/utils/SVGPathUtils.js.map +1 -0
  69. package/src/esm/utils/algorithms/pixelCornersToRoundPaths.d.ts +23 -0
  70. package/src/esm/utils/algorithms/pixelCornersToRoundPaths.js +266 -0
  71. package/src/esm/utils/algorithms/pixelCornersToRoundPaths.js.map +1 -0
  72. package/src/esm/utils/datastructures/DataGrid2d.d.ts +6 -0
  73. package/src/esm/utils/datastructures/DataGrid2dArrayMatrix.d.ts +88 -0
  74. package/src/esm/utils/datastructures/DataGrid2dArrayMatrix.js +150 -0
  75. package/src/esm/utils/datastructures/DataGrid2dArrayMatrix.js.map +1 -0
  76. package/src/esm/utils/datastructures/DataGrid2dListAdapter.d.ts +1 -7
  77. package/src/esm/utils/datastructures/DataGrid2dListAdapter.js +3 -3
  78. package/src/esm/utils/datastructures/DataGrid2dListAdapter.js.map +1 -1
  79. package/src/esm/utils/datastructures/GeometryMesh.d.ts +49 -0
  80. package/src/esm/utils/datastructures/GeometryMesh.js +53 -0
  81. package/src/esm/utils/datastructures/GeometryMesh.js.map +1 -0
  82. package/src/esm/utils/detectDarkMode.js +16 -7
  83. package/src/esm/utils/detectDarkMode.js.map +1 -1
  84. package/src/esm/utils/dom/components/ColorGradientPicker.d.ts +4 -3
  85. package/src/esm/utils/dom/components/ColorGradientPicker.js +18 -7
  86. package/src/esm/utils/dom/components/ColorGradientPicker.js.map +1 -1
  87. package/src/esm/utils/dom/components/ColorGradientSelector.d.ts +1 -0
  88. package/src/esm/utils/dom/components/ColorGradientSelector.js +9 -2
  89. package/src/esm/utils/dom/components/ColorGradientSelector.js.map +1 -1
  90. package/src/esm/utils/parsers/svg/types.d.ts +8 -8
  91. package/src/ts/Bounds.ts +107 -22
  92. package/src/ts/CircleSector.ts +39 -6
  93. package/src/ts/drawutilssvg.ts +8 -3
  94. package/src/ts/utils/LissajousFigure.ts +110 -0
  95. package/src/ts/utils/PerlinNoise.ts +368 -0
  96. package/src/ts/utils/SVGPathUtils.ts +55 -0
  97. package/src/ts/utils/algorithms/pixelCornersToRoundPaths.ts +379 -0
  98. package/src/ts/utils/datastructures/DataGrid2d.ts +7 -0
  99. package/src/ts/utils/datastructures/DataGrid2dArrayMatrix.ts +182 -0
  100. package/src/ts/utils/datastructures/DataGrid2dListAdapter.ts +4 -11
  101. package/src/ts/utils/datastructures/GeometryMesh.ts +79 -0
  102. package/src/ts/utils/detectDarkMode.ts +17 -8
  103. package/src/ts/utils/dom/components/ColorGradientPicker.tsx +18 -6
  104. package/src/ts/utils/dom/components/ColorGradientSelector.tsx +9 -2
  105. package/src/ts/utils/parsers/svg/types.ts +8 -8
@@ -109,16 +109,16 @@ export class CircleSector implements IBounded, Intersectable, SVGSerializable {
109
109
  **/
110
110
  getBounds(): Bounds {
111
111
  const _self = this;
112
- const circleBounds : Bounds = this.circle.getBounds();
112
+ const circleBounds: Bounds = this.circle.getBounds();
113
113
  // Calculage angles from east, west, north and south box points and check if they are inside
114
- const candidates : Array<Vertex> = [
114
+ const candidates: Array<Vertex> = [
115
115
  circleBounds.getNorthPoint(),
116
116
  circleBounds.getSouthPoint(),
117
117
  circleBounds.getWestPoint(),
118
118
  circleBounds.getEastPoint()
119
- ].filter( (point : Vertex) => {
119
+ ].filter((point: Vertex) => {
120
120
  // Check for each candidate points if they are contained in this sector. Drop if not.
121
- const angle : number = new Line(_self.circle.center, point).angle();
121
+ const angle: number = new Line(_self.circle.center, point).angle();
122
122
  return _self.containsAngle(angle);
123
123
  });
124
124
  // Compute bounds and inlcude start end end point (they are definitely part of the bounds)
@@ -126,7 +126,6 @@ export class CircleSector implements IBounded, Intersectable, SVGSerializable {
126
126
  }
127
127
  //--- BEGIN --- Implement interface `IBounded`
128
128
 
129
-
130
129
  /**
131
130
  * Move the circle sector by the given amount.
132
131
  *
@@ -316,6 +315,38 @@ export class CircleSector implements IBounded, Intersectable, SVGSerializable {
316
315
  }
317
316
  //--- END --- Implement interface `Intersectable`
318
317
 
318
+ describeSVGPath(options?: { moveToStart: boolean }): SVGPathParams {
319
+ // const buffer: SVGPathParams = [];
320
+ // const start = this.getStartPoint();
321
+ // const end = this.getEndPoint();
322
+ // // describeSVGArc
323
+ // // x: number,
324
+ // // y: number,
325
+ // // radius: number,
326
+ // // startAngle: number,
327
+ // // endAngle: number,
328
+ // // options?: { moveToStart: boolean }
329
+ // // ): SVGPathParams => {
330
+ // var arcRotation = 0.0;
331
+ // var largeArcFlag = 1;
332
+ // var sweepFlag = 0;
333
+ // if (options && options.moveToStart) {
334
+ // buffer.push("M", start.x, start.y);
335
+ // }
336
+ // buffer.push("A", cSector.circle.radius, cSector.circle.radius, arcRotation, largeArcFlag, sweepFlag, end.x, end.y);
337
+ // return buffer;
338
+
339
+ const arc = CircleSector.circleSectorUtils.describeSVGArc(
340
+ this.circle.center.x, // end.x,
341
+ this.circle.center.y, // end.y,
342
+ this.circle.radius,
343
+ this.startAngle,
344
+ this.endAngle,
345
+ options // options?: { moveToStart: boolean }
346
+ );
347
+ return arc;
348
+ }
349
+
319
350
  /**
320
351
  * This function should invalidate any installed listeners and invalidate this object.
321
352
  * After calling this function the object might not hold valid data any more and
@@ -363,7 +394,9 @@ export class CircleSector implements IBounded, Intersectable, SVGSerializable {
363
394
  endAngle: number,
364
395
  options?: { moveToStart: boolean }
365
396
  ): SVGPathParams => {
366
- if (typeof options === "undefined") options = { moveToStart: true };
397
+ if (typeof options === "undefined") {
398
+ options = { moveToStart: true };
399
+ }
367
400
 
368
401
  const end: XYCoords = CircleSector.circleSectorUtils.polarToCartesian(x, y, radius, endAngle);
369
402
  const start: XYCoords = CircleSector.circleSectorUtils.polarToCartesian(x, y, radius, startAngle);
@@ -47,7 +47,8 @@
47
47
  * @modified 2024-01-30 Fixing an issue with immutable style sets; changes to the global draw config did not reflect here (do now).
48
48
  * @modified 2024-03-10 Fixing some types for Typescript 5 compatibility.
49
49
  * @modified 2024-07-24 Caching custom style defs in a private buffer variable.
50
- * @version 1.6.10
50
+ * @modified 2025-11-14 Fixing a bug in the CSS `mix-blend-mode` property handling (caused a runtime error).
51
+ * @version 1.6.11
51
52
  **/
52
53
 
53
54
  import { CircleSector } from "./CircleSector";
@@ -416,8 +417,12 @@ export class drawutilssvg implements DrawLib<void | SVGElement> {
416
417
  node = this.createSVGNode(nodeName);
417
418
  }
418
419
  if (this.drawlibConfiguration.blendMode) {
419
- // node.style["mix-blend-mode"] = this.drawlibConfiguration.blendMode;
420
- node.style["mix-blend-mode" as keyof Object](this.drawlibConfiguration.blendMode);
420
+ const blendMode = node.style["mix-blend-mode" as keyof Object];
421
+ if (typeof blendMode === "function") {
422
+ blendMode(this.drawlibConfiguration.blendMode);
423
+ } else {
424
+ node.style["mix-blend-mode"] = this.drawlibConfiguration.blendMode;
425
+ }
421
426
  }
422
427
  // if (this.lineDashEnabled && this.lineDash && this.lineDash.length > 0 && drawutilssvg.nodeSupportsLineDash(nodeName)) {
423
428
  // node.setAttribute("stroke-dasharray", this.lineDash.join(" "));
@@ -0,0 +1,110 @@
1
+ /**
2
+ * A wrapper for Lissajous figure params.
3
+ *
4
+ * @author Ikaros Kappler
5
+ * @date 2018-11-22
6
+ * @modified 2025-10-29 Ported to typescript from demo 13-lissajous.
7
+ * @version 1.0.0
8
+ */
9
+
10
+ import { Vertex } from "../Vertex";
11
+
12
+ export class LissajousFigure {
13
+ freqA: number;
14
+ freqB: number;
15
+ phaseA: number;
16
+ phaseB: number;
17
+
18
+ /**
19
+ * Create a new figure with the given settings.
20
+ * @param {number} freqA - The 'horizontal' frequency.
21
+ * @param {number} freqB - The 'vertical' frequency.
22
+ * @param {number} phaseA - The 'horizonal' phase shift.
23
+ * @param {number} phaseB - The 'vertical' phase shift.
24
+ */
25
+ constructor(freqA: number, freqB: number, phaseA: number, phaseB: number) {
26
+ this.freqA = freqA;
27
+ this.freqB = freqB;
28
+ this.phaseA = phaseA;
29
+ this.phaseB = phaseB;
30
+ }
31
+
32
+ /**
33
+ * Get the point at the given abstract time.
34
+ *
35
+ * The result is periodic in 0..TWO_PI.
36
+ *
37
+ * @param {number} t - The timing value (for example milliseconds).
38
+ * @returns {Vertex} The x-y-position on the Lissajous figure at the given time.
39
+ */
40
+ public getPointAt(t: number): Vertex {
41
+ return new Vertex(Math.sin(this.phaseA + this.freqA * t), Math.sin(this.phaseB + this.freqB * t));
42
+ }
43
+
44
+ public toPolyLine(stepSize: number): Array<Vertex> {
45
+ const polyLine: Array<Vertex> = [];
46
+
47
+ let pA = new Vertex(0, 0);
48
+
49
+ stepSize = Math.abs(stepSize);
50
+ for (var t = 0; t <= 2 * Math.PI; t += stepSize) {
51
+ pA = this.getPointAt(t);
52
+ polyLine.push(pA.clone());
53
+ }
54
+ return polyLine;
55
+ }
56
+
57
+ public toQuadraticBezierApproximation(
58
+ stepSize: number
59
+ // scale: number
60
+ // alternating: boolean
61
+ ): Array<[Vertex, Vertex, Vertex] | [Vertex, Vertex]> {
62
+ const result: Array<[Vertex, Vertex, Vertex] | [Vertex, Vertex]> = [];
63
+ let pA = new Vertex(0, 0);
64
+ let pB = new Vertex(0, 0);
65
+ stepSize = Math.abs(stepSize);
66
+
67
+ let p1 = new Vertex(0, 0);
68
+ let dx1 = this.freqA;
69
+ let dy1 = this.freqB;
70
+ pA = this.getPointAt(stepSize);
71
+ let x2, y2, dx2, dy2, det, x3, y3;
72
+ var i = 0;
73
+ for (var t = stepSize; t <= 2 * Math.PI + 2 * stepSize; t += stepSize) {
74
+ x2 = Math.sin(this.phaseA + this.freqA * t);
75
+ y2 = Math.sin(this.phaseB + this.freqB * t);
76
+ dx2 = this.freqA * Math.cos(this.phaseA + this.freqA * t);
77
+ dy2 = this.freqB * Math.cos(this.phaseB + this.freqB * t);
78
+ det = dx1 * dy2 - dy1 * dx2;
79
+ if (Math.abs(det) > 0.1) {
80
+ x3 = ((x2 * dy2 - y2 * dx2) * dx1 - (p1.x * dy1 - p1.y * dx1) * dx2) / det;
81
+ y3 = ((x2 * dy2 - y2 * dx2) * dy1 - (p1.x * dy1 - p1.y * dx1) * dy2) / det;
82
+ // pB.set(scale * x2, scale * y2 * (alternating ? -1 : 1));
83
+ // pB.set(scale * x2, scale * y2);
84
+ pB.set(x2, y2);
85
+
86
+ // pB.set(x2, y2);
87
+
88
+ if (i > 0) {
89
+ // pb.draw.quadraticBezier(pA, new Vertex(scale * x3, scale * y3), pB, "rgba(0,108,255,1.0)", 2);
90
+ // result.push([pA.clone(), new Vertex(scale * x3, scale * y3), pB.clone()]);
91
+ result.push([pA.clone(), new Vertex(x3, y3), pB.clone()]);
92
+ }
93
+ } else {
94
+ // pB.set(scale * x2, scale * y2);
95
+ pB.set(x2, y2);
96
+
97
+ if (i > 0) {
98
+ // pb.draw.line(pA, pB, "rgba(0,192,192,0.8)", 2);
99
+ result.push([pA.clone(), pB.clone()]);
100
+ }
101
+ }
102
+ p1.set(x2, y2);
103
+ dx1 = dx2;
104
+ dy1 = dy2;
105
+ pA.set(pB);
106
+ i++;
107
+ } // END for
108
+ return result;
109
+ }
110
+ }
@@ -0,0 +1,368 @@
1
+ /*
2
+ * A speed-improved perlin and simplex noise algorithms for 2D.
3
+ *
4
+ * Based on example code by Stefan Gustavson (stegu@itn.liu.se).
5
+ * Optimisations by Peter Eastman (peastman@drizzle.stanford.edu).
6
+ * Better rank ordering method by Stefan Gustavson in 2012.
7
+ * Converted to Javascript by Joseph Gentle.
8
+ *
9
+ * Version 2012-03-09
10
+ *
11
+ * This code was placed in the public domain by its original author,
12
+ * Stefan Gustavson. You may use it as you see fit, but
13
+ * attribution is appreciated.
14
+ *
15
+ * @modified 2023-03-07 Ikaros Kappler; ported to Typescript & refactored to class.
16
+ * @modified 2025-11-12 Ikaros Kappler; moved from a different project `floatsim` and refactored the class.
17
+ */
18
+
19
+ class Grad {
20
+ x: number;
21
+ y: number;
22
+ z: number;
23
+ constructor(x: number, y: number, z: number) {
24
+ this.x = x;
25
+ this.y = y;
26
+ this.z = z;
27
+ }
28
+ dot2(x: number, y: number) {
29
+ return this.x * x + this.y * y;
30
+ }
31
+ dot3(x: number, y: number, z: number) {
32
+ return this.x * x + this.y * y + this.z * z;
33
+ }
34
+ }
35
+
36
+ const grad3: Array<Grad> = [
37
+ new Grad(1, 1, 0),
38
+ new Grad(-1, 1, 0),
39
+ new Grad(1, -1, 0),
40
+ new Grad(-1, -1, 0),
41
+ new Grad(1, 0, 1),
42
+ new Grad(-1, 0, 1),
43
+ new Grad(1, 0, -1),
44
+ new Grad(-1, 0, -1),
45
+ new Grad(0, 1, 1),
46
+ new Grad(0, -1, 1),
47
+ new Grad(0, 1, -1),
48
+ new Grad(0, -1, -1)
49
+ ];
50
+
51
+ const p: Array<number> = [
52
+ 151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23,
53
+ 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33, 88, 237, 149, 56, 87, 174, 20,
54
+ 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, 230, 220,
55
+ 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, 200, 196,
56
+ 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255,
57
+ 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, 223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221,
58
+ 153, 101, 155, 167, 43, 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228,
59
+ 251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, 181, 199, 106,
60
+ 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78,
61
+ 66, 215, 61, 156, 180
62
+ ];
63
+ // To remove the need for index wrapping, double the permutation table length
64
+ // const perm = new Array<number>(512);
65
+ // const gradP = new Array<Grad>(512);
66
+
67
+ // Skewing and unskewing factors for 2, 3, and 4 dimensions
68
+ const F2 = 0.5 * (Math.sqrt(3) - 1);
69
+ const G2 = (3 - Math.sqrt(3)) / 6;
70
+
71
+ const F3 = 1 / 3;
72
+ const G3 = 1 / 6;
73
+
74
+ const fade = (t: number) => {
75
+ return t * t * t * (t * (t * 6 - 15) + 10);
76
+ };
77
+
78
+ const lerp = (a: number, b: number, t: number) => {
79
+ return (1 - t) * a + t * b;
80
+ };
81
+
82
+ // export const noise = {
83
+ export class PerlinNoise {
84
+ // To remove the need for index wrapping, double the permutation table length
85
+ perm = new Array<number>(512);
86
+ gradP = new Array<Grad>(512);
87
+
88
+ constructor() {
89
+ // Use initial seed.
90
+ this.seed(0);
91
+ }
92
+
93
+ // This isn't a very good seeding function, but it works ok. It supports 2^16
94
+ // different seed values. Write something better if you need more seeds.
95
+ // module.seed = function (seed) {
96
+ seed(seed: number): PerlinNoise {
97
+ if (seed > 0 && seed < 1) {
98
+ // Scale the seed out
99
+ seed *= 65536;
100
+ }
101
+
102
+ seed = Math.floor(seed);
103
+ if (seed < 256) {
104
+ seed |= seed << 8;
105
+ }
106
+
107
+ for (var i = 0; i < 256; i++) {
108
+ var v: number;
109
+ if (i & 1) {
110
+ v = p[i] ^ (seed & 255);
111
+ } else {
112
+ v = p[i] ^ ((seed >> 8) & 255);
113
+ }
114
+
115
+ this.perm[i] = this.perm[i + 256] = v;
116
+ this.gradP[i] = this.gradP[i + 256] = grad3[v % 12];
117
+ }
118
+ return this;
119
+ }
120
+
121
+ // 2D simplex noise
122
+ simplex2(xin: number, yin: number): number {
123
+ var n0: number, n1: number, n2: number; // Noise contributions from the three corners
124
+ // Skew the input space to determine which simplex cell we're in
125
+ const s = (xin + yin) * F2; // Hairy factor for 2D
126
+ var i: number = Math.floor(xin + s);
127
+ var j: number = Math.floor(yin + s);
128
+ const t: number = (i + j) * G2;
129
+ const x0: number = xin - i + t; // The x,y distances from the cell origin, unskewed.
130
+ const y0: number = yin - j + t;
131
+ // For the 2D case, the simplex shape is an equilateral triangle.
132
+ // Determine which simplex we are in.
133
+ var i1: number, j1: number; // Offsets for second (middle) corner of simplex in (i,j) coords
134
+ if (x0 > y0) {
135
+ // lower triangle, XY order: (0,0)->(1,0)->(1,1)
136
+ i1 = 1;
137
+ j1 = 0;
138
+ } else {
139
+ // upper triangle, YX order: (0,0)->(0,1)->(1,1)
140
+ i1 = 0;
141
+ j1 = 1;
142
+ }
143
+ // A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and
144
+ // a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where
145
+ // c = (3-sqrt(3))/6
146
+ const x1 = x0 - i1 + G2; // Offsets for middle corner in (x,y) unskewed coords
147
+ const y1 = y0 - j1 + G2;
148
+ const x2 = x0 - 1 + 2 * G2; // Offsets for last corner in (x,y) unskewed coords
149
+ const y2 = y0 - 1 + 2 * G2;
150
+ // Work out the hashed gradient indices of the three simplex corners
151
+ i &= 255;
152
+ j &= 255;
153
+ const gi0 = this.gradP[i + this.perm[j]];
154
+ const gi1 = this.gradP[i + i1 + this.perm[j + j1]];
155
+ const gi2 = this.gradP[i + 1 + this.perm[j + 1]];
156
+ // Calculate the contribution from the three corners
157
+ var t0 = 0.5 - x0 * x0 - y0 * y0;
158
+ if (t0 < 0) {
159
+ n0 = 0;
160
+ } else {
161
+ t0 *= t0;
162
+ n0 = t0 * t0 * gi0.dot2(x0, y0); // (x,y) of grad3 used for 2D gradient
163
+ }
164
+ var t1 = 0.5 - x1 * x1 - y1 * y1;
165
+ if (t1 < 0) {
166
+ n1 = 0;
167
+ } else {
168
+ t1 *= t1;
169
+ n1 = t1 * t1 * gi1.dot2(x1, y1);
170
+ }
171
+ var t2 = 0.5 - x2 * x2 - y2 * y2;
172
+ if (t2 < 0) {
173
+ n2 = 0;
174
+ } else {
175
+ t2 *= t2;
176
+ n2 = t2 * t2 * gi2.dot2(x2, y2);
177
+ }
178
+ // Add contributions from each corner to get the final noise value.
179
+ // The result is scaled to return values in the interval [-1,1].
180
+ return 70 * (n0 + n1 + n2);
181
+ }
182
+
183
+ // 3D simplex noise
184
+ simplex3(xin: number, yin: number, zin: number): number {
185
+ var n0: number, n1: number, n2: number, n3: number; // Noise contributions from the four corners
186
+
187
+ // Skew the input space to determine which simplex cell we're in
188
+ const s: number = (xin + yin + zin) * F3; // Hairy factor for 2D
189
+ var i: number = Math.floor(xin + s);
190
+ var j: number = Math.floor(yin + s);
191
+ var k: number = Math.floor(zin + s);
192
+
193
+ const t: number = (i + j + k) * G3;
194
+ const x0: number = xin - i + t; // The x,y distances from the cell origin, unskewed.
195
+ const y0: number = yin - j + t;
196
+ const z0: number = zin - k + t;
197
+
198
+ // For the 3D case, the simplex shape is a slightly irregular tetrahedron.
199
+ // Determine which simplex we are in.
200
+ var i1: number, j1: number, k1: number; // Offsets for second corner of simplex in (i,j,k) coords
201
+ var i2: number, j2: number, k2: number; // Offsets for third corner of simplex in (i,j,k) coords
202
+ if (x0 >= y0) {
203
+ if (y0 >= z0) {
204
+ i1 = 1;
205
+ j1 = 0;
206
+ k1 = 0;
207
+ i2 = 1;
208
+ j2 = 1;
209
+ k2 = 0;
210
+ } else if (x0 >= z0) {
211
+ i1 = 1;
212
+ j1 = 0;
213
+ k1 = 0;
214
+ i2 = 1;
215
+ j2 = 0;
216
+ k2 = 1;
217
+ } else {
218
+ i1 = 0;
219
+ j1 = 0;
220
+ k1 = 1;
221
+ i2 = 1;
222
+ j2 = 0;
223
+ k2 = 1;
224
+ }
225
+ } else {
226
+ if (y0 < z0) {
227
+ i1 = 0;
228
+ j1 = 0;
229
+ k1 = 1;
230
+ i2 = 0;
231
+ j2 = 1;
232
+ k2 = 1;
233
+ } else if (x0 < z0) {
234
+ i1 = 0;
235
+ j1 = 1;
236
+ k1 = 0;
237
+ i2 = 0;
238
+ j2 = 1;
239
+ k2 = 1;
240
+ } else {
241
+ i1 = 0;
242
+ j1 = 1;
243
+ k1 = 0;
244
+ i2 = 1;
245
+ j2 = 1;
246
+ k2 = 0;
247
+ }
248
+ }
249
+ // A step of (1,0,0) in (i,j,k) means a step of (1-c,-c,-c) in (x,y,z),
250
+ // a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and
251
+ // a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where
252
+ // c = 1/6.
253
+ const x1: number = x0 - i1 + G3; // Offsets for second corner
254
+ const y1: number = y0 - j1 + G3;
255
+ const z1: number = z0 - k1 + G3;
256
+
257
+ const x2: number = x0 - i2 + 2 * G3; // Offsets for third corner
258
+ const y2: number = y0 - j2 + 2 * G3;
259
+ const z2: number = z0 - k2 + 2 * G3;
260
+
261
+ const x3: number = x0 - 1 + 3 * G3; // Offsets for fourth corner
262
+ const y3: number = y0 - 1 + 3 * G3;
263
+ const z3: number = z0 - 1 + 3 * G3;
264
+
265
+ // Work out the hashed gradient indices of the four simplex corners
266
+ i &= 255;
267
+ j &= 255;
268
+ k &= 255;
269
+ const gi0: Grad = this.gradP[i + this.perm[j + this.perm[k]]];
270
+ const gi1: Grad = this.gradP[i + i1 + this.perm[j + j1 + this.perm[k + k1]]];
271
+ const gi2: Grad = this.gradP[i + i2 + this.perm[j + j2 + this.perm[k + k2]]];
272
+ const gi3: Grad = this.gradP[i + 1 + this.perm[j + 1 + this.perm[k + 1]]];
273
+
274
+ // Calculate the contribution from the four corners
275
+ var t0: number = 0.5 - x0 * x0 - y0 * y0 - z0 * z0;
276
+ if (t0 < 0) {
277
+ n0 = 0;
278
+ } else {
279
+ t0 *= t0;
280
+ n0 = t0 * t0 * gi0.dot3(x0, y0, z0); // (x,y) of grad3 used for 2D gradient
281
+ }
282
+ var t1 = 0.5 - x1 * x1 - y1 * y1 - z1 * z1;
283
+ if (t1 < 0) {
284
+ n1 = 0;
285
+ } else {
286
+ t1 *= t1;
287
+ n1 = t1 * t1 * gi1.dot3(x1, y1, z1);
288
+ }
289
+ var t2 = 0.5 - x2 * x2 - y2 * y2 - z2 * z2;
290
+ if (t2 < 0) {
291
+ n2 = 0;
292
+ } else {
293
+ t2 *= t2;
294
+ n2 = t2 * t2 * gi2.dot3(x2, y2, z2);
295
+ }
296
+ var t3 = 0.5 - x3 * x3 - y3 * y3 - z3 * z3;
297
+ if (t3 < 0) {
298
+ n3 = 0;
299
+ } else {
300
+ t3 *= t3;
301
+ n3 = t3 * t3 * gi3.dot3(x3, y3, z3);
302
+ }
303
+ // Add contributions from each corner to get the final noise value.
304
+ // The result is scaled to return values in the interval [-1,1].
305
+ return 32 * (n0 + n1 + n2 + n3);
306
+ }
307
+
308
+ // 2D Perlin Noise
309
+ perlin2(x_init: number, y_init: number): number {
310
+ // Find unit grid cell containing point
311
+ var X: number = Math.floor(x_init),
312
+ Y: number = Math.floor(y_init);
313
+ // Get relative xy coordinates of point within that cell
314
+ const x: number = x_init - X;
315
+ const y: number = y_init - Y;
316
+ // Wrap the integer cells at 255 (smaller integer period can be introduced here)
317
+ X = X & 255;
318
+ Y = Y & 255;
319
+
320
+ // Calculate noise contributions from each of the four corners
321
+ const n00: number = this.gradP[X + this.perm[Y]].dot2(x, y);
322
+ const n01: number = this.gradP[X + this.perm[Y + 1]].dot2(x, y - 1);
323
+ const n10: number = this.gradP[X + 1 + this.perm[Y]].dot2(x - 1, y);
324
+ const n11: number = this.gradP[X + 1 + this.perm[Y + 1]].dot2(x - 1, y - 1);
325
+
326
+ // Compute the fade curve value for x
327
+ const u: number = fade(x);
328
+
329
+ // Interpolate the four results
330
+ return lerp(lerp(n00, n10, u), lerp(n01, n11, u), fade(y));
331
+ }
332
+
333
+ // 3D Perlin Noise
334
+ perlin3(x_init: number, y_init: number, z_init: number): number {
335
+ // Find unit grid cell containing point
336
+ var X: number = Math.floor(x_init),
337
+ Y: number = Math.floor(y_init),
338
+ Z: number = Math.floor(z_init);
339
+ // Get relative xyz coordinates of point within that cell
340
+ const x: number = x_init - X;
341
+ const y: number = y_init - Y;
342
+ const z: number = z_init - Z;
343
+ // Wrap the integer cells at 255 (smaller integer period can be introduced here)
344
+ X = X & 255;
345
+ Y = Y & 255;
346
+ Z = Z & 255;
347
+
348
+ // Calculate noise contributions from each of the eight corners
349
+ const n000: number = this.gradP[X + this.perm[Y + this.perm[Z]]].dot3(x, y, z);
350
+ const n001: number = this.gradP[X + this.perm[Y + this.perm[Z + 1]]].dot3(x, y, z - 1);
351
+ const n010: number = this.gradP[X + this.perm[Y + 1 + this.perm[Z]]].dot3(x, y - 1, z);
352
+ const n011: number = this.gradP[X + this.perm[Y + 1 + this.perm[Z + 1]]].dot3(x, y - 1, z - 1);
353
+ const n100: number = this.gradP[X + 1 + this.perm[Y + this.perm[Z]]].dot3(x - 1, y, z);
354
+ const n101: number = this.gradP[X + 1 + this.perm[Y + this.perm[Z + 1]]].dot3(x - 1, y, z - 1);
355
+ const n110: number = this.gradP[X + 1 + this.perm[Y + 1 + this.perm[Z]]].dot3(x - 1, y - 1, z);
356
+ const n111: number = this.gradP[X + 1 + this.perm[Y + 1 + this.perm[Z + 1]]].dot3(x - 1, y - 1, z - 1);
357
+
358
+ // Compute the fade curve value for x, y, z
359
+ const u: number = fade(x);
360
+ const v: number = fade(y);
361
+ const w: number = fade(z);
362
+
363
+ // Interpolate
364
+ return lerp(lerp(lerp(n000, n100, u), lerp(n001, n101, u), w), lerp(lerp(n010, n110, u), lerp(n011, n111, u), w), v);
365
+ }
366
+ }
367
+
368
+ // noise.seed(0);
@@ -0,0 +1,55 @@
1
+ /**
2
+ * A collection of SVG path generation tools.
3
+ *
4
+ * @author Ikaros Kappler
5
+ * @date 2025-04-04
6
+ * @version 1.0.0
7
+ */
8
+
9
+ import { Circle } from "../Circle";
10
+ import { Vertex } from "../Vertex";
11
+ import { geomutils } from "../geomutils";
12
+ import { SVGPathParams } from "../interfaces";
13
+
14
+ export const SVGPathUtils = {
15
+ /**
16
+ * Creates an SVG shape resembling a circlular ring sector.
17
+ *
18
+ * @param {Vertex} center - The center position of the ring.
19
+ * @param {number} innerRadius - The inner radius of the ring.
20
+ * @param {number} outerRadius - The outer radius of the ring.
21
+ * @param {number} startAngle - The start angle of the ring.
22
+ * @param {number} endAngle - The end angle of the ring.
23
+ * @returns {SVGPathParams} SVG path parmams for a closed shape representing the circular ring sector.
24
+ */
25
+ mkCircularRingSector: (
26
+ center: Vertex,
27
+ innerRadius: number,
28
+ outerRadius: number,
29
+ startAngle: number,
30
+ endAngle: number
31
+ ): SVGPathParams => {
32
+ const innerStart: Vertex = Circle.circleUtils.vertAt(startAngle, innerRadius).add(center);
33
+ const innerEnd: Vertex = Circle.circleUtils.vertAt(endAngle, innerRadius).add(center);
34
+ const outerStart: Vertex = Circle.circleUtils.vertAt(startAngle, outerRadius).add(center);
35
+ const outerEnd: Vertex = Circle.circleUtils.vertAt(endAngle, outerRadius).add(center);
36
+
37
+ const buffer: SVGPathParams = ["M", innerStart.x, innerStart.y];
38
+ // var isLargeArcRequired = geomutils.mapAngleTo2PI(Math.abs(startAngle - endAngle)) >= Math.PI;
39
+ // var isLargeArcRequired = Math.abs(geomutils.mapAngleTo2PI(startAngle) - geomutils.mapAngleTo2PI(endAngle)) >= Math.PI;
40
+ const isLargeArcRequired =
41
+ geomutils.mapAngleTo2PI(geomutils.mapAngleTo2PI(startAngle) - geomutils.mapAngleTo2PI(endAngle)) >= Math.PI;
42
+
43
+ const rotation: number = 0.0;
44
+ const innerLargeArcFlag: number = isLargeArcRequired ? 0 : 1;
45
+ const innerSweepFlag: number = 1; // isLargeArcRequired ? 1 : 0; // 1;
46
+ const outerLargeArcFlag: number = isLargeArcRequired ? 0 : 1;
47
+ const outerSweepFlag: number = 0; // isLargeArcRequired ? 0 : 1; // 0;
48
+ buffer.push("A", innerRadius, innerRadius, rotation, innerLargeArcFlag, innerSweepFlag, innerEnd.x, innerEnd.y);
49
+ buffer.push("L", outerEnd.x, outerEnd.y);
50
+ buffer.push("A", outerRadius, outerRadius, rotation, outerLargeArcFlag, outerSweepFlag, outerStart.x, outerStart.y);
51
+ buffer.push("Z");
52
+
53
+ return buffer;
54
+ }
55
+ };