Took the plunge and converted my 'shaperators' into templates so they'll work on any 'matrix-like' thing.

This commit is contained in:
Zed A. Shaw 2024-12-31 08:13:20 -05:00
parent 5adeb4e078
commit 4cb41a61db
5 changed files with 182 additions and 192 deletions

View file

@ -39,7 +39,7 @@ TEST_CASE("basic matrix iterator", "[matrix:basic]") {
{
// test getting the correct height in the middle
row_count = 0;
matrix::in_box box{walls, 2,2, 1};
matrix::box box{walls, 2,2, 1};
while(box.next()) {
row_count += box.x == box.left;
@ -55,7 +55,7 @@ TEST_CASE("basic matrix iterator", "[matrix:basic]") {
// confirm boxes have the right number of rows
// when x goes to 0 on first next call
row_count = 0;
matrix::in_box box{walls, 1, 1, 1};
matrix::box box{walls, 1, 1, 1};
while(box.next()) {
row_count += box.x == box.left;
@ -81,7 +81,7 @@ inline void random_matrix(Matrix &out) {
}
}
TEST_CASE("thash matrix iterators", "[matrix]") {
TEST_CASE("thrash matrix iterators", "[matrix]") {
for(int count = 0; count < Random::uniform<int>(10,30); count++) {
size_t width = Random::uniform<size_t>(1, 100);
size_t height = Random::uniform<size_t>(1, 100);
@ -111,7 +111,7 @@ TEST_CASE("thrash box distance iterators", "[matrix:distance]") {
size_t size = Random::uniform<int>(4, 10);
Point target{width/2, height/2};
matrix::in_box box{result, target.x, target.y, size};
matrix::box box{result, target.x, target.y, size};
while(box.next()) {
result[box.y][box.x] = box.distance();
}
@ -138,7 +138,7 @@ TEST_CASE("thrash box iterators", "[matrix]") {
PointList result;
// make a random size box
size_t size = Random::uniform<int>(1, 33);
matrix::in_box box{test, target.x, target.y, size};
matrix::box box{test, target.x, target.y, size};
while(box.next()) {
test[box.y][box.x] = test_i;
@ -217,7 +217,7 @@ TEST_CASE("prototype line algorithm", "[matrix:line]") {
// create a target for the paths
Point start{.x=map.width() / 2, .y=map.height()/2};
for(matrix::in_box box{map.walls(), start.x, start.y, 3};
for(matrix::box box{map.walls(), start.x, start.y, 3};
box.next();)
{
Matrix result = map.walls();