82 lines
1.9 KiB
C++
82 lines
1.9 KiB
C++
namespace dk {
|
|
template <uint32_t D>
|
|
TileCoords<D>::TileCoords (const coords& parSize) :
|
|
m_pos(CoordinateScalarType(0)),
|
|
m_size(parSize)
|
|
{
|
|
DK_ASSERT(m_pos <= m_size);
|
|
}
|
|
|
|
template <uint32_t D>
|
|
TileCoords<D>::TileCoords (const coords& parValue, const coords& parSize) :
|
|
m_pos(parValue),
|
|
m_size(parSize)
|
|
{
|
|
DK_ASSERT(m_pos <= m_size);
|
|
}
|
|
|
|
template <uint32_t D>
|
|
TileCoords<D>& TileCoords<D>::operator++ () {
|
|
const coords lower(0);
|
|
for (std::size_t d = 0; d < static_cast<std::size_t>(D - 1); ++d) {
|
|
++m_pos[d];
|
|
if (m_pos[d] > m_size[d])
|
|
m_pos[d] = lower[d];
|
|
else
|
|
return *this;
|
|
}
|
|
++m_pos[static_cast<std::size_t>(D - 1)];
|
|
return *this;
|
|
}
|
|
|
|
template <uint32_t D>
|
|
TileCoords<D> TileCoords<D>::operator++ (int) {
|
|
TileCoords<D> retval(*this);
|
|
++(*this);
|
|
return retval;
|
|
}
|
|
|
|
template <uint32_t D>
|
|
TileCoords<D>& TileCoords<D>::operator-- () {
|
|
const coords lower(0);
|
|
for (std::size_t d = 0; d < static_cast<std::size_t>(D); ++d) {
|
|
if (m_pos[d] > lower[d]) {
|
|
--m_pos[d];
|
|
return;
|
|
}
|
|
else {
|
|
m_pos[d] = m_size[d];
|
|
}
|
|
}
|
|
++m_pos[static_cast<std::size_t>(D - 1)];
|
|
return *this;
|
|
}
|
|
|
|
template <uint32_t D>
|
|
TileCoords<D> TileCoords<D>::operator-- (int) {
|
|
TileCoords<D> retval(*this);
|
|
--(*this);
|
|
return retval;
|
|
}
|
|
|
|
template <uint32_t D>
|
|
const TileCoords<D>& TileCoords<D>::operator+= (CoordinateScalarType parValue) {
|
|
CoordinateScalarType acc(parValue);
|
|
CoordinateScalarType div(1);
|
|
for (std::size_t z = 0; z < D; ++z) {
|
|
m_pos[z] = (m_pos[z] + acc / div) % m_size[z];
|
|
div *= m_size[z];
|
|
acc += m_pos[z];
|
|
}
|
|
}
|
|
|
|
template <uint32_t D>
|
|
bool TileCoords<D>::operator== (const TileCoords& parOther) const {
|
|
return m_pos == parOther.m_pos and m_size == parOther.m_size;
|
|
}
|
|
|
|
template <uint32_t D>
|
|
bool TileCoords<D>::operator!= (const TileCoords& parOther) const {
|
|
return not(*this == parOther);
|
|
}
|
|
} //namespace dk
|