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

View File

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