From d4d799cac8080d4066394f338c31611ae655d5f6 Mon Sep 17 00:00:00 2001
From: Stanislaw Halik <sthalik@misaki.pl>
Date: Sun, 26 Sep 2021 20:56:25 +0200
Subject: compat: use std::clamp, remove own version

---
 spline/spline-widget.cpp |  4 ++--
 spline/spline.cpp        | 12 ++++++------
 spline/spline.hpp        |  2 +-
 3 files changed, 9 insertions(+), 9 deletions(-)

(limited to 'spline')

diff --git a/spline/spline-widget.cpp b/spline/spline-widget.cpp
index 7aeaf590..9df9b3be 100644
--- a/spline/spline-widget.cpp
+++ b/spline/spline-widget.cpp
@@ -635,8 +635,8 @@ QPointF spline_widget::pixel_to_point(const QPointF& point)
     if (snap_y > 0)
         y = snap(y, snap_y);
 
-    x = clamp(x, 0, config->max_input());
-    y = clamp(y, 0, config->max_output());
+    x = std::clamp(x, 0., config->max_input());
+    y = std::clamp(y, 0., config->max_output());
 
     return { x, y };
 }
diff --git a/spline/spline.cpp b/spline/spline.cpp
index 21044b34..4c1ff389 100644
--- a/spline/spline.cpp
+++ b/spline/spline.cpp
@@ -101,7 +101,7 @@ double spline::get_value_internal(int x) const
     const float sign = signum(x);
     x = std::abs(x);
     const float ret_ = data[std::min(unsigned(x), value_count - 1)];
-    return (double)(sign * clamp(ret_, 0, 1000));
+    return (double)(sign * std::clamp(ret_, 0.f, 1000.f));
 }
 
 void spline::ensure_in_bounds(const QList<QPointF>& points, int i, f& x, f& y)
@@ -129,7 +129,7 @@ void spline::ensure_in_bounds(const QList<QPointF>& points, int i, f& x, f& y)
 
 int spline::element_count(const QList<QPointF>& points, double max_input)
 {
-    const unsigned sz = (unsigned)points.size();
+    const int sz = points.size();
     for (int k = sz-1; k >= 0; k--)
     {
         const QPointF& pt = points[k];
@@ -139,7 +139,7 @@ int spline::element_count(const QList<QPointF>& points, double max_input)
     return sz;
 }
 
-bool spline::sort_fn(const QPointF& one, const QPointF& two)
+bool spline::sort_fn(QPointF one, QPointF two)
 {
     return one.x() < two.x();
 }
@@ -165,7 +165,7 @@ void spline::update_interp_data() const
         const QPointF& pt = list[0];
         const double x = pt.x();
         const double y = pt.y();
-        const unsigned max = clamp(uround(x * c), 0, value_count-1);
+        const unsigned max = std::clamp((unsigned)iround(x * c), 0u, value_count-1);
 
         for (unsigned k = 0; k <= max; k++)
             data[k] = float(y * k / max); // no need for bresenham
@@ -235,7 +235,7 @@ void spline::update_interp_data() const
     {
         if (data[i] == magic_fill_value)
             data[i] = last;
-        data[i] = clamp(data[i], 0, maxy);
+        data[i] = std::clamp(data[i], 0.f, maxy);
         last = data[i];
     }
 
@@ -472,7 +472,7 @@ double spline::bucket_size_coefficient(const QList<QPointF>& points) const
     const int sz = element_count(points, maxx);
     const double last_x = sz ? points[sz - 1].x() : maxx;
 
-    return clamp((value_count-1) / clamp(last_x, eps, maxx), 0., (value_count-1));
+    return std::clamp((value_count-1) / std::clamp(last_x, eps, maxx), 0., (value_count-1.));
 }
 
 void spline::disconnect_signals()
diff --git a/spline/spline.hpp b/spline/spline.hpp
index e4f64069..76ac79b8 100644
--- a/spline/spline.hpp
+++ b/spline/spline.hpp
@@ -110,7 +110,7 @@ class OTR_SPLINE_EXPORT spline : public base_spline
     double bucket_size_coefficient(const QList<QPointF>& points) const;
     void update_interp_data() const;
     double get_value_internal(int x) const;
-    static bool sort_fn(const QPointF& one, const QPointF& two);
+    static bool sort_fn(QPointF one, QPointF two);
 
     static void ensure_in_bounds(const QList<QPointF>& points, int i, f& x, f& y);
     static int element_count(const QList<QPointF>& points, double max_input);
-- 
cgit v1.2.3