summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Tony Wasserka2014-11-13 20:25:39 +0100
committerGravatar Tony Wasserka2014-11-18 13:15:59 +0100
commite02ff0121f9594cf441e180115e4cc86eb69a47c (patch)
tree4f8bdfaabba88ba2700d71e40a8f71bdace17966
parentOpenGL Renderer: Cleanup viewport extent calculation. (diff)
downloadyuzu-e02ff0121f9594cf441e180115e4cc86eb69a47c.tar.gz
yuzu-e02ff0121f9594cf441e180115e4cc86eb69a47c.tar.xz
yuzu-e02ff0121f9594cf441e180115e4cc86eb69a47c.zip
MathUtil: Make Rectangle work with unsigned types.
-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 @@
7#include "common/common.h" 7#include "common/common.h"
8 8
9#include <algorithm> 9#include <algorithm>
10#include <type_traits>
10#include <vector> 11#include <vector>
11 12
12namespace MathUtil 13namespace MathUtil
@@ -109,11 +110,11 @@ struct Rectangle
109 Rectangle(T theLeft, T theTop, T theRight, T theBottom) 110 Rectangle(T theLeft, T theTop, T theRight, T theBottom)
110 : left(theLeft), top(theTop), right(theRight), bottom(theBottom) 111 : left(theLeft), top(theTop), right(theRight), bottom(theBottom)
111 { } 112 { }
112 113
113 bool operator==(const Rectangle& r) { return left==r.left && top==r.top && right==r.right && bottom==r.bottom; } 114 bool operator==(const Rectangle& r) { return left==r.left && top==r.top && right==r.right && bottom==r.bottom; }
114 115
115 T GetWidth() const { return abs(right - left); } 116 T GetWidth() const { return std::abs(static_cast<typename std::make_signed<T>::type>(right - left)); }
116 T GetHeight() const { return abs(bottom - top); } 117 T GetHeight() const { return std::abs(static_cast<typename std::make_signed<T>::type>(bottom - top)); }
117 118
118 // If the rectangle is in a coordinate system with a lower-left origin, use 119 // If the rectangle is in a coordinate system with a lower-left origin, use
119 // this Clamp. 120 // this Clamp.
@@ -127,7 +128,7 @@ struct Rectangle
127 128
128 // If the rectangle is in a coordinate system with an upper-left origin, 129 // If the rectangle is in a coordinate system with an upper-left origin,
129 // use this Clamp. 130 // use this Clamp.
130 void ClampUL(T x1, T y1, T x2, T y2) 131 void ClampUL(T x1, T y1, T x2, T y2)
131 { 132 {
132 if (left < x1) left = x1; 133 if (left < x1) left = x1;
133 if (right > x2) right = x2; 134 if (right > x2) right = x2;