diff --git a/extent.cpp b/extent.cpp index 37ae21ba..810ab828 100644 --- a/extent.cpp +++ b/extent.cpp @@ -90,11 +90,11 @@ util::extent::area (void) const /////////////////////////////////////////////////////////////////////////////// template util::extent -util::extent::expanded (util::vector<2,T> size) const +util::extent::expanded (util::vector<2,T> mag) const { return { - w + size.x, - h + size.y + w + mag.x, + h + mag.y }; } @@ -126,6 +126,45 @@ util::extent::empty (void) const } +/////////////////////////////////////////////////////////////////////////////// +template +T& +util::extent::operator[] (size_t idx) +{ + switch (idx) { + case 0: return w; + case 1: return h; + + default: + unreachable (); + } +} + + +//----------------------------------------------------------------------------- +template +const T& +util::extent::operator[] (size_t idx) const +{ + switch (idx) { + case 0: return w; + case 1: return h; + + default: + unreachable (); + } +} + + +//----------------------------------------------------------------------------- +template +size_t +util::extent::size (void) const +{ + return 2u; +} + + /////////////////////////////////////////////////////////////////////////////// template bool diff --git a/extent.hpp b/extent.hpp index bc6fe503..244ebd2b 100644 --- a/extent.hpp +++ b/extent.hpp @@ -50,6 +50,11 @@ namespace util { bool empty (void) const; + T& operator[] (size_t idx); + const T& operator[] (size_t idx) const; + + size_t size (void) const; + bool operator ==(const extent& rhs) const; bool operator !=(const extent& rhs) const { return !(*this == rhs); }