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

Function FL_TEST_FILE

tests/fl/gfx/draw_ring.hpp:7–122  ·  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("drawRing basic rendering") {
10 FL_SUBCASE("center hole is transparent in ring") {
11 CRGB buffer[1024] = {};
12 fl::CanvasRGB canvas(buffer, 32, 32);
13
14 canvas.drawRing(CRGB(255, 0, 0), 15.5f, 15.5f, 5.0f, 2.0f);
15
16 // Center pixel (15, 15) should be black (inside hole)
17 FL_CHECK_EQ(buffer[15 * 32 + 15].r, 0);
18 }
19
20 FL_SUBCASE("band is lit at r+thickness/2") {
21 CRGB buffer[1024] = {};
22 fl::CanvasRGB canvas(buffer, 32, 32);
23
24 canvas.drawRing(CRGB(255, 0, 0), 15.5f, 15.5f, 5.0f, 2.0f);
25
26 // Pixel at r + thickness/2 from center should be non-zero
27 bool found_lit = false;
28 for (int y = 10; y < 21; ++y) {
29 for (int x = 10; x < 21; ++x) {
30 float dist = fl::sqrt((x - 15.5f) * (x - 15.5f) + (y - 15.5f) * (y - 15.5f));
31 if (dist > 5.5f && dist < 6.5f && buffer[y * 32 + x].r > 0) {
32 found_lit = true;
33 break;
34 }
35 }
36 if (found_lit) break;
37 }
38 FL_CHECK(found_lit);
39 }
40
41 FL_SUBCASE("outside ring is black") {
42 CRGB buffer[1024] = {};
43 fl::CanvasRGB canvas(buffer, 32, 32);
44
45 canvas.drawRing(CRGB(255, 0, 0), 15.5f, 15.5f, 5.0f, 2.0f);
46
47 // Pixel far outside the ring should be black
48 FL_CHECK_EQ(buffer[25 * 32 + 15].r, 0);
49 }
50}
51
52FL_TEST_CASE("drawRing antialiasing") {
53 FL_SUBCASE("inner AA fringe") {
54 CRGB buffer[1024] = {};
55 fl::CanvasRGB canvas(buffer, 32, 32);
56
57 canvas.drawRing(CRGB(255, 0, 0), 15.5f, 15.5f, 5.0f, 2.0f);
58
59 // Find a pixel at approximately r from center - should have intermediate brightness
60 bool found_aa = false;
61 for (int y = 10; y < 21; ++y) {
62 for (int x = 10; x < 21; ++x) {
63 float dist = fl::sqrt((x - 15.5f) * (x - 15.5f) + (y - 15.5f) * (y - 15.5f));
64 if (dist > 4.5f && dist < 5.5f) {

Callers

nothing calls this directly

Calls 3

sqrtFunction · 0.85
CRGBClass · 0.50
drawRingMethod · 0.45

Tested by

no test coverage detected