Add diameter methods to region and extent

This commit is contained in:
Danny Robson 2011-10-24 19:55:51 +11:00
parent 1c73bddf8b
commit 020a3a4afe
2 changed files with 21 additions and 1 deletions

View File

@ -23,6 +23,7 @@
#include "enable_if.hpp" #include "enable_if.hpp"
#include "debug.hpp" #include "debug.hpp"
#include <cmath>
#include <type_traits> #include <type_traits>
using namespace util; using namespace util;
@ -37,6 +38,13 @@ extent<T>::extent (const T _width, const T _height):
{ ; } { ; }
template <typename T>
T
extent<T>::diameter (void) const {
return (T)sqrt (width * width + height * height);
}
template <typename T> template <typename T>
T T
extent<T>::area (void) const extent<T>::area (void) const
@ -92,6 +100,13 @@ region<T>::area (void) const
{ return width * height; } { return width * height; }
template <typename T>
T
region<T>::diameter (void) const {
return (T)sqrt (width * width + height * height);
}
template <typename T> template <typename T>
bool bool
region<T>::empty (void) const region<T>::empty (void) const

View File

@ -34,6 +34,8 @@ namespace util {
extent (const T _width, const T _height); extent (const T _width, const T _height);
T area (void) const; T area (void) const;
T diameter (void) const;
bool empty (void) const; bool empty (void) const;
bool operator ==(const extent& rhs) const; bool operator ==(const extent& rhs) const;
@ -55,7 +57,10 @@ namespace util {
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;
T diameter (void) const;
bool empty (void) const; bool empty (void) const;
point centre (void) const; point centre (void) const;
bool includes (const point&) const; // inclusive of borders bool includes (const point&) const; // inclusive of borders