Make width/height unsigned where possible

This commit is contained in:
Danny Robson 2012-05-25 15:30:28 +10:00
parent 4899f08772
commit 45a1b6b93c
2 changed files with 12 additions and 9 deletions

View File

@ -29,7 +29,7 @@ using namespace util;
template <typename T>
region<T>::region (T _x, T _y, T _w, T _h):
region<T>::region (T _x, T _y, size_type _w, size_type _h):
x (_x),
y (_y),
w (_w),
@ -49,15 +49,15 @@ region<T>::operator+= (const vector<2> &rhs) {
template <typename T>
T
typename region<T>::size_type
region<T>::area (void) const
{ return w * h; }
template <typename T>
T
typename region<T>::size_type
region<T>::diameter (void) const {
return (T)sqrt (w * w + h * h);
return static_cast<size_type> (sqrt (w * w + h * h));
}

View File

@ -22,6 +22,7 @@
#define __UTIL_REGION_HPP
#include "point.hpp"
#include "types/traits.hpp"
namespace util {
/**
@ -29,15 +30,17 @@ namespace util {
*/
template <typename T>
struct region {
T x, y;
T w, h;
typedef typename always_unsigned<T>::type size_type;
region (T _x, T _y, T _w, T _h);
T x, y;
size_type w, h;
region (T _x, T _y, size_type _w, size_type _h);
region& operator +=(const vector<2>& rhs);
T area (void) const;
T diameter (void) const;
size_type area (void) const;
size_type diameter (void) const;
bool empty (void) const;