From 5f9df4beee7256a63ef1f125ac2476eac962a2e3 Mon Sep 17 00:00:00 2001 From: Noel Berry Date: Thu, 6 May 2021 20:47:40 -0700 Subject: [PATCH] cleaned up Calc template functions --- include/blah/math/calc.h | 14 ++++++++++---- src/math/rectI.cpp | 8 ++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/blah/math/calc.h b/include/blah/math/calc.h index 68f6c0f..10fe9c8 100644 --- a/include/blah/math/calc.h +++ b/include/blah/math/calc.h @@ -42,11 +42,17 @@ namespace Blah template T clamp(T value, T min, T max) { return value < min ? min : (value > max ? max : value); } - template - T min(T a, U b) { return (T)(a < b ? a : b); } + template + T min(T a, T b) { return (T)(a < b ? a : b); } - template - T max(T a, U b) { return (T)(a > b ? a : b); } + template + T min(const T& a, const T& b, const Args&... args) { return Calc::min(a, Calc::min(b, args...)); } + + template + T max(T a, T b) { return (T)(a > b ? a : b); } + + template + T max(const T& a, const T& b, const Args&... args) { return Calc::max(a, Calc::max(b, args...)); } float round(float x); diff --git a/src/math/rectI.cpp b/src/math/rectI.cpp index 9e81e9e..c8d3a5e 100644 --- a/src/math/rectI.cpp +++ b/src/math/rectI.cpp @@ -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;