From b0804710eec4aeb55d82d5284d481ccb76559de4 Mon Sep 17 00:00:00 2001 From: "HuYingzhuo(hugo/hyzboy)" Date: Fri, 10 Feb 2023 15:59:29 +0800 Subject: [PATCH] added ClampU8/ClampU16 --- inc/hgl/math/PrimaryMathematics.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/inc/hgl/math/PrimaryMathematics.h b/inc/hgl/math/PrimaryMathematics.h index d360619..0b7d366 100644 --- a/inc/hgl/math/PrimaryMathematics.h +++ b/inc/hgl/math/PrimaryMathematics.h @@ -1,5 +1,7 @@ #ifndef HGL_Primary_Mathematics_INCLUDE #define HGL_Primary_Mathematics_INCLUDE + +#include namespace hgl { /** @@ -50,5 +52,19 @@ namespace hgl { return Clamp(value,0,1); } + + inline constexpr uint8 ClampU8(const int &value) + { + if(value<0)return 0; + if(value>0xFF)return 0xFF; + return value; + } + + inline constexpr uint16 ClampU16(const int value) + { + if(value<0)return 0; + if(value>0xFFFF)return 0xFFFF; + return value; + } }//namespace hgl #endif//HGL_Primary_Mathematics_INCLUDE