u02: Implement rectangle tool

This commit is contained in:
Simon Bruder 2023-05-07 10:03:41 +02:00
parent 5a1ba0ca93
commit b780d4b8c4

View file

@ -9,6 +9,7 @@
#include "canvas_buffer.h"
#include "dda_line_tool.h"
#include "non_recursive_fill_tool.h"
#include "rectangle_tool.h"
#include "recursive_fill_tool.h"
#include "util.h"
@ -263,3 +264,37 @@ TEST_CASE("Fill recursive == Fill non recursive (prop, 5 random lines)") {
}
REQUIRE(equal);
}
TEST_CASE("Rectangle (prop)") {
const int size = 100;
const int x0 = GENERATE(take(5, random(0, size - 1)));
const int y0 = GENERATE(take(5, random(0, size - 1)));
const int x1 = GENERATE(take(5, random(0, size - 1)));
const int y1 = GENERATE(take(5, random(0, size - 1)));
const int x_min = std::min(x0, x1);
const int x_max = std::max(x0, x1);
const int y_min = std::min(y0, y1);
const int y_max = std::max(y0, y1);
canvas_buffer *canvas = new canvas_buffer(size, size);
rectangle_tool *tool = new rectangle_tool(*canvas);
tool->draw(x0, y0, x1, y1);
bool pass = true;
for (int x = 0; x < size; x++) {
for (int y = 0; y < size; y++) {
if (((x == x0 || x == x1) && (y >= y_min && y <= y_max)) ||
((y == y0 || y == y1) && (x >= x_min && x <= x_max))) {
if (!canvas->get_pixel(x, y))
pass = false;
} else {
if (canvas->get_pixel(x, y))
pass = false;
}
}
}
REQUIRE(pass);
}