From e3fc3ee8bb4627ace30217b217d02151173059d6 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 21 Aug 2016 01:57:20 +0200 Subject: spline-widget: omit too-close points. add missing locking. --- spline-widget/spline.cpp | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) (limited to 'spline-widget') diff --git a/spline-widget/spline.cpp b/spline-widget/spline.cpp index c71076f4..8e5ef31b 100644 --- a/spline-widget/spline.cpp +++ b/spline-widget/spline.cpp @@ -267,10 +267,44 @@ void spline::save() void spline::set_bundle(bundle b) { - if (b) - s = std::unique_ptr(new settings(b)); - else - s = std::unique_ptr(new settings(options::make_bundle(""))); + QMutexLocker foo(&_mutex); + + if (b && (!s || s->b != b)) + s = ::make_unique(b); + else if (!b) + s = ::make_unique(nullptr); + + QList list = s->points; + + const int sz = list.size(); + + QList ret_list; + ret_list.reserve(sz); + + for (int i = 0; i < sz; i++) + { + QPointF& pt(list[i]); + + pt = QPointF(clamp(pt.x(), 0, max_x), + clamp(pt.y(), 0, max_y)); + + const bool overlap = progn( + for (int j = 0; j < i; j++) + { + QPointF& pt2(list[j]); + const double dist_sq = (pt.x() - pt2.x())*(pt.x() - pt2.x()); + if (dist_sq < .33) + { + return true; + } + } + return false; + ); + if (!overlap) + ret_list.push_back(pt); + } + + s->points = ret_list; last_input_value = QPointF(0, 0); activep = false; -- cgit v1.2.3