Use error macros in the wfc module instead of asserts.

This commit is contained in:
Relintai 2022-04-21 16:51:10 +02:00
parent ec6b52f5d8
commit e4a2429b45
3 changed files with 19 additions and 20 deletions

View File

@ -1,7 +1,6 @@
#ifndef FAST_WFC_UTILS_ARRAY2D_HPP_
#define FAST_WFC_UTILS_ARRAY2D_HPP_
#include "assert.h"
#include "core/vector.h"
template <typename T>
@ -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];
}

View File

@ -1,7 +1,6 @@
#ifndef FAST_WFC_UTILS_ARRAY3D_HPP_
#define FAST_WFC_UTILS_ARRAY3D_HPP_
#include "assert.h"
#include "core/vector.h"
template <typename T>
@ -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];
}

View File

@ -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<double> patterns_weight;
Vector<Array2D<T>> symmetries(
8, Array2D<T>(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<Array2D<T>> symmetries(8, Array2D<T>(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;