#pragma once #include "opentrack-library-path.h" #include "ndebug-guard.hpp" #include "run-in-thread.hpp" #include "meta.hpp" #include "functional.hpp" #include "macros.hpp" #include "value-templates.hpp" #include #include #include #include #include #define progn(...) (([&]() { __VA_ARGS__ })()) #define prog1(x, ...) (([&]() { auto _ret1324 = (x); do { __VA_ARGS__; } while (0); return _ret1324; })()) #define once_only(...) do { static bool once = false; if (!once) { once = true; __VA_ARGS__; } } while(false) #define load_time_value(x) \ progn( \ static const auto _value132((x)); \ return static_cast(value132); \ ) template using mem = std::shared_ptr; template using ptr = std::unique_ptr; template inline int iround(const t& val) { return int(std::round(val)); } template inline unsigned uround(const t& val) { return std::round(std::fmax(t(0), val)); } namespace util_detail { template inline auto clamp_float(n val, n min, n max) { return std::fmin(std::fmax(val, min), max); } template struct clamp final { static inline auto clamp_(const n& val, const n& min, const n& max) { if (unlikely(val > max)) return max; if (unlikely(val < min)) return min; return val; } }; template struct clamp { static inline auto clamp_(float val, float min, float max) { return clamp_float(val, min, max); } }; template struct clamp { static inline auto clamp_(double val, double min, double max) { return clamp_float(val, min, max); } }; } // ns util_detail template inline auto clamp(const t& val, const u& min, const w& max) { using tp = decltype(val + min + max); return ::util_detail::clamp, tp>::clamp_(val, min, max); }