summaryrefslogtreecommitdiff
path: root/modules/noise/noise.cpp
diff options
context:
space:
mode:
authorHendrik Brucker <hendrik.brucker@mail.de>2023-01-06 02:46:08 +0100
committerHendrik Brucker <hendrik.brucker@mail.de>2023-01-06 02:46:08 +0100
commitffb8c74f266f585ff3b494bb9cbaf9d25b8591da (patch)
tree0c091fcb667f8579f0263cc9112f7455ce365e3e /modules/noise/noise.cpp
parent95ce236b7d6a70a06ecc13fb08d48da90ed98430 (diff)
Add tests for FastNoiseLite/NoiseTexture
+ fix some issues with seamless noise generation
Diffstat (limited to 'modules/noise/noise.cpp')
-rw-r--r--modules/noise/noise.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/modules/noise/noise.cpp b/modules/noise/noise.cpp
index 30bf126859..5a901cb6e1 100644
--- a/modules/noise/noise.cpp
+++ b/modules/noise/noise.cpp
@@ -30,11 +30,13 @@
#include "noise.h"
+#include <float.h>
+
Ref<Image> Noise::get_seamless_image(int p_width, int p_height, bool p_invert, bool p_in_3d_space, real_t p_blend_skirt) const {
ERR_FAIL_COND_V(p_width <= 0 || p_height <= 0, Ref<Image>());
- int skirt_width = p_width * p_blend_skirt;
- int skirt_height = p_height * p_blend_skirt;
+ int skirt_width = MAX(1, p_width * p_blend_skirt);
+ int skirt_height = MAX(1, p_height * p_blend_skirt);
int src_width = p_width + skirt_width;
int src_height = p_height + skirt_height;
@@ -67,8 +69,8 @@ Ref<Image> Noise::get_image(int p_width, int p_height, bool p_invert, bool p_in_
// Get all values and identify min/max values.
Vector<real_t> values;
values.resize(p_width * p_height);
- real_t min_val = 1000;
- real_t max_val = -1000;
+ real_t min_val = FLT_MAX;
+ real_t max_val = -FLT_MAX;
for (int y = 0, i = 0; y < p_height; y++) {
for (int x = 0; x < p_width; x++, i++) {