summaryrefslogtreecommitdiff
path: root/src/common/math_util.h
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2014-11-18 18:32:01 -0500
committerbunnei <bunneidev@gmail.com>2014-11-18 18:32:01 -0500
commit40acd63631eeaca248b2393cde399714a730214f (patch)
treef87fe583cad412012a034665a5269567f008cf4d /src/common/math_util.h
parent219628d1c81701132f417f22aeb862be06abe72b (diff)
parent963c923d5931dc9d20eb298001282da88e31c31a (diff)
Merge pull request #165 from neobrain/viewport-scaling
Stretch emulation output to render window and be display density independent
Diffstat (limited to 'src/common/math_util.h')
-rw-r--r--src/common/math_util.h9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/common/math_util.h b/src/common/math_util.h
index b32e7bb14..b10a25c13 100644
--- a/src/common/math_util.h
+++ b/src/common/math_util.h
@@ -7,6 +7,7 @@
#include "common/common.h"
#include <algorithm>
+#include <type_traits>
#include <vector>
namespace MathUtil
@@ -109,11 +110,11 @@ struct Rectangle
Rectangle(T theLeft, T theTop, T theRight, T theBottom)
: left(theLeft), top(theTop), right(theRight), bottom(theBottom)
{ }
-
+
bool operator==(const Rectangle& r) { return left==r.left && top==r.top && right==r.right && bottom==r.bottom; }
- T GetWidth() const { return abs(right - left); }
- T GetHeight() const { return abs(bottom - top); }
+ T GetWidth() const { return std::abs(static_cast<typename std::make_signed<T>::type>(right - left)); }
+ T GetHeight() const { return std::abs(static_cast<typename std::make_signed<T>::type>(bottom - top)); }
// If the rectangle is in a coordinate system with a lower-left origin, use
// this Clamp.
@@ -127,7 +128,7 @@ struct Rectangle
// If the rectangle is in a coordinate system with an upper-left origin,
// use this Clamp.
- void ClampUL(T x1, T y1, T x2, T y2)
+ void ClampUL(T x1, T y1, T x2, T y2)
{
if (left < x1) left = x1;
if (right > x2) right = x2;