mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 20:52:37 +01:00
Added min/max with 3 values, and clamp.
This commit is contained in:
@@ -35,24 +35,37 @@ namespace bx
|
||||
template<bool>
|
||||
bool isEnabled();
|
||||
|
||||
///
|
||||
bool ignoreC4127(bool _x);
|
||||
|
||||
///
|
||||
/// Exchange two values.
|
||||
template<typename Ty>
|
||||
void xchg(Ty& _a, Ty& _b);
|
||||
|
||||
///
|
||||
/// Exchange memory.
|
||||
void xchg(void* _a, void* _b, size_t _numBytes);
|
||||
|
||||
///
|
||||
/// Returns minimum of two values.
|
||||
template<typename Ty>
|
||||
Ty min(const Ty& _a, const Ty& _b);
|
||||
|
||||
///
|
||||
/// Returns maximum of two values.
|
||||
template<typename Ty>
|
||||
Ty max(const Ty& _a, const Ty& _b);
|
||||
|
||||
/// Returns minimum of three values.
|
||||
template<typename Ty>
|
||||
Ty min(const Ty& _a, const Ty& _b, const Ty& _c);
|
||||
|
||||
/// Returns maximum of three values.
|
||||
template<typename Ty>
|
||||
Ty max(const Ty& _a, const Ty& _b, const Ty& _c);
|
||||
|
||||
/// Returns middle of three values.
|
||||
template<typename Ty>
|
||||
Ty mid(const Ty& _a, const Ty& _b, const Ty& _c);
|
||||
|
||||
/// Returns clamped value between min/max.
|
||||
template<typename Ty>
|
||||
Ty clamp(const Ty& _a, const Ty& _min, const Ty& _max);
|
||||
|
||||
// http://cnicholson.net/2011/01/stupid-c-tricks-a-better-sizeof_array/
|
||||
template<typename T, size_t N>
|
||||
char (&COUNTOF_REQUIRES_ARRAY_ARGUMENT(const T(&)[N]) )[N];
|
||||
|
||||
@@ -44,4 +44,28 @@ namespace bx
|
||||
return _a > _b ? _a : _b;
|
||||
}
|
||||
|
||||
template<typename Ty>
|
||||
inline Ty min(const Ty& _a, const Ty& _b, const Ty& _c)
|
||||
{
|
||||
return min(min(_a, _b), _c);
|
||||
}
|
||||
|
||||
template<typename Ty>
|
||||
inline Ty max(const Ty& _a, const Ty& _b, const Ty& _c)
|
||||
{
|
||||
return max(max(_a, _b), _c);
|
||||
}
|
||||
|
||||
template<typename Ty>
|
||||
inline Ty mid(const Ty& _a, const Ty& _b, const Ty& _c)
|
||||
{
|
||||
return max(min(_a, _b), min(max(_a, _b), _c) );
|
||||
}
|
||||
|
||||
template<typename Ty>
|
||||
inline Ty clamp(const Ty& _a, const Ty& _min, const Ty& _max)
|
||||
{
|
||||
return max(min(_a, _max), _min);
|
||||
}
|
||||
|
||||
} // namespace bx
|
||||
|
||||
Reference in New Issue
Block a user