summaryrefslogtreecommitdiffhomepage
path: root/spline-widget/spline.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-08-21 01:57:20 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-08-23 00:05:15 +0200
commite3fc3ee8bb4627ace30217b217d02151173059d6 (patch)
treef91eb074aaa6aae04281ef4300399a7f2543caf8 /spline-widget/spline.cpp
parentf3172cbb18fadc89785733022438b15730752663 (diff)
spline-widget: omit too-close points. add missing locking.
Diffstat (limited to 'spline-widget/spline.cpp')
-rw-r--r--spline-widget/spline.cpp42
1 files changed, 38 insertions, 4 deletions
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<settings>(new settings(b));
- else
- s = std::unique_ptr<settings>(new settings(options::make_bundle("")));
+ QMutexLocker foo(&_mutex);
+
+ if (b && (!s || s->b != b))
+ s = ::make_unique<settings>(b);
+ else if (!b)
+ s = ::make_unique<settings>(nullptr);
+
+ QList<QPointF> list = s->points;
+
+ const int sz = list.size();
+
+ QList<QPointF> 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;