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

◆ simplify()

template<typename NumberT = float>
template<typename VectorType = fl::vector<Point>>
void fl::LineSimplifierExact< NumberT >::simplify ( const fl::Slice< const Point > & polyLine,
VectorType * out )
inline

Definition at line 250 of file line_simplification.h.

250 {
251 if (mCount > polyLine.size()) {
253 return;
254 } else if (mCount == polyLine.size()) {
256 return;
257 } else if (mCount < 2) {
259 if (polyLine.size() > 0) {
260 temp.push_back(polyLine[0]);
261 }
262 if (polyLine.size() > 1) {
263 temp.push_back(polyLine[polyLine.size() - 1]);
264 }
265 out->assign(temp.begin(), temp.end());
266 return;
267 }
269 NumberT min = 0;
271 NumberT mid = (min + max) / 2.0f;
272 while (true) {
273 // min < max;
274 auto diff = max - min;
275 const bool done = (diff < 0.01f);
276 out->clear();
277 mLineSimplifier.setMinimumDistance(mid);
278 mLineSimplifier.simplify(polyLine, out);
279
280 size_t n = out->size();
281
282 if (n == mCount) {
283 return; // we are done
284 }
285
286 // Handle the last few iterations manually. Often the algo will get
287 // stuck here.
288 if (n == mCount + 1) {
289 // Just one more left, so peel it off.
290 mLineSimplifier.removeOneLeastError(out);
291 return;
292 }
293
294 if (n == mCount + 2) {
295 // Just two more left, so peel them off.
296 mLineSimplifier.removeOneLeastError(out);
297 mLineSimplifier.removeOneLeastError(out);
298 return;
299 }
300
301 if (done) {
302 while (out->size() > mCount) {
303 // we have too many points, so we need to increase the
304 // distance
305 mLineSimplifier.removeOneLeastError(out);
306 }
307 return;
308 }
309 if (out->size() < mCount) {
310 max = mid;
311 } else {
312 min = mid;
313 }
314 mid = (min + max) / 2.0f;
315 }
316 }
static NumberT estimateMaxDistance(const fl::Slice< const Point > &polyLine)
void safeCopy(const fl::Slice< const Point > &polyLine, VectorType *out)
LineSimplifier< NumberT > mLineSimplifier

References fl::FixedVector< T, N >::begin(), fl::FixedVector< T, N >::end(), estimateMaxDistance(), mCount, mLineSimplifier, fl::FixedVector< T, N >::push_back(), safeCopy(), and fl::Slice< T >::size().

Referenced by simplifyInplace().

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