diff options
Diffstat (limited to 'spline-widget/spline.hpp')
-rw-r--r-- | spline-widget/spline.hpp | 68 |
1 files changed, 47 insertions, 21 deletions
diff --git a/spline-widget/spline.hpp b/spline-widget/spline.hpp index 26775402..4f6531b9 100644 --- a/spline-widget/spline.hpp +++ b/spline-widget/spline.hpp @@ -8,15 +8,16 @@ #pragma once -#include <QtGlobal> -#include <QList> +#include <QObject> #include <QPointF> #include <QString> -#include <QSettings> #include <QMutex> #include <vector> #include <limits> +#include <memory> #include "compat/qcopyable-mutex.hpp" +#include "options/options.hpp" +using namespace options; #ifdef BUILD_spline_widget # define SPLINE_WIDGET_EXPORT Q_DECL_EXPORT @@ -24,47 +25,72 @@ # define SPLINE_WIDGET_EXPORT Q_DECL_IMPORT #endif -class SPLINE_WIDGET_EXPORT spline +class SPLINE_WIDGET_EXPORT spline final { private: - int precision() const; - void reload(); - float getValueInternal(int x); - - struct State + struct settings { - QList<QPointF> input; - std::vector<float> data; - bool operator==(const State& s) const; + bundle b; + value<QList<QPointF>> points; + settings(bundle b) : + b(b), + points(b, "points", QList<QPointF>()) + {} }; + ptr<settings> s; + + std::vector<float> data; + using interp_data_t = decltype(data); + + static constexpr int value_count = 10000; + + int precision(const QList<QPointF>& points) const; + void update_interp_data(); + float getValueInternal(int x); + void add_lone_point(); + static bool sort_fn(const QPointF& one, const QPointF& two); + + static QPointF ensure_in_bounds(const QList<QPointF>& points, int i); + MyMutex _mutex; QPointF last_input_value; - State cur, saved; qreal max_x, max_y; volatile bool activep; - static constexpr int value_count = 10000; + template<typename t, typename u, typename w> + static inline auto clamp(t val, u min, w max) -> decltype (val * min * max) + { + if (val > max) + return max; + if (val < min) + return min; + return val; + } + public: + void reload(); + void save(); + void set_bundle(bundle b); + qreal maxInput() const; qreal maxOutput() const; spline(); - spline(qreal maxx, qreal maxy); + spline(qreal maxx, qreal maxy, const QString& name); - float getValue(float x); + float getValue(double x); bool getLastPoint(QPointF& point); void removePoint(int i); void removeAllPoints(); void addPoint(QPointF pt); void movePoint(int idx, QPointF pt); - const QList<QPointF> getPoints(); + QList<QPointF> getPoints() const; void setMaxInput(qreal MaxInput); void setMaxOutput(qreal MaxOutput); - void saveSettings(QSettings& settings, const QString& title); - void loadSettings(QSettings& settings, const QString& title); - void invalidate_unsaved_settings(); - void setTrackingActive(bool blnActive); + bundle get_bundle() { return s->b; } + + using points_t = decltype(s->points.get()); }; |