FastNoiseLite.patch 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. --- orig/FastNoiseLite.h 1900-01-00 00:00:00 +0000
  2. +++ noise/FastNoiseLite.h 1900-01-00 00:00:00 +0000
  3. @@ -52,6 +52,8 @@
  4. #include <cmath>
  5. +namespace fastnoiselite{
  6. +
  7. class FastNoiseLite
  8. {
  9. public:
  10. @@ -2583,4 +2585,5 @@
  11. -0.7870349638f, 0.03447489231f, 0.6159443543f, 0, -0.2015596421f, 0.6859872284f, 0.6991389226f, 0, -0.08581082512f, -0.10920836f, -0.9903080513f, 0, 0.5532693395f, 0.7325250401f, -0.396610771f, 0, -0.1842489331f, -0.9777375055f, -0.1004076743f, 0, 0.0775473789f, -0.9111505856f, 0.4047110257f, 0, 0.1399838409f, 0.7601631212f, -0.6344734459f, 0, 0.4484419361f, -0.845289248f, 0.2904925424f, 0
  12. };
  13. -#endif
  14. +}
  15. +#endif // namespace fastnoiselite
  16. @@ -295,7 +295,7 @@ public:
  17. /// Noise output bounded between -1...1
  18. /// </returns>
  19. template <typename FNfloat>
  20. - float GetNoise(FNfloat x, FNfloat y)
  21. + float GetNoise(FNfloat x, FNfloat y) const
  22. {
  23. Arguments_must_be_floating_point_values<FNfloat>();
  24. @@ -321,7 +321,7 @@ public:
  25. /// Noise output bounded between -1...1
  26. /// </returns>
  27. template <typename FNfloat>
  28. - float GetNoise(FNfloat x, FNfloat y, FNfloat z)
  29. + float GetNoise(FNfloat x, FNfloat y, FNfloat z) const
  30. {
  31. Arguments_must_be_floating_point_values<FNfloat>();
  32. @@ -350,7 +350,7 @@ public:
  33. /// noise = GetNoise(x, y)</code>
  34. /// </example>
  35. template <typename FNfloat>
  36. - void DomainWarp(FNfloat& x, FNfloat& y)
  37. + void DomainWarp(FNfloat& x, FNfloat& y) const
  38. {
  39. Arguments_must_be_floating_point_values<FNfloat>();
  40. @@ -377,7 +377,7 @@ public:
  41. /// noise = GetNoise(x, y, z)</code>
  42. /// </example>
  43. template <typename FNfloat>
  44. - void DomainWarp(FNfloat& x, FNfloat& y, FNfloat& z)
  45. + void DomainWarp(FNfloat& x, FNfloat& y, FNfloat& z) const
  46. {
  47. Arguments_must_be_floating_point_values<FNfloat>();
  48. @@ -528,7 +528,7 @@ private:
  49. }
  50. - float GradCoord(int seed, int xPrimed, int yPrimed, float xd, float yd)
  51. + float GradCoord(int seed, int xPrimed, int yPrimed, float xd, float yd) const
  52. {
  53. int hash = Hash(seed, xPrimed, yPrimed);
  54. hash ^= hash >> 15;
  55. @@ -541,7 +541,7 @@ private:
  56. }
  57. - float GradCoord(int seed, int xPrimed, int yPrimed, int zPrimed, float xd, float yd, float zd)
  58. + float GradCoord(int seed, int xPrimed, int yPrimed, int zPrimed, float xd, float yd, float zd) const
  59. {
  60. int hash = Hash(seed, xPrimed, yPrimed, zPrimed);
  61. hash ^= hash >> 15;
  62. @@ -555,7 +555,7 @@ private:
  63. }
  64. - void GradCoordOut(int seed, int xPrimed, int yPrimed, float& xo, float& yo)
  65. + void GradCoordOut(int seed, int xPrimed, int yPrimed, float& xo, float& yo) const
  66. {
  67. int hash = Hash(seed, xPrimed, yPrimed) & (255 << 1);
  68. @@ -564,7 +564,7 @@ private:
  69. }
  70. - void GradCoordOut(int seed, int xPrimed, int yPrimed, int zPrimed, float& xo, float& yo, float& zo)
  71. + void GradCoordOut(int seed, int xPrimed, int yPrimed, int zPrimed, float& xo, float& yo, float& zo) const
  72. {
  73. int hash = Hash(seed, xPrimed, yPrimed, zPrimed) & (255 << 2);
  74. @@ -574,7 +574,7 @@ private:
  75. }
  76. - void GradCoordDual(int seed, int xPrimed, int yPrimed, float xd, float yd, float& xo, float& yo)
  77. + void GradCoordDual(int seed, int xPrimed, int yPrimed, float xd, float yd, float& xo, float& yo) const
  78. {
  79. int hash = Hash(seed, xPrimed, yPrimed);
  80. int index1 = hash & (127 << 1);
  81. @@ -592,7 +592,7 @@ private:
  82. }
  83. - void GradCoordDual(int seed, int xPrimed, int yPrimed, int zPrimed, float xd, float yd, float zd, float& xo, float& yo, float& zo)
  84. + void GradCoordDual(int seed, int xPrimed, int yPrimed, int zPrimed, float xd, float yd, float zd, float& xo, float& yo, float& zo) const
  85. {
  86. int hash = Hash(seed, xPrimed, yPrimed, zPrimed);
  87. int index1 = hash & (63 << 2);
  88. @@ -616,7 +616,7 @@ private:
  89. // Generic noise gen
  90. template <typename FNfloat>
  91. - float GenNoiseSingle(int seed, FNfloat x, FNfloat y)
  92. + float GenNoiseSingle(int seed, FNfloat x, FNfloat y) const
  93. {
  94. switch (mNoiseType)
  95. {
  96. @@ -638,7 +638,7 @@ private:
  97. }
  98. template <typename FNfloat>
  99. - float GenNoiseSingle(int seed, FNfloat x, FNfloat y, FNfloat z)
  100. + float GenNoiseSingle(int seed, FNfloat x, FNfloat y, FNfloat z) const
  101. {
  102. switch (mNoiseType)
  103. {
  104. @@ -663,7 +663,7 @@ private:
  105. // Noise Coordinate Transforms (frequency, and possible skew or rotation)
  106. template <typename FNfloat>
  107. - void TransformNoiseCoordinate(FNfloat& x, FNfloat& y)
  108. + void TransformNoiseCoordinate(FNfloat& x, FNfloat& y) const
  109. {
  110. x *= mFrequency;
  111. y *= mFrequency;
  112. @@ -686,7 +686,7 @@ private:
  113. }
  114. template <typename FNfloat>
  115. - void TransformNoiseCoordinate(FNfloat& x, FNfloat& y, FNfloat& z)
  116. + void TransformNoiseCoordinate(FNfloat& x, FNfloat& y, FNfloat& z) const
  117. {
  118. x *= mFrequency;
  119. y *= mFrequency;
  120. @@ -757,7 +757,7 @@ private:
  121. // Domain Warp Coordinate Transforms
  122. template <typename FNfloat>
  123. - void TransformDomainWarpCoordinate(FNfloat& x, FNfloat& y)
  124. + void TransformDomainWarpCoordinate(FNfloat& x, FNfloat& y) const
  125. {
  126. switch (mDomainWarpType)
  127. {
  128. @@ -777,7 +777,7 @@ private:
  129. }
  130. template <typename FNfloat>
  131. - void TransformDomainWarpCoordinate(FNfloat& x, FNfloat& y, FNfloat& z)
  132. + void TransformDomainWarpCoordinate(FNfloat& x, FNfloat& y, FNfloat& z) const
  133. {
  134. switch (mWarpTransformType3D)
  135. {
  136. @@ -844,7 +844,7 @@ private:
  137. // Fractal FBm
  138. template <typename FNfloat>
  139. - float GenFractalFBm(FNfloat x, FNfloat y)
  140. + float GenFractalFBm(FNfloat x, FNfloat y) const
  141. {
  142. int seed = mSeed;
  143. float sum = 0;
  144. @@ -865,7 +865,7 @@ private:
  145. }
  146. template <typename FNfloat>
  147. - float GenFractalFBm(FNfloat x, FNfloat y, FNfloat z)
  148. + float GenFractalFBm(FNfloat x, FNfloat y, FNfloat z) const
  149. {
  150. int seed = mSeed;
  151. float sum = 0;
  152. @@ -890,7 +890,7 @@ private:
  153. // Fractal Ridged
  154. template <typename FNfloat>
  155. - float GenFractalRidged(FNfloat x, FNfloat y)
  156. + float GenFractalRidged(FNfloat x, FNfloat y) const
  157. {
  158. int seed = mSeed;
  159. float sum = 0;
  160. @@ -911,7 +911,7 @@ private:
  161. }
  162. template <typename FNfloat>
  163. - float GenFractalRidged(FNfloat x, FNfloat y, FNfloat z)
  164. + float GenFractalRidged(FNfloat x, FNfloat y, FNfloat z) const
  165. {
  166. int seed = mSeed;
  167. float sum = 0;
  168. @@ -936,7 +936,7 @@ private:
  169. // Fractal PingPong
  170. template <typename FNfloat>
  171. - float GenFractalPingPong(FNfloat x, FNfloat y)
  172. + float GenFractalPingPong(FNfloat x, FNfloat y) const
  173. {
  174. int seed = mSeed;
  175. float sum = 0;
  176. @@ -957,7 +957,7 @@ private:
  177. }
  178. template <typename FNfloat>
  179. - float GenFractalPingPong(FNfloat x, FNfloat y, FNfloat z)
  180. + float GenFractalPingPong(FNfloat x, FNfloat y, FNfloat z) const
  181. {
  182. int seed = mSeed;
  183. float sum = 0;
  184. @@ -982,7 +982,7 @@ private:
  185. // Simplex/OpenSimplex2 Noise
  186. template <typename FNfloat>
  187. - float SingleSimplex(int seed, FNfloat x, FNfloat y)
  188. + float SingleSimplex(int seed, FNfloat x, FNfloat y) const
  189. {
  190. // 2D OpenSimplex2 case uses the same algorithm as ordinary Simplex.
  191. @@ -1053,7 +1053,7 @@ private:
  192. }
  193. template <typename FNfloat>
  194. - float SingleOpenSimplex2(int seed, FNfloat x, FNfloat y, FNfloat z)
  195. + float SingleOpenSimplex2(int seed, FNfloat x, FNfloat y, FNfloat z) const
  196. {
  197. // 3D OpenSimplex2 case uses two offset rotated cube grids.
  198. @@ -1155,7 +1155,7 @@ private:
  199. // OpenSimplex2S Noise
  200. template <typename FNfloat>
  201. - float SingleOpenSimplex2S(int seed, FNfloat x, FNfloat y)
  202. + float SingleOpenSimplex2S(int seed, FNfloat x, FNfloat y) const
  203. {
  204. // 2D OpenSimplex2S case is a modified 2D simplex noise.
  205. @@ -1286,7 +1286,7 @@ private:
  206. }
  207. template <typename FNfloat>
  208. - float SingleOpenSimplex2S(int seed, FNfloat x, FNfloat y, FNfloat z)
  209. + float SingleOpenSimplex2S(int seed, FNfloat x, FNfloat y, FNfloat z) const
  210. {
  211. // 3D OpenSimplex2S case uses two offset rotated cube grids.
  212. @@ -1482,7 +1482,7 @@ private:
  213. // Cellular Noise
  214. template <typename FNfloat>
  215. - float SingleCellular(int seed, FNfloat x, FNfloat y)
  216. + float SingleCellular(int seed, FNfloat x, FNfloat y) const
  217. {
  218. int xr = FastRound(x);
  219. int yr = FastRound(y);
  220. @@ -1612,7 +1612,7 @@ private:
  221. }
  222. template <typename FNfloat>
  223. - float SingleCellular(int seed, FNfloat x, FNfloat y, FNfloat z)
  224. + float SingleCellular(int seed, FNfloat x, FNfloat y, FNfloat z) const
  225. {
  226. int xr = FastRound(x);
  227. int yr = FastRound(y);
  228. @@ -1769,7 +1769,7 @@ private:
  229. // Perlin Noise
  230. template <typename FNfloat>
  231. - float SinglePerlin(int seed, FNfloat x, FNfloat y)
  232. + float SinglePerlin(int seed, FNfloat x, FNfloat y) const
  233. {
  234. int x0 = FastFloor(x);
  235. int y0 = FastFloor(y);
  236. @@ -1794,7 +1794,7 @@ private:
  237. }
  238. template <typename FNfloat>
  239. - float SinglePerlin(int seed, FNfloat x, FNfloat y, FNfloat z)
  240. + float SinglePerlin(int seed, FNfloat x, FNfloat y, FNfloat z) const
  241. {
  242. int x0 = FastFloor(x);
  243. int y0 = FastFloor(y);
  244. @@ -1833,7 +1833,7 @@ private:
  245. // Value Cubic Noise
  246. template <typename FNfloat>
  247. - float SingleValueCubic(int seed, FNfloat x, FNfloat y)
  248. + float SingleValueCubic(int seed, FNfloat x, FNfloat y) const
  249. {
  250. int x1 = FastFloor(x);
  251. int y1 = FastFloor(y);
  252. @@ -1863,7 +1863,7 @@ private:
  253. }
  254. template <typename FNfloat>
  255. - float SingleValueCubic(int seed, FNfloat x, FNfloat y, FNfloat z)
  256. + float SingleValueCubic(int seed, FNfloat x, FNfloat y, FNfloat z) const
  257. {
  258. int x1 = FastFloor(x);
  259. int y1 = FastFloor(y);
  260. @@ -1920,7 +1920,7 @@ private:
  261. // Value Noise
  262. template <typename FNfloat>
  263. - float SingleValue(int seed, FNfloat x, FNfloat y)
  264. + float SingleValue(int seed, FNfloat x, FNfloat y) const
  265. {
  266. int x0 = FastFloor(x);
  267. int y0 = FastFloor(y);
  268. @@ -1940,7 +1940,7 @@ private:
  269. }
  270. template <typename FNfloat>
  271. - float SingleValue(int seed, FNfloat x, FNfloat y, FNfloat z)
  272. + float SingleValue(int seed, FNfloat x, FNfloat y, FNfloat z) const
  273. {
  274. int x0 = FastFloor(x);
  275. int y0 = FastFloor(y);
  276. @@ -1972,7 +1972,7 @@ private:
  277. // Domain Warp
  278. template <typename FNfloat>
  279. - void DoSingleDomainWarp(int seed, float amp, float freq, FNfloat x, FNfloat y, FNfloat& xr, FNfloat& yr)
  280. + void DoSingleDomainWarp(int seed, float amp, float freq, FNfloat x, FNfloat y, FNfloat& xr, FNfloat& yr) const
  281. {
  282. switch (mDomainWarpType)
  283. {
  284. @@ -1989,7 +1989,7 @@ private:
  285. }
  286. template <typename FNfloat>
  287. - void DoSingleDomainWarp(int seed, float amp, float freq, FNfloat x, FNfloat y, FNfloat z, FNfloat& xr, FNfloat& yr, FNfloat& zr)
  288. + void DoSingleDomainWarp(int seed, float amp, float freq, FNfloat x, FNfloat y, FNfloat z, FNfloat& xr, FNfloat& yr, FNfloat& zr) const
  289. {
  290. switch (mDomainWarpType)
  291. {
  292. @@ -2009,7 +2009,7 @@ private:
  293. // Domain Warp Single Wrapper
  294. template <typename FNfloat>
  295. - void DomainWarpSingle(FNfloat& x, FNfloat& y)
  296. + void DomainWarpSingle(FNfloat& x, FNfloat& y) const
  297. {
  298. int seed = mSeed;
  299. float amp = mDomainWarpAmp * mFractalBounding;
  300. @@ -2023,7 +2023,7 @@ private:
  301. }
  302. template <typename FNfloat>
  303. - void DomainWarpSingle(FNfloat& x, FNfloat& y, FNfloat& z)
  304. + void DomainWarpSingle(FNfloat& x, FNfloat& y, FNfloat& z) const
  305. {
  306. int seed = mSeed;
  307. float amp = mDomainWarpAmp * mFractalBounding;
  308. @@ -2041,7 +2041,7 @@ private:
  309. // Domain Warp Fractal Progressive
  310. template <typename FNfloat>
  311. - void DomainWarpFractalProgressive(FNfloat& x, FNfloat& y)
  312. + void DomainWarpFractalProgressive(FNfloat& x, FNfloat& y) const
  313. {
  314. int seed = mSeed;
  315. float amp = mDomainWarpAmp * mFractalBounding;
  316. @@ -2062,7 +2062,7 @@ private:
  317. }
  318. template <typename FNfloat>
  319. - void DomainWarpFractalProgressive(FNfloat& x, FNfloat& y, FNfloat& z)
  320. + void DomainWarpFractalProgressive(FNfloat& x, FNfloat& y, FNfloat& z) const
  321. {
  322. int seed = mSeed;
  323. float amp = mDomainWarpAmp * mFractalBounding;
  324. @@ -2087,7 +2087,7 @@ private:
  325. // Domain Warp Fractal Independant
  326. template <typename FNfloat>
  327. - void DomainWarpFractalIndependent(FNfloat& x, FNfloat& y)
  328. + void DomainWarpFractalIndependent(FNfloat& x, FNfloat& y) const
  329. {
  330. FNfloat xs = x;
  331. FNfloat ys = y;
  332. @@ -2108,7 +2108,7 @@ private:
  333. }
  334. template <typename FNfloat>
  335. - void DomainWarpFractalIndependent(FNfloat& x, FNfloat& y, FNfloat& z)
  336. + void DomainWarpFractalIndependent(FNfloat& x, FNfloat& y, FNfloat& z) const
  337. {
  338. FNfloat xs = x;
  339. FNfloat ys = y;
  340. @@ -2133,7 +2133,7 @@ private:
  341. // Domain Warp Basic Grid
  342. template <typename FNfloat>
  343. - void SingleDomainWarpBasicGrid(int seed, float warpAmp, float frequency, FNfloat x, FNfloat y, FNfloat& xr, FNfloat& yr)
  344. + void SingleDomainWarpBasicGrid(int seed, float warpAmp, float frequency, FNfloat x, FNfloat y, FNfloat& xr, FNfloat& yr) const
  345. {
  346. FNfloat xf = x * frequency;
  347. FNfloat yf = y * frequency;
  348. @@ -2166,7 +2166,7 @@ private:
  349. }
  350. template <typename FNfloat>
  351. - void SingleDomainWarpBasicGrid(int seed, float warpAmp, float frequency, FNfloat x, FNfloat y, FNfloat z, FNfloat& xr, FNfloat& yr, FNfloat& zr)
  352. + void SingleDomainWarpBasicGrid(int seed, float warpAmp, float frequency, FNfloat x, FNfloat y, FNfloat z, FNfloat& xr, FNfloat& yr, FNfloat& zr) const
  353. {
  354. FNfloat xf = x * frequency;
  355. FNfloat yf = y * frequency;
  356. @@ -2228,7 +2228,7 @@ private:
  357. // Domain Warp Simplex/OpenSimplex2
  358. template <typename FNfloat>
  359. - void SingleDomainWarpSimplexGradient(int seed, float warpAmp, float frequency, FNfloat x, FNfloat y, FNfloat& xr, FNfloat& yr, bool outGradOnly)
  360. + void SingleDomainWarpSimplexGradient(int seed, float warpAmp, float frequency, FNfloat x, FNfloat y, FNfloat& xr, FNfloat& yr, bool outGradOnly) const
  361. {
  362. const float SQRT3 = 1.7320508075688772935274463415059f;
  363. const float G2 = (3 - SQRT3) / 6;
  364. @@ -2326,7 +2326,7 @@ private:
  365. }
  366. template <typename FNfloat>
  367. - void SingleDomainWarpOpenSimplex2Gradient(int seed, float warpAmp, float frequency, FNfloat x, FNfloat y, FNfloat z, FNfloat& xr, FNfloat& yr, FNfloat& zr, bool outGradOnly)
  368. + void SingleDomainWarpOpenSimplex2Gradient(int seed, float warpAmp, float frequency, FNfloat x, FNfloat y, FNfloat z, FNfloat& xr, FNfloat& yr, FNfloat& zr, bool outGradOnly) const
  369. {
  370. x *= frequency;
  371. y *= frequency;
  372. @@ -1611,6 +1611,12 @@ private:
  373. }
  374. }
  375. +// GCC raises warnings when integer overflows occur, which are needed for hashing here.
  376. +#if defined(__GNUC__) && !defined(__clang__)
  377. +#pragma GCC diagnostic push
  378. +#pragma GCC diagnostic ignored "-Waggressive-loop-optimizations"
  379. +#endif
  380. +
  381. template <typename FNfloat>
  382. float SingleCellular(int seed, FNfloat x, FNfloat y, FNfloat z) const
  383. {
  384. @@ -1765,6 +1771,9 @@ private:
  385. }
  386. }
  387. +#if defined(__GNUC__) && !defined(__clang__)
  388. +#pragma GCC diagnostic pop
  389. +#endif
  390. // Perlin Noise