added ClampU8/ClampU16

This commit is contained in:
HuYingzhuo(hugo/hyzboy) 2023-02-10 15:59:29 +08:00
parent 4826d5d9dc
commit b0804710ee

View File

@ -1,5 +1,7 @@
#ifndef HGL_Primary_Mathematics_INCLUDE #ifndef HGL_Primary_Mathematics_INCLUDE
#define HGL_Primary_Mathematics_INCLUDE #define HGL_Primary_Mathematics_INCLUDE
#include<hgl/platform/Platform.h>
namespace hgl namespace hgl
{ {
/** /**
@ -50,5 +52,19 @@ namespace hgl
{ {
return Clamp<T>(value,0,1); return Clamp<T>(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 }//namespace hgl
#endif//HGL_Primary_Mathematics_INCLUDE #endif//HGL_Primary_Mathematics_INCLUDE