cleaned up Calc template functions

This commit is contained in:
Noel Berry 2021-05-06 20:47:40 -07:00
parent 6f2cf82b8e
commit 5f9df4beee
2 changed files with 14 additions and 8 deletions

View File

@ -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);

View File

@ -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;