59 template <
typename VectorType>
64 template <
typename VectorType>
67 VectorType &poly = *_poly;
68 keep.assign(poly.size(), 1);
69 const int n = poly.size();
74 for (
int i = 1; i + 1 < n; ++i) {
80 while (L >= 0 && !
keep[L])
84 while (R < n && !
keep[R])
91 NumberT dx = poly[R].x - poly[L].x;
92 NumberT dy = poly[R].y - poly[L].y;
93 NumberT vx = poly[i].x - poly[L].x;
94 NumberT vy = poly[i].y - poly[L].y;
95 NumberT len2 = dx * dx + dy * dy;
98 ? ((dx * vy - dy * vx) * (dx * vy - dy * vx) / len2)
99 : (vx * vx + vy * vy);
110 poly.erase(poly.begin() + bestIdx);
116 span<Point> slice(polyLine->data(), polyLine->size());
120 template <
typename VectorType>
132 int n = polyLine.size();
135 mSimplified.assign(polyLine.data(), polyLine.data() + n);
156 const bool has_interior = (i1 - i0) > 1;
165 NumberT maxDist2 = 0;
167 for (
int i = i0 + 1; i < i1; ++i) {
183 if (maxDist2 > minDist2) {
189 for (
int i = i0 + 1; i < i1; ++i) {
198 for (
int i = 0; i < n; ++i) {
216 NumberT dx = b.x - a.x;
217 NumberT dy = b.y - a.y;
219 NumberT vx = pt.x - a.x;
220 NumberT vy = pt.y - a.y;
223 NumberT len2 = dx * dx + dy * dy;
224 if (len2 <= NumberT(0)) {
226 return vx * vx + vy * vy;
230 NumberT cross = dx * vy - dy * vx;
232 return (cross * cross) / len2;
245 template <
typename VectorType = fl::vector<Po
int>>
247 return simplify(*polyLine, polyLine);
250 template <
typename VectorType = fl::vector<Po
int>>
252 if (
mCount > polyLine.size()) {
255 }
else if (
mCount == polyLine.size()) {
260 if (polyLine.size() > 0) {
263 if (polyLine.size() > 1) {
264 temp.
push_back(polyLine[polyLine.size() - 1]);
266 out->assign(temp.
begin(), temp.
end());
271 NumberT
max = est_max_dist;
272 NumberT mid = (
min +
max) / 2.0f;
276 const bool done = (diff < 0.01f);
281 fl::size n = out->size();
303 while (out->size() >
mCount) {
310 if (out->size() <
mCount) {
322 if (polyLine.size() < 2)
325 const Point &first = polyLine[0];
326 const Point &last = polyLine[polyLine.size() - 1];
327 NumberT dx = last.
x - first.
x;
328 NumberT dy = last.
y - first.
y;
329 return sqrt(dx * dx + dy * dy);
332 template <
typename VectorType>
334 auto *first_out = out->data();
336 auto *other_first_out = polyLine.data();
338 const bool is_same = first_out == other_first_out;
342 auto *last_out = first_out +
mCount;
343 auto *other_last_out = other_first_out + polyLine.size();
345 const bool is_overlapping =
346 (first_out >= other_first_out && first_out < other_last_out) ||
347 (other_first_out >= first_out && other_first_out < last_out);
349 if (!is_overlapping) {
350 out->assign(polyLine.data(), polyLine.data() + polyLine.size());
356 temp.
assign(polyLine.begin(), polyLine.end());
357 out->assign(temp.
begin(), temp.
end());
iterator end() FL_NO_EXCEPT
void push_back(const T &value) FL_NO_EXCEPT
iterator begin() FL_NO_EXCEPT
LineSimplifier(LineSimplifier &&other) FL_NO_EXCEPT=default
LineSimplifier() FL_NO_EXCEPT
void simplifyInternal(const fl::span< const Point > &polyLine) FL_NO_EXCEPT
void simplifyInplace(VectorType *polyLine) FL_NO_EXCEPT
static void removeOneLeastError(VectorType *_poly) FL_NO_EXCEPT
void simplify(const fl::span< const Point > &polyLine, fl::vector< Point > *out) FL_NO_EXCEPT
LineSimplifier & operator=(LineSimplifier &&other) FL_NO_EXCEPT=default
void simplifyT(const fl::span< const Point > &polyLine, VectorType *out) FL_NO_EXCEPT
void setMinimumDistance(NumberT eps) FL_NO_EXCEPT
LineSimplifier & operator=(const LineSimplifier &other) FL_NO_EXCEPT=default
void simplifyInplaceT(VectorType *polyLine) FL_NO_EXCEPT
LineSimplifier(NumberT e) FL_NO_EXCEPT
void simplify(const fl::span< Point > &polyLine, VectorType *out) FL_NO_EXCEPT
fl::vector< Point > VectorPoint
static NumberT PerpendicularDistance2(const Point &pt, const Point &a, const Point &b) FL_NO_EXCEPT
LineSimplifier(const LineSimplifier &other) FL_NO_EXCEPT=default
fl::vector_inlined< fl::pair< int, int >, 64 > indexStack
fl::vec2< NumberT > Point
void simplifyInplace(fl::vector< Point > *polyline) FL_NO_EXCEPT
void simplifyInplace(VectorType *polyLine) FL_NO_EXCEPT
void setCount(u32 count) FL_NO_EXCEPT
void simplify(const fl::span< const Point > &polyLine, VectorType *out) FL_NO_EXCEPT
void safeCopy(const fl::span< const Point > &polyLine, VectorType *out) FL_NO_EXCEPT
static NumberT estimateMaxDistance(const fl::span< const Point > &polyLine) FL_NO_EXCEPT
LineSimplifierExact() FL_NO_EXCEPT=default
LineSimplifier< NumberT > mLineSimplifier
iterator end() FL_NO_EXCEPT
void assign(InputIt first, InputIt last) FL_NO_EXCEPT
iterator begin() FL_NO_EXCEPT
#define FL_INFINITY_DOUBLE
constexpr common_type_t< T, U > max(T a, U b) FL_NO_EXCEPT
u8 u8 fract8 blur_amount FL_NO_EXCEPT
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NO_EXCEPT
VectorN< T, INLINED_SIZE > vector_inlined
constexpr enable_if< is_fixed_point< T >::value, T >::type sqrt(T x) FL_NO_EXCEPT
FixedVector< T, INLINED_SIZE > vector_fixed
Base definition for an LED controller.