From 46036e81aa947556f80313ae30a382c561d726ce Mon Sep 17 00:00:00 2001 From: vng Date: Fri, 27 Jan 2012 16:54:47 +0300 Subject: [PATCH] [search] Remove calculatin of feature viewport rect in IntermediateResult. Close #522. --- indexer/feature_utils.cpp | 47 ++++++++++++-------------------- indexer/feature_utils.hpp | 12 ++++---- indexer/feature_visibility.cpp | 9 ++++-- indexer/feature_visibility.hpp | 4 +++ indexer/search_index_builder.cpp | 6 ++-- search/intermediate_result.cpp | 7 +++-- 6 files changed, 42 insertions(+), 43 deletions(-) diff --git a/indexer/feature_utils.cpp b/indexer/feature_utils.cpp index 6c19a577af..a72ec90090 100644 --- a/indexer/feature_utils.cpp +++ b/indexer/feature_utils.cpp @@ -1,7 +1,7 @@ #include "feature_utils.hpp" #include "feature_visibility.hpp" #include "classificator.hpp" -#include "feature.hpp" +#include "feature_data.hpp" #include "scales.hpp" #include "../geometry/point2d.hpp" @@ -51,51 +51,40 @@ public: m_TypeSmallVillage[2] = GetType("place", "farm"); } - void CorrectScaleForVisibility(FeatureType const & f, int & scale) const + void CorrectScaleForVisibility(TypesHolder const & types, int & scale) const { - pair const scaleR = feature::DrawableScaleRangeForText(f); + pair const scaleR = feature::DrawableScaleRangeForText(types); if (scale < scaleR.first || scale > scaleR.second) scale = scaleR.first; } - void CorrectRectForScales(FeatureType const & f, m2::PointD const & center, m2::RectD & rect) const + m2::RectD CorrectRectForScales(TypesHolder const & types, m2::RectD const & rect) const { int const scale = scales::GetScaleLevel(rect); int scaleNew = scale; - CorrectScaleForVisibility(f, scaleNew); + CorrectScaleForVisibility(types, scaleNew); - if (scale != scaleNew) - rect = scales::GetRectForLevel(scaleNew, center, 1.0); + return ((scale != scaleNew) ? scales::GetRectForLevel(scaleNew, rect.Center(), 1.0) : rect); } - m2::RectD GetViewport(FeatureType const & f) const + m2::RectD GetViewport(TypesHolder const & types, m2::RectD const & limitRect) const { - m2::RectD limitR = f.GetLimitRect(-2); - if (f.GetFeatureType() != feature::GEOM_POINT) - { - CorrectRectForScales(f, limitR.Center(), limitR); - return limitR; - } - - feature::TypesHolder types(f); + if (types.GetGeoType() != feature::GEOM_POINT) + return CorrectRectForScales(types, limitRect); int const upperScale = scales::GetUpperScale(); int scale = upperScale; for (size_t i = 0; i < types.Size(); ++i) - scale = min(scale, GetScaleForType(types[i], f)); + scale = min(scale, GetScaleForType(types[i])); - CorrectScaleForVisibility(f, scale); + CorrectScaleForVisibility(types, scale); - m2::PointD const centerXY = limitR.Center(); + m2::PointD const centerXY = limitRect.Center(); return scales::GetRectForLevel(scale, centerXY, 1.0); } - uint8_t GetSearchRank(FeatureType const & feature) const + uint8_t GetSearchRank(TypesHolder const & types, uint32_t population) const { - uint32_t population = feature.GetPopulation(); - - feature::TypesHolder types(feature); - for (size_t i = 0; i < types.Size(); ++i) { if (IsEqual(types[i], m_TypeSmallVillage)) @@ -120,7 +109,7 @@ public: private: // Returns width and height (lon and lat) for a given type. - int GetScaleForType(uint32_t const type, FeatureType const & feature) const + int GetScaleForType(uint32_t const type) const { if (type == m_TypeContinent) return 2; @@ -180,14 +169,14 @@ FeatureEstimator const & GetFeatureEstimator() } // namespace feature::impl -m2::RectD GetFeatureViewport(FeatureType const & feature) +m2::RectD GetFeatureViewport(TypesHolder const & types, m2::RectD const & limitRect) { - return impl::GetFeatureEstimator().GetViewport(feature); + return impl::GetFeatureEstimator().GetViewport(types, limitRect); } -uint8_t GetSearchRank(FeatureType const & feature) +uint8_t GetSearchRank(TypesHolder const & types, uint32_t population) { - return impl::GetFeatureEstimator().GetSearchRank(feature); + return impl::GetFeatureEstimator().GetSearchRank(types, population); } } // namespace feature diff --git a/indexer/feature_utils.hpp b/indexer/feature_utils.hpp index 0321f62711..e380f25d8d 100644 --- a/indexer/feature_utils.hpp +++ b/indexer/feature_utils.hpp @@ -4,15 +4,15 @@ #include "../base/base.hpp" -class FeatureType; namespace feature { + class TypesHolder; -// Get viewport to show given feature. Used in search. -m2::RectD GetFeatureViewport(FeatureType const & feature); - -// Get search rank for a feature. Roughly, rank + 1 means that feature is 1.x times more popular. -uint8_t GetSearchRank(FeatureType const & feature); + /// Get viewport to show given feature. Used in search. + m2::RectD GetFeatureViewport(TypesHolder const & types, m2::RectD const & limitRect); + /// Get search rank for a feature. + /// Roughly, rank + 1 means that feature is 1.x times more popular. + uint8_t GetSearchRank(TypesHolder const & types, uint32_t population); } // namespace feature diff --git a/indexer/feature_visibility.cpp b/indexer/feature_visibility.cpp index 1b840595b1..8881da212e 100644 --- a/indexer/feature_visibility.cpp +++ b/indexer/feature_visibility.cpp @@ -280,10 +280,8 @@ namespace } } -pair DrawableScaleRangeForText(FeatureBase const & f) +pair DrawableScaleRangeForText(feature::TypesHolder const & types) { - feature::TypesHolder types(f); - int const upBound = scales::GetUpperScale(); int lowL = -1; for (int level = 0; level <= upBound; ++level) @@ -311,6 +309,11 @@ pair DrawableScaleRangeForText(FeatureBase const & f) return make_pair(lowL, highL); } +pair DrawableScaleRangeForText(FeatureBase const & f) +{ + return DrawableScaleRangeForText(TypesHolder(f)); +} + bool IsHighway(vector const & types) { ClassifObject const * pRoot = classif().GetRoot(); diff --git a/indexer/feature_visibility.hpp b/indexer/feature_visibility.hpp index 27b15c136e..70b8790b37 100644 --- a/indexer/feature_visibility.hpp +++ b/indexer/feature_visibility.hpp @@ -13,6 +13,8 @@ class FeatureBase; namespace feature { + class TypesHolder; + // Note! do not change this values. Should be equal with EGeomType. enum FeatureGeoType { FEATURE_TYPE_POINT = 0, @@ -25,6 +27,8 @@ namespace feature bool IsDrawableForIndex(FeatureBase const & f, int level); int MinDrawableScaleForFeature(FeatureBase const & f); + + pair DrawableScaleRangeForText(TypesHolder const & types); pair DrawableScaleRangeForText(FeatureBase const & f); /// @return (geometry type, is coastline) diff --git a/indexer/search_index_builder.cpp b/indexer/search_index_builder.cpp index 21a37d70ac..3ece446110 100644 --- a/indexer/search_index_builder.cpp +++ b/indexer/search_index_builder.cpp @@ -68,12 +68,14 @@ struct FeatureInserter void operator() (FeatureType const & feature, uint64_t pos) const { + feature::TypesHolder types(feature); + // Add names of the feature. - FeatureNameInserter f(m_names, static_cast(pos), feature::GetSearchRank(feature)); + FeatureNameInserter f(m_names, static_cast(pos), + feature::GetSearchRank(types, feature.GetPopulation())); feature.ForEachNameRef(f); // Add names of categories of the feature. - feature::TypesHolder types(feature); for (size_t i = 0; i < types.Size(); ++i) f.AddToken(0, search::FeatureTypeToString(types[i])); } diff --git a/search/intermediate_result.cpp b/search/intermediate_result.cpp index 9dead7a056..f055e1b713 100644 --- a/search/intermediate_result.cpp +++ b/search/intermediate_result.cpp @@ -25,7 +25,7 @@ IntermediateResult::IntermediateResult(m2::RectD const & viewportRect, m2::Point string const & fileName) : m_types(f), m_str(displayName), - m_rect(feature::GetFeatureViewport(f)), + m_rect(f.GetLimitRect(-2)), m_resultType(RESULT_FEATURE) { ASSERT_GREATER(m_types.Size(), 0, ()); @@ -42,7 +42,7 @@ IntermediateResult::IntermediateResult(m2::RectD const & viewportRect, m2::Point // get common params m_distance = ResultDistance(pos, m_rect.Center()); m_direction = ResultDirection(pos, m_rect.Center()); - m_searchRank = feature::GetSearchRank(f); + m_searchRank = feature::GetSearchRank(m_types, f.GetPopulation()); m_viewportDistance = ViewportDistance(viewportRect, m_rect.Center()); } @@ -130,7 +130,8 @@ Result IntermediateResult::GenerateFinalResult( + ' ' + strings::to_string(static_cast(m_searchRank)) #endif , - GetBestType(), m_rect, m_distance, m_direction); + GetBestType(), feature::GetFeatureViewport(m_types, m_rect), + m_distance, m_direction); case RESULT_LATLON: return Result(m_str, info.m_name, info.m_flag, GetFeatureType(pCat),