FastLED 3.9.15
Loading...
Searching...
No Matches

◆ removeOneLeastError()

template<typename NumberT = float>
template<typename VectorType>
static void fl::LineSimplifier< NumberT >::removeOneLeastError ( VectorType * _poly)
inlinestatic

Definition at line 64 of file line_simplification.h.

64 {
67 keep.assign(poly.size(), 1);
68 const int n = poly.size();
70 int bestIdx = -1;
71
72 // scan all interior “alive” points
73 for (int i = 1; i + 1 < n; ++i) {
74 if (!keep[i])
75 continue;
76
77 // find previous alive
78 int L = i - 1;
79 while (L >= 0 && !keep[L])
80 --L;
81 // find next alive
82 int R = i + 1;
83 while (R < n && !keep[R])
84 ++R;
85
86 if (L < 0 || R >= n)
87 continue; // endpoints
88
89 // compute perp‐distance² to the chord L→R
90 NumberT dx = poly[R].x - poly[L].x;
91 NumberT dy = poly[R].y - poly[L].y;
92 NumberT vx = poly[i].x - poly[L].x;
93 NumberT vy = poly[i].y - poly[L].y;
94 NumberT len2 = dx * dx + dy * dy;
95 NumberT err =
96 (len2 > NumberT(0))
97 ? ((dx * vy - dy * vx) * (dx * vy - dy * vx) / len2)
98 : (vx * vx + vy * vy);
99
100 if (err < bestErr) {
101 bestErr = err;
102 bestIdx = i;
103 }
104 }
105
106 // now “remove” that one point
107 if (bestIdx >= 0)
108 // keep[bestIdx] = 0;
109 poly.erase(poly.begin() + bestIdx);
110 }
fl::bitset< 256 > keep

References INFINITY_DOUBLE, and keep.