diff --git a/indexer/covering.cpp b/indexer/covering.cpp index a6dacfb65d..c9f5695a74 100644 --- a/indexer/covering.cpp +++ b/indexer/covering.cpp @@ -60,8 +60,10 @@ public: } -vector covering::CoverFeature(FeatureType const & f, - uint64_t cellPenaltyArea) +namespace covering +{ + +vector CoverFeature(FeatureType const & f, uint64_t cellPenaltyArea) { FeatureIntersector featureIntersector; f.ForEachPointRef(featureIntersector, -1); @@ -87,7 +89,7 @@ vector covering::CoverFeature(FeatureType const & f, return res; } -vector > covering::SortAndMergeIntervals(vector > v) +vector > SortAndMergeIntervals(vector > v) { #ifdef DEBUG for (size_t i = 0; i < v.size(); ++i) @@ -106,23 +108,45 @@ vector > covering::SortAndMergeIntervals(vector > covering::CoverViewportAndAppendLowerLevels(m2::RectD const & rect) +namespace +{ + vector > AppendLowerLevels(vector const & ids) + { + vector > intervals; + intervals.reserve(ids.size() * 4); + + for (vector::const_iterator it = ids.begin(); it != ids.end(); ++it) + { + RectId id = *it; + int64_t idInt64 = id.ToInt64(); + intervals.push_back(pair(idInt64, idInt64 + id.SubTreeSize())); + while (id.Level() > 0) + { + id = id.Parent(); + idInt64 = id.ToInt64(); + intervals.push_back(pair(idInt64, idInt64 + 1)); + } + } + + return SortAndMergeIntervals(intervals); + } +} + +vector > CoverViewportAndAppendLowerLevels(m2::RectD const & r) { vector ids; - CoverRect(rect.minX(), rect.minY(), rect.maxX(), rect.maxY(), 8, ids); - vector > intervals; - intervals.reserve(ids.size() * 4); - for (vector::const_iterator it = ids.begin(); it != ids.end(); ++it) - { - RectId id = *it; - int64_t idInt64 = id.ToInt64(); - intervals.push_back(pair(idInt64, idInt64 + id.SubTreeSize())); - while (id.Level() > 0) - { - id = id.Parent(); - idInt64 = id.ToInt64(); - intervals.push_back(pair(idInt64, idInt64 + 1)); - } - } - return SortAndMergeIntervals(intervals); + CoverRect(r.minX(), r.minY(), r.maxX(), r.maxY(), 8, ids); + + return AppendLowerLevels(ids); +} + +vector > CoverLowerLevelsOnly(m2::RectD const & r) +{ + vector ids; + ids.push_back(CellIdConverter::Cover2PointsWithCell( + r.minX(), r.minY(), r.maxX(), r.maxY())); + + return AppendLowerLevels(ids); +} + } diff --git a/indexer/covering.hpp b/indexer/covering.hpp index 14c93d769d..52e597b17e 100644 --- a/indexer/covering.hpp +++ b/indexer/covering.hpp @@ -14,8 +14,12 @@ namespace covering // Cover feature with RectIds and return their integer representations. vector CoverFeature(FeatureType const & feature, uint64_t cellPenaltyArea); + // Cover viewport with RectIds and append their RectIds as well. vector > CoverViewportAndAppendLowerLevels(m2::RectD const & rect); + + vector > CoverLowerLevelsOnly(m2::RectD const & rect); + // Given a vector of intervals [a, b), sort them and merge overlapping intervals. vector > SortAndMergeIntervals(vector > intervals); }