Move region to the util namespace

This commit is contained in:
Danny Robson 2011-08-15 20:10:43 +10:00
parent 8f796bd214
commit 712cd39625
2 changed files with 53 additions and 46 deletions

View File

@ -20,14 +20,18 @@
#include "region.hpp"
#include "enable_if.hpp"
#include "debug.hpp"
#include <type_traits>
using namespace util;
/*
* Rect
*/
template <typename T>
_rect<T>::_rect (const T _width, const T _height):
extent<T>::extent (const T _width, const T _height):
width (_width),
height (_height)
{ ; }
@ -35,37 +39,40 @@ _rect<T>::_rect (const T _width, const T _height):
template <typename T>
T
_rect<T>::area (void) const
extent<T>::area (void) const
{ return width * height; }
template <typename T>
bool
_rect<T>::empty (void) const
{ return area() == 0; }
extent<T>::empty (void) const
{ return almost_equal (area(), 0); }
template <typename T>
bool
_rect<T>::operator ==(const _rect& rhs) const
{ return width == rhs.width && height == rhs.height; }
extent<T>::operator ==(const extent& rhs) const {
return almost_equal (width, rhs.width) &&
almost_equal (height, rhs.height);
}
template <typename T>
void
_rect<T>::sanity (void) const
extent<T>::sanity (void) const
{ check (width >= 0 && height >= 0); }
// Replace the check, as unsigned types do not ever go negative. This would
// trigger a compile warning if left.
template <>
void
_rect<unsigned int>::sanity (void) const
{ check (true); }
namespace util {
template <>
void
extent<unsigned int>::sanity (void) const
{ return; }
}
template struct _rect<unsigned int>;
template struct extent<unsigned int>;
template struct extent<double>;
/*
* Region

View File

@ -21,48 +21,48 @@
#ifndef __UTIL_REGION_HPP
#define __UTIL_REGION_HPP
/**
* A pure two-dimensional size, without positioning
*/
template <typename T>
struct _rect {
T width, height;
namespace util {
/**
* A pure two-dimensional size, without positioning
*/
template <typename T>
struct extent {
T width, height;
_rect (const T _width, const T _height);
extent (const T _width, const T _height);
T area (void) const;
bool empty (void) const;
T area (void) const;
bool empty (void) const;
bool operator ==(const _rect& rhs) const;
bool operator !=(const _rect& rhs) const
{ return !(*this == rhs); }
bool operator ==(const extent& rhs) const;
bool operator !=(const extent& rhs) const
{ return !(*this == rhs); }
void sanity (void) const;
};
typedef _rect<unsigned int> rect;
void sanity (void) const;
};
/**
* A two-dimensional rectangle, with size and position.
*/
template <typename T>
struct _region {
T x, y;
T width, height;
/**
* A two-dimensional rectangle, with size and position.
*/
template <typename T>
struct _region {
T x, y;
T width, height;
_region (T _x, T _y, T _width, T _height);
_region (T _x, T _y, T _width, T _height);
T area (void) const;
bool empty (void) const;
T area (void) const;
bool empty (void) const;
bool operator ==(const _region<T>& rhs) const;
bool operator !=(const _region<T>& rhs) const
{ return !(*this == rhs); }
bool operator ==(const _region<T>& rhs) const;
bool operator !=(const _region<T>& rhs) const
{ return !(*this == rhs); }
void sanity (void) const;
};
void sanity (void) const;
};
typedef _region<unsigned int> region;
typedef _region<unsigned int> region;
}
#endif