Enable iteration over subtiles.

This feature has not been tested yet. I only made sure the regular iteration still works.
This commit is contained in:
King_DuckZ 2015-01-06 16:00:24 +01:00
parent 2e0f59f189
commit 90d759c696
2 changed files with 43 additions and 13 deletions

View file

@ -2,6 +2,7 @@
#define id873715F57B504CCF8227CE03EA28CAFA
#include "primitivetypes.hpp"
#include "implem/helpers.hpp"
#include <boost/iterator/iterator_facade.hpp>
#include <iterator>
#include <vector>
@ -48,6 +49,7 @@ namespace dk {
TileIterator ( TileIterator&& parOther ) = default;
TileIterator ( qualif_vector_type* parData, const coords& parFrom, const coords& parTo );
TileIterator ( qualif_vector_type* parData, const coords& parFrom, const coords& parTo, const coords& parAreaFrom, const coords& parAreaTo );
TileIterator ( qualif_vector_type* parData, const coords& parFrom, const coords& parTo, const coords& parAreaFrom, const coords& parAreaTo, const coords& parSubdiv );
~TileIterator ( void ) = default;
const coords& position ( void ) const { return m_pos; }
@ -59,14 +61,15 @@ namespace dk {
ptrdiff_t distance_to ( const TileIterator& parOther );
bool equal ( const TileIterator& parOther ) const;
T& dereference ( void ) const { return (*m_data)[get_current_index()]; }
size_t get_current_index ( void ) const { return implem::get_index_from_pos<D>(m_pos, m_areato - m_areafrom); }
size_t get_current_index ( void ) const { return implem::get_index_from_pos<D>(m_pos, m_subdivareasize) + m_subindex; }
coords m_pos;
coords m_from;
coords m_to;
coords m_areafrom;
coords m_areato;
coords m_subdivareasize;
qualif_vector_type* m_data;
CoordinateScalarType m_subindex;
CoordinateScalarType m_maxsubindex;
};
} //namespace dk

View file

@ -37,9 +37,10 @@ namespace dk {
m_pos(CoordinateScalarType()),
m_from(CoordinateScalarType()),
m_to(CoordinateScalarType()),
m_areafrom(CoordinateScalarType()),
m_areato(CoordinateScalarType()),
m_data(nullptr)
m_subdivareasize(CoordinateScalarType()),
m_data(nullptr),
m_subindex(0),
m_maxsubindex(0)
{
}
@ -48,9 +49,10 @@ namespace dk {
m_pos(parFrom),
m_from(parFrom),
m_to(parTo),
m_areafrom(parFrom),
m_areato(parTo),
m_data(parData)
m_subdivareasize(parTo - parFrom),
m_data(parData),
m_subindex(0),
m_maxsubindex(0)
{
DK_ASSERT(parData);
}
@ -60,15 +62,35 @@ namespace dk {
m_pos(parFrom),
m_from(parFrom),
m_to(parTo),
m_areafrom(parAreaFrom),
m_areato(parAreaTo),
m_data(parData)
m_subdivareasize(parAreaTo - parAreaFrom),
m_data(parData),
m_subindex(0),
m_maxsubindex(0)
{
DK_ASSERT(parData);
}
template <typename T, size_t D, typename T1>
TileIterator<T, D, T1>::TileIterator (qualif_vector_type* parData, const coords& parFrom, const coords& parTo, const coords& parAreaFrom, const coords& parAreaTo, const coords& parSubdiv) :
m_pos(parFrom),
m_from(parFrom),
m_to(parTo),
m_subdivareasize((parAreaTo - parAreaFrom) * parSubdiv),
m_data(parData),
m_subindex(0),
m_maxsubindex(implem::area(parSubdiv) - 1)
{
DK_ASSERT(parData);
}
template <typename T, size_t D, typename T1>
void TileIterator<T, D, T1>::increment() {
if (m_subindex < m_maxsubindex) {
++m_subindex;
return;
}
m_subindex = 0;
for (size_t d = 0; d < D - 1; ++d) {
++m_pos[d];
if (m_pos[d] >= m_to[d])
@ -81,13 +103,18 @@ namespace dk {
template <typename T, size_t D, typename T1>
void TileIterator<T, D, T1>::decrement() {
if (m_maxsubindex > 0 and m_subindex == 0) {
--m_subindex;
}
m_subindex = m_maxsubindex;
for (size_t d = 0; d < D; ++d) {
if (m_pos[d] > m_from[d]) {
--m_pos[d];
return;
}
else {
m_pos[d] = m_areato[d];
m_pos[d] = m_to[d];
}
}
++m_pos[D - 1];