Smaller improvements.

This commit is contained in:
Relintai 2022-04-21 17:33:44 +02:00
parent 2680c89948
commit 4e8d254ba9
5 changed files with 27 additions and 27 deletions

View File

@ -73,7 +73,7 @@ public:
return false;
}
for (uint32_t i = 0; i < data.size(); i++) {
for (int i = 0; i < data.size(); i++) {
if (a.data[i] != data[i]) {
return false;
}

View File

@ -48,7 +48,7 @@ public:
return false;
}
for (uint32_t i = 0; i < data.size(); i++) {
for (int i = 0; i < data.size(); i++) {
if (a.data[i] != data[i]) {
return false;
}

View File

@ -79,7 +79,7 @@ private:
Array2D<T> ground_pattern = input.get_sub_array(input.height - 1, input.width / 2, options.pattern_size, options.pattern_size);
// Retrieve the id of the pattern.
for (uint32_t i = 0; i < patterns.size(); i++) {
for (int i = 0; i < patterns.size(); i++) {
if (ground_pattern == patterns[i]) {
return i;
}
@ -115,8 +115,7 @@ private:
// The number of symmetries in the option class define which symetries
// will be used.
for (uint32_t k = 0; k < options.symmetry; k++) {
auto res = patterns_id.insert(
std::make_pair(symmetries[k], patterns.size()));
auto res = patterns_id.insert(std::make_pair(symmetries[k], patterns.size()));
// If the pattern already exist, we just have to increase its number
// of appearance.
@ -149,6 +148,7 @@ private:
}
}
}
return true;
}
@ -157,12 +157,13 @@ private:
// contains pattern2, where direction is the direction defined by (dy, dx)
// (see direction.hpp).
static Vector<PropagatorEntry> generate_compatible(const Vector<Array2D<T>> &patterns) {
Vector<PropagatorEntry> compatible = Vector<PropagatorEntry>(patterns.size());
Vector<PropagatorEntry> compatible;
compatible.resize(patterns.size());
// Iterate on every dy, dx, pattern1 and pattern2
for (uint32_t pattern1 = 0; pattern1 < patterns.size(); pattern1++) {
for (int pattern1 = 0; pattern1 < patterns.size(); pattern1++) {
for (uint32_t direction = 0; direction < 4; direction++) {
for (uint32_t pattern2 = 0; pattern2 < patterns.size(); pattern2++) {
for (int pattern2 = 0; pattern2 < patterns.size(); pattern2++) {
if (agrees(patterns[pattern1], patterns[pattern2], directions_y[direction], directions_x[direction])) {
compatible[pattern1][direction].push_back(pattern2);
}
@ -230,7 +231,7 @@ private:
// Set the pattern at a specific position, given its pattern id
// pattern_id needs to be a valid pattern id, and i and j needs to be in the wave range
void set_pattern(uint32_t pattern_id, uint32_t i, uint32_t j) {
for (uint32_t p = 0; p < patterns.size(); p++) {
for (int p = 0; p < patterns.size(); p++) {
if (pattern_id != p) {
wfc.remove_wave_pattern(i, j, p);
}

View File

@ -90,23 +90,23 @@ struct Tile {
static Vector<Vector<uint32_t>> generate_action_map(const Symmetry &symmetry) {
Vector<uint32_t> rotation_map = generate_rotation_map(symmetry);
Vector<uint32_t> reflection_map = generate_reflection_map(symmetry);
size_t size = rotation_map.size();
Vector<Vector<uint32_t>> action_map(8,
Vector<uint32_t>(size));
for (size_t i = 0; i < size; ++i) {
int size = rotation_map.size();
Vector<Vector<uint32_t>> action_map(8, Vector<uint32_t>(size));
for (int i = 0; i < size; ++i) {
action_map[0][i] = i;
}
for (size_t a = 1; a < 4; ++a) {
for (size_t i = 0; i < size; ++i) {
for (int a = 1; a < 4; ++a) {
for (int i = 0; i < size; ++i) {
action_map[a][i] = rotation_map[action_map[a - 1][i]];
}
}
for (size_t i = 0; i < size; ++i) {
for (int i = 0; i < size; ++i) {
action_map[4][i] = reflection_map[action_map[0][i]];
}
for (size_t a = 5; a < 8; ++a) {
for (size_t i = 0; i < size; ++i) {
for (int a = 5; a < 8; ++a) {
for (int i = 0; i < size; ++i) {
action_map[a][i] = rotation_map[action_map[a - 1][i]];
}
}
@ -114,8 +114,7 @@ struct Tile {
}
// Generate all distincts rotations of a 2D array given its symmetries;
static Vector<Array2D<T>> generate_oriented(Array2D<T> data,
Symmetry symmetry) {
static Vector<Array2D<T>> generate_oriented(Array2D<T> data, Symmetry symmetry) {
Vector<Array2D<T>> oriented;
oriented.push_back(data);
@ -187,9 +186,9 @@ private:
Vector<Vector<uint32_t>> oriented_tile_ids;
uint32_t id = 0;
for (uint32_t i = 0; i < tiles.size(); i++) {
for (int i = 0; i < tiles.size(); i++) {
oriented_tile_ids.push_back({});
for (uint32_t j = 0; j < tiles[i].data.size(); j++) {
for (int j = 0; j < tiles[i].data.size(); j++) {
id_to_oriented_tile.push_back({ i, j });
oriented_tile_ids[i].push_back(id);
id++;
@ -272,8 +271,8 @@ private:
static Vector<double> get_tiles_weights(const Vector<Tile<T>> &tiles) {
Vector<double> frequencies;
for (size_t i = 0; i < tiles.size(); ++i) {
for (size_t j = 0; j < tiles[i].data.size(); ++j) {
for (int i = 0; i < tiles.size(); ++i) {
for (int j = 0; j < tiles[i].data.size(); ++j) {
frequencies.push_back(tiles[i].weight / tiles[i].data.size());
}
}
@ -302,7 +301,7 @@ private:
}
void set_tile(uint32_t tile_id, uint32_t i, uint32_t j) {
for (uint32_t p = 0; p < id_to_oriented_tile.size(); p++) {
for (int p = 0; p < id_to_oriented_tile.size(); p++) {
if (tile_id != p) {
wfc.remove_wave_pattern(i, j, p);
}

View File

@ -8,7 +8,7 @@ namespace {
Vector<double> get_plogp(const Vector<double> &distribution) {
Vector<double> plogp;
for (uint32_t i = 0; i < distribution.size(); i++) {
for (int i = 0; i < distribution.size(); i++) {
plogp.push_back(distribution[i] * log(distribution[i]));
}
@ -19,7 +19,7 @@ Vector<double> get_plogp(const Vector<double> &distribution) {
double get_min_abs_half(const Vector<double> &v) {
double min_abs_half = std::numeric_limits<double>::infinity();
for (uint32_t i = 0; i < v.size(); i++) {
for (int i = 0; i < v.size(); i++) {
min_abs_half = std::min(min_abs_half, std::abs(v[i] / 2.0));
}