diff --git a/indexer/covering.cpp b/indexer/covering.cpp index c9f5695a74..afbfdd6415 100644 --- a/indexer/covering.cpp +++ b/indexer/covering.cpp @@ -89,14 +89,16 @@ vector CoverFeature(FeatureType const & f, uint64_t cellPenaltyArea) return res; } -vector > SortAndMergeIntervals(vector > v) +IntervalsT SortAndMergeIntervals(IntervalsT v) { #ifdef DEBUG for (size_t i = 0; i < v.size(); ++i) ASSERT_LESS(v[i].first, v[i].second, (i)); #endif + sort(v.begin(), v.end()); - vector > res; + + IntervalsT res; res.reserve(v.size()); for (size_t i = 0; i < v.size(); ++i) { @@ -105,48 +107,45 @@ vector > SortAndMergeIntervals(vector > AppendLowerLevels(vector const & ids) + int64_t idInt64 = id.ToInt64(); + intervals.push_back(make_pair(idInt64, idInt64 + id.SubTreeSize())); + while (id.Level() > 0) { - 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); + id = id.Parent(); + idInt64 = id.ToInt64(); + intervals.push_back(make_pair(idInt64, idInt64 + 1)); } } -vector > CoverViewportAndAppendLowerLevels(m2::RectD const & r) +IntervalsT CoverViewportAndAppendLowerLevels(m2::RectD const & r) { vector ids; CoverRect(r.minX(), r.minY(), r.maxX(), r.maxY(), 8, ids); - return AppendLowerLevels(ids); + IntervalsT intervals; + intervals.reserve(ids.size() * 4); + + for (size_t i = 0; i < ids.size(); ++i) + AppendLowerLevels(ids[i], intervals); + + return SortAndMergeIntervals(intervals); } -vector > CoverLowerLevelsOnly(m2::RectD const & r) +RectId GetRectIdAsIs(m2::RectD const & r) { - vector ids; - ids.push_back(CellIdConverter::Cover2PointsWithCell( - r.minX(), r.minY(), r.maxX(), r.maxY())); + double const eps = MercatorBounds::GetCellID2PointAbsEpsilon(); - return AppendLowerLevels(ids); + return CellIdConverter::Cover2PointsWithCell( + MercatorBounds::ClampX(r.minX() + eps), + MercatorBounds::ClampY(r.minY() + eps), + MercatorBounds::ClampX(r.maxX() - eps), + MercatorBounds::ClampY(r.maxY() - eps)); } } diff --git a/indexer/covering.hpp b/indexer/covering.hpp index 52e597b17e..d171cf1edf 100644 --- a/indexer/covering.hpp +++ b/indexer/covering.hpp @@ -1,4 +1,5 @@ #pragma once +#include "point_to_int64.hpp" #include "../geometry/rect2d.hpp" @@ -11,15 +12,19 @@ class FeatureType; namespace covering { + typedef vector > IntervalsT; + // 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); + void AppendLowerLevels(RectId id, IntervalsT & intervals); - vector > CoverLowerLevelsOnly(m2::RectD const & rect); + // Cover viewport with RectIds and append their RectIds as well. + IntervalsT CoverViewportAndAppendLowerLevels(m2::RectD const & rect); // Given a vector of intervals [a, b), sort them and merge overlapping intervals. - vector > SortAndMergeIntervals(vector > intervals); + IntervalsT SortAndMergeIntervals(IntervalsT intervals); + + RectId GetRectIdAsIs(m2::RectD const & r); } diff --git a/indexer/index.hpp b/indexer/index.hpp index 8bc3bad504..d706c63273 100644 --- a/indexer/index.hpp +++ b/indexer/index.hpp @@ -38,10 +38,18 @@ public: template void ForEachInRect(F const & f, m2::RectD const & rect, uint32_t scale, Query & query) const { - vector > intervals = covering::CoverViewportAndAppendLowerLevels(rect); + using namespace covering; + + //IntervalsT const intervals = CoverViewportAndAppendLowerLevels(rect); + + IntervalsT intervals; + AppendLowerLevels(GetRectIdAsIs(rect), intervals); + for (size_t i = 0; i < intervals.size(); ++i) - BaseT::ForEachInIntervalAndScale(f, intervals[i].first, intervals[i].second, scale, - rect, query); + { + BaseT::ForEachInIntervalAndScale(f, intervals[i].first, intervals[i].second, + scale, rect, query); + } } template diff --git a/map/render_queue_routine.cpp b/map/render_queue_routine.cpp index 474bcd3add..59fb6a2893 100644 --- a/map/render_queue_routine.cpp +++ b/map/render_queue_routine.cpp @@ -173,9 +173,10 @@ void RenderQueueRoutine::Do() m2::RectD selectionRect; - double inflationSize = 24 * m_visualScale; + double const inflationSize = 24 * m_visualScale; - frameScreen.PtoG(m2::Inflate(m2::RectD(renderRect), inflationSize, inflationSize), selectionRect); + //frameScreen.PtoG(m2::Inflate(m2::RectD(renderRect), inflationSize, inflationSize), selectionRect); + frameScreen.PtoG(m2::RectD(renderRect), selectionRect); m_currentCommand->m_renderFn( m_currentCommand->m_paintEvent,