diff --git a/modules/wfc/array_2d.h b/modules/wfc/array_2d.h index 1090db721..2f6585eff 100644 --- a/modules/wfc/array_2d.h +++ b/modules/wfc/array_2d.h @@ -1,7 +1,6 @@ #ifndef FAST_WFC_UTILS_ARRAY2D_HPP_ #define FAST_WFC_UTILS_ARRAY2D_HPP_ -#include "assert.h" #include "core/vector.h" template @@ -26,12 +25,16 @@ public: } const T &get(uint32_t i, uint32_t j) const { - assert(i < height && j < width); + CRASH_BAD_INDEX(i, height); + CRASH_BAD_INDEX(j, width); + return data[j + i * width]; } T &get(uint32_t i, uint32_t j) { - assert(i < height && j < width); + CRASH_BAD_INDEX(i, height); + CRASH_BAD_INDEX(j, width); + return data.write[j + i * width]; } diff --git a/modules/wfc/array_3d.h b/modules/wfc/array_3d.h index eb0c526f6..1087caeb8 100644 --- a/modules/wfc/array_3d.h +++ b/modules/wfc/array_3d.h @@ -1,7 +1,6 @@ #ifndef FAST_WFC_UTILS_ARRAY3D_HPP_ #define FAST_WFC_UTILS_ARRAY3D_HPP_ -#include "assert.h" #include "core/vector.h" template @@ -29,11 +28,18 @@ public: } const T &get(uint32_t i, uint32_t j, uint32_t k) const { - assert(i < height && j < width && k < depth); + CRASH_BAD_INDEX(i, height); + CRASH_BAD_INDEX(j, width); + CRASH_BAD_INDEX(k, depth); + return data[i * width * depth + j * depth + k]; } T &get(uint32_t i, uint32_t j, uint32_t k) { + CRASH_BAD_INDEX(i, height); + CRASH_BAD_INDEX(j, width); + CRASH_BAD_INDEX(k, depth); + return data.write[i * width * depth + j * depth + k]; } diff --git a/modules/wfc/overlapping_wfc.h b/modules/wfc/overlapping_wfc.h index f3850ab53..8c635eebf 100644 --- a/modules/wfc/overlapping_wfc.h +++ b/modules/wfc/overlapping_wfc.h @@ -85,9 +85,7 @@ private: } } - // The pattern exists. - assert(false); - return 0; + ERR_FAIL_V(0); } //Return the list of patterns, as well as their probabilities of apparition. @@ -98,22 +96,14 @@ private: // The number of time a pattern is seen in the input image. Vector patterns_weight; - Vector> symmetries( - 8, Array2D(options.pattern_size, options.pattern_size)); - uint32_t max_i = options.periodic_input - ? input.height - : input.height - options.pattern_size + 1; - uint32_t max_j = options.periodic_input - ? input.width - : input.width - options.pattern_size + 1; + Vector> symmetries(8, Array2D(options.pattern_size, options.pattern_size)); + uint32_t max_i = options.periodic_input ? input.height : input.height - options.pattern_size + 1; + uint32_t max_j = options.periodic_input ? input.width : input.width - options.pattern_size + 1; for (uint32_t i = 0; i < max_i; i++) { for (uint32_t j = 0; j < max_j; j++) { // Compute the symmetries of every pattern in the image. - symmetries[0].data = - input - .get_sub_array(i, j, options.pattern_size, options.pattern_size) - .data; + symmetries[0].data = input.get_sub_array(i, j, options.pattern_size, options.pattern_size).data; symmetries[1].data = symmetries[0].reflected().data; symmetries[2].data = symmetries[0].rotated().data; symmetries[3].data = symmetries[2].reflected().data;