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();
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>>
260 if (polyLine.
size() > 0) {
263 if (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());
357 out->assign(temp.
begin(), temp.
end());
iterator end() FL_NOEXCEPT
void push_back(const T &value) FL_NOEXCEPT
iterator begin() FL_NOEXCEPT
void simplify(const fl::span< const Point > &polyLine, fl::vector< Point > *out)
LineSimplifier(const LineSimplifier &other) FL_NOEXCEPT=default
LineSimplifier & operator=(const LineSimplifier &other) FL_NOEXCEPT=default
LineSimplifier(LineSimplifier &&other) FL_NOEXCEPT=default
void simplifyT(const fl::span< const Point > &polyLine, VectorType *out)
void simplifyInplace(fl::vector< Point > *polyline)
LineSimplifier & operator=(LineSimplifier &&other) FL_NOEXCEPT=default
void simplify(const fl::span< Point > &polyLine, VectorType *out)
static NumberT PerpendicularDistance2(const Point &pt, const Point &a, const Point &b)
LineSimplifier() FL_NOEXCEPT
void simplifyInplaceT(VectorType *polyLine)
void setMinimumDistance(NumberT eps)
void simplifyInternal(const fl::span< const Point > &polyLine)
LineSimplifier(NumberT e)
fl::vector< Point > VectorPoint
static void removeOneLeastError(VectorType *_poly)
fl::vector_inlined< fl::pair< int, int >, 64 > indexStack
fl::vec2< NumberT > Point
void simplifyInplace(VectorType *polyLine)
LineSimplifierExact() FL_NOEXCEPT=default
void simplifyInplace(VectorType *polyLine)
void simplify(const fl::span< const Point > &polyLine, VectorType *out)
void safeCopy(const fl::span< const Point > &polyLine, VectorType *out)
LineSimplifier< NumberT > mLineSimplifier
static NumberT estimateMaxDistance(const fl::span< const Point > &polyLine)
iterator begin() FL_NOEXCEPT
const T * data() const FL_NOEXCEPT
iterator end() FL_NOEXCEPT
constexpr fl::size size() const FL_NOEXCEPT
iterator begin() FL_NOEXCEPT
iterator end() FL_NOEXCEPT
void assign(InputIt first, InputIt last) FL_NOEXCEPT
#define FL_INFINITY_DOUBLE
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NOEXCEPT
constexpr common_type_t< T, U > max(T a, U b) FL_NOEXCEPT
constexpr enable_if< is_fixed_point< T >::value, T >::type sqrt(T x) FL_NOEXCEPT
VectorN< T, INLINED_SIZE > vector_inlined
FixedVector< T, INLINED_SIZE > vector_fixed
Base definition for an LED controller.