Add copy and assignment operators to util::extent

This commit is contained in:
Danny Robson 2012-06-05 22:50:52 +10:00
parent aad9a8377c
commit 4795e7f054
2 changed files with 27 additions and 1 deletions

View File

@ -27,13 +27,32 @@
using namespace util; using namespace util;
//-----------------------------------------------------------------------------
template <typename T> template <typename T>
extent<T>::extent (const T _width, const T _height): extent<T>::extent (const T _width, const T _height):
width (_width), width (_width),
height (_height) height (_height)
{ ; } { ; }
template <typename T>
extent<T>::extent (const extent<T> &rhs):
width (rhs.width),
height (rhs.height)
{ ; }
template <typename T>
extent<T>&
extent<T>::operator= (const extent<T> &rhs) {
width = rhs.width;
height = rhs.height;
return *this;
}
//-----------------------------------------------------------------------------
template <typename T> template <typename T>
T T
extent<T>::diameter (void) const { extent<T>::diameter (void) const {
@ -47,18 +66,21 @@ extent<T>::area (void) const
{ return width * height; } { return width * height; }
//-----------------------------------------------------------------------------
template <typename T> template <typename T>
double double
extent<T>::aspect (void) const extent<T>::aspect (void) const
{ return static_cast<double> (width) / height; } { return static_cast<double> (width) / height; }
//-----------------------------------------------------------------------------
template <typename T> template <typename T>
bool bool
extent<T>::empty (void) const extent<T>::empty (void) const
{ return almost_equal (area(), 0); } { return almost_equal (area(), 0); }
//-----------------------------------------------------------------------------
template <typename T> template <typename T>
bool bool
extent<T>::operator ==(const extent& rhs) const { extent<T>::operator ==(const extent& rhs) const {
@ -67,6 +89,7 @@ extent<T>::operator ==(const extent& rhs) const {
} }
//-----------------------------------------------------------------------------
template <typename T> template <typename T>
void void
extent<T>::sanity (void) const extent<T>::sanity (void) const
@ -86,6 +109,7 @@ namespace util {
} }
//-----------------------------------------------------------------------------
namespace util { namespace util {
template struct extent<unsigned int>; template struct extent<unsigned int>;
template struct extent<unsigned long>; template struct extent<unsigned long>;

View File

@ -29,6 +29,8 @@ namespace util {
T width, height; T width, height;
extent (const T _width, const T _height); extent (const T _width, const T _height);
extent (const extent&);
extent& operator= (const extent&);
T area (void) const; T area (void) const;
T diameter (void) const; T diameter (void) const;