js8call/JS8_Main/RDP.h
Chris-AC9KH 356bdc0f50 Code cleanup - move loose source and header files in source tree to group folders
Rename all header files with .h extension
Fix function declaration in HamlibTransceiver.h that overrode member function but was not marked override
Remove unused variable in Modulator.cpp
Remove unused files from source tree
Remove duplicate LazyFillComboBox files
Reformat codebase to LLVM C++ standard
2026-01-02 16:46:38 -06:00

40 lines
1.4 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef RDP_HPP__
#define RDP_HPP__
#include <QBitArray>
#include <QPair>
#include <QPolygonF>
#include <QStack>
class RDP {
// This gets called approximately 10 times per second, and until
// the associated view resizes, it's going to need exactly the
// same amount of stack and tracking array as it did last time.
// Throwing that away and requesting it again every 100ms isn't
// ideal, which is why this is a functor instead of a function.
QStack<QPair<qsizetype, qsizetype>> stack;
QBitArray array;
public:
// Process the provided polygon through the RamerDouglasPeucker
// algorithm at the requested epsilon level, modifying it in-place
// and returning an iterator suitable for erase-remove idiom usage,
// e.g.,
//
// QPolygonF polygon;
// RDP rdp;
//
// polygon.erase(rdp(polygon), polygon.end());
//
// Essentially, this acts the same as a std::remove_if() predicate
// does; points to retain are moved to the range [begin, iterator),
// while points to be elided are in the tail range [iterator, end].
// As the polygon remains the same size, the length of the tail is
// the number of elided points, and as with std::remove_if(), these
// points exist in memory but in an unspecified state.
QPolygonF::iterator operator()(QPolygonF &polygon, qreal epsilon = 2.0);
};
#endif