| 5 | #include "fl/gfx/gfx.h" |
| 6 | |
| 7 | FL_TEST_FILE(FL_FILEPATH) { |
| 8 | |
| 9 | FL_TEST_CASE("drawDisc basic rendering") { |
| 10 | FL_SUBCASE("center pixel is lit in 32x32 at (15.5, 15.5), r=5") { |
| 11 | CRGB buffer[1024] = {}; |
| 12 | fl::CanvasRGB canvas(buffer, 32, 32); |
| 13 | canvas.drawDisc(CRGB(255, 0, 0), 15.5f, 15.5f, 5.0f); |
| 14 | |
| 15 | // Center pixel (15, 15) should be non-zero |
| 16 | FL_CHECK(buffer[15 * 32 + 15].r > 0); |
| 17 | } |
| 18 | |
| 19 | FL_SUBCASE("pixel beyond r+1 is black") { |
| 20 | CRGB buffer[1024] = {}; |
| 21 | fl::CanvasRGB canvas(buffer, 32, 32); |
| 22 | canvas.drawDisc(CRGB(255, 0, 0), 15.5f, 15.5f, 5.0f); |
| 23 | |
| 24 | // Pixel at (15, 22) is over r+1 away, should be black |
| 25 | FL_CHECK_EQ(buffer[22 * 32 + 15].r, 0); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | FL_TEST_CASE("drawDisc antialiasing") { |
| 30 | FL_SUBCASE("AA fringe at radius edge") { |
| 31 | CRGB buffer[1024] = {}; |
| 32 | fl::CanvasRGB canvas(buffer, 32, 32); |
| 33 | canvas.drawDisc(CRGB(255, 0, 0), 15.5f, 15.5f, 5.5f); |
| 34 | |
| 35 | // Find a pixel at approximately the radius - should have intermediate brightness |
| 36 | bool found_aa = false; |
| 37 | for (int y = 10; y < 21; ++y) { |
| 38 | for (int x = 10; x < 21; ++x) { |
| 39 | float dist = fl::sqrt((x - 15.5f) * (x - 15.5f) + (y - 15.5f) * (y - 15.5f)); |
| 40 | if (dist > 5.0f && dist < 6.0f) { |
| 41 | uint8_t r = buffer[y * 32 + x].r; |
| 42 | if (r > 0 && r < 255) { |
| 43 | found_aa = true; |
| 44 | break; |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | if (found_aa) break; |
| 49 | } |
| 50 | FL_CHECK(found_aa); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | FL_TEST_CASE("drawDisc edge cases") { |
| 55 | FL_SUBCASE("zero radius (no crash)") { |
| 56 | CRGB buffer[1024] = {}; |
| 57 | fl::CanvasRGB canvas(buffer, 32, 32); |
| 58 | canvas.drawDisc(CRGB(255, 0, 0), 15.5f, 15.5f, 0.0f); |
| 59 | // Should not crash |
| 60 | FL_CHECK(true); |
| 61 | } |
| 62 | |
| 63 | FL_SUBCASE("off-screen center (no crash)") { |
| 64 | CRGB buffer[1024] = {}; |