diff --git a/indexer/cell_coverer.hpp b/indexer/cell_coverer.hpp index dcd94fbf5e..165dbe179a 100644 --- a/indexer/cell_coverer.hpp +++ b/indexer/cell_coverer.hpp @@ -34,9 +34,9 @@ inline size_t SplitRectCell(CellId const & id, m2::RectD const & rect, return index; } -// Covers rect with cells starting from |maxDepth| - 1 level. +// Covers |rect| with at most |cellsCount| cells that have levels equal to or less than |maxLevel|. template -inline void CoverRect(m2::RectD rect, size_t cellsCount, int maxDepth, std::vector & result) +inline void CoverRectByCells(m2::RectD rect, size_t cellsCount, int maxLevel, std::vector & result) { ASSERT(result.empty(), ()); { @@ -54,17 +54,15 @@ inline void CoverRect(m2::RectD rect, size_t cellsCount, int maxDepth, std::vect cellQueue; cellQueue.push(commonCell); - maxDepth -= 1; - while (!cellQueue.empty() && cellQueue.size() + result.size() < cellsCount) { auto id = cellQueue.top(); cellQueue.pop(); - while (id.Level() > maxDepth) + while (id.Level() > maxLevel) id = id.Parent(); - if (id.Level() == maxDepth) + if (id.Level() == maxLevel) { result.push_back(id); break; @@ -92,7 +90,7 @@ inline void CoverRect(m2::RectD rect, size_t cellsCount, int maxDepth, std::vect for (; !cellQueue.empty(); cellQueue.pop()) { auto id = cellQueue.top(); - while (id.Level() < maxDepth) + while (id.Level() < maxLevel) { std::array, 4> arr; size_t const count = SplitRectCell(id, rect, arr); @@ -105,9 +103,9 @@ inline void CoverRect(m2::RectD rect, size_t cellsCount, int maxDepth, std::vect } } -// Covers rect with cells using spiral order starting from the rect center cell of |maxDepth| - 1 level. +// Covers |rect| with cells using spiral order starting from the rect center cell of |maxLevel|. template -void CoverSpiral(m2::RectD rect, int maxDepth, std::vector & result) +void CoverSpiralByCells(m2::RectD rect, int maxLevel, std::vector & result) { using Converter = CellIdConverter; @@ -126,11 +124,10 @@ void CoverSpiral(m2::RectD rect, int maxDepth, std::vector & result) CHECK(rect.IsValid(), ()); auto centralCell = Converter::ToCellId(rect.Center().x, rect.Center().y); - auto const levelMax = maxDepth - 1; - while (levelMax < centralCell.Level() && centralCell.Level() > 0) + while (maxLevel < centralCell.Level() && centralCell.Level() > 0) centralCell = centralCell.Parent(); - if (levelMax < centralCell.Level()) + if (maxLevel < centralCell.Level()) return; result.push_back(centralCell); diff --git a/indexer/feature_covering.hpp b/indexer/feature_covering.hpp index 3a852dc877..1a12025ddf 100644 --- a/indexer/feature_covering.hpp +++ b/indexer/feature_covering.hpp @@ -78,7 +78,7 @@ void CoverViewportAndAppendLowerLevels(m2::RectD const & r, int cellDepth, Inter { std::vector> ids; ids.reserve(SPLIT_RECT_CELLS_COUNT); - CoverRect>(r, SPLIT_RECT_CELLS_COUNT, cellDepth, ids); + CoverRectByCells>(r, SPLIT_RECT_CELLS_COUNT, cellDepth - 1, ids); Intervals intervals; for (auto const & id : ids) @@ -153,7 +153,7 @@ public: case Spiral: { std::vector> ids; - CoverSpiral>(m_rect, cellDepth, ids); + CoverSpiralByCells>(m_rect, cellDepth - 1, ids); std::set uniqueIds; auto insertInterval = [this, ind, &uniqueIds](Interval const & interval) { diff --git a/indexer/indexer_tests/cell_coverer_test.cpp b/indexer/indexer_tests/cell_coverer_test.cpp index 865d28d760..307c7d5270 100644 --- a/indexer/indexer_tests/cell_coverer_test.cpp +++ b/indexer/indexer_tests/cell_coverer_test.cpp @@ -18,10 +18,10 @@ UNIT_TEST(CellIdToStringRecode) TEST_EQUAL(CellIdT::FromString(kTest).ToString(), kTest, ()); } -UNIT_TEST(GoldenCoverRect) +UNIT_TEST(GoldenCoverRectByCells) { vector cells; - CoverRect({27.43, 53.83, 27.70, 53.96}, 4, RectId::DEPTH_LEVELS, cells); + CoverRectByCells({27.43, 53.83, 27.70, 53.96}, 4, RectId::DEPTH_LEVELS - 1, cells); TEST_EQUAL(cells.size(), 4, ()); @@ -31,12 +31,12 @@ UNIT_TEST(GoldenCoverRect) TEST_EQUAL(cells[3].ToString(), "32012211303", ()); } -UNIT_TEST(ArtificialCoverRect) +UNIT_TEST(ArtificialCoverRectByCells) { typedef Bounds<0, 0, 16, 16> TestBounds; vector cells; - CoverRect({5, 5, 11, 11}, 4, RectId::DEPTH_LEVELS, cells); + CoverRectByCells({5, 5, 11, 11}, 4, RectId::DEPTH_LEVELS - 1, cells); TEST_EQUAL(cells.size(), 4, ()); @@ -46,15 +46,15 @@ UNIT_TEST(ArtificialCoverRect) TEST_EQUAL(cells[3].ToString(), "30", ()); } -UNIT_TEST(MaxDepthCoverSpiral) +UNIT_TEST(MaxDepthCoverSpiralByCells) { using TestBounds = Bounds<0, 0, 8, 8>; - for (auto depthMax = 1; depthMax <= 3; ++depthMax) + for (auto levelMax = 0; levelMax <= 2; ++levelMax) { auto cells = vector>{}; - CoverSpiral>({2.1, 4.1, 2.1, 4.1}, depthMax, cells); + CoverSpiralByCells>({2.1, 4.1, 2.1, 4.1}, levelMax, cells); TEST_EQUAL(cells.size(), 1, ()); TEST_EQUAL(cells[0].Level(), depthMax - 1, ());