Move region to the util namespace
This commit is contained in:
parent
8f796bd214
commit
712cd39625
31
region.cpp
31
region.cpp
@ -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.
|
||||
namespace util {
|
||||
template <>
|
||||
void
|
||||
_rect<unsigned int>::sanity (void) const
|
||||
{ check (true); }
|
||||
extent<unsigned int>::sanity (void) const
|
||||
{ return; }
|
||||
}
|
||||
|
||||
|
||||
template struct _rect<unsigned int>;
|
||||
template struct extent<unsigned int>;
|
||||
template struct extent<double>;
|
||||
|
||||
/*
|
||||
* Region
|
||||
|
12
region.hpp
12
region.hpp
@ -21,27 +21,26 @@
|
||||
#ifndef __UTIL_REGION_HPP
|
||||
#define __UTIL_REGION_HPP
|
||||
|
||||
namespace util {
|
||||
/**
|
||||
* A pure two-dimensional size, without positioning
|
||||
*/
|
||||
template <typename T>
|
||||
struct _rect {
|
||||
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;
|
||||
|
||||
bool operator ==(const _rect& rhs) const;
|
||||
bool operator !=(const _rect& rhs) const
|
||||
bool operator ==(const extent& rhs) const;
|
||||
bool operator !=(const extent& rhs) const
|
||||
{ return !(*this == rhs); }
|
||||
|
||||
void sanity (void) const;
|
||||
};
|
||||
|
||||
typedef _rect<unsigned int> rect;
|
||||
|
||||
|
||||
/**
|
||||
* A two-dimensional rectangle, with size and position.
|
||||
@ -64,5 +63,6 @@ struct _region {
|
||||
};
|
||||
|
||||
typedef _region<unsigned int> region;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user