forked from organicmaps/organicmaps
[indexer] Change API Cover*
This commit is contained in:
parent
76c719abbd
commit
50b66e6985
3 changed files with 18 additions and 21 deletions
|
@ -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 <typename Bounds, typename CellId>
|
||||
inline void CoverRect(m2::RectD rect, size_t cellsCount, int maxDepth, std::vector<CellId> & result)
|
||||
inline void CoverRectByCells(m2::RectD rect, size_t cellsCount, int maxLevel, std::vector<CellId> & 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<std::pair<CellId, m2::RectD>, 4> arr;
|
||||
size_t const count = SplitRectCell<Bounds>(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 <typename Bounds, typename CellId>
|
||||
void CoverSpiral(m2::RectD rect, int maxDepth, std::vector<CellId> & result)
|
||||
void CoverSpiralByCells(m2::RectD rect, int maxLevel, std::vector<CellId> & result)
|
||||
{
|
||||
using Converter = CellIdConverter<Bounds, CellId>;
|
||||
|
||||
|
@ -126,11 +124,10 @@ void CoverSpiral(m2::RectD rect, int maxDepth, std::vector<CellId> & 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);
|
||||
|
|
|
@ -78,7 +78,7 @@ void CoverViewportAndAppendLowerLevels(m2::RectD const & r, int cellDepth, Inter
|
|||
{
|
||||
std::vector<m2::CellId<DEPTH_LEVELS>> ids;
|
||||
ids.reserve(SPLIT_RECT_CELLS_COUNT);
|
||||
CoverRect<MercatorBounds, m2::CellId<DEPTH_LEVELS>>(r, SPLIT_RECT_CELLS_COUNT, cellDepth, ids);
|
||||
CoverRectByCells<MercatorBounds, m2::CellId<DEPTH_LEVELS>>(r, SPLIT_RECT_CELLS_COUNT, cellDepth - 1, ids);
|
||||
|
||||
Intervals intervals;
|
||||
for (auto const & id : ids)
|
||||
|
@ -153,7 +153,7 @@ public:
|
|||
case Spiral:
|
||||
{
|
||||
std::vector<m2::CellId<DEPTH_LEVELS>> ids;
|
||||
CoverSpiral<MercatorBounds, m2::CellId<DEPTH_LEVELS>>(m_rect, cellDepth, ids);
|
||||
CoverSpiralByCells<MercatorBounds, m2::CellId<DEPTH_LEVELS>>(m_rect, cellDepth - 1, ids);
|
||||
|
||||
std::set<Interval> uniqueIds;
|
||||
auto insertInterval = [this, ind, &uniqueIds](Interval const & interval) {
|
||||
|
|
|
@ -18,10 +18,10 @@ UNIT_TEST(CellIdToStringRecode)
|
|||
TEST_EQUAL(CellIdT::FromString(kTest).ToString(), kTest, ());
|
||||
}
|
||||
|
||||
UNIT_TEST(GoldenCoverRect)
|
||||
UNIT_TEST(GoldenCoverRectByCells)
|
||||
{
|
||||
vector<CellIdT> cells;
|
||||
CoverRect<OrthoBounds>({27.43, 53.83, 27.70, 53.96}, 4, RectId::DEPTH_LEVELS, cells);
|
||||
CoverRectByCells<OrthoBounds>({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<CellIdT> cells;
|
||||
CoverRect<TestBounds>({5, 5, 11, 11}, 4, RectId::DEPTH_LEVELS, cells);
|
||||
CoverRectByCells<TestBounds>({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<m2::CellId<3>>{};
|
||||
|
||||
CoverSpiral<TestBounds, m2::CellId<3>>({2.1, 4.1, 2.1, 4.1}, depthMax, cells);
|
||||
CoverSpiralByCells<TestBounds, m2::CellId<3>>({2.1, 4.1, 2.1, 4.1}, levelMax, cells);
|
||||
|
||||
TEST_EQUAL(cells.size(), 1, ());
|
||||
TEST_EQUAL(cells[0].Level(), depthMax - 1, ());
|
||||
|
|
Loading…
Add table
Reference in a new issue