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

Function FL_TEST_FILE

tests/fl/math/line_simplification.cpp:13–213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11#include "fl/stl/move.h"
12
13FL_TEST_FILE(FL_FILEPATH) {
14
15
16FL_TEST_CASE("Test Line Simplification") {
17 // default‐constructed bitset is empty
18 fl::LineSimplifier<float> ls;
19 ls.setMinimumDistance(0.1f);
20 fl::vector<fl::vec2<float>> points;
21 points.push_back({0.0f, 0.0f});
22 points.push_back({1.0f, 1.0f});
23 points.push_back({2.0f, 2.0f});
24 points.push_back({3.0f, 3.0f});
25 points.push_back({4.0f, 4.0f});
26 ls.simplifyInplace(&points);
27 FL_REQUIRE_EQ(2,
28 points.size()); // Only 2 points on co-linear line should remain.
29 FL_REQUIRE_EQ(fl::vec2<float>(0.0f, 0.0f), points[0]);
30 FL_REQUIRE_EQ(fl::vec2<float>(4.0f, 4.0f), points[1]);
31}
32
33FL_TEST_CASE("Test simple triangle") {
34 fl::LineSimplifier<float> ls;
35
36 fl::vector<fl::vec2<float>> points;
37 points.push_back({0.0f, 0.0f}); // First point of triangle
38 points.push_back({0.5f, 0.5f});
39 points.push_back({0.0f, 1.0f});
40 float exceeds_thresh = 0.49f;
41 float under_thresh = 0.51f;
42 ls.setMinimumDistance(exceeds_thresh);
43 fl::vector<fl::vec2<float>> output;
44 ls.simplify(points, &output);
45 FL_REQUIRE_EQ(3, output.size());
46 FL_REQUIRE_EQ(fl::vec2<float>(0.0f, 0.0f), output[0]);
47 FL_REQUIRE_EQ(fl::vec2<float>(0.5f, 0.5f), output[1]);
48 FL_REQUIRE_EQ(fl::vec2<float>(0.0f, 1.0f), output[2]);
49
50 ls.setMinimumDistance(under_thresh);
51 ls.simplify(points, &output);
52 FL_REQUIRE_EQ(2, output.size());
53 FL_REQUIRE_EQ(fl::vec2<float>(0.0f, 0.0f), output[0]);
54 FL_REQUIRE_EQ(fl::vec2<float>(0.0f, 1.0f), output[1]);
55}
56
57FL_TEST_CASE("Test Line Simplification with Different Distance Thresholds") {
58 fl::LineSimplifier<float> ls;
59
60 // Test with a triangle shape - non-collinear points
61 ls.setMinimumDistance(0.5f);
62 fl::vector<fl::vec2<float>> points1;
63 points1.push_back({0.0f, 0.0f}); // First point of triangle
64 points1.push_back({0.3f, 0.3f}); // Should be filtered out (distance < 0.5)
65 points1.push_back({1.0f, 1.0f}); // Second point of triangle
66 points1.push_back({0.8f, 1.2f}); // Should be filtered out (distance < 0.5)
67 points1.push_back({0.0f, 2.0f}); // Third point of triangle
68 ls.simplifyInplace(&points1);
69 FL_REQUIRE_EQ(3, points1.size()); // Triangle vertices should remain
70 FL_REQUIRE_EQ(fl::vec2<float>(0.0f, 0.0f), points1[0]);

Callers

nothing calls this directly

Calls 7

almost_equalFunction · 0.85
setMinimumDistanceMethod · 0.80
setCountMethod · 0.80
push_backMethod · 0.45
simplifyInplaceMethod · 0.45
sizeMethod · 0.45
simplifyMethod · 0.45

Tested by

no test coverage detected