mirror of
https://github.com/NoelFB/blah.git
synced 2024-11-28 16:58:57 +08:00
cleaned up Calc template functions
This commit is contained in:
parent
6f2cf82b8e
commit
5f9df4beee
|
@ -42,11 +42,17 @@ namespace Blah
|
|||
template<class T>
|
||||
T clamp(T value, T min, T max) { return value < min ? min : (value > max ? max : value); }
|
||||
|
||||
template<class T, class U>
|
||||
T min(T a, U b) { return (T)(a < b ? a : b); }
|
||||
template<class T>
|
||||
T min(T a, T b) { return (T)(a < b ? a : b); }
|
||||
|
||||
template<class T, class U>
|
||||
T max(T a, U b) { return (T)(a > b ? a : b); }
|
||||
template<class T, typename ... Args>
|
||||
T min(const T& a, const T& b, const Args&... args) { return Calc::min(a, Calc::min(b, args...)); }
|
||||
|
||||
template<class T>
|
||||
T max(T a, T b) { return (T)(a > b ? a : b); }
|
||||
|
||||
template<class T, typename ... Args>
|
||||
T max(const T& a, const T& b, const Args&... args) { return Calc::max(a, Calc::max(b, args...)); }
|
||||
|
||||
float round(float x);
|
||||
|
||||
|
|
|
@ -96,14 +96,14 @@ RectI RectI::overlap_rect(const Rect& against) const
|
|||
|
||||
if (x + w >= against.x && x < against.x + against.w)
|
||||
{
|
||||
result.x = Calc::max(x, against.x);
|
||||
result.w = Calc::min(x + w, against.x + against.w) - result.x;
|
||||
result.x = Calc::max(x, (int)against.x);
|
||||
result.w = Calc::min(x + w, (int)(against.x + against.w)) - result.x;
|
||||
}
|
||||
|
||||
if (y + h >= against.y && y < against.y + against.h)
|
||||
{
|
||||
result.y = Calc::max(y, against.y);
|
||||
result.h = Calc::min(y + h, against.y + against.h) - result.y;
|
||||
result.y = Calc::max(y, (int)against.y);
|
||||
result.h = Calc::min(y + h, (int)(against.y + against.h)) - result.y;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
Loading…
Reference in New Issue
Block a user