From 54f1f5ad9daf950258d7aec9cd476f38334f8823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Lu=C3=ADs=20Vaz=20Silva?= Date: Mon, 30 Jun 2025 23:20:07 -0300 Subject: [PATCH] stop stupid clamp asserts --- src/common/textures/image.h | 7 ++----- src/common/utility/basics.h | 8 +++++++- src/common/utility/vectors.h | 4 +++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/common/textures/image.h b/src/common/textures/image.h index 72b5ca9df..5ff158fb7 100644 --- a/src/common/textures/image.h +++ b/src/common/textures/image.h @@ -5,6 +5,8 @@ #include "bitmap.h" #include "memarena.h" +#include "common/utility/basics.h" + #ifndef MAKE_ID #ifndef __BIG_ENDIAN__ #define MAKE_ID(a,b,c,d) ((uint32_t)((a)|((b)<<8)|((c)<<16)|((d)<<24))) @@ -13,11 +15,6 @@ #endif #endif -using std::min; -using std::max; -using std::clamp; - - class FImageSource; using PrecacheInfo = TMap>; extern FMemArena ImageArena; diff --git a/src/common/utility/basics.h b/src/common/utility/basics.h index 0dbb47c67..4d9921ded 100644 --- a/src/common/utility/basics.h +++ b/src/common/utility/basics.h @@ -68,4 +68,10 @@ const double M_PI = 3.14159265358979323846; // matches value in gcc v2 math.h using std::min; using std::max; -using std::clamp; +//using std::clamp; + +template +T clamp(T val, T minval, T maxval) +{ + return std::max(std::min(val, maxval), minval); +} \ No newline at end of file diff --git a/src/common/utility/vectors.h b/src/common/utility/vectors.h index 154d42f7c..62cf9b9c9 100644 --- a/src/common/utility/vectors.h +++ b/src/common/utility/vectors.h @@ -46,6 +46,8 @@ #include #include +#include "common/utility/basics.h" + // this is needed to properly normalize angles. We cannot do that with compiler provided conversions because they differ too much #include "xs_Float.h" @@ -1585,7 +1587,7 @@ constexpr inline TVector2 clamp(const TVector2 &vec, const TVector2 &mi template constexpr inline TVector3 clamp(const TVector3 &vec, const TVector3 &min, const TVector3 &max) { - return TVector3(std::clamp(vec.X, min.X, max.X), std::clamp(vec.Y, min.Y, max.Y), std::clamp(vec.Z, min.Z, max.Z)); + return TVector3(clamp(vec.X, min.X, max.X), clamp(vec.Y, min.Y, max.Y), clamp(vec.Z, min.Z, max.Z)); } template