From d8ad3ee99ba8cfdfeee8376237df55653883a765 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 1 Aug 2019 10:43:25 +0200 Subject: spline: ensure cubic spline drawn up to max value --- spline/spline-widget.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/spline/spline-widget.cpp b/spline/spline-widget.cpp index 0dfac0e9..f56522bd 100644 --- a/spline/spline-widget.cpp +++ b/spline/spline-widget.cpp @@ -204,18 +204,22 @@ void spline_widget::drawFunction() : QPointF{max_x_pixel, val.y()}; }; - for (double k = 0; k < maxx; k += step*3) // NOLINT - { - const auto next_1 = config->get_value_no_save(k + step*1); - const auto next_2 = config->get_value_no_save(k + step*2); - const auto next_3 = config->get_value_no_save(k + step*3); + const auto fn = [&] (double k) { + const auto next_1 = config->get_value_no_save(k + step*1); + const auto next_2 = config->get_value_no_save(k + step*2); + const auto next_3 = config->get_value_no_save(k + step*3); - QPointF b(clamp(point_to_pixel({k + step*1, next_1}))), - c(clamp(point_to_pixel({k + step*2, next_2}))), - d(clamp(point_to_pixel({k + step*3, next_3}))); + QPointF b(clamp(point_to_pixel({k + step*1, next_1}))), + c(clamp(point_to_pixel({k + step*2, next_2}))), + d(clamp(point_to_pixel({k + step*3, next_3}))); - path.cubicTo(b, c, d); - } + path.cubicTo(b, c, d); + }; + + for (double k = 0; k < maxx; k += step*3) // NOLINT + fn(k); + + fn(maxx); painter.drawPath(path); #else -- cgit v1.2.3