From 85e38a358d1d22e1eddb70170d3f4927661cd704 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Wed, 10 May 2023 20:47:08 +0200 Subject: [PATCH] u02/tests: Use floats for r/d in circle prop test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It does not improve the test’s accuracy, but it seems weird to first convert the radius to an int and then save the distance as a double. --- u02/src/tests.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/u02/src/tests.cpp b/u02/src/tests.cpp index 97862b7..2fc9cd0 100644 --- a/u02/src/tests.cpp +++ b/u02/src/tests.cpp @@ -352,7 +352,7 @@ TEST_CASE("Bresenham circle (prop: √(x²+y²)-r<ε)") { SKIP("All coordinates have extreme value, skipping (avoid rounding error)"); } - const int r = + const float r = round(std::sqrt(std::pow((x1 - x0), 2) + std::pow((y1 - y0), 2))); canvas_buffer *canvas = new canvas_buffer(size, size); @@ -363,7 +363,7 @@ TEST_CASE("Bresenham circle (prop: √(x²+y²)-r<ε)") { bool pass = true; for (int x = 0; x < size; x++) { for (int y = 0; y < size; y++) { - double distance = + float distance = std::abs(std::sqrt(std::pow(x0 - x, 2) + std::pow(y0 - y, 2)) - r); // Because of rounding errors, an exact test (for all pixels) is not // feasible.