DoorKeeper/include/implem/tileiterator.inl
King_DuckZ 9086de8dae Advancing with the implementation.
The iterator is not included anywhere yet so it's completely untested.
Next step is to define the relationship between views and layers, so iterators can be put
into the class that will be responsible to spawn them.
2014-12-11 23:58:52 +01:00

90 lines
2 KiB
C++

namespace dk {
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()),
m_total(CoordinateScalarType())
{
}
template <typename T, size_t D>
TileIterator<T, D>::TileIterator (const coords& parFrom, const coords& parTo) :
m_pos(parFrom),
m_from(parFrom),
m_to(parTo),
m_areafrom(parFrom),
m_areato(parTo),
m_total(parTo - parFrom)
{
}
template <typename T, size_t D>
TileIterator<T, D>::TileIterator (const coords& parFrom, const coords& parTo, const coords& parAreaFrom, const coords& parAreaTo, const coords& parTotal) :
m_pos(parFrom),
m_from(parFrom),
m_to(parTo),
m_areafrom(parAreaFrom),
m_areato(parAreaTo),
m_total(parTotal)
{
}
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];
}
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>
size_t TileIterator<T, D>::get_current_index() const {
size_t index = 0;
for (size_t d = 0; d < D; ++d) {
size_t pos = static_cast<size_t>(m_pos[D - 1 - d]);
for (size_t p = 0; p < D - 1 - d; ++p) {
pos *= static_cast<size_t>(m_total[p]);
}
index += pos;
}
return index;
}
template <typename T, size_t D>
void TileIterator<T, D>::advance (size_t parAdvance) {
//TODO: implement
}
template <typename T, size_t D>
ptrdiff_t TileIterator<T, D>::distance_to (const MeshSelectionIterator& parOther) {
//TODO: implement
}
template <typename T, size_t D>
bool TileIterator<T, D>::equal (const MeshSelectionIterator& parOther) const {
//TODO: implement
return true;
}
} //namespace dk