Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYury Melnichek <melnichek@gmail.com>2011-09-23 15:57:43 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:24:19 +0300
commit50130c101e07c531c6e1a0d6048b07b2808ec00b (patch)
tree7a86f69175e4744e989e730916facaac7ccef5f1 /geometry
parent19cebe3a73efb3b07f9d2f1b5d96d107e63642f0 (diff)
Fix CellId.ToInt64(depth) when depth <= m_Level.
Diffstat (limited to 'geometry')
-rw-r--r--geometry/cellid.hpp26
-rw-r--r--geometry/geometry_tests/cellid_test.cpp18
2 files changed, 34 insertions, 10 deletions
diff --git a/geometry/cellid.hpp b/geometry/cellid.hpp
index f37054c328..ea1df53b5f 100644
--- a/geometry/cellid.hpp
+++ b/geometry/cellid.hpp
@@ -238,18 +238,24 @@ public:
{
ASSERT(0 < depth && depth <= DEPTH_LEVELS, (m_Bits, m_Level, depth));
ASSERT(IsValid(), (m_Bits, m_Level));
- uint64_t bits = m_Bits, res = 0;
- for (int i = 0; i <= m_Level; ++i, bits >>= 2)
- res += bits + 1;
- bits = m_Bits;
- for (int i = m_Level + 1; i < depth; ++i)
+
+ if (m_Level >= depth)
+ return AncestorAtLevel(depth - 1).ToInt64(depth);
+ else
{
- bits <<= 2;
- res += bits;
+ uint64_t bits = m_Bits, res = 0;
+ for (int i = 0; i <= m_Level; ++i, bits >>= 2)
+ res += bits + 1;
+ bits = m_Bits;
+ for (int i = m_Level + 1; i < depth; ++i)
+ {
+ bits <<= 2;
+ res += bits;
+ }
+ ASSERT_GREATER(res, 0, (m_Bits, m_Level));
+ ASSERT_LESS_OR_EQUAL(res, TreeSizeForDepth(depth), (m_Bits, m_Level));
+ return static_cast<int64_t>(res);
}
- ASSERT_GREATER(res, 0, (m_Bits, m_Level));
- ASSERT_LESS_OR_EQUAL(res, TreeSizeForDepth(depth), (m_Bits, m_Level));
- return static_cast<int64_t>(res);
}
// Level order, numbering by Z-curve.
diff --git a/geometry/geometry_tests/cellid_test.cpp b/geometry/geometry_tests/cellid_test.cpp
index 07e7ed2ec7..a664f33e9e 100644
--- a/geometry/geometry_tests/cellid_test.cpp
+++ b/geometry/geometry_tests/cellid_test.cpp
@@ -49,6 +49,24 @@ UNIT_TEST(CellId_ToInt64)
TEST_EQUAL(m2::CellId<3>("33").ToInt64(3), 21, ());
}
+UNIT_TEST(CellId_ToInt64_LevelLessThanDepth)
+{
+ TEST_EQUAL(m2::CellId<3>("").ToInt64(2), 1, ());
+ TEST_EQUAL(m2::CellId<3>("0").ToInt64(2), 2, ());
+ TEST_EQUAL(m2::CellId<3>("1").ToInt64(2), 3, ());
+ TEST_EQUAL(m2::CellId<3>("2").ToInt64(2), 4, ());
+ TEST_EQUAL(m2::CellId<3>("3").ToInt64(2), 5, ());
+ TEST_EQUAL(m2::CellId<3>("00").ToInt64(2), 2, ());
+ TEST_EQUAL(m2::CellId<3>("01").ToInt64(2), 2, ());
+ TEST_EQUAL(m2::CellId<3>("03").ToInt64(2), 2, ());
+ TEST_EQUAL(m2::CellId<3>("10").ToInt64(2), 3, ());
+ TEST_EQUAL(m2::CellId<3>("20").ToInt64(2), 4, ());
+ TEST_EQUAL(m2::CellId<3>("23").ToInt64(2), 4, ());
+ TEST_EQUAL(m2::CellId<3>("30").ToInt64(2), 5, ());
+ TEST_EQUAL(m2::CellId<3>("31").ToInt64(2), 5, ());
+ TEST_EQUAL(m2::CellId<3>("33").ToInt64(2), 5, ());
+}
+
UNIT_TEST(CellId_FromInt64)
{
TEST_EQUAL(m2::CellId<3>(""), m2::CellId<3>::FromInt64(1, 3), ());