diff --git a/indexer/feature_covering.cpp b/indexer/feature_covering.cpp index 1a9179e59d..945ad91deb 100644 --- a/indexer/feature_covering.cpp +++ b/indexer/feature_covering.cpp @@ -187,19 +187,17 @@ RectId GetRectIdAsIs(m2::RectD const & r) MercatorBounds::ClampY(r.maxY() - eps)); } -int GetCodingDepth(pair const & scalesR) +int GetCodingDepth(int scale) { - ASSERT_LESS_OR_EQUAL ( scalesR.first, scalesR.second, () ); - - int const delta = scales::GetUpperScale() - scalesR.second; + int const delta = scales::GetUpperScale() - scale; ASSERT_GREATER_OR_EQUAL ( delta, 0, () ); return (RectId::DEPTH_LEVELS - delta); } -IntervalsT const & CoveringGetter::Get(pair const & scaleR) +IntervalsT const & CoveringGetter::Get(int scale) { - int const cellDepth = GetCodingDepth(scaleR); + int const cellDepth = GetCodingDepth(scale); int const ind = (cellDepth == RectId::DEPTH_LEVELS ? 0 : 1); if (m_res[ind].empty()) diff --git a/indexer/feature_covering.hpp b/indexer/feature_covering.hpp index 984f712d0c..593ecbc137 100644 --- a/indexer/feature_covering.hpp +++ b/indexer/feature_covering.hpp @@ -31,7 +31,7 @@ namespace covering RectId GetRectIdAsIs(m2::RectD const & r); // Calculate cell coding depth according to max visual scale for mwm. - int GetCodingDepth(pair const & scalesR); + int GetCodingDepth(int scale); class CoveringGetter { @@ -47,6 +47,6 @@ namespace covering /// - 2 - make full cover\n CoveringGetter(m2::RectD const & r, int mode) : m_rect(r), m_mode(mode) {} - IntervalsT const & Get(pair const & scaleR); + IntervalsT const & Get(int scale); }; } diff --git a/indexer/index.hpp b/indexer/index.hpp index cf49839b2c..7d65749721 100644 --- a/indexer/index.hpp +++ b/indexer/index.hpp @@ -108,8 +108,14 @@ private: { feature::DataHeader const & header = pValue->GetHeader(); - // prepare needed covering - covering::IntervalsT const & interval = cov.Get(header.GetScaleRange()); + // Prepare needed covering. + + // In case of WorldCoasts we should pass correct scale in ForEachInIntervalAndScale. + int const lastScale = header.GetLastScale(); + if (scale > lastScale) scale = lastScale; + + // Use last coding scale for covering (see index_builder.cpp). + covering::IntervalsT const & interval = cov.Get(lastScale); // prepare features reading FeaturesVector fv(pValue->m_cont, header); diff --git a/indexer/index_builder.cpp b/indexer/index_builder.cpp index 0d26bbd9b9..360cc504e0 100644 --- a/indexer/index_builder.cpp +++ b/indexer/index_builder.cpp @@ -24,7 +24,7 @@ namespace indexer FeaturesVector featuresVector(readCont, header); - BuildIndex(header.GetLastScale() + 1, header.GetScaleRange(), featuresVector, writer, tmpFile); + BuildIndex(header.GetLastScale() + 1, header.GetLastScale(), featuresVector, writer, tmpFile); } catch (Reader::Exception const & e) { diff --git a/indexer/index_builder.hpp b/indexer/index_builder.hpp index b570dc8a27..edd9e5c45d 100644 --- a/indexer/index_builder.hpp +++ b/indexer/index_builder.hpp @@ -6,7 +6,7 @@ namespace indexer { template void BuildIndex(uint32_t bucketsCount, - pair const & scaleRange, + int codingScale, FeaturesVectorT const & featuresVector, WriterT & writer, string const & tmpFilePrefix) @@ -15,7 +15,7 @@ namespace indexer uint64_t indexSize; { SubWriter subWriter(writer); - IndexScales(bucketsCount, scaleRange, featuresVector, subWriter, tmpFilePrefix); + IndexScales(bucketsCount, codingScale, featuresVector, subWriter, tmpFilePrefix); indexSize = subWriter.Size(); } LOG(LINFO, ("Built scale index. Size =", indexSize)); diff --git a/indexer/indexer_tests/index_builder_test.cpp b/indexer/indexer_tests/index_builder_test.cpp index 8a746d95e3..821b82f5d8 100644 --- a/indexer/indexer_tests/index_builder_test.cpp +++ b/indexer/indexer_tests/index_builder_test.cpp @@ -35,7 +35,7 @@ UNIT_TEST(BuildIndexTest) MemWriter > serialWriter(serialIndex); indexer::BuildIndex(ScaleIndexBase::NUM_BUCKETS, - make_pair(0, scales::GetUpperScale()), + scales::GetUpperScale(), featuresVector, serialWriter, "build_index_test"); } diff --git a/indexer/scale_index_builder.hpp b/indexer/scale_index_builder.hpp index a28530d959..dc0b708f6e 100644 --- a/indexer/scale_index_builder.hpp +++ b/indexer/scale_index_builder.hpp @@ -56,11 +56,11 @@ class FeatureCoverer public: FeatureCoverer(uint32_t bucket, - pair const & scaleRange, + int codingScale, SorterT & sorter, uint32_t & numFeatures) : m_Sorter(sorter), - m_mwmScaleRange(scaleRange), + m_codingDepth(covering::GetCodingDepth(codingScale)), m_ScaleRange(ScaleIndexBase::ScaleRangeForBucket(bucket)), m_NumFeatures(numFeatures) { @@ -71,8 +71,7 @@ public: { if (FeatureShouldBeIndexed(f)) { - vector const cells = covering::CoverFeature(f, - covering::GetCodingDepth(m_mwmScaleRange), 250); + vector const cells = covering::CoverFeature(f, m_codingDepth, 250); for (vector::const_iterator it = cells.begin(); it != cells.end(); ++it) m_Sorter.Add(CellFeaturePair(*it, offset)); @@ -93,7 +92,7 @@ public: private: SorterT & m_Sorter; - pair m_mwmScaleRange; + int m_codingDepth; pair m_ScaleRange; uint32_t & m_NumFeatures; }; @@ -117,7 +116,7 @@ private: template inline void IndexScales(uint32_t bucketsCount, - pair const & scaleRange, + int codingScale, FeaturesVectorT const & featuresVector, WriterT & writer, string const & tmpFilePrefix) @@ -139,7 +138,7 @@ inline void IndexScales(uint32_t bucketsCount, WriterFunctor out(cellsToFeaturesWriter); SorterType sorter(1024*1024, tmpFilePrefix + ".c2f.tmp", out); featuresVector.ForEachOffset( - FeatureCoverer(bucket, scaleRange, sorter, numFeatures)); + FeatureCoverer(bucket, codingScale, sorter, numFeatures)); // LOG(LINFO, ("Sorting...")); sorter.SortAndFinish(); } diff --git a/search/search_query.cpp b/search/search_query.cpp index 4ba9909ee3..09220a7efe 100644 --- a/search/search_query.cpp +++ b/search/search_query.cpp @@ -74,7 +74,7 @@ void Query::UpdateViewportOffsets() pair const scaleR = header.GetScaleRange(); int const scale = min(max(viewScale + 7, scaleR.first), scaleR.second); - covering::IntervalsT const & interval = cov.Get(scaleR); + covering::IntervalsT const & interval = cov.Get(header.GetLastScale()); ScaleIndex index(pMwm->m_cont.GetReader(INDEX_FILE_TAG), pMwm->m_factory);