MCPcopy Create free account
hub / github.com/FastLED/FastLED / FL_TEST_FILE

Function FL_TEST_FILE

tests/fl/gfx/draw_disc.hpp:7–228  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5#include "fl/gfx/gfx.h"
6
7FL_TEST_FILE(FL_FILEPATH) {
8
9FL_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
29FL_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
54FL_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] = {};

Callers

nothing calls this directly

Calls 6

sqrtFunction · 0.85
printfFunction · 0.85
CRGBClass · 0.50
s16x16Class · 0.50
drawDiscMethod · 0.45
to_floatMethod · 0.45

Tested by

no test coverage detected