JS8Call-Improved master
Loading...
Searching...
No Matches
RDP.h
1#ifndef RDP_HPP__
2#define RDP_HPP__
3
4#include <QBitArray>
5#include <QPair>
6#include <QPolygonF>
7#include <QStack>
8
9class RDP {
10 // This gets called approximately 10 times per second, and until
11 // the associated view resizes, it's going to need exactly the
12 // same amount of stack and tracking array as it did last time.
13 // Throwing that away and requesting it again every 100ms isn't
14 // ideal, which is why this is a functor instead of a function.
15
16 QStack<QPair<qsizetype, qsizetype>> stack;
17 QBitArray array;
18
19 public:
20 // Process the provided polygon through the Ramer–Douglas–Peucker
21 // algorithm at the requested epsilon level, modifying it in-place
22 // and returning an iterator suitable for erase-remove idiom usage,
23 // e.g.,
24 //
25 // QPolygonF polygon;
26 // RDP rdp;
27 //
28 // polygon.erase(rdp(polygon), polygon.end());
29 //
30 // Essentially, this acts the same as a std::remove_if() predicate
31 // does; points to retain are moved to the range [begin, iterator),
32 // while points to be elided are in the tail range [iterator, end].
33 // As the polygon remains the same size, the length of the tail is
34 // the number of elided points, and as with std::remove_if(), these
35 // points exist in memory but in an unspecified state.
36
37 QPolygonF::iterator operator()(QPolygonF &polygon, qreal epsilon = 2.0);
38};
39
40#endif
Definition RDP.h:9