From e3345c5ccad499dab0c33c00aeacf29d6489b557 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Fri, 14 Aug 2015 22:13:14 +0200 Subject: [PATCH] Finish implementing operator+= for positive offsets. --- include/doorkeeper/implem/tilecoords.inl | 9 ++++++++- test/unit/tilecoords.cpp | 4 ++-- tools/calc_advance.rb | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) mode change 100644 => 100755 tools/calc_advance.rb diff --git a/include/doorkeeper/implem/tilecoords.inl b/include/doorkeeper/implem/tilecoords.inl index 9c6ff8b..b3247bf 100644 --- a/include/doorkeeper/implem/tilecoords.inl +++ b/include/doorkeeper/implem/tilecoords.inl @@ -1,5 +1,8 @@ namespace dk { namespace implem { + ///---------------------------------------------------------------------- + ///Equivalent to (parA + parB) % parDiv + ///---------------------------------------------------------------------- inline CoordinateScalarType sum_mod (CoordinateScalarType parA, CoordinateScalarType parB, CoordinateScalarType parDiv) { //const auto sum = m_pos[index] + parValue; //const auto sz = m_size[index] + 1; @@ -12,6 +15,9 @@ namespace dk { return std::max(parA, parB) - rounded_sum + std::min(parA, parB); } + ///---------------------------------------------------------------------- + ///Equivalent to (parA + parB) / parDiv + ///---------------------------------------------------------------------- inline CoordinateScalarType sum_div (CoordinateScalarType parA, CoordinateScalarType parB, CoordinateScalarType parDiv) { const auto x = ((parA % parDiv) + (parB % parDiv)) / parDiv; return parA / parDiv + parB / parDiv + x; @@ -88,12 +94,13 @@ namespace dk { //parValue += m_pos[index]; //m_pos[index] = parValue % (m_size[index] + 1); //parValue /= (m_size[index] + 1); - //++index; //overflow-aware implementation const auto new_pos = implem::sum_mod(m_pos[index], parValue, m_size[index] + 1); parValue = implem::sum_div(m_pos[index], parValue, m_size[index] + 1); m_pos[index] = new_pos; + + ++index; } return *this; } diff --git a/test/unit/tilecoords.cpp b/test/unit/tilecoords.cpp index e64d6a6..18c8cba 100644 --- a/test/unit/tilecoords.cpp +++ b/test/unit/tilecoords.cpp @@ -81,9 +81,9 @@ TEST(advance, tilecoords) { } { - const coords4 max_coords(max_scalar, 800, max_scalar, max_scalar); + const coords4 max_coords(max_scalar - 1, 800, max_scalar - 1, max_scalar - 1); - tcoords4 test(coords4(max_scalar, 800, 1200, 710), max_coords); + tcoords4 test(coords4(max_scalar - 1, 800, 1200, 710), max_coords); test += max_scalar; EXPECT_EQ(2147483646, test[0]); EXPECT_EQ(0, test[1]); diff --git a/tools/calc_advance.rb b/tools/calc_advance.rb old mode 100644 new mode 100755 index 590c2d3..e0beb10 --- a/tools/calc_advance.rb +++ b/tools/calc_advance.rb @@ -17,4 +17,4 @@ def calc(arr, m) end p calc([540, 800, 1200, 710], [M - 10, M - 11, M - 12, M - 13]) -p calc([M, 800, 1200, 710], [M, 800, M, M]) +p calc([M - 1, 800, 1200, 710], [M - 1, 800, M - 1, M - 1])