Fix operator++

This commit is contained in:
King_DuckZ 2015-07-30 02:04:02 +02:00
parent 971cd54688
commit ba82a2e066
2 changed files with 15 additions and 3 deletions

View File

@ -4,6 +4,7 @@ namespace dk {
m_pos(CoordinateScalarType(0)),
m_size(parSize)
{
assert(m_pos <= m_size);
}
template <uint32_t D>
@ -11,7 +12,7 @@ namespace dk {
m_pos(parValue),
m_size(parSize)
{
assert(parValue < parSize);
assert(m_pos <= m_size);
}
template <uint32_t D>
@ -19,7 +20,7 @@ namespace dk {
const coords lower(0);
for (CoordinateDistType d = 0; d < D - 1; ++d) {
++m_pos[d];
if (m_pos[d] >= m_size[d])
if (m_pos[d] > m_size[d])
m_pos[d] = lower[d];
else
return *this;

View File

@ -4,13 +4,15 @@
TEST(increment, tilecoords) {
typedef dk::TileCoords<2> tcoords2;
typedef dk::TileCoords<2>::coords coords2;
typedef dk::TileCoords<5> tcoords5;
typedef dk::TileCoords<5>::coords coords5;
{
const coords2 max_coords(150, 200);
tcoords2 test(max_coords);
EXPECT_EQ(tcoords2(coords2(0), max_coords), test);
for (auto z = coords2(0).x(); z < max_coords.x(); ++z) {
for (auto z = coords2(0).x(); z <= max_coords.x(); ++z) {
EXPECT_EQ(tcoords2(coords2(z, 0), max_coords), test);
++test;
}
@ -18,4 +20,13 @@ TEST(increment, tilecoords) {
EXPECT_EQ(tcoords2(coords2(1, 1), max_coords), test);
EXPECT_EQ(tcoords2(coords2(0, 1), max_coords), test_old);
}
{
const coords5 max_coords(3);
tcoords5 test(max_coords);
for (int z = 0; z < 4 * 4 * 4 * 4 * 4 - 1; ++z) {
++test;
}
EXPECT_EQ(tcoords5(max_coords, max_coords), test);
}
}