region: try to use unsigned types for extent

This commit is contained in:
Danny Robson 2015-02-17 16:23:34 +11:00
parent 93ec5be1f3
commit 6bd9ad333c
3 changed files with 8 additions and 10 deletions

View File

@ -335,8 +335,6 @@ util::operator<< (std::ostream &os, const util::region<T> &rhs) {
//-----------------------------------------------------------------------------
namespace util {
template struct region<int32_t>;
template struct region<int64_t>;
template struct region<uint32_t>;
template struct region<uint64_t>;
template struct region<float>;

View File

@ -31,8 +31,8 @@ namespace util {
*/
template <typename T>
struct region {
typedef T position_type;
typedef T size_type;
using position_type = T;
using size_type = typename try_unsigned<T>::type;
static constexpr size_t dimension = 2u;
static constexpr size_t elements = dimension * 2;

View File

@ -21,13 +21,13 @@ main (int, char **) {
CHECK_EQ (region<double>::UNIT.area (), 1.0);
CHECK_EQ (region< float>::UNIT.area (), 1.0f);
CHECK (region<int> (0, 0, 2, 2).includes (point<2,int>(1, 1)));
CHECK (region<int> (0, 0, 2, 2).includes (point<2,int>(0, 0)));
CHECK (region<int> (0, 0, 2, 2).includes (point<2,int>(2, 2)));
CHECK (region<unsigned> (0, 0, 2, 2).includes (point<2,unsigned>(1, 1)));
CHECK (region<unsigned> (0, 0, 2, 2).includes (point<2,unsigned>(0, 0)));
CHECK (region<unsigned> (0, 0, 2, 2).includes (point<2,unsigned>(2, 2)));
CHECK ( region<int> (0, 0, 2, 2).contains (point<2,int>(1, 1)));
CHECK (!region<int> (0, 0, 2, 2).contains (point<2,int>(0, 0)));
CHECK (!region<int> (0, 0, 2, 2).contains (point<2,int>(2, 2)));
CHECK ( region<unsigned> (0, 0, 2, 2).contains (point<2,unsigned>(1, 1)));
CHECK (!region<unsigned> (0, 0, 2, 2).contains (point<2,unsigned>(0, 0)));
CHECK (!region<unsigned> (0, 0, 2, 2).contains (point<2,unsigned>(2, 2)));
//CHECK (region<intmax_t> (0, 0, 10, 10).includes (point2d (0.4, 0.01)));
//CHECK (region<intmax_t> (0, 0, 10, 10).contains (point2d (0.4, 0.01)));