diff --git a/storage/storage_helpers.cpp b/storage/storage_helpers.cpp index bd1a4caac0..1807a61e24 100644 --- a/storage/storage_helpers.cpp +++ b/storage/storage_helpers.cpp @@ -3,9 +3,29 @@ #include "storage/country_info_getter.hpp" #include "storage/storage.hpp" +namespace +{ +using namespace storage; + +class CalcLimitRectAccumulator +{ + m2::RectD m_boundBox; + CountryInfoGetter const & m_countryInfoGetter; +public: + CalcLimitRectAccumulator(CountryInfoGetter const & countryInfoGetter) + : m_countryInfoGetter(countryInfoGetter) {} + + m2::RectD GetBoundBox() { return m_boundBox; } + void operator()(TCountryId const & descendantCountryId, bool expandableNode) + { + if (!expandableNode) + m_boundBox.Add(m_countryInfoGetter.CalcLimitRectForLeaf(descendantCountryId)); + } +}; +} // namespace + namespace storage { - bool IsPointCoveredByDownloadedMaps(m2::PointD const & position, Storage const & storage, CountryInfoGetter const & countryInfoGetter) @@ -18,4 +38,17 @@ bool IsDownloadFailed(Status status) return status == Status::EDownloadFailed || status == Status::EOutOfMemFailed || status == Status::EUnknown; } + +m2::RectD CalcLimitRect(TCountryId countryId, + Storage const & storage, + CountryInfoGetter const & countryInfoGetter) +{ + CalcLimitRectAccumulator accumulater(countryInfoGetter); + storage.ForEachInSubtree(countryId, accumulater); + m2::RectD const boundBox = accumulater.GetBoundBox(); + + ASSERT(boundBox.IsValid(), ()); + + return accumulater.GetBoundBox(); +} } // namespace storage diff --git a/storage/storage_helpers.hpp b/storage/storage_helpers.hpp index 67a1a77104..72cc07563a 100644 --- a/storage/storage_helpers.hpp +++ b/storage/storage_helpers.hpp @@ -1,8 +1,10 @@ #pragma once #include "geometry/point2d.hpp" +#include "geometry/rect2d.hpp" -#include "storage_defines.hpp" +#include "storage/index.hpp" +#include "storage/storage_defines.hpp" namespace storage { @@ -17,4 +19,10 @@ bool IsPointCoveredByDownloadedMaps(m2::PointD const & position, CountryInfoGetter const & countryInfoGetter); bool IsDownloadFailed(Status status); + +/// \brief Calculates limit rect for |countryId| (non expandable or not). +/// \returns bound box in mercator coordinates. +m2::RectD CalcLimitRect(TCountryId countryId, + Storage const & storage, + CountryInfoGetter const & countryInfoGetter); } // namespace storage