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

Function FL_TEST_FILE

tests/fl/gfx/draw_disc_16.hpp:11–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9using fl::u8x8;
10
11FL_TEST_FILE(FL_FILEPATH) {
12
13FL_TEST_CASE("Canvas<CRGB16> drawDisc") {
14 FL_SUBCASE("center pixel is lit") {
15 CRGB16 buffer[1024] = {};
16 fl::Canvas<CRGB16> canvas(fl::span<CRGB16>(buffer, 1024), 32, 32);
17 canvas.drawDisc(CRGB16(u8x8(255.0f), u8x8(0.0f), u8x8(0.0f)), 15.5f, 15.5f, 5.0f);
18 FL_CHECK(buffer[15 * 32 + 15].r.raw() > 0);
19 }
20
21 FL_SUBCASE("pixel beyond radius is black") {
22 CRGB16 buffer[1024] = {};
23 fl::Canvas<CRGB16> canvas(fl::span<CRGB16>(buffer, 1024), 32, 32);
24 canvas.drawDisc(CRGB16(u8x8(255.0f), u8x8(0.0f), u8x8(0.0f)), 15.5f, 15.5f, 5.0f);
25 FL_CHECK(buffer[22 * 32 + 15].r.raw() == 0);
26 }
27
28 FL_SUBCASE("AA fringe has intermediate brightness") {
29 CRGB16 buffer[1024] = {};
30 fl::Canvas<CRGB16> canvas(fl::span<CRGB16>(buffer, 1024), 32, 32);
31 canvas.drawDisc(CRGB16(u8x8(255.0f), u8x8(0.0f), u8x8(0.0f)), 15.5f, 15.5f, 5.5f);
32
33 bool found_aa = false;
34 for (int y = 10; y < 21; ++y) {
35 for (int x = 10; x < 21; ++x) {
36 float dist = fl::sqrt((x - 15.5f) * (x - 15.5f) + (y - 15.5f) * (y - 15.5f));
37 if (dist > 5.0f && dist < 6.0f) {
38 fl::u16 rv = buffer[y * 32 + x].r.raw();
39 if (rv > 0 && rv < 0xFF00) {
40 found_aa = true;
41 break;
42 }
43 }
44 }
45 if (found_aa) break;
46 }
47 FL_CHECK(found_aa);
48 }
49}
50
51FL_TEST_CASE("Canvas<CRGB16> drawLine") {
52 FL_SUBCASE("horizontal line lights correct pixels") {
53 CRGB16 buffer[256] = {};
54 fl::Canvas<CRGB16> canvas(fl::span<CRGB16>(buffer, 256), 16, 16);
55 canvas.drawLine(CRGB16(u8x8(255.0f), u8x8(0.0f), u8x8(0.0f)), 2.0f, 8.0f, 13.0f, 8.0f);
56
57 int non_zero = 0;
58 for (int x = 0; x < 16; ++x) {
59 if (buffer[8 * 16 + x].r.raw() > 0) non_zero++;
60 }
61 FL_CHECK(non_zero >= 10);
62 }
63}
64
65FL_TEST_CASE("Canvas<CRGB16> drawRing") {
66 FL_SUBCASE("center hole is transparent") {
67 CRGB16 buffer[1024] = {};
68 fl::Canvas<CRGB16> canvas(fl::span<CRGB16>(buffer, 1024), 32, 32);

Callers

nothing calls this directly

Calls 8

CRGB16Class · 0.85
u8x8Class · 0.85
sqrtFunction · 0.85
drawDiscMethod · 0.45
rawMethod · 0.45
drawLineMethod · 0.45
drawRingMethod · 0.45
drawStrokeLineMethod · 0.45

Tested by

no test coverage detected