12#include "../3rdparty/catch2/catch.hpp"
14#include "../tilearea_type.h"
15#include "../map_func.h"
17#include "../safeguards.h"
23static void TestSpiralTileSequence(
TileCoord center, uint diameter, std::span<TileCoord> expected)
25 auto tile =
TileXY(center.x, center.y);
27 std::vector<TileIndex> result;
31 REQUIRE(result.size() == expected.size());
32 for (
size_t i = 0; i < result.size(); ++i) {
33 CHECK(
TileX(result[i]) == expected[i].x);
34 CHECK(
TileY(result[i]) == expected[i].y);
38static void TestSpiralTileSequence(
TileCoord start_north, uint radius, uint w, uint h, std::span<TileCoord> expected)
40 auto tile =
TileXY(start_north.x, start_north.y);
42 std::vector<TileIndex> result;
46 REQUIRE(result.size() == expected.size());
47 for (
size_t i = 0; i < result.size(); ++i) {
48 CHECK(
TileX(result[i]) == expected[i].x);
49 CHECK(
TileY(result[i]) == expected[i].y);
53TEST_CASE(
"SpiralTileSequence - minimum")
58 TestSpiralTileSequence({63, 63}, 1, expected);
59 TestSpiralTileSequence({63, 63}, 2, expected);
60 TestSpiralTileSequence({63, 63}, 1, 0, 0, expected);
61 TestSpiralTileSequence({63, 63}, 1, 2, 2, expected);
64TEST_CASE(
"SpiralTileSequence - odd")
70 {2, 0}, {1, 0}, {0, 0}, {0, 1}, {0, 2}, {1, 2}, {2, 2}, {2, 1},
71 {0, 3}, {1, 3}, {2, 3}, {3, 3}, {3, 2}, {3, 1}, {3, 0},
73 TestSpiralTileSequence({1, 1}, 5, expected);
76TEST_CASE(
"SpiralTileSequence - even")
81 {2, 1}, {1, 1}, {1, 2}, {2, 2},
82 {3, 0}, {2, 0}, {1, 0}, {0, 0}, {0, 1}, {0, 2}, {0, 3}, {1, 3}, {2, 3}, {3, 3}, {3, 2}, {3, 1},
83 {0, 4}, {1, 4}, {2, 4}, {3, 4}, {4, 4}, {4, 3}, {4, 2}, {4, 1}, {4, 0},
85 TestSpiralTileSequence({1, 1}, 6, expected);
86 TestSpiralTileSequence({1, 1}, 3, 0, 0, expected);
89TEST_CASE(
"SpiralTileSequence - zero hole")
94 {5, 2}, {4, 2}, {3, 2}, {2, 2}, {2, 3}, {3, 3}, {4, 3}, {5, 3},
95 {6, 1}, {5, 1}, {4, 1}, {3, 1}, {2, 1}, {1, 1}, {1, 2}, {1, 3}, {1, 4}, {2, 4}, {3, 4}, {4, 4}, {5, 4}, {6, 4}, {6, 3}, {6, 2},
97 TestSpiralTileSequence({2, 2}, 2, 2, 0, expected);
100TEST_CASE(
"SpiralTileSequence - normal hole")
105 {4, 2}, {3, 2}, {2, 2}, {2, 3}, {2, 4}, {2, 5}, {3, 5}, {4, 5}, {4, 4}, {4, 3},
107 TestSpiralTileSequence({2, 2}, 1, 1, 2, expected);
Generate TileIndices around a center tile or tile area, with increasing distance.
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
static void Allocate(uint size_x, uint size_y)
(Re)allocates a map with the given dimension