summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--compat/correlation-calibrator.cpp2
-rw-r--r--compat/math.hpp48
-rw-r--r--filter-accela/ftnoir_filter_accela.cpp2
-rw-r--r--proto-mouse/ftnoir_protocol_mouse.cpp4
-rw-r--r--proto-vjoystick/vjoystick.cpp2
-rw-r--r--spline/spline-widget.cpp4
-rw-r--r--spline/spline.cpp12
-rw-r--r--spline/spline.hpp2
-rw-r--r--tracker-aruco/ftnoir_tracker_aruco.cpp6
-rw-r--r--tracker-freepie-udp/ftnoir_tracker_freepie-udp.cpp6
-rw-r--r--tracker-hatire/ftnoir_tracker_hat.cpp2
-rw-r--r--tracker-joystick/ftnoir_tracker_joystick.cpp4
-rw-r--r--tracker-neuralnet/ftnoir_tracker_neuralnet.cpp2
-rw-r--r--tracker-s2bot/ftnoir_tracker_s2bot.cpp6
-rw-r--r--tracker-wii/wii_point_extractor.cpp2
15 files changed, 28 insertions, 76 deletions
diff --git a/compat/correlation-calibrator.cpp b/compat/correlation-calibrator.cpp
index 01f3b14f..08fbcaa7 100644
--- a/compat/correlation-calibrator.cpp
+++ b/compat/correlation-calibrator.cpp
@@ -49,7 +49,7 @@ bool correlation_calibrator::check_buckets(const vec6& data)
for (unsigned k = 0; k < 6; k++)
{
- const double val = clamp(data[k], min[k], max[k]);
+ const double val = std::clamp(data[k], min[k], max[k]);
pos[k] = unsigned((val-min[k])/spacing[k]);
if (pos[k] >= nbuckets[k])
diff --git a/compat/math.hpp b/compat/math.hpp
index 34428cbd..1387324e 100644
--- a/compat/math.hpp
+++ b/compat/math.hpp
@@ -5,54 +5,6 @@
#include <cmath>
#include <type_traits>
-namespace util_detail {
-
-template<typename n>
-inline auto clamp_float(n val, n min_, n max_)
-{
- return std::fmin(std::fmax(val, min_), max_);
-}
-
-template<typename t>
-struct clamp final
-{
- static inline auto clamp_(t val, t min_, t max_)
- {
- if (unlikely(val > max_))
- return max_;
- if (unlikely(val < min_))
- return min_;
- return val;
- }
-};
-
-template<>
-struct clamp<float>
-{
- static inline auto clamp_(float val, float min_, float max_)
- {
- return clamp_float(val, min_, max_);
- }
-};
-
-template<>
-struct clamp<double>
-{
- static inline auto clamp_(double val, double min_, double max_)
- {
- return clamp_float(val, min_, max_);
- }
-};
-
-} // ns util_detail
-
-template<typename t, typename u, typename v>
-inline auto clamp(const t& val, const u& min, const v& max)
-{
- using w = cv_qualified<decltype(val + min + max)>;
- return util_detail::clamp<w>::clamp_(val, min, max);
-}
-
template<typename t>
inline auto iround(t val) -> std::enable_if_t<std::is_floating_point_v<remove_cvref_t<t>>, int>
{
diff --git a/filter-accela/ftnoir_filter_accela.cpp b/filter-accela/ftnoir_filter_accela.cpp
index b70f08cf..0f31f6a6 100644
--- a/filter-accela/ftnoir_filter_accela.cpp
+++ b/filter-accela/ftnoir_filter_accela.cpp
@@ -37,7 +37,7 @@ static void do_deltas(const double* deltas, double* output, F&& fun)
for (unsigned k = 0; k < N; k++)
{
- const double c = dist > 1e-6 ? clamp((fabs(deltas[k]) / dist), 0., 1.) : 0;
+ const double c = dist > 1e-6 ? std::clamp((fabs(deltas[k]) / dist), 0., 1.) : 0;
norm[k] = c;
}
diff --git a/proto-mouse/ftnoir_protocol_mouse.cpp b/proto-mouse/ftnoir_protocol_mouse.cpp
index aed49f2b..e5b2192b 100644
--- a/proto-mouse/ftnoir_protocol_mouse.cpp
+++ b/proto-mouse/ftnoir_protocol_mouse.cpp
@@ -31,12 +31,12 @@ void mouse::pose(const double* headpose, const double*)
int mouse_x = 0, mouse_y = 0;
- if (axis_x == clamp(axis_x, Axis_MIN, Axis_MAX))
+ if (axis_x == std::clamp(axis_x, (int)Axis_MIN, (int)Axis_MAX))
mouse_x = get_value(headpose[axis_x] * invert[axis_x],
*s.sensitivity_x,
axis_x >= 3);
- if (axis_y == clamp(axis_y, Axis_MIN, Axis_MAX))
+ if (axis_y == std::clamp(axis_y, (int)Axis_MIN, (int)Axis_MAX))
mouse_y = get_value(headpose[axis_y] * invert[axis_y],
*s.sensitivity_y,
axis_y >= 3);
diff --git a/proto-vjoystick/vjoystick.cpp b/proto-vjoystick/vjoystick.cpp
index 2962a393..292e8259 100644
--- a/proto-vjoystick/vjoystick.cpp
+++ b/proto-vjoystick/vjoystick.cpp
@@ -88,7 +88,7 @@ int vjoystick::to_axis_value(unsigned axis_id, double val) const
const double min = axis_min[axis_id];
const double max = axis_max[axis_id];
- return (int)(clamp((val+minmax) * max / (2*minmax) - min, min, max));
+ return (int)(std::clamp((val+minmax) * max / (2*minmax) - min, min, max));
}
vjoystick::vjoystick() = default;
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);
diff --git a/tracker-aruco/ftnoir_tracker_aruco.cpp b/tracker-aruco/ftnoir_tracker_aruco.cpp
index 803b91dc..a3678b46 100644
--- a/tracker-aruco/ftnoir_tracker_aruco.cpp
+++ b/tracker-aruco/ftnoir_tracker_aruco.cpp
@@ -102,8 +102,8 @@ bool aruco_tracker::detect_with_roi()
{
if (last_roi.width > 1 && last_roi.height > 1)
{
- detector.setMinMaxSize(clamp(size_min * grayscale.cols / last_roi.width, .01f, 1.f),
- clamp(size_max * grayscale.cols / last_roi.width, .01f, 1.f));
+ detector.setMinMaxSize(std::clamp(size_min * grayscale.cols / last_roi.width, .01f, 1.f),
+ std::clamp(size_max * grayscale.cols / last_roi.width, .01f, 1.f));
detector.detect(grayscale(last_roi), markers, cv::Mat(), cv::Mat(), -1, false);
@@ -225,7 +225,7 @@ void aruco_tracker::draw_ar(bool ok)
}
char buf[9];
- ::snprintf(buf, sizeof(buf), "Hz: %d", clamp(int(fps), 0, 9999));
+ ::snprintf(buf, sizeof(buf), "Hz: %d", std::clamp(int(fps), 0, 9999));
cv::putText(frame, buf, cv::Point(10, 32), cv::FONT_HERSHEY_PLAIN, 2, cv::Scalar(0, 255, 0), 1);
}
diff --git a/tracker-freepie-udp/ftnoir_tracker_freepie-udp.cpp b/tracker-freepie-udp/ftnoir_tracker_freepie-udp.cpp
index c9d374ed..3950af0c 100644
--- a/tracker-freepie-udp/ftnoir_tracker_freepie-udp.cpp
+++ b/tracker-freepie-udp/ftnoir_tracker_freepie-udp.cpp
@@ -40,9 +40,9 @@ void tracker_freepie::run() {
{
int order[] =
{
- clamp(s.idx_x, 0, 2),
- clamp(s.idx_y, 0, 2),
- clamp(s.idx_z, 0, 2)
+ std::clamp(*s.idx_x, 0, 2),
+ std::clamp(*s.idx_y, 0, 2),
+ std::clamp(*s.idx_z, 0, 2)
};
double orient[3] = {0, 0, 0};
diff --git a/tracker-hatire/ftnoir_tracker_hat.cpp b/tracker-hatire/ftnoir_tracker_hat.cpp
index b53a9213..9948c30e 100644
--- a/tracker-hatire/ftnoir_tracker_hat.cpp
+++ b/tracker-hatire/ftnoir_tracker_hat.cpp
@@ -122,7 +122,7 @@ void hatire::data(double *data)
}
for (unsigned k = 0; k < 3; k++)
- HAT.Rot[k] = clamp(HAT.Rot[k], -180, 180);
+ HAT.Rot[k] = std::clamp(HAT.Rot[k], -180.f, 180.f);
const struct
{
diff --git a/tracker-joystick/ftnoir_tracker_joystick.cpp b/tracker-joystick/ftnoir_tracker_joystick.cpp
index bd7e51ed..940abfd1 100644
--- a/tracker-joystick/ftnoir_tracker_joystick.cpp
+++ b/tracker-joystick/ftnoir_tracker_joystick.cpp
@@ -56,8 +56,8 @@ void joystick::data(double *data)
if (k < 0 || k >= 8)
data[i] = 0;
else
- data[i] = clamp(axes[k] * limits[i] / AXIS_MAX,
- -limits[i], limits[i]);
+ data[i] = std::clamp(axes[k] * limits[i] / AXIS_MAX,
+ -limits[i], limits[i]);
}
}
}
diff --git a/tracker-neuralnet/ftnoir_tracker_neuralnet.cpp b/tracker-neuralnet/ftnoir_tracker_neuralnet.cpp
index 8fd65bc9..79796e92 100644
--- a/tracker-neuralnet/ftnoir_tracker_neuralnet.cpp
+++ b/tracker-neuralnet/ftnoir_tracker_neuralnet.cpp
@@ -525,7 +525,7 @@ void neuralnet_tracker::draw_gizmos(
}
char buf[128];
- ::snprintf(buf, sizeof(buf), "%d Hz, pose inference: %d ms", clamp(int(fps), 0, 9999), int(last_inference_time));
+ ::snprintf(buf, sizeof(buf), "%d Hz, pose inference: %d ms", std::clamp(int(fps), 0, 9999), int(last_inference_time));
cv::putText(frame, buf, cv::Point(10, frame.rows-10), cv::FONT_HERSHEY_PLAIN, 1, cv::Scalar(0, 255, 0), 1);
}
diff --git a/tracker-s2bot/ftnoir_tracker_s2bot.cpp b/tracker-s2bot/ftnoir_tracker_s2bot.cpp
index 21cc88cb..98a299ca 100644
--- a/tracker-s2bot/ftnoir_tracker_s2bot.cpp
+++ b/tracker-s2bot/ftnoir_tracker_s2bot.cpp
@@ -57,9 +57,9 @@ void tracker_s2bot::run() {
int order[] =
{
- clamp(s.idx_x, 0, 3),
- clamp(s.idx_y, 0, 3),
- clamp(s.idx_z, 0, 3),
+ std::clamp(*s.idx_x, 0, 3),
+ std::clamp(*s.idx_y, 0, 3),
+ std::clamp(*s.idx_z, 0, 3),
};
int add_indices[] = { s.add_yaw, s.add_pitch, s.add_roll, };
diff --git a/tracker-wii/wii_point_extractor.cpp b/tracker-wii/wii_point_extractor.cpp
index 5e860c14..ae62908b 100644
--- a/tracker-wii/wii_point_extractor.cpp
+++ b/tracker-wii/wii_point_extractor.cpp
@@ -72,7 +72,7 @@ bool WIIPointExtractor::draw_points(cv::Mat& preview_frame, const struct wii_inf
std::tie(dt[0], dt[1]) = to_screen_pos(RX, RY, W, H);
points.push_back(dt);
- draw_point(preview_frame, dt, cv::Scalar(0, 255, 0), clamp(dot.isize, 1, 32));
+ draw_point(preview_frame, dt, cv::Scalar(0, 255, 0), std::clamp(dot.isize, 1, 32));
}
}
const bool success = points.size() >= PointModel::N_POINTS;