diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-12-08 05:37:46 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-12-08 05:37:46 +0100 |
commit | ec4c9bb2b53d351dd20f3db342a79a9a75fbc5b9 (patch) | |
tree | f2a48069188b5eedb6eda4ede3dc91b19371773a | |
parent | be051e0b0d1207c2cc1932e647ddfeeb16b0b3fe (diff) |
spline-widget: lazy-recompute spline buckets
-rw-r--r-- | spline-widget/spline.cpp | 29 | ||||
-rw-r--r-- | spline-widget/spline.hpp | 4 |
2 files changed, 23 insertions, 10 deletions
diff --git a/spline-widget/spline.cpp b/spline-widget/spline.cpp index 4742bdc8..57817d40 100644 --- a/spline-widget/spline.cpp +++ b/spline-widget/spline.cpp @@ -29,7 +29,8 @@ spline::spline(qreal maxx, qreal maxy, const QString& name) : _mutex(QMutex::Recursive), max_x(maxx), max_y(maxy), - activep(false) + activep(false), + validp(false) { set_bundle(options::make_bundle(name)); } @@ -62,7 +63,7 @@ void spline::removeAllPoints() { QMutexLocker l(&_mutex); s->points = points_t(); - update_interp_data(); + validp = false; } void spline::setMaxInput(qreal max_input) @@ -123,6 +124,12 @@ bool spline::getLastPoint(QPointF& point) float spline::getValueInternal(int x) { + if (!validp) + { + update_interp_data(); + validp = true; + } + float sign = x < 0 ? -1 : 1; x = std::abs(x); float ret; @@ -247,7 +254,7 @@ void spline::removePoint(int i) { points.erase(points.begin() + i); s->points = points; - update_interp_data(); + validp = false; } } @@ -259,7 +266,12 @@ void spline::addPoint(QPointF pt) points.push_back(pt); std::stable_sort(points.begin(), points.end(), sort_fn); s->points = points; - update_interp_data(); + validp = false; +} + +void spline::addPoint(double x, double y) +{ + addPoint(QPointF(x, y)); } void spline::movePoint(int idx, QPointF pt) @@ -274,7 +286,7 @@ void spline::movePoint(int idx, QPointF pt) // we don't allow points to be reordered, but sort due to possible caller logic error std::stable_sort(points.begin(), points.end(), sort_fn); s->points = points; - update_interp_data(); + validp = false; } } @@ -287,7 +299,7 @@ QList<QPointF> spline::getPoints() const int spline::get_point_count() const { QMutexLocker foo(&_mutex); - return s->points.get().size(); + return s->points().size(); } void spline::reload() @@ -322,7 +334,7 @@ void spline::set_bundle(bundle b) if (b) { - connection = QObject::connect(b.get(), &bundle_type::changed, + connection = QObject::connect(b.get(), &bundle_::changed, s.get(), [&]() { // we're holding the mutex to allow signal disconnection in spline dtor // before this slot gets called for the next time @@ -389,8 +401,7 @@ void spline::recompute() last_input_value = QPointF(0, 0); activep = false; - - update_interp_data(); + validp = false; } // the return value is only safe to use with no spline::set_bundle calls diff --git a/spline-widget/spline.hpp b/spline-widget/spline.hpp index 37789c00..adabd33c 100644 --- a/spline-widget/spline.hpp +++ b/spline-widget/spline.hpp @@ -62,6 +62,7 @@ class OPENTRACK_SPLINE_EXPORT spline final QPointF last_input_value; qreal max_x, max_y; volatile bool activep; + bool validp; public: using settings = spline_detail::settings; @@ -87,6 +88,7 @@ public: void removeAllPoints(); void addPoint(QPointF pt); + void addPoint(double x, double y); void movePoint(int idx, QPointF pt); QList<QPointF> getPoints() const; void setMaxInput(qreal MaxInput); @@ -99,6 +101,6 @@ public: mem<settings> get_settings(); mem<const settings> get_settings() const; - using points_t = decltype(s->points.get()); + using points_t = decltype(s->points()); int get_point_count() const; }; |