From ba82a2e066a76e5bd19f8c7ac3ff656748ae7c6e Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Thu, 30 Jul 2015 02:04:02 +0200 Subject: [PATCH] Fix operator++ --- include/doorkeeper/implem/tilecoords.inl | 5 +++-- test/unit/tilecoords.cpp | 13 ++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/include/doorkeeper/implem/tilecoords.inl b/include/doorkeeper/implem/tilecoords.inl index e0d504d..8036db3 100644 --- a/include/doorkeeper/implem/tilecoords.inl +++ b/include/doorkeeper/implem/tilecoords.inl @@ -4,6 +4,7 @@ namespace dk { m_pos(CoordinateScalarType(0)), m_size(parSize) { + assert(m_pos <= m_size); } template @@ -11,7 +12,7 @@ namespace dk { m_pos(parValue), m_size(parSize) { - assert(parValue < parSize); + assert(m_pos <= m_size); } template @@ -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; diff --git a/test/unit/tilecoords.cpp b/test/unit/tilecoords.cpp index 870eec5..56714e5 100644 --- a/test/unit/tilecoords.cpp +++ b/test/unit/tilecoords.cpp @@ -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); + } }