Circle iterator now compensates for the matrix size and won't overflow.
This commit is contained in:
parent
35f2defc11
commit
857cd2f910
5 changed files with 25 additions and 23 deletions
|
@ -226,7 +226,7 @@ TEST_CASE("prototype line algorithm", "[matrix:line]") {
|
|||
}
|
||||
|
||||
TEST_CASE("prototype circle algorithm", "[matrix:circle]") {
|
||||
for(int count = 0; count < 20; count++) {
|
||||
for(int count = 0; count < 2000; count++) {
|
||||
size_t width = Random::uniform<size_t>(10, 13);
|
||||
size_t height = Random::uniform<size_t>(10, 15);
|
||||
int pos_mod = Random::uniform<int>(-3,3);
|
||||
|
@ -238,12 +238,15 @@ TEST_CASE("prototype circle algorithm", "[matrix:circle]") {
|
|||
// use an empty map
|
||||
Matrix result = map.walls();
|
||||
|
||||
for(matrix::circle it{start, radius}; it.next();) {
|
||||
for(matrix::circle it{result, start, radius}; it.next();) {
|
||||
for(int x = it.left; x < it.right; x++) {
|
||||
// println("top={}, bottom={}, center.y={}, dy={}, left={}, right={}, x={}, y={}", it.top, it.bottom, it.center.y, it.dy, it.left, it.right, x, it.y);
|
||||
if(matrix::inbounds(result, x, it.y)) {
|
||||
result[it.y][x] += 1;
|
||||
}
|
||||
// println("RESULT {},{}", matrix::width(result), matrix::height(result));
|
||||
REQUIRE(it.y >= 0);
|
||||
REQUIRE(x >= 0);
|
||||
REQUIRE(it.y < int(matrix::height(result)));
|
||||
REQUIRE(x < int(matrix::width(result)));
|
||||
result[it.y][x] += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue