CMCore/inc/hgl/math/PrimaryMathematics.h

71 lines
1.4 KiB
C
Raw Normal View History

2022-05-31 17:21:17 +08:00
#ifndef HGL_Primary_Mathematics_INCLUDE
2021-09-14 09:55:36 +08:00
#define HGL_Primary_Mathematics_INCLUDE
2023-02-10 15:59:29 +08:00
#include<hgl/platform/Platform.h>
2021-09-14 09:55:36 +08:00
namespace hgl
{
/**
2022-05-31 17:21:17 +08:00
*
2021-09-14 09:55:36 +08:00
*/
template<typename T>
const T sum(const T *data,const int count)
{
T result=0;
for(int i=0;i<count;i++)
{
result+=*data;
++data;
}
return result;
}
/**
2022-05-31 17:21:17 +08:00
*
2021-09-14 09:55:36 +08:00
*/
template<typename R,typename T>
const R sum(const T *data,const int count)
{
R result=0;
for(int i=0;i<count;i++)
{
result+=*data;
++data;
}
return result;
}
template<typename T,typename T2>
inline constexpr T Clamp(const T &value,const T2 &min_value,const T2 &max_value)
{
if(value<min_value)return min_value;
if(value>max_value)return max_value;
return value;
}
template<typename T>
inline constexpr T Clamp(const T &value)
{
return Clamp<T>(value,0,1);
}
2023-02-10 15:59:29 +08:00
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;
}
2021-09-14 09:55:36 +08:00
}//namespace hgl
#endif//HGL_Primary_Mathematics_INCLUDE