math 0.0.3 → 0.1.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 (203) hide show
  1. package/API.md +1605 -0
  2. package/LICENSE +21 -0
  3. package/README.md +197 -0
  4. package/dist/color/color.js +136 -0
  5. package/dist/color/color.js.map +1 -0
  6. package/dist/color/colorspace.js +43 -0
  7. package/dist/color/colorspace.js.map +1 -0
  8. package/dist/color/hsl.js +123 -0
  9. package/dist/color/hsl.js.map +1 -0
  10. package/dist/color/index.js +7 -0
  11. package/dist/color/index.js.map +1 -0
  12. package/dist/color/parse.js +276 -0
  13. package/dist/color/parse.js.map +1 -0
  14. package/dist/core/angle.js +43 -0
  15. package/dist/core/angle.js.map +1 -0
  16. package/dist/core/euler.js +212 -0
  17. package/dist/core/euler.js.map +1 -0
  18. package/dist/core/mat2.js +385 -0
  19. package/dist/core/mat2.js.map +1 -0
  20. package/dist/core/mat2d.js +422 -0
  21. package/dist/core/mat2d.js.map +1 -0
  22. package/dist/core/mat3.js +749 -0
  23. package/dist/core/mat3.js.map +1 -0
  24. package/dist/core/mat4.js +2197 -0
  25. package/dist/core/mat4.js.map +1 -0
  26. package/dist/core/polar.js +200 -0
  27. package/dist/core/polar.js.map +1 -0
  28. package/dist/core/quat.js +730 -0
  29. package/dist/core/quat.js.map +1 -0
  30. package/dist/core/quat2.js +883 -0
  31. package/dist/core/quat2.js.map +1 -0
  32. package/dist/core/scalar.js +112 -0
  33. package/dist/core/scalar.js.map +1 -0
  34. package/dist/core/spherical.js +248 -0
  35. package/dist/core/spherical.js.map +1 -0
  36. package/dist/core/vec2.js +597 -0
  37. package/dist/core/vec2.js.map +1 -0
  38. package/dist/core/vec3.js +916 -0
  39. package/dist/core/vec3.js.map +1 -0
  40. package/dist/core/vec4.js +573 -0
  41. package/dist/core/vec4.js.map +1 -0
  42. package/dist/geometry/circumcircle.js +39 -0
  43. package/dist/geometry/circumcircle.js.map +1 -0
  44. package/dist/geometry/index.js +6 -0
  45. package/dist/geometry/index.js.map +1 -0
  46. package/dist/geometry/polygon2-decompose.js +411 -0
  47. package/dist/geometry/polygon2-decompose.js.map +1 -0
  48. package/dist/geometry/polygon2-triangulate.js +222 -0
  49. package/dist/geometry/polygon2-triangulate.js.map +1 -0
  50. package/dist/geometry/quickhull2.js +123 -0
  51. package/dist/geometry/quickhull2.js.map +1 -0
  52. package/dist/geometry/quickhull3.js +605 -0
  53. package/dist/geometry/quickhull3.js.map +1 -0
  54. package/dist/ik/fabrik2.js +675 -0
  55. package/dist/ik/fabrik2.js.map +1 -0
  56. package/dist/ik/fabrik3.js +912 -0
  57. package/dist/ik/fabrik3.js.map +1 -0
  58. package/dist/ik/index.js +5 -0
  59. package/dist/ik/index.js.map +1 -0
  60. package/dist/index.js +27 -0
  61. package/dist/index.js.map +1 -0
  62. package/dist/noise/fractal.js +185 -0
  63. package/dist/noise/fractal.js.map +1 -0
  64. package/dist/noise/index.js +16 -0
  65. package/dist/noise/index.js.map +1 -0
  66. package/dist/noise/perlin2d.js +50 -0
  67. package/dist/noise/perlin2d.js.map +1 -0
  68. package/dist/noise/perlin3d.js +72 -0
  69. package/dist/noise/perlin3d.js.map +1 -0
  70. package/dist/noise/permutation.js +120 -0
  71. package/dist/noise/permutation.js.map +1 -0
  72. package/dist/noise/simplex2d.js +84 -0
  73. package/dist/noise/simplex2d.js.map +1 -0
  74. package/dist/noise/simplex3d.js +147 -0
  75. package/dist/noise/simplex3d.js.map +1 -0
  76. package/dist/noise/simplex4d.js +149 -0
  77. package/dist/noise/simplex4d.js.map +1 -0
  78. package/dist/noise/worley2d.js +50 -0
  79. package/dist/noise/worley2d.js.map +1 -0
  80. package/dist/noise/worley3d.js +61 -0
  81. package/dist/noise/worley3d.js.map +1 -0
  82. package/dist/random/index.js +9 -0
  83. package/dist/random/index.js.map +1 -0
  84. package/dist/random/isaac32.js +164 -0
  85. package/dist/random/isaac32.js.map +1 -0
  86. package/dist/random/isaac64.js +215 -0
  87. package/dist/random/isaac64.js.map +1 -0
  88. package/dist/random/mulberry32.js +48 -0
  89. package/dist/random/mulberry32.js.map +1 -0
  90. package/dist/random/random.js +120 -0
  91. package/dist/random/random.js.map +1 -0
  92. package/dist/shapes/box2.js +300 -0
  93. package/dist/shapes/box2.js.map +1 -0
  94. package/dist/shapes/box3.js +550 -0
  95. package/dist/shapes/box3.js.map +1 -0
  96. package/dist/shapes/circle.js +6 -0
  97. package/dist/shapes/circle.js.map +1 -0
  98. package/dist/shapes/frustum.js +662 -0
  99. package/dist/shapes/frustum.js.map +1 -0
  100. package/dist/shapes/index.js +25 -0
  101. package/dist/shapes/index.js.map +1 -0
  102. package/dist/shapes/obb3.js +557 -0
  103. package/dist/shapes/obb3.js.map +1 -0
  104. package/dist/shapes/plane3.js +267 -0
  105. package/dist/shapes/plane3.js.map +1 -0
  106. package/dist/shapes/polygon2.js +451 -0
  107. package/dist/shapes/polygon2.js.map +1 -0
  108. package/dist/shapes/raycast3.js +164 -0
  109. package/dist/shapes/raycast3.js.map +1 -0
  110. package/dist/shapes/segment2.js +82 -0
  111. package/dist/shapes/segment2.js.map +1 -0
  112. package/dist/shapes/sphere.js +23 -0
  113. package/dist/shapes/sphere.js.map +1 -0
  114. package/dist/shapes/triangle2.js +79 -0
  115. package/dist/shapes/triangle2.js.map +1 -0
  116. package/dist/shapes/triangle3.js +60 -0
  117. package/dist/shapes/triangle3.js.map +1 -0
  118. package/dist/src/color/color.d.ts +50 -0
  119. package/dist/src/color/colorspace.d.ts +15 -0
  120. package/dist/src/color/hsl.d.ts +28 -0
  121. package/dist/src/color/index.d.ts +5 -0
  122. package/dist/src/color/parse.d.ts +15 -0
  123. package/dist/src/core/angle.d.ts +29 -0
  124. package/dist/src/core/arrays.d.ts +4 -0
  125. package/dist/src/core/euler.d.ts +78 -0
  126. package/dist/src/core/index.d.ts +27 -0
  127. package/dist/src/core/mat2.d.ts +217 -0
  128. package/dist/src/core/mat2d.d.ts +218 -0
  129. package/dist/src/core/mat3.d.ts +295 -0
  130. package/dist/src/core/mat4.d.ts +667 -0
  131. package/dist/src/core/polar.d.ts +151 -0
  132. package/dist/src/core/quat.d.ts +370 -0
  133. package/dist/src/core/quat2.d.ts +344 -0
  134. package/dist/src/core/scalar.d.ts +75 -0
  135. package/dist/src/core/spherical.d.ts +165 -0
  136. package/dist/src/core/vec2.d.ts +403 -0
  137. package/dist/src/core/vec3.d.ts +493 -0
  138. package/dist/src/core/vec4.d.ts +336 -0
  139. package/dist/src/geometry/circumcircle.d.ts +9 -0
  140. package/dist/src/geometry/index.d.ts +5 -0
  141. package/dist/src/geometry/polygon2-decompose.d.ts +25 -0
  142. package/dist/src/geometry/polygon2-triangulate.d.ts +15 -0
  143. package/dist/src/geometry/quickhull2.d.ts +10 -0
  144. package/dist/src/geometry/quickhull3.d.ts +27 -0
  145. package/dist/src/ik/fabrik2.d.ts +314 -0
  146. package/dist/src/ik/fabrik3.d.ts +371 -0
  147. package/dist/src/ik/index.d.ts +2 -0
  148. package/dist/src/index.d.ts +1 -0
  149. package/dist/src/noise/fractal.d.ts +95 -0
  150. package/dist/src/noise/index.d.ts +9 -0
  151. package/dist/src/noise/perlin2d.d.ts +19 -0
  152. package/dist/src/noise/perlin3d.d.ts +20 -0
  153. package/dist/src/noise/permutation.d.ts +22 -0
  154. package/dist/src/noise/simplex2d.d.ts +19 -0
  155. package/dist/src/noise/simplex3d.d.ts +20 -0
  156. package/dist/src/noise/simplex4d.d.ts +24 -0
  157. package/dist/src/noise/worley2d.d.ts +22 -0
  158. package/dist/src/noise/worley3d.d.ts +23 -0
  159. package/dist/src/random/index.d.ts +8 -0
  160. package/dist/src/random/isaac32.d.ts +62 -0
  161. package/dist/src/random/isaac64.d.ts +75 -0
  162. package/dist/src/random/mulberry32.d.ts +43 -0
  163. package/dist/src/random/random.d.ts +67 -0
  164. package/dist/src/shapes/box2.d.ts +174 -0
  165. package/dist/src/shapes/box3.d.ts +213 -0
  166. package/dist/src/shapes/circle.d.ts +7 -0
  167. package/dist/src/shapes/frustum.d.ts +147 -0
  168. package/dist/src/shapes/index.d.ts +20 -0
  169. package/dist/src/shapes/obb3.d.ts +105 -0
  170. package/dist/src/shapes/plane3.d.ts +130 -0
  171. package/dist/src/shapes/polygon2.d.ts +155 -0
  172. package/dist/src/shapes/raycast3.d.ts +42 -0
  173. package/dist/src/shapes/segment2.d.ts +34 -0
  174. package/dist/src/shapes/sphere.d.ts +19 -0
  175. package/dist/src/shapes/triangle2.d.ts +53 -0
  176. package/dist/src/shapes/triangle3.d.ts +29 -0
  177. package/dist/src/time/easing.d.ts +21 -0
  178. package/dist/src/time/index.d.ts +6 -0
  179. package/dist/src/time/spring-core.d.ts +15 -0
  180. package/dist/src/time/spring.d.ts +36 -0
  181. package/dist/src/time/spring2.d.ts +11 -0
  182. package/dist/src/time/spring3.d.ts +11 -0
  183. package/dist/src/time/spring4.d.ts +11 -0
  184. package/dist/time/easing.js +24 -0
  185. package/dist/time/easing.js.map +1 -0
  186. package/dist/time/index.js +11 -0
  187. package/dist/time/index.js.map +1 -0
  188. package/dist/time/spring-core.js +48 -0
  189. package/dist/time/spring-core.js.map +1 -0
  190. package/dist/time/spring.js +62 -0
  191. package/dist/time/spring.js.map +1 -0
  192. package/dist/time/spring2.js +31 -0
  193. package/dist/time/spring2.js.map +1 -0
  194. package/dist/time/spring3.js +32 -0
  195. package/dist/time/spring3.js.map +1 -0
  196. package/dist/time/spring4.js +32 -0
  197. package/dist/time/spring4.js.map +1 -0
  198. package/package.json +90 -16
  199. package/skills/math/SKILL.md +140 -0
  200. package/AUTHORS +0 -1
  201. package/Cakefile +0 -28
  202. package/math.coffee +0 -112
  203. package/math.js +0 -141
@@ -0,0 +1,120 @@
1
+ // Adapated from https://github.com/josephg/noisejs
2
+ //
3
+ // ```
4
+ // A speed-improved perlin and simplex noise algorithms for 2D.
5
+ //
6
+ // Based on example code by Stefan Gustavson (stegu@itn.liu.se).
7
+ // Optimisations by Peter Eastman (peastman@drizzle.stanford.edu).
8
+ // Better rank ordering method by Stefan Gustavson in 2012.
9
+ // Converted to Javascript by Joseph Gentle.
10
+ //
11
+ // Version 2012-03-09
12
+ //
13
+ // This code was placed in the public domain by its original author,
14
+ // Stefan Gustavson. You may use it as you see fit, but
15
+ // attribution is appreciated.
16
+ // ```
17
+ // the 12 3D gradient directions (edges of a cube), indexed by perm value % 12
18
+ const GRAD3 = [
19
+ [1, 1, 0],
20
+ [-1, 1, 0],
21
+ [1, -1, 0],
22
+ [-1, -1, 0],
23
+ [1, 0, 1],
24
+ [-1, 0, 1],
25
+ [1, 0, -1],
26
+ [-1, 0, -1],
27
+ [0, 1, 1],
28
+ [0, -1, 1],
29
+ [0, 1, -1],
30
+ [0, -1, -1],
31
+ ];
32
+ // the 32 4D gradient directions (edges of a hypercube), indexed by perm value % 32
33
+ const GRAD4 = [
34
+ [0, 1, 1, 1],
35
+ [0, 1, 1, -1],
36
+ [0, 1, -1, 1],
37
+ [0, 1, -1, -1],
38
+ [0, -1, 1, 1],
39
+ [0, -1, 1, -1],
40
+ [0, -1, -1, 1],
41
+ [0, -1, -1, -1],
42
+ [1, 0, 1, 1],
43
+ [1, 0, 1, -1],
44
+ [1, 0, -1, 1],
45
+ [1, 0, -1, -1],
46
+ [-1, 0, 1, 1],
47
+ [-1, 0, 1, -1],
48
+ [-1, 0, -1, 1],
49
+ [-1, 0, -1, -1],
50
+ [1, 1, 0, 1],
51
+ [1, 1, 0, -1],
52
+ [1, -1, 0, 1],
53
+ [1, -1, 0, -1],
54
+ [-1, 1, 0, 1],
55
+ [-1, 1, 0, -1],
56
+ [-1, -1, 0, 1],
57
+ [-1, -1, 0, -1],
58
+ [1, 1, 1, 0],
59
+ [1, 1, -1, 0],
60
+ [1, -1, 1, 0],
61
+ [1, -1, -1, 0],
62
+ [-1, 1, 1, 0],
63
+ [-1, 1, -1, 0],
64
+ [-1, -1, 1, 0],
65
+ [-1, -1, -1, 0],
66
+ ];
67
+ const p = [
68
+ 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,
69
+ 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,
70
+ 20, 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,
71
+ 220, 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,
72
+ 200, 196, 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,
73
+ 126, 255, 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,
74
+ 163, 70, 221, 153, 101, 155, 167, 43, 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218,
75
+ 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31,
76
+ 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243,
77
+ 141, 128, 195, 78, 66, 215, 61, 156, 180,
78
+ ];
79
+ /**
80
+ * Creates the seeded permutation and gradient tables for a noise generator.
81
+ *
82
+ * @param seed The seed value for the noise generator
83
+ * @returns The permutation tables derived from the seed
84
+ */
85
+ function createPermutation(seed) {
86
+ if (seed > 0 && seed < 1) {
87
+ // Scale the seed out
88
+ seed *= 65536;
89
+ }
90
+ seed = Math.floor(seed);
91
+ if (seed < 256) {
92
+ seed |= seed << 8;
93
+ }
94
+ // To remove the need for index wrapping, double the permutation table length
95
+ const perm = new Uint8Array(512);
96
+ const grad3 = new Float64Array(512 * 3);
97
+ const grad4 = new Float64Array(512 * 4);
98
+ for (let i = 0; i < 256; i++) {
99
+ let v;
100
+ if (i & 1) {
101
+ v = p[i] ^ (seed & 255);
102
+ }
103
+ else {
104
+ v = p[i] ^ ((seed >> 8) & 255);
105
+ }
106
+ perm[i] = perm[i + 256] = v;
107
+ const g3 = GRAD3[v % 12];
108
+ const g4 = GRAD4[v % 32];
109
+ for (let k = 0; k < 3; k++) {
110
+ grad3[i * 3 + k] = grad3[(i + 256) * 3 + k] = g3[k];
111
+ }
112
+ for (let k = 0; k < 4; k++) {
113
+ grad4[i * 4 + k] = grad4[(i + 256) * 4 + k] = g4[k];
114
+ }
115
+ }
116
+ return { perm, grad3, grad4 };
117
+ }
118
+
119
+ export { createPermutation };
120
+ //# sourceMappingURL=permutation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permutation.js","sources":["../../src/noise/permutation.ts"],"sourcesContent":["// Adapated from https://github.com/josephg/noisejs\n//\n// ```\n// A speed-improved perlin and simplex noise algorithms for 2D.\n//\n// Based on example code by Stefan Gustavson (stegu@itn.liu.se).\n// Optimisations by Peter Eastman (peastman@drizzle.stanford.edu).\n// Better rank ordering method by Stefan Gustavson in 2012.\n// Converted to Javascript by Joseph Gentle.\n//\n// Version 2012-03-09\n//\n// This code was placed in the public domain by its original author,\n// Stefan Gustavson. You may use it as you see fit, but\n// attribution is appreciated.\n// ```\n\n/**\n * Seeded permutation and gradient tables that back a noise generator.\n *\n * All noise variants (simplex/perlin, 2D/3D/4D) share this same table shape, so\n * each generator type is a structural alias of this. `perm` is the doubled\n * (512 entry) permutation table. `grad3` holds the 3D gradient for each\n * permutation index as flat xyz triples (used by 2D and 3D noise), and `grad4`\n * holds the 4D gradient for each index as flat xyzw quads. Flat typed arrays\n * keep sampling free of nested array loads and allocation.\n */\nexport type Permutation = { perm: Uint8Array; grad3: Float64Array; grad4: Float64Array };\n\n// the 12 3D gradient directions (edges of a cube), indexed by perm value % 12\nconst GRAD3: number[][] = [\n [1, 1, 0],\n [-1, 1, 0],\n [1, -1, 0],\n [-1, -1, 0],\n [1, 0, 1],\n [-1, 0, 1],\n [1, 0, -1],\n [-1, 0, -1],\n [0, 1, 1],\n [0, -1, 1],\n [0, 1, -1],\n [0, -1, -1],\n];\n\n// the 32 4D gradient directions (edges of a hypercube), indexed by perm value % 32\nconst GRAD4: number[][] = [\n [0, 1, 1, 1],\n [0, 1, 1, -1],\n [0, 1, -1, 1],\n [0, 1, -1, -1],\n [0, -1, 1, 1],\n [0, -1, 1, -1],\n [0, -1, -1, 1],\n [0, -1, -1, -1],\n [1, 0, 1, 1],\n [1, 0, 1, -1],\n [1, 0, -1, 1],\n [1, 0, -1, -1],\n [-1, 0, 1, 1],\n [-1, 0, 1, -1],\n [-1, 0, -1, 1],\n [-1, 0, -1, -1],\n [1, 1, 0, 1],\n [1, 1, 0, -1],\n [1, -1, 0, 1],\n [1, -1, 0, -1],\n [-1, 1, 0, 1],\n [-1, 1, 0, -1],\n [-1, -1, 0, 1],\n [-1, -1, 0, -1],\n [1, 1, 1, 0],\n [1, 1, -1, 0],\n [1, -1, 1, 0],\n [1, -1, -1, 0],\n [-1, 1, 1, 0],\n [-1, 1, -1, 0],\n [-1, -1, 1, 0],\n [-1, -1, -1, 0],\n];\n\nconst p = [\n 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,\n 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,\n 20, 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,\n 220, 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,\n 200, 196, 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,\n 126, 255, 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,\n 163, 70, 221, 153, 101, 155, 167, 43, 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218,\n 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31,\n 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243,\n 141, 128, 195, 78, 66, 215, 61, 156, 180,\n];\n\n/**\n * Creates the seeded permutation and gradient tables for a noise generator.\n *\n * @param seed The seed value for the noise generator\n * @returns The permutation tables derived from the seed\n */\nexport function createPermutation(seed: number): Permutation {\n if (seed > 0 && seed < 1) {\n // Scale the seed out\n seed *= 65536;\n }\n\n seed = Math.floor(seed);\n if (seed < 256) {\n seed |= seed << 8;\n }\n\n // To remove the need for index wrapping, double the permutation table length\n const perm = new Uint8Array(512);\n const grad3 = new Float64Array(512 * 3);\n const grad4 = new Float64Array(512 * 4);\n\n for (let i = 0; i < 256; i++) {\n let v: number;\n if (i & 1) {\n v = p[i] ^ (seed & 255);\n } else {\n v = p[i] ^ ((seed >> 8) & 255);\n }\n\n perm[i] = perm[i + 256] = v;\n\n const g3 = GRAD3[v % 12];\n const g4 = GRAD4[v % 32];\n for (let k = 0; k < 3; k++) {\n grad3[i * 3 + k] = grad3[(i + 256) * 3 + k] = g3[k];\n }\n for (let k = 0; k < 4; k++) {\n grad4[i * 4 + k] = grad4[(i + 256) * 4 + k] = g4[k];\n }\n }\n\n return { perm, grad3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AC;QACvD;IACJ;AAEA,IAAA,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE;AACjC;;;;"}
@@ -0,0 +1,84 @@
1
+ import { createPermutation } from './permutation.js';
2
+
3
+ // skewing and unskewing factors for 2 dimensions
4
+ const F2 = 0.5 * (Math.sqrt(3) - 1);
5
+ const G2 = (3 - Math.sqrt(3)) / 6;
6
+ /**
7
+ * Creates a 2D simplex noise generator with the given seed.
8
+ *
9
+ * @param seed The seed value for the noise generator
10
+ * @returns A generator to pass to {@link sample}
11
+ */
12
+ function create(seed) {
13
+ return createPermutation(seed);
14
+ }
15
+ /**
16
+ * Samples 2D simplex noise, returning a value in the interval [-1, 1].
17
+ *
18
+ * @param generator A generator created with {@link create}
19
+ * @param x X coordinate
20
+ * @param y Y coordinate
21
+ * @returns The noise value at (x, y)
22
+ */
23
+ function sample({ perm, grad3 }, x, y) {
24
+ // Skew the input space to determine which simplex cell we're in
25
+ const s = (x + y) * F2; // Hairy factor for 2D
26
+ let i = Math.floor(x + s);
27
+ let j = Math.floor(y + s);
28
+ const t = (i + j) * G2;
29
+ const x0 = x - i + t; // The x,y distances from the cell origin, unskewed.
30
+ const y0 = y - j + t;
31
+ // For the 2D case, the simplex shape is an equilateral triangle.
32
+ // Determine which simplex we are in.
33
+ let i1;
34
+ let j1; // Offsets for second (middle) corner of simplex in (i,j) coords
35
+ if (x0 > y0) {
36
+ // lower triangle, XY order: (0,0)->(1,0)->(1,1)
37
+ i1 = 1;
38
+ j1 = 0;
39
+ }
40
+ else {
41
+ // upper triangle, YX order: (0,0)->(0,1)->(1,1)
42
+ i1 = 0;
43
+ j1 = 1;
44
+ }
45
+ // A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and
46
+ // a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where
47
+ // c = (3-sqrt(3))/6
48
+ const x1 = x0 - i1 + G2; // Offsets for middle corner in (x,y) unskewed coords
49
+ const y1 = y0 - j1 + G2;
50
+ const x2 = x0 - 1 + 2 * G2; // Offsets for last corner in (x,y) unskewed coords
51
+ const y2 = y0 - 1 + 2 * G2;
52
+ // Work out the hashed gradient indices of the three simplex corners
53
+ // (flat xyz triples in grad3; only x and y are used for 2D)
54
+ i &= 255;
55
+ j &= 255;
56
+ const gi0 = (i + perm[j]) * 3;
57
+ const gi1 = (i + i1 + perm[j + j1]) * 3;
58
+ const gi2 = (i + 1 + perm[j + 1]) * 3;
59
+ // Calculate the contribution from the three corners
60
+ let n0 = 0;
61
+ let n1 = 0;
62
+ let n2 = 0;
63
+ let t0 = 0.5 - x0 * x0 - y0 * y0;
64
+ if (t0 >= 0) {
65
+ t0 *= t0;
66
+ n0 = t0 * t0 * (grad3[gi0] * x0 + grad3[gi0 + 1] * y0);
67
+ }
68
+ let t1 = 0.5 - x1 * x1 - y1 * y1;
69
+ if (t1 >= 0) {
70
+ t1 *= t1;
71
+ n1 = t1 * t1 * (grad3[gi1] * x1 + grad3[gi1 + 1] * y1);
72
+ }
73
+ let t2 = 0.5 - x2 * x2 - y2 * y2;
74
+ if (t2 >= 0) {
75
+ t2 *= t2;
76
+ n2 = t2 * t2 * (grad3[gi2] * x2 + grad3[gi2 + 1] * y2);
77
+ }
78
+ // Add contributions from each corner to get the final noise value.
79
+ // The result is scaled to return values in the interval [-1,1].
80
+ return 70 * (n0 + n1 + n2);
81
+ }
82
+
83
+ export { create, sample };
84
+ //# sourceMappingURL=simplex2d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simplex2d.js","sources":["../../src/noise/simplex2d.ts"],"sourcesContent":["import { createPermutation, type Permutation } from './permutation';\n\n/** A seeded 2D simplex noise generator. Create one with {@link create}. */\nexport type Simplex2DGenerator = Permutation;\n\n// skewing and unskewing factors for 2 dimensions\nconst F2 = 0.5 * (Math.sqrt(3) - 1);\nconst G2 = (3 - Math.sqrt(3)) / 6;\n\n/**\n * Creates a 2D simplex noise generator with the given seed.\n *\n * @param seed The seed value for the noise generator\n * @returns A generator to pass to {@link sample}\n */\nexport function create(seed: number): Simplex2DGenerator {\n return createPermutation(seed);\n}\n\n/**\n * Samples 2D simplex noise, returning a value in the interval [-1, 1].\n *\n * @param generator A generator created with {@link create}\n * @param x X coordinate\n * @param y Y coordinate\n * @returns The noise value at (x, y)\n */\nexport function sample({ perm, grad3 }: Simplex2DGenerator, x: number, y: number): number {\n // Skew the input space to determine which simplex cell we're in\n const s = (x + y) * F2; // Hairy factor for 2D\n let i = Math.floor(x + s);\n let j = Math.floor(y + s);\n const t = (i + j) * G2;\n const x0 = x - i + t; // The x,y distances from the cell origin, unskewed.\n const y0 = y - j + t;\n // For the 2D case, the simplex shape is an equilateral triangle.\n // Determine which simplex we are in.\n let i1: number;\n let j1: number; // Offsets for second (middle) corner of simplex in (i,j) coords\n if (x0 > y0) {\n // lower triangle, XY order: (0,0)->(1,0)->(1,1)\n i1 = 1;\n j1 = 0;\n } else {\n // upper triangle, YX order: (0,0)->(0,1)->(1,1)\n i1 = 0;\n j1 = 1;\n }\n // A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and\n // a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where\n // c = (3-sqrt(3))/6\n const x1 = x0 - i1 + G2; // Offsets for middle corner in (x,y) unskewed coords\n const y1 = y0 - j1 + G2;\n const x2 = x0 - 1 + 2 * G2; // Offsets for last corner in (x,y) unskewed coords\n const y2 = y0 - 1 + 2 * G2;\n // Work out the hashed gradient indices of the three simplex corners\n // (flat xyz triples in grad3; only x and y are used for 2D)\n i &= 255;\n j &= 255;\n const gi0 = (i + perm[j]) * 3;\n const gi1 = (i + i1 + perm[j + j1]) * 3;\n const gi2 = (i + 1 + perm[j + 1]) * 3;\n // Calculate the contribution from the three corners\n let n0 = 0;\n let n1 = 0;\n let n2 = 0;\n let t0 = 0.5 - x0 * x0 - y0 * y0;\n if (t0 >= 0) {\n t0 *= t0;\n n0 = t0 * t0 * (grad3[gi0] * x0 + grad3[gi0 + 1] * y0);\n }\n let t1 = 0.5 - x1 * x1 - y1 * y1;\n if (t1 >= 0) {\n t1 *= t1;\n n1 = t1 * t1 * (grad3[gi1] * x1 + grad3[gi1 + 1] * y1);\n }\n let t2 = 0.5 - x2 * x2 - y2 * y2;\n if (t2 >= 0) {\n t2 *= t2;\n n2 = t2 * t2 * (grad3[gi2] * x2 + grad3[gi2 + 1] * y2);\n }\n // Add contributions from each corner to get the final noise value.\n // The result is scaled to return values in the interval [-1,1].\n return 70 * (n0 + n1 + n2);\n}\n"],"names":[],"mappings":";;AAKA;AACA,MAAM,EAAE,GAAG,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AACnC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;AAEjC;;;;;AAKG;AACG,SAAU,MAAM,CAAC,IAAY,EAAA;AAC/B,IAAA,OAAO,iBAAiB,CAAC,IAAI,CAAC;AAClC;AAEA;;;;;;;AAOG;AACG,SAAU,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK,EAAsB,EAAE,CAAS,EAAE,CAAS,EAAA;;IAE5E,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IACvB,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC;IACzB,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC;IACzB,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE;IACtB,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACrB,IAAA,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC;;;AAGpB,IAAA,IAAI,EAAU;IACd,IAAI,EAAU,CAAC;AACf,IAAA,IAAI,EAAE,GAAG,EAAE,EAAE;;QAET,EAAE,GAAG,CAAC;QACN,EAAE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GAAG,EAAE,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;IAC1D;IACA,IAAI,EAAE,GAAG,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;AAChC,IAAA,IAAI,EAAE,IAAI,CAAC,EAAE;QACT,EAAE,IAAI,EAAE;QACR,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;IAC1D;;;IAGA,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AAC9B;;;;"}
@@ -0,0 +1,147 @@
1
+ import { createPermutation } from './permutation.js';
2
+
3
+ // skewing and unskewing factors for 3 dimensions
4
+ const F3 = 1 / 3;
5
+ const G3 = 1 / 6;
6
+ /**
7
+ * Creates a 3D simplex noise generator with the given seed.
8
+ *
9
+ * @param seed The seed value for the noise generator
10
+ * @returns A generator to pass to {@link sample}
11
+ */
12
+ function create(seed) {
13
+ return createPermutation(seed);
14
+ }
15
+ /**
16
+ * Samples 3D simplex noise, returning a value in the interval [-1, 1].
17
+ *
18
+ * @param generator A generator created with {@link create}
19
+ * @param x X coordinate
20
+ * @param y Y coordinate
21
+ * @param z Z coordinate
22
+ * @returns The noise value at (x, y, z)
23
+ */
24
+ function sample({ perm, grad3 }, x, y, z) {
25
+ // Skew the input space to determine which simplex cell we're in
26
+ const s = (x + y + z) * F3; // Hairy factor for 3D
27
+ let i = Math.floor(x + s);
28
+ let j = Math.floor(y + s);
29
+ let k = Math.floor(z + s);
30
+ const t = (i + j + k) * G3;
31
+ const x0 = x - i + t; // The x,y,z distances from the cell origin, unskewed.
32
+ const y0 = y - j + t;
33
+ const z0 = z - k + t;
34
+ // For the 3D case, the simplex shape is a slightly irregular tetrahedron.
35
+ // Determine which simplex we are in.
36
+ let i1;
37
+ let j1;
38
+ let k1; // Offsets for second corner of simplex in (i,j,k) coords
39
+ let i2;
40
+ let j2;
41
+ let k2; // Offsets for third corner of simplex in (i,j,k) coords
42
+ if (x0 >= y0) {
43
+ if (y0 >= z0) {
44
+ i1 = 1;
45
+ j1 = 0;
46
+ k1 = 0;
47
+ i2 = 1;
48
+ j2 = 1;
49
+ k2 = 0;
50
+ }
51
+ else if (x0 >= z0) {
52
+ i1 = 1;
53
+ j1 = 0;
54
+ k1 = 0;
55
+ i2 = 1;
56
+ j2 = 0;
57
+ k2 = 1;
58
+ }
59
+ else {
60
+ i1 = 0;
61
+ j1 = 0;
62
+ k1 = 1;
63
+ i2 = 1;
64
+ j2 = 0;
65
+ k2 = 1;
66
+ }
67
+ }
68
+ else {
69
+ if (y0 < z0) {
70
+ i1 = 0;
71
+ j1 = 0;
72
+ k1 = 1;
73
+ i2 = 0;
74
+ j2 = 1;
75
+ k2 = 1;
76
+ }
77
+ else if (x0 < z0) {
78
+ i1 = 0;
79
+ j1 = 1;
80
+ k1 = 0;
81
+ i2 = 0;
82
+ j2 = 1;
83
+ k2 = 1;
84
+ }
85
+ else {
86
+ i1 = 0;
87
+ j1 = 1;
88
+ k1 = 0;
89
+ i2 = 1;
90
+ j2 = 1;
91
+ k2 = 0;
92
+ }
93
+ }
94
+ // A step of (1,0,0) in (i,j,k) means a step of (1-c,-c,-c) in (x,y,z),
95
+ // a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and
96
+ // a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where
97
+ // c = 1/6.
98
+ const x1 = x0 - i1 + G3; // Offsets for second corner
99
+ const y1 = y0 - j1 + G3;
100
+ const z1 = z0 - k1 + G3;
101
+ const x2 = x0 - i2 + 2 * G3; // Offsets for third corner
102
+ const y2 = y0 - j2 + 2 * G3;
103
+ const z2 = z0 - k2 + 2 * G3;
104
+ const x3 = x0 - 1 + 3 * G3; // Offsets for fourth corner
105
+ const y3 = y0 - 1 + 3 * G3;
106
+ const z3 = z0 - 1 + 3 * G3;
107
+ // Work out the hashed gradient indices of the four simplex corners
108
+ // (flat xyz triples in grad3)
109
+ i &= 255;
110
+ j &= 255;
111
+ k &= 255;
112
+ const gi0 = (i + perm[j + perm[k]]) * 3;
113
+ const gi1 = (i + i1 + perm[j + j1 + perm[k + k1]]) * 3;
114
+ const gi2 = (i + i2 + perm[j + j2 + perm[k + k2]]) * 3;
115
+ const gi3 = (i + 1 + perm[j + 1 + perm[k + 1]]) * 3;
116
+ // Calculate the contribution from the four corners
117
+ let n0 = 0;
118
+ let n1 = 0;
119
+ let n2 = 0;
120
+ let n3 = 0;
121
+ let t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0;
122
+ if (t0 >= 0) {
123
+ t0 *= t0;
124
+ n0 = t0 * t0 * (grad3[gi0] * x0 + grad3[gi0 + 1] * y0 + grad3[gi0 + 2] * z0);
125
+ }
126
+ let t1 = 0.6 - x1 * x1 - y1 * y1 - z1 * z1;
127
+ if (t1 >= 0) {
128
+ t1 *= t1;
129
+ n1 = t1 * t1 * (grad3[gi1] * x1 + grad3[gi1 + 1] * y1 + grad3[gi1 + 2] * z1);
130
+ }
131
+ let t2 = 0.6 - x2 * x2 - y2 * y2 - z2 * z2;
132
+ if (t2 >= 0) {
133
+ t2 *= t2;
134
+ n2 = t2 * t2 * (grad3[gi2] * x2 + grad3[gi2 + 1] * y2 + grad3[gi2 + 2] * z2);
135
+ }
136
+ let t3 = 0.6 - x3 * x3 - y3 * y3 - z3 * z3;
137
+ if (t3 >= 0) {
138
+ t3 *= t3;
139
+ n3 = t3 * t3 * (grad3[gi3] * x3 + grad3[gi3 + 1] * y3 + grad3[gi3 + 2] * z3);
140
+ }
141
+ // Add contributions from each corner to get the final noise value.
142
+ // The result is scaled to return values in the interval [-1,1].
143
+ return 32 * (n0 + n1 + n2 + n3);
144
+ }
145
+
146
+ export { create, sample };
147
+ //# sourceMappingURL=simplex3d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simplex3d.js","sources":["../../src/noise/simplex3d.ts"],"sourcesContent":["import { createPermutation, type Permutation } from './permutation';\n\n/** A seeded 3D simplex noise generator. Create one with {@link create}. */\nexport type Simplex3DGenerator = Permutation;\n\n// skewing and unskewing factors for 3 dimensions\nconst F3 = 1 / 3;\nconst G3 = 1 / 6;\n\n/**\n * Creates a 3D simplex noise generator with the given seed.\n *\n * @param seed The seed value for the noise generator\n * @returns A generator to pass to {@link sample}\n */\nexport function create(seed: number): Simplex3DGenerator {\n return createPermutation(seed);\n}\n\n/**\n * Samples 3D simplex noise, returning a value in the interval [-1, 1].\n *\n * @param generator A generator created with {@link create}\n * @param x X coordinate\n * @param y Y coordinate\n * @param z Z coordinate\n * @returns The noise value at (x, y, z)\n */\nexport function sample({ perm, grad3 }: Simplex3DGenerator, x: number, y: number, z: number): number {\n // Skew the input space to determine which simplex cell we're in\n const s = (x + y + z) * F3; // Hairy factor for 3D\n let i = Math.floor(x + s);\n let j = Math.floor(y + s);\n let k = Math.floor(z + s);\n\n const t = (i + j + k) * G3;\n const x0 = x - i + t; // The x,y,z distances from the cell origin, unskewed.\n const y0 = y - j + t;\n const z0 = z - k + t;\n\n // For the 3D case, the simplex shape is a slightly irregular tetrahedron.\n // Determine which simplex we are in.\n let i1: number;\n let j1: number;\n let k1: number; // Offsets for second corner of simplex in (i,j,k) coords\n let i2: number;\n let j2: number;\n let k2: number; // Offsets for third corner of simplex in (i,j,k) coords\n if (x0 >= y0) {\n if (y0 >= z0) {\n i1 = 1;\n j1 = 0;\n k1 = 0;\n i2 = 1;\n j2 = 1;\n k2 = 0;\n } else if (x0 >= z0) {\n i1 = 1;\n j1 = 0;\n k1 = 0;\n i2 = 1;\n j2 = 0;\n k2 = 1;\n } else {\n i1 = 0;\n j1 = 0;\n k1 = 1;\n i2 = 1;\n j2 = 0;\n k2 = 1;\n }\n } else {\n if (y0 < z0) {\n i1 = 0;\n j1 = 0;\n k1 = 1;\n i2 = 0;\n j2 = 1;\n k2 = 1;\n } else if (x0 < z0) {\n i1 = 0;\n j1 = 1;\n k1 = 0;\n i2 = 0;\n j2 = 1;\n k2 = 1;\n } else {\n i1 = 0;\n j1 = 1;\n k1 = 0;\n i2 = 1;\n j2 = 1;\n k2 = 0;\n }\n }\n // A step of (1,0,0) in (i,j,k) means a step of (1-c,-c,-c) in (x,y,z),\n // a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and\n // a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where\n // c = 1/6.\n const x1 = x0 - i1 + G3; // Offsets for second corner\n const y1 = y0 - j1 + G3;\n const z1 = z0 - k1 + G3;\n\n const x2 = x0 - i2 + 2 * G3; // Offsets for third corner\n const y2 = y0 - j2 + 2 * G3;\n const z2 = z0 - k2 + 2 * G3;\n\n const x3 = x0 - 1 + 3 * G3; // Offsets for fourth corner\n const y3 = y0 - 1 + 3 * G3;\n const z3 = z0 - 1 + 3 * G3;\n\n // Work out the hashed gradient indices of the four simplex corners\n // (flat xyz triples in grad3)\n i &= 255;\n j &= 255;\n k &= 255;\n const gi0 = (i + perm[j + perm[k]]) * 3;\n const gi1 = (i + i1 + perm[j + j1 + perm[k + k1]]) * 3;\n const gi2 = (i + i2 + perm[j + j2 + perm[k + k2]]) * 3;\n const gi3 = (i + 1 + perm[j + 1 + perm[k + 1]]) * 3;\n\n // Calculate the contribution from the four corners\n let n0 = 0;\n let n1 = 0;\n let n2 = 0;\n let n3 = 0;\n let t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0;\n if (t0 >= 0) {\n t0 *= t0;\n n0 = t0 * t0 * (grad3[gi0] * x0 + grad3[gi0 + 1] * y0 + grad3[gi0 + 2] * z0);\n }\n let t1 = 0.6 - x1 * x1 - y1 * y1 - z1 * z1;\n if (t1 >= 0) {\n t1 *= t1;\n n1 = t1 * t1 * (grad3[gi1] * x1 + grad3[gi1 + 1] * y1 + grad3[gi1 + 2] * z1);\n }\n let t2 = 0.6 - x2 * x2 - y2 * y2 - z2 * z2;\n if (t2 >= 0) {\n t2 *= t2;\n n2 = t2 * t2 * (grad3[gi2] * x2 + grad3[gi2 + 1] * y2 + grad3[gi2 + 2] * z2);\n }\n let t3 = 0.6 - x3 * x3 - y3 * y3 - z3 * z3;\n if (t3 >= 0) {\n t3 *= t3;\n n3 = t3 * t3 * (grad3[gi3] * x3 + grad3[gi3 + 1] * y3 + grad3[gi3 + 2] * z3);\n }\n // Add contributions from each corner to get the final noise value.\n // The result is scaled to return values in the interval [-1,1].\n return 32 * (n0 + n1 + n2 + n3);\n}\n"],"names":[],"mappings":";;AAKA;AACA,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC;AAChB,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC;AAEhB;;;;;AAKG;AACG,SAAU,MAAM,CAAC,IAAY,EAAA;AAC/B,IAAA,OAAO,iBAAiB,CAAC,IAAI,CAAC;AAClC;AAEA;;;;;;;;AAQG;AACG,SAAU,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK,EAAsB,EAAE,CAAS,EAAE,CAAS,EAAE,CAAS,EAAA;;AAEvF,IAAA,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IAC3B,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC;IACzB,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC;IACzB,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC;IAEzB,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE;IAC1B,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACrB,IAAA,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC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E,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;IAChF;AACA,IAAA,IAAI,EAAE,GAAG,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;AAC1C,IAAA,IAAI,EAAE,IAAI,CAAC,EAAE;QACT,EAAE,IAAI,EAAE;AACR,QAAA,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;IAChF;;;IAGA,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AACnC;;;;"}
@@ -0,0 +1,149 @@
1
+ import { createPermutation } from './permutation.js';
2
+
3
+ // Skewing and unskewing factors for 4 dimensions
4
+ const F4 = (Math.sqrt(5) - 1) / 4;
5
+ const G4 = (5 - Math.sqrt(5)) / 20;
6
+ /**
7
+ * Creates a 4D simplex noise generator with the given seed.
8
+ *
9
+ * @param seed The seed value for the noise generator
10
+ * @returns A generator to pass to {@link sample}
11
+ */
12
+ function create(seed) {
13
+ return createPermutation(seed);
14
+ }
15
+ /**
16
+ * Samples 4D simplex noise, returning a value in the interval [-1, 1].
17
+ *
18
+ * The fourth axis is commonly used as time (for animated 3D noise) or as a wrap
19
+ * dimension (map a coordinate around a circle in w for seamless looping).
20
+ *
21
+ * @param generator A generator created with {@link create}
22
+ * @param x X coordinate
23
+ * @param y Y coordinate
24
+ * @param z Z coordinate
25
+ * @param w W coordinate
26
+ * @returns The noise value at (x, y, z, w)
27
+ */
28
+ function sample({ perm, grad4 }, x, y, z, w) {
29
+ // Skew the input space to determine which simplex cell we're in
30
+ const s = (x + y + z + w) * F4; // Factor for 4D skewing
31
+ const i = Math.floor(x + s);
32
+ const j = Math.floor(y + s);
33
+ const k = Math.floor(z + s);
34
+ const l = Math.floor(w + s);
35
+ const t = (i + j + k + l) * G4; // Factor for 4D unskewing
36
+ const x0 = x - (i - t); // The x,y,z,w distances from the cell origin, unskewed
37
+ const y0 = y - (j - t);
38
+ const z0 = z - (k - t);
39
+ const w0 = w - (l - t);
40
+ // For the 4D case, the simplex is a 5-cell (4-simplex). Rank the coordinates
41
+ // to work out the traversal order of the four middle corners: the largest
42
+ // coordinate steps first, then the next, and so on (Gustavson's rank method).
43
+ let rankx = 0;
44
+ let ranky = 0;
45
+ let rankz = 0;
46
+ let rankw = 0;
47
+ if (x0 > y0)
48
+ rankx++;
49
+ else
50
+ ranky++;
51
+ if (x0 > z0)
52
+ rankx++;
53
+ else
54
+ rankz++;
55
+ if (x0 > w0)
56
+ rankx++;
57
+ else
58
+ rankw++;
59
+ if (y0 > z0)
60
+ ranky++;
61
+ else
62
+ rankz++;
63
+ if (y0 > w0)
64
+ ranky++;
65
+ else
66
+ rankw++;
67
+ if (z0 > w0)
68
+ rankz++;
69
+ else
70
+ rankw++;
71
+ // rank 3 is the largest coordinate, so it gets the +1 first, and so on.
72
+ const i1 = rankx >= 3 ? 1 : 0;
73
+ const j1 = ranky >= 3 ? 1 : 0;
74
+ const k1 = rankz >= 3 ? 1 : 0;
75
+ const l1 = rankw >= 3 ? 1 : 0;
76
+ const i2 = rankx >= 2 ? 1 : 0;
77
+ const j2 = ranky >= 2 ? 1 : 0;
78
+ const k2 = rankz >= 2 ? 1 : 0;
79
+ const l2 = rankw >= 2 ? 1 : 0;
80
+ const i3 = rankx >= 1 ? 1 : 0;
81
+ const j3 = ranky >= 1 ? 1 : 0;
82
+ const k3 = rankz >= 1 ? 1 : 0;
83
+ const l3 = rankw >= 1 ? 1 : 0;
84
+ // Offsets for the remaining corners, unskewed (subtract the step, add G4 per step)
85
+ const x1 = x0 - i1 + G4;
86
+ const y1 = y0 - j1 + G4;
87
+ const z1 = z0 - k1 + G4;
88
+ const w1 = w0 - l1 + G4;
89
+ const x2 = x0 - i2 + 2 * G4;
90
+ const y2 = y0 - j2 + 2 * G4;
91
+ const z2 = z0 - k2 + 2 * G4;
92
+ const w2 = w0 - l2 + 2 * G4;
93
+ const x3 = x0 - i3 + 3 * G4;
94
+ const y3 = y0 - j3 + 3 * G4;
95
+ const z3 = z0 - k3 + 3 * G4;
96
+ const w3 = w0 - l3 + 3 * G4;
97
+ const x4 = x0 - 1 + 4 * G4;
98
+ const y4 = y0 - 1 + 4 * G4;
99
+ const z4 = z0 - 1 + 4 * G4;
100
+ const w4 = w0 - 1 + 4 * G4;
101
+ // Work out the hashed gradient indices of the five simplex corners
102
+ // (flat xyzw quads in grad4)
103
+ const ii = i & 255;
104
+ const jj = j & 255;
105
+ const kk = k & 255;
106
+ const ll = l & 255;
107
+ const g0 = (ii + perm[jj + perm[kk + perm[ll]]]) * 4;
108
+ const g1 = (ii + i1 + perm[jj + j1 + perm[kk + k1 + perm[ll + l1]]]) * 4;
109
+ const g2 = (ii + i2 + perm[jj + j2 + perm[kk + k2 + perm[ll + l2]]]) * 4;
110
+ const g3 = (ii + i3 + perm[jj + j3 + perm[kk + k3 + perm[ll + l3]]]) * 4;
111
+ const g4 = (ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]) * 4;
112
+ // Calculate the contribution from the five corners
113
+ let n0 = 0;
114
+ let n1 = 0;
115
+ let n2 = 0;
116
+ let n3 = 0;
117
+ let n4 = 0;
118
+ let t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0;
119
+ if (t0 >= 0) {
120
+ t0 *= t0;
121
+ n0 = t0 * t0 * (grad4[g0] * x0 + grad4[g0 + 1] * y0 + grad4[g0 + 2] * z0 + grad4[g0 + 3] * w0);
122
+ }
123
+ let t1 = 0.6 - x1 * x1 - y1 * y1 - z1 * z1 - w1 * w1;
124
+ if (t1 >= 0) {
125
+ t1 *= t1;
126
+ n1 = t1 * t1 * (grad4[g1] * x1 + grad4[g1 + 1] * y1 + grad4[g1 + 2] * z1 + grad4[g1 + 3] * w1);
127
+ }
128
+ let t2 = 0.6 - x2 * x2 - y2 * y2 - z2 * z2 - w2 * w2;
129
+ if (t2 >= 0) {
130
+ t2 *= t2;
131
+ n2 = t2 * t2 * (grad4[g2] * x2 + grad4[g2 + 1] * y2 + grad4[g2 + 2] * z2 + grad4[g2 + 3] * w2);
132
+ }
133
+ let t3 = 0.6 - x3 * x3 - y3 * y3 - z3 * z3 - w3 * w3;
134
+ if (t3 >= 0) {
135
+ t3 *= t3;
136
+ n3 = t3 * t3 * (grad4[g3] * x3 + grad4[g3 + 1] * y3 + grad4[g3 + 2] * z3 + grad4[g3 + 3] * w3);
137
+ }
138
+ let t4 = 0.6 - x4 * x4 - y4 * y4 - z4 * z4 - w4 * w4;
139
+ if (t4 >= 0) {
140
+ t4 *= t4;
141
+ n4 = t4 * t4 * (grad4[g4] * x4 + grad4[g4 + 1] * y4 + grad4[g4 + 2] * z4 + grad4[g4 + 3] * w4);
142
+ }
143
+ // Add contributions from each corner to get the final noise value.
144
+ // The result is scaled to return values in the interval [-1, 1].
145
+ return 27 * (n0 + n1 + n2 + n3 + n4);
146
+ }
147
+
148
+ export { create, sample };
149
+ //# sourceMappingURL=simplex4d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simplex4d.js","sources":["../../src/noise/simplex4d.ts"],"sourcesContent":["import { createPermutation, type Permutation } from './permutation';\n\n/** A seeded 4D simplex noise generator. Create one with {@link create}. */\nexport type Simplex4DGenerator = Permutation;\n\n// Skewing and unskewing factors for 4 dimensions\nconst F4 = (Math.sqrt(5) - 1) / 4;\nconst G4 = (5 - Math.sqrt(5)) / 20;\n\n/**\n * Creates a 4D simplex noise generator with the given seed.\n *\n * @param seed The seed value for the noise generator\n * @returns A generator to pass to {@link sample}\n */\nexport function create(seed: number): Simplex4DGenerator {\n return createPermutation(seed);\n}\n\n/**\n * Samples 4D simplex noise, returning a value in the interval [-1, 1].\n *\n * The fourth axis is commonly used as time (for animated 3D noise) or as a wrap\n * dimension (map a coordinate around a circle in w for seamless looping).\n *\n * @param generator A generator created with {@link create}\n * @param x X coordinate\n * @param y Y coordinate\n * @param z Z coordinate\n * @param w W coordinate\n * @returns The noise value at (x, y, z, w)\n */\nexport function sample({ perm, grad4 }: Simplex4DGenerator, x: number, y: number, z: number, w: number): number {\n // Skew the input space to determine which simplex cell we're in\n const s = (x + y + z + w) * F4; // Factor for 4D skewing\n const i = Math.floor(x + s);\n const j = Math.floor(y + s);\n const k = Math.floor(z + s);\n const l = Math.floor(w + s);\n\n const t = (i + j + k + l) * G4; // Factor for 4D unskewing\n const x0 = x - (i - t); // The x,y,z,w distances from the cell origin, unskewed\n const y0 = y - (j - t);\n const z0 = z - (k - t);\n const w0 = w - (l - t);\n\n // For the 4D case, the simplex is a 5-cell (4-simplex). Rank the coordinates\n // to work out the traversal order of the four middle corners: the largest\n // coordinate steps first, then the next, and so on (Gustavson's rank method).\n let rankx = 0;\n let ranky = 0;\n let rankz = 0;\n let rankw = 0;\n if (x0 > y0) rankx++;\n else ranky++;\n if (x0 > z0) rankx++;\n else rankz++;\n if (x0 > w0) rankx++;\n else rankw++;\n if (y0 > z0) ranky++;\n else rankz++;\n if (y0 > w0) ranky++;\n else rankw++;\n if (z0 > w0) rankz++;\n else rankw++;\n\n // rank 3 is the largest coordinate, so it gets the +1 first, and so on.\n const i1 = rankx >= 3 ? 1 : 0;\n const j1 = ranky >= 3 ? 1 : 0;\n const k1 = rankz >= 3 ? 1 : 0;\n const l1 = rankw >= 3 ? 1 : 0;\n\n const i2 = rankx >= 2 ? 1 : 0;\n const j2 = ranky >= 2 ? 1 : 0;\n const k2 = rankz >= 2 ? 1 : 0;\n const l2 = rankw >= 2 ? 1 : 0;\n\n const i3 = rankx >= 1 ? 1 : 0;\n const j3 = ranky >= 1 ? 1 : 0;\n const k3 = rankz >= 1 ? 1 : 0;\n const l3 = rankw >= 1 ? 1 : 0;\n\n // Offsets for the remaining corners, unskewed (subtract the step, add G4 per step)\n const x1 = x0 - i1 + G4;\n const y1 = y0 - j1 + G4;\n const z1 = z0 - k1 + G4;\n const w1 = w0 - l1 + G4;\n\n const x2 = x0 - i2 + 2 * G4;\n const y2 = y0 - j2 + 2 * G4;\n const z2 = z0 - k2 + 2 * G4;\n const w2 = w0 - l2 + 2 * G4;\n\n const x3 = x0 - i3 + 3 * G4;\n const y3 = y0 - j3 + 3 * G4;\n const z3 = z0 - k3 + 3 * G4;\n const w3 = w0 - l3 + 3 * G4;\n\n const x4 = x0 - 1 + 4 * G4;\n const y4 = y0 - 1 + 4 * G4;\n const z4 = z0 - 1 + 4 * G4;\n const w4 = w0 - 1 + 4 * G4;\n\n // Work out the hashed gradient indices of the five simplex corners\n // (flat xyzw quads in grad4)\n const ii = i & 255;\n const jj = j & 255;\n const kk = k & 255;\n const ll = l & 255;\n const g0 = (ii + perm[jj + perm[kk + perm[ll]]]) * 4;\n const g1 = (ii + i1 + perm[jj + j1 + perm[kk + k1 + perm[ll + l1]]]) * 4;\n const g2 = (ii + i2 + perm[jj + j2 + perm[kk + k2 + perm[ll + l2]]]) * 4;\n const g3 = (ii + i3 + perm[jj + j3 + perm[kk + k3 + perm[ll + l3]]]) * 4;\n const g4 = (ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]) * 4;\n\n // Calculate the contribution from the five corners\n let n0 = 0;\n let n1 = 0;\n let n2 = 0;\n let n3 = 0;\n let n4 = 0;\n let t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0;\n if (t0 >= 0) {\n t0 *= t0;\n n0 = t0 * t0 * (grad4[g0] * x0 + grad4[g0 + 1] * y0 + grad4[g0 + 2] * z0 + grad4[g0 + 3] * w0);\n }\n let t1 = 0.6 - x1 * x1 - y1 * y1 - z1 * z1 - w1 * w1;\n if (t1 >= 0) {\n t1 *= t1;\n n1 = t1 * t1 * (grad4[g1] * x1 + grad4[g1 + 1] * y1 + grad4[g1 + 2] * z1 + grad4[g1 + 3] * w1);\n }\n let t2 = 0.6 - x2 * x2 - y2 * y2 - z2 * z2 - w2 * w2;\n if (t2 >= 0) {\n t2 *= t2;\n n2 = t2 * t2 * (grad4[g2] * x2 + grad4[g2 + 1] * y2 + grad4[g2 + 2] * z2 + grad4[g2 + 3] * w2);\n }\n let t3 = 0.6 - x3 * x3 - y3 * y3 - z3 * z3 - w3 * w3;\n if (t3 >= 0) {\n t3 *= t3;\n n3 = t3 * t3 * (grad4[g3] * x3 + grad4[g3 + 1] * y3 + grad4[g3 + 2] * z3 + grad4[g3 + 3] * w3);\n }\n let t4 = 0.6 - x4 * x4 - y4 * y4 - z4 * z4 - w4 * w4;\n if (t4 >= 0) {\n t4 *= t4;\n n4 = t4 * t4 * (grad4[g4] * x4 + grad4[g4 + 1] * y4 + grad4[g4 + 2] * z4 + grad4[g4 + 3] * w4);\n }\n\n // Add contributions from each corner to get the final noise value.\n // The result is scaled to return values in the interval [-1, 1].\n return 27 * (n0 + n1 + n2 + n3 + n4);\n}\n"],"names":[],"mappings":";;AAKA;AACA,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC;AACjC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE;AAElC;;;;;AAKG;AACG,SAAU,MAAM,CAAC,IAAY,EAAA;AAC/B,IAAA,OAAO,iBAAiB,CAAC,IAAI,CAAC;AAClC;AAEA;;;;;;;;;;;;AAYG;AACG,SAAU,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK,EAAsB,EAAE,CAAS,EAAE,CAAS,EAAE,CAAS,EAAE,CAAS,EAAA;;AAElG,IAAA,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IAC/B,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC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,IAAA,IAAI,EAAE,GAAG,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;AACpD,IAAA,IAAI,EAAE,IAAI,CAAC,EAAE;QACT,EAAE,IAAI,EAAE;AACR,QAAA,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;IAClG;;;AAIA,IAAA,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AACxC;;;;"}
@@ -0,0 +1,50 @@
1
+ import { createPermutation } from './permutation.js';
2
+
3
+ /**
4
+ * Creates a 2D Worley noise generator with the given seed.
5
+ *
6
+ * @param seed The seed value for the noise generator
7
+ * @returns A generator to pass to {@link sample}
8
+ */
9
+ function create(seed) {
10
+ return createPermutation(seed);
11
+ }
12
+ /**
13
+ * Samples 2D Worley (cellular) noise: the Euclidean distance to the nearest of a
14
+ * set of feature points, one scattered per unit cell. Gives organic cell / scale
15
+ * / caustic patterns; values are roughly in [0, 1] (0 right at a feature point,
16
+ * rising between them). Threshold it for cracks, cells, or region masks.
17
+ *
18
+ * @param generator A generator created with {@link create}
19
+ * @param x X coordinate
20
+ * @param y Y coordinate
21
+ * @returns The distance to the nearest feature point (F1)
22
+ */
23
+ function sample({ perm }, x, y) {
24
+ const ix = Math.floor(x);
25
+ const iy = Math.floor(y);
26
+ let f1 = Infinity; // squared nearest distance
27
+ // check the point's cell and its 8 neighbours; the nearest feature point can
28
+ // only be in one of these. The row (y) hashes are shared by the three cells
29
+ // in a row, so hash them once per row.
30
+ for (let gy = -1; gy <= 1; gy++) {
31
+ const cy = iy + gy;
32
+ const py = perm[cy & 255];
33
+ const qy = perm[(cy + 37) & 255];
34
+ for (let gx = -1; gx <= 1; gx++) {
35
+ const cx = ix + gx;
36
+ // a hashed feature-point offset in [0, 1) per axis, decorrelated
37
+ const rx = perm[(cx & 255) + py] / 256;
38
+ const ry = perm[((cx + 71) & 255) + qy] / 256;
39
+ const dx = cx + rx - x;
40
+ const dy = cy + ry - y;
41
+ const d2 = dx * dx + dy * dy;
42
+ if (d2 < f1)
43
+ f1 = d2;
44
+ }
45
+ }
46
+ return Math.sqrt(f1);
47
+ }
48
+
49
+ export { create, sample };
50
+ //# sourceMappingURL=worley2d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worley2d.js","sources":["../../src/noise/worley2d.ts"],"sourcesContent":["import { createPermutation, type Permutation } from './permutation';\n\n/** A seeded 2D Worley (cellular) noise generator. Create one with {@link create}. */\nexport type Worley2DGenerator = Permutation;\n\n/**\n * Creates a 2D Worley noise generator with the given seed.\n *\n * @param seed The seed value for the noise generator\n * @returns A generator to pass to {@link sample}\n */\nexport function create(seed: number): Worley2DGenerator {\n return createPermutation(seed);\n}\n\n/**\n * Samples 2D Worley (cellular) noise: the Euclidean distance to the nearest of a\n * set of feature points, one scattered per unit cell. Gives organic cell / scale\n * / caustic patterns; values are roughly in [0, 1] (0 right at a feature point,\n * rising between them). Threshold it for cracks, cells, or region masks.\n *\n * @param generator A generator created with {@link create}\n * @param x X coordinate\n * @param y Y coordinate\n * @returns The distance to the nearest feature point (F1)\n */\nexport function sample({ perm }: Worley2DGenerator, x: number, y: number): number {\n const ix = Math.floor(x);\n const iy = Math.floor(y);\n let f1 = Infinity; // squared nearest distance\n\n // check the point's cell and its 8 neighbours; the nearest feature point can\n // only be in one of these. The row (y) hashes are shared by the three cells\n // in a row, so hash them once per row.\n for (let gy = -1; gy <= 1; gy++) {\n const cy = iy + gy;\n const py = perm[cy & 255];\n const qy = perm[(cy + 37) & 255];\n for (let gx = -1; gx <= 1; gx++) {\n const cx = ix + gx;\n // a hashed feature-point offset in [0, 1) per axis, decorrelated\n const rx = perm[(cx & 255) + py] / 256;\n const ry = perm[((cx + 71) & 255) + qy] / 256;\n const dx = cx + rx - x;\n const dy = cy + ry - y;\n const d2 = dx * dx + dy * dy;\n if (d2 < f1) f1 = d2;\n }\n }\n\n return Math.sqrt(f1);\n}\n"],"names":[],"mappings":";;AAKA;;;;;AAKG;AACG,SAAU,MAAM,CAAC,IAAY,EAAA;AAC/B,IAAA,OAAO,iBAAiB,CAAC,IAAI,CAAC;AAClC;AAEA;;;;;;;;;;AAUG;AACG,SAAU,MAAM,CAAC,EAAE,IAAI,EAAqB,EAAE,CAAS,EAAE,CAAS,EAAA;IACpE,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACxB,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AACxB,IAAA,IAAI,EAAE,GAAG,QAAQ,CAAC;;;;AAKlB,IAAA,KAAK,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE,EAAE;AAC7B,QAAA,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE;QAClB,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC;AACzB,QAAA,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,GAAG,CAAC;AAChC,QAAA,KAAK,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE,EAAE;AAC7B,YAAA,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE;;AAElB,YAAA,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE,GAAG,GAAG,IAAI,EAAE,CAAC,GAAG,GAAG;AACtC,YAAA,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,GAAG,IAAI,EA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