summaryrefslogtreecommitdiffhomepage
path: root/spline-widget
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-01-29 03:10:28 +0100
committerStanislaw Halik <sthalik@misaki.pl>2017-01-29 03:10:28 +0100
commit01210b7fba37356ee2c18420762eeeed52489d20 (patch)
tree9c2494842b9183d28b6b77ecf3b0d0760f05a922 /spline-widget
parent0ea648f8254ff49942e7f83d9034155b50498ac9 (diff)
gui/mapping-window, spline-widget, logic/main-settings: limited mapping range
Diffstat (limited to 'spline-widget')
-rw-r--r--spline-widget/spline-widget.hpp3
-rw-r--r--spline-widget/spline.cpp55
-rw-r--r--spline-widget/spline.hpp2
3 files changed, 34 insertions, 26 deletions
diff --git a/spline-widget/spline-widget.hpp b/spline-widget/spline-widget.hpp
index 921f44a2..4d5a7680 100644
--- a/spline-widget/spline-widget.hpp
+++ b/spline-widget/spline-widget.hpp
@@ -57,12 +57,13 @@ public:
void set_snap(double x, double y) { snap_x = x; snap_y = y; }
void get_snap(double& x, double& y) const { x = snap_x; y = snap_y; }
+public slots:
+ void reload_spline();
protected slots:
void paintEvent(QPaintEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void mouseMoveEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
- void reload_spline();
private:
int get_closeness_limit();
void show_tooltip(const QPoint& pos, const QPointF& value = QPointF(0, 0));
diff --git a/spline-widget/spline.cpp b/spline-widget/spline.cpp
index 59ed9939..8d8fe0e5 100644
--- a/spline-widget/spline.cpp
+++ b/spline-widget/spline.cpp
@@ -147,31 +147,41 @@ void spline::add_lone_point()
s->points = points;
}
-QPointF spline::ensure_in_bounds(const QList<QPointF>& points, int i)
+QPointF spline::ensure_in_bounds(const QList<QPointF>& points, double max_x, int i)
{
const int sz = points.size();
-start:
- if (i < 0 || sz == 0)
- return QPointF(0, 0);
+ if (!(max_x > 0))
+ {
+ if (i < 0 || sz == 0)
+ return QPointF(0, 0);
+
+ if (i < sz)
+ return points[i];
- if (i < sz)
+ return points[sz - 1];
+ }
+ else
{
- if (max_x > 0 && max_x < points[i])
+ do
{
- i--;
- goto start;
- }
- return points[i];
- }
+ QPointF ret;
- if (max_x > 0 && max_x < points[sz - 1])
- {
- i = sz - 2;
- goto start;
- }
+ if (i < 0 || sz == 0)
+ return QPointF(0, 0);
+
+ if (i < sz)
+ ret = points[i];
+ else
+ ret = points[sz - 1];
- return points[sz - 1];
+ if (!(ret.x() > max_x))
+ return ret;
+ else
+ i--;
+ }
+ while (1);
+ }
}
bool spline::sort_fn(const QPointF& one, const QPointF& two)
@@ -212,10 +222,10 @@ void spline::update_interp_data()
for (int i = 0; i < points.size(); i++)
{
- const QPointF p0 = ensure_in_bounds(points, i - 1);
- const QPointF p1 = ensure_in_bounds(points, i + 0);
- const QPointF p2 = ensure_in_bounds(points, i + 1);
- const QPointF p3 = ensure_in_bounds(points, i + 2);
+ const QPointF p0 = ensure_in_bounds(points, max_x, i - 1);
+ const QPointF p1 = ensure_in_bounds(points, max_x, i + 0);
+ const QPointF p2 = ensure_in_bounds(points, max_x, i + 1);
+ const QPointF p3 = ensure_in_bounds(points, max_x, i + 2);
const double p0_x = p0.x(), p1_x = p1.x(), p2_x = p2.x(), p3_x = p3.x();
const double p0_y = p0.y(), p1_y = p1.y(), p2_y = p2.y(), p3_y = p3.y();
@@ -395,9 +405,6 @@ void spline::recompute()
{
QPointF& pt(list[i]);
- pt.setX(clamp(pt.x(), 0, max_x));
- pt.setY(clamp(pt.y(), 0, max_y));
-
const bool overlap = progn(
for (int j = 0; j < i; j++)
{
diff --git a/spline-widget/spline.hpp b/spline-widget/spline.hpp
index 660757f2..ade7f69a 100644
--- a/spline-widget/spline.hpp
+++ b/spline-widget/spline.hpp
@@ -48,7 +48,7 @@ class OPENTRACK_SPLINE_EXPORT spline final
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);
+ static QPointF ensure_in_bounds(const QList<QPointF>& points, double max_x, int i);
mem<spline_detail::settings> s;
QMetaObject::Connection connection;