summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-07-23 05:54:47 +0200
committerStanislaw Halik <sthalik@misaki.pl>2017-07-23 06:31:09 +0200
commit52606b92439f97a95b9917c01d451c902d620052 (patch)
treef617ace28a76427f63f65dd0213d076d885c18a3
parent7653f6f4459e8b7e03dd3db488bfc5d55e0bc94c (diff)
spline/widget: avoid drawing past the graph's end
-rw-r--r--spline/spline-widget.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/spline/spline-widget.cpp b/spline/spline-widget.cpp
index 6593d5a6..44576342 100644
--- a/spline/spline-widget.cpp
+++ b/spline/spline-widget.cpp
@@ -213,15 +213,23 @@ void spline_widget::drawFunction()
path.moveTo(point_to_pixel(QPointF(0, 0)));
+ const double max_x_pixel = point_to_pixel_(QPointF(maxx, 0)).x();
+
+ auto check = [=](const QPointF& val) {
+ return val.x() < max_x_pixel
+ ? val
+ : QPointF(max_x_pixel, val.y());
+ };
+
for (double k = 0; k < maxx; k += step*3)
{
const float next_1(_config->get_value_no_save(k + step*1));
const float next_2(_config->get_value_no_save(k + step*2));
const float next_3(_config->get_value_no_save(k + step*3));
- const QPointF b(point_to_pixel_(QPointF(k + step*1, qreal(next_1)))),
- c(point_to_pixel_(QPointF(k + step*2, qreal(next_2)))),
- d(point_to_pixel_(QPointF(k + step*3, qreal(next_3))));
+ QPointF b(check(point_to_pixel_(QPointF(k + step*1, qreal(next_1))))),
+ c(check(point_to_pixel_(QPointF(k + step*2, qreal(next_2))))),
+ d(check(point_to_pixel_(QPointF(k + step*3, qreal(next_3)))));
path.cubicTo(b, c, d);
}