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

◆ simplifyInternal()

template<typename NumberT = float>
void fl::LineSimplifier< NumberT >::simplifyInternal ( const fl::span< const Point > & polyLine)
inlineprivate

Definition at line 130 of file line_simplification.h.

130 {
131 mSimplified.clear();
132 int n = polyLine.size();
133 if (n < 2) {
134 if (n) {
135 mSimplified.assign(polyLine.data(), polyLine.data() + n);
136 }
137 return;
138 }
140
141 // mark all points as “kept” initially
142 keep.assign(n, 1);
143
144 // explicit stack of (start,end) index pairs
145 indexStack.clear();
146 // indexStack.reserve(64);
147 indexStack.push_back({0, n - 1});
148
149 // process segments
150 while (!indexStack.empty()) {
151 // auto [i0, i1] = indexStack.back();
152 auto pair = indexStack.back();
153 int i0 = pair.first;
154 int i1 = pair.second;
155 indexStack.pop_back();
156 const bool has_interior = (i1 - i0) > 1;
157 if (!has_interior) {
158 // no interior points, just keep the endpoints
159 // keep[i0] = 1;
160 // keep[i1] = 1;
161 continue;
162 }
163
164 // find farthest point in [i0+1 .. i1-1]
165 NumberT maxDist2 = 0;
166 int split = i0;
167 for (int i = i0 + 1; i < i1; ++i) {
168 if (!keep[i])
169 continue;
171 polyLine[i1]);
172
173 // FL_WARN("Perpendicular distance2 between "
174 // << polyLine[i] << " and " << polyLine[i0]
175 // << " and " << polyLine[i1] << " is " << d2);
176
177 if (d2 > maxDist2) {
178 maxDist2 = d2;
179 split = i;
180 }
181 }
182
183 if (maxDist2 > minDist2) {
184 // need to keep that split point and recurse on both halves
185 indexStack.push_back({i0, split});
186 indexStack.push_back({split, i1});
187 } else {
188 // drop all interior points in this segment
189 for (int i = i0 + 1; i < i1; ++i) {
190 keep[i] = 0;
191 }
192 }
193 }
194
195 // collect survivors
196 mSimplified.clear();
197 mSimplified.reserve(n);
198 for (int i = 0; i < n; ++i) {
199 if (keep[i])
200 mSimplified.push_back(polyLine[i]);
201 }
202 }
static NumberT PerpendicularDistance2(const Point &pt, const Point &a, const Point &b)
fl::bitset< 256 > keep
fl::vector_inlined< fl::pair< int, int >, 64 > indexStack

References fl::span< T, Extent >::data(), fl::pair< T1, T2 >::first, indexStack, keep, mMinDistance, mSimplified, PerpendicularDistance2(), fl::pair< T1, T2 >::second, and fl::span< T, Extent >::size().

Referenced by simplifyT().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: