Add structure for region iterator
It is not currently enabled as the exact semantics aren't really known, but as we're likely to want something similar later then we shouldn't throw the code away.
This commit is contained in:
parent
23c9bf17e6
commit
9447910061
70
region.cpp
70
region.cpp
@ -26,9 +26,12 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
using namespace util;
|
using namespace util;
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
template <typename T>
|
template <typename T>
|
||||||
region<T>::region (T _x, T _y, size_type _w, size_type _h):
|
region<T>::region (T _x, T _y, size_type _w, size_type _h):
|
||||||
x (_x),
|
x (_x),
|
||||||
@ -49,6 +52,7 @@ region<T>::operator+= (const vector<2> &rhs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
template <typename T>
|
template <typename T>
|
||||||
typename region<T>::size_type
|
typename region<T>::size_type
|
||||||
region<T>::area (void) const
|
region<T>::area (void) const
|
||||||
@ -68,6 +72,7 @@ region<T>::empty (void) const
|
|||||||
{ return almost_equal (area (), 0); }
|
{ return almost_equal (area (), 0); }
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
template <typename T>
|
template <typename T>
|
||||||
point<2>
|
point<2>
|
||||||
region<T>::base (void) const {
|
region<T>::base (void) const {
|
||||||
@ -85,6 +90,7 @@ region<T>::centre (void) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool
|
bool
|
||||||
region<T>::includes (const point<2> &p) const {
|
region<T>::includes (const point<2> &p) const {
|
||||||
@ -117,6 +123,7 @@ region<T>::overlaps (const region<T> &rhs) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
template<typename T>
|
template<typename T>
|
||||||
region<T>
|
region<T>
|
||||||
region<T>::overlap (const region<T> &rhs) const {
|
region<T>::overlap (const region<T> &rhs) const {
|
||||||
@ -135,6 +142,7 @@ region<T>::overlap (const region<T> &rhs) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool
|
bool
|
||||||
region<T>::operator== (const region& rhs) const
|
region<T>::operator== (const region& rhs) const
|
||||||
@ -144,6 +152,7 @@ region<T>::operator ==(const region& rhs) const
|
|||||||
almost_equal (h, rhs.h); }
|
almost_equal (h, rhs.h); }
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void
|
void
|
||||||
region<T>::sanity (void) const {
|
region<T>::sanity (void) const {
|
||||||
@ -152,6 +161,60 @@ region<T>::sanity (void) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// The desired iterator semantics have been difficult to nail down; is it
|
||||||
|
// edge-inclusive, left-bottom inclusive, purely exclusive, integral only?
|
||||||
|
// The code has been left here because it was a little annoying to write and
|
||||||
|
// we're likely to need it again some day.
|
||||||
|
#if 0
|
||||||
|
template <typename T>
|
||||||
|
typename region<T>::iterator&
|
||||||
|
region<T>::iterator::operator++ (void) {
|
||||||
|
if (++x > static_cast<T> (w)) {
|
||||||
|
x = a;
|
||||||
|
++y;
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
typename region<T>::iterator&
|
||||||
|
region<T>::iterator::operator* (void) {
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
bool
|
||||||
|
region<T>::iterator::operator== (const iterator &rhs) const {
|
||||||
|
return almost_equal (rhs.x, x) && almost_equal (rhs.y, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
bool
|
||||||
|
region<T>::iterator::operator!= (const iterator &rhs) const {
|
||||||
|
return !(*this == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
typename region<T>::iterator
|
||||||
|
region<T>::begin (void) {
|
||||||
|
return { x, y, x, w, h };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
typename region<T>::iterator
|
||||||
|
region<T>::end (void) {
|
||||||
|
return { x, y + sign_cast<T> (h) + 1, x, w, h };
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace util {
|
namespace util {
|
||||||
template <>
|
template <>
|
||||||
void region<double>::sanity (void) const {
|
void region<double>::sanity (void) const {
|
||||||
@ -166,6 +229,7 @@ namespace util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
template <typename T>
|
template <typename T>
|
||||||
std::ostream&
|
std::ostream&
|
||||||
util::operator<< (std::ostream &os, const region<T> &rhs) {
|
util::operator<< (std::ostream &os, const region<T> &rhs) {
|
||||||
@ -174,6 +238,7 @@ util::operator<< (std::ostream &os, const region<T> &rhs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
namespace util {
|
namespace util {
|
||||||
template struct region<int32_t>;
|
template struct region<int32_t>;
|
||||||
template struct region<int64_t>;
|
template struct region<int64_t>;
|
||||||
@ -181,6 +246,9 @@ namespace util {
|
|||||||
template struct region<uint64_t>;
|
template struct region<uint64_t>;
|
||||||
template struct region<double>;
|
template struct region<double>;
|
||||||
|
|
||||||
template std::ostream& operator<< (std::ostream&, const region<unsigned int>&);
|
template std::ostream& operator<< (std::ostream&, const region< int32_t>&);
|
||||||
|
template std::ostream& operator<< (std::ostream&, const region< int64_t>&);
|
||||||
|
template std::ostream& operator<< (std::ostream&, const region<uint32_t>&);
|
||||||
|
template std::ostream& operator<< (std::ostream&, const region<uint64_t>&);
|
||||||
template std::ostream& operator<< (std::ostream&, const region< double>&);
|
template std::ostream& operator<< (std::ostream&, const region< double>&);
|
||||||
}
|
}
|
||||||
|
16
region.hpp
16
region.hpp
@ -59,6 +59,22 @@ namespace util {
|
|||||||
{ return !(*this == rhs); }
|
{ return !(*this == rhs); }
|
||||||
|
|
||||||
void sanity (void) const;
|
void sanity (void) const;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
struct iterator {
|
||||||
|
T x, y;
|
||||||
|
T a;
|
||||||
|
size_type w, h;
|
||||||
|
|
||||||
|
iterator& operator++ (void);
|
||||||
|
iterator& operator* (void);
|
||||||
|
bool operator== (const iterator&) const;
|
||||||
|
bool operator!= (const iterator&) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
iterator begin (void);
|
||||||
|
iterator end (void);
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user