2014-12-09 21:30:06 +00:00
|
|
|
namespace dk {
|
2014-12-12 19:04:48 +00:00
|
|
|
namespace implem {
|
|
|
|
template <size_t D>
|
|
|
|
inline size_t get_index_from_pos (const Vector<CoordinateScalarType, D>& parPos, const Vector<CoordinateScalarType, D>& parSize) {
|
|
|
|
size_t index = 0;
|
|
|
|
for (size_t d = 0; d < D; ++d) {
|
|
|
|
size_t pos = static_cast<size_t>(parPos[D - 1 - d]);
|
|
|
|
for (size_t p = 0; p < D - 1 - d; ++p) {
|
|
|
|
pos *= static_cast<size_t>(parSize[p]);
|
|
|
|
}
|
|
|
|
|
|
|
|
index += pos;
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(NDEBUG)
|
|
|
|
template <>
|
2014-12-12 23:22:50 +00:00
|
|
|
inline size_t get_index_from_pos<2> (const Vector<CoordinateScalarType, 2>& parPos, const Vector<CoordinateScalarType, 2>& parSize) {
|
2014-12-12 19:04:48 +00:00
|
|
|
return parPos.y() * parSize.x() + parPos.x();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} //namespace implem
|
|
|
|
|
2014-12-09 21:30:06 +00:00
|
|
|
template <typename T, size_t D>
|
|
|
|
TileIterator<T, D>::TileIterator() :
|
|
|
|
m_pos(CoordinateScalarType()),
|
|
|
|
m_from(CoordinateScalarType()),
|
|
|
|
m_to(CoordinateScalarType()),
|
|
|
|
m_areafrom(CoordinateScalarType()),
|
|
|
|
m_areato(CoordinateScalarType()),
|
2014-12-12 19:04:48 +00:00
|
|
|
m_total(CoordinateScalarType()),
|
|
|
|
m_data(nullptr)
|
2014-12-09 21:30:06 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, size_t D>
|
2014-12-12 19:04:48 +00:00
|
|
|
TileIterator<T, D>::TileIterator (std::vector<T>* parData, const coords& parFrom, const coords& parTo) :
|
2014-12-09 21:30:06 +00:00
|
|
|
m_pos(parFrom),
|
|
|
|
m_from(parFrom),
|
|
|
|
m_to(parTo),
|
|
|
|
m_areafrom(parFrom),
|
|
|
|
m_areato(parTo),
|
2014-12-12 19:04:48 +00:00
|
|
|
m_total(parTo - parFrom),
|
|
|
|
m_data(parData)
|
2014-12-09 21:30:06 +00:00
|
|
|
{
|
2014-12-12 19:04:48 +00:00
|
|
|
DK_ASSERT(parData);
|
2014-12-09 21:30:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, size_t D>
|
2014-12-12 19:04:48 +00:00
|
|
|
TileIterator<T, D>::TileIterator (std::vector<T>* parData, const coords& parFrom, const coords& parTo, const coords& parAreaFrom, const coords& parAreaTo, const coords& parTotal) :
|
2014-12-09 21:30:06 +00:00
|
|
|
m_pos(parFrom),
|
|
|
|
m_from(parFrom),
|
|
|
|
m_to(parTo),
|
|
|
|
m_areafrom(parAreaFrom),
|
|
|
|
m_areato(parAreaTo),
|
2014-12-12 19:04:48 +00:00
|
|
|
m_total(parTotal),
|
|
|
|
m_data(parData)
|
2014-12-09 21:30:06 +00:00
|
|
|
{
|
2014-12-12 19:04:48 +00:00
|
|
|
DK_ASSERT(parData);
|
2014-12-09 21:30:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, size_t D>
|
|
|
|
void TileIterator<T, D>::increment() {
|
|
|
|
for (size_t d = 0; d < D - 1; ++d) {
|
|
|
|
++m_pos[d];
|
|
|
|
if (m_pos[d] >= m_areato[d])
|
|
|
|
m_pos[d] = m_areafrom[d];
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
++m_pos[D - 1];
|
|
|
|
}
|
2014-12-11 22:58:52 +00:00
|
|
|
|
|
|
|
template <typename T, size_t D>
|
|
|
|
void TileIterator<T, D>::decrement() {
|
|
|
|
for (size_t d = 0; d < D; ++d) {
|
|
|
|
if (m_pos[d] > m_areafrom[d]) {
|
|
|
|
--m_pos[d];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_pos[d] = m_areato[d];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++m_pos[D - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, size_t D>
|
|
|
|
void TileIterator<T, D>::advance (size_t parAdvance) {
|
|
|
|
//TODO: implement
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, size_t D>
|
2014-12-12 19:04:48 +00:00
|
|
|
ptrdiff_t TileIterator<T, D>::distance_to (const TileIterator& parOther) {
|
|
|
|
return std::distance(this->get_current_index(), parOther.get_current_index());
|
2014-12-11 22:58:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, size_t D>
|
2014-12-12 19:04:48 +00:00
|
|
|
bool TileIterator<T, D>::equal (const TileIterator& parOther) const {
|
|
|
|
return m_data == parOther.m_data and m_pos == parOther.m_pos;
|
2014-12-11 22:58:52 +00:00
|
|
|
}
|
2014-12-09 21:30:06 +00:00
|
|
|
} //namespace dk
|