Add to_index() function to convert coords to scalar.
This commit is contained in:
parent
a1996b2d75
commit
cb9e4bce19
3 changed files with 59 additions and 0 deletions
|
@ -40,6 +40,32 @@ namespace dk {
|
|||
}
|
||||
} //namespace implem
|
||||
|
||||
template <uint32_t D>
|
||||
inline CoordinateDistType to_index (const Vector<D>& parPos, const Vector<D>& parUpper) {
|
||||
CoordinateDistType index = 0;
|
||||
for (CoordinateDistType d = 0; d < D; ++d) {
|
||||
auto pos = static_cast<CoordinateDistType>(parPos[D - 1 - d]);
|
||||
for (CoordinateDistType p = 0; p < D - 1 - d; ++p) {
|
||||
pos *= static_cast<CoordinateDistType>(parUpper[p] + 1);
|
||||
}
|
||||
|
||||
index += pos;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
#if defined(NDEBUG)
|
||||
template <>
|
||||
inline CoordinateDistType to_index<2> (const Vector<2>& parPos, const Vector<2>& parUpper) {
|
||||
return parPos.y() * (parUpper.x() + 1) + parPos.x();
|
||||
}
|
||||
#endif
|
||||
|
||||
template <uint32_t D>
|
||||
inline CoordinateDistType to_index (const TileCoords<D>& parTC) {
|
||||
return to_index<D>(parTC.position(), parTC.upper());
|
||||
}
|
||||
|
||||
template <uint32_t D>
|
||||
TileCoords<D>::TileCoords (const coords& parSize) :
|
||||
m_pos(CoordinateScalarType(0)),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue