forked from organicmaps/organicmaps
Move GetSearchRank() from FeatureType to an external function.
This commit is contained in:
parent
b22c5fe719
commit
0226c8c3eb
6 changed files with 38 additions and 19 deletions
|
@ -279,9 +279,3 @@ double FeatureType::GetPopulationDrawRank() const
|
|||
return min(upperBound, static_cast<double>(n)) / upperBound;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t FeatureType::GetSearchRank() const
|
||||
{
|
||||
ParseCommon();
|
||||
return m_Params.rank;
|
||||
}
|
||||
|
|
|
@ -222,7 +222,6 @@ public:
|
|||
|
||||
uint32_t GetPopulation() const;
|
||||
double GetPopulationDrawRank() const;
|
||||
uint8_t GetSearchRank() const;
|
||||
|
||||
inline string GetRoadNumber() const { return m_Params.ref; }
|
||||
|
||||
|
|
|
@ -4,14 +4,17 @@
|
|||
#include "../base/base.hpp"
|
||||
#include "../std/vector.hpp"
|
||||
|
||||
namespace
|
||||
namespace feature
|
||||
{
|
||||
|
||||
class FeatureViewportEstimator
|
||||
namespace impl
|
||||
{
|
||||
|
||||
class FeatureEstimator
|
||||
{
|
||||
public:
|
||||
|
||||
FeatureViewportEstimator()
|
||||
FeatureEstimator()
|
||||
{
|
||||
m_TypeContinent = GetType("place", "continent");
|
||||
m_TypeCountry = GetType("place", "country");
|
||||
|
@ -42,6 +45,14 @@ public:
|
|||
maxSizeMeters.x, maxSizeMeters.y);
|
||||
}
|
||||
|
||||
uint8_t GetSearchRank(FeatureType const & feature) const
|
||||
{
|
||||
uint32_t const population = feature.GetPopulation();
|
||||
return static_cast<uint8_t>(log(double(population)) / log(1.1));
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// Returns width and height (lon and lat) for a given type.
|
||||
m2::PointD GetSizeForType(uint32_t const type, FeatureType const & feature) const
|
||||
{
|
||||
|
@ -66,8 +77,6 @@ public:
|
|||
return m2::PointD(0, 0);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
static uint32_t GetType(string const & s1,
|
||||
string const & s2 = string(),
|
||||
string const & s3 = string())
|
||||
|
@ -87,10 +96,22 @@ private:
|
|||
uint32_t m_TypeVillage;
|
||||
};
|
||||
|
||||
} // unnamed namespace
|
||||
|
||||
m2::RectD feature::GetFeatureViewport(FeatureType const & feature)
|
||||
FeatureEstimator const & GetFeatureEstimator()
|
||||
{
|
||||
static FeatureViewportEstimator const featureViewportEstimator;
|
||||
return featureViewportEstimator.GetViewport(feature);
|
||||
static FeatureEstimator const featureEstimator;
|
||||
return featureEstimator;
|
||||
}
|
||||
|
||||
} // namespace feature::impl
|
||||
|
||||
m2::RectD GetFeatureViewport(FeatureType const & feature)
|
||||
{
|
||||
return impl::GetFeatureEstimator().GetViewport(feature);
|
||||
}
|
||||
|
||||
uint8_t GetSearchRank(FeatureType const & feature)
|
||||
{
|
||||
return impl::GetFeatureEstimator().GetSearchRank(feature);
|
||||
}
|
||||
|
||||
} // namespace feature
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
#include "feature.hpp"
|
||||
#include "../geometry/rect2d.hpp"
|
||||
#include "../base/base.hpp"
|
||||
|
||||
namespace feature
|
||||
{
|
||||
|
@ -8,4 +9,7 @@ namespace feature
|
|||
// 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);
|
||||
|
||||
} // namespace feature
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "search_index_builder.hpp"
|
||||
|
||||
#include "feature_utils.hpp"
|
||||
#include "features_vector.hpp"
|
||||
#include "search_delimiters.hpp"
|
||||
#include "search_trie.hpp"
|
||||
|
@ -92,7 +93,7 @@ struct FeatureInserter
|
|||
explicit FeatureInserter(vector<FeatureName> & names) : m_names(names) {}
|
||||
void operator() (FeatureType const & feature, uint64_t pos) const
|
||||
{
|
||||
FeatureNameInserter f(m_names, static_cast<uint32_t>(pos), feature.GetSearchRank());
|
||||
FeatureNameInserter f(m_names, static_cast<uint32_t>(pos), feature::GetSearchRank(feature));
|
||||
feature.ForEachNameRef(f);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -22,7 +22,7 @@ IntermediateResult::IntermediateResult(m2::RectD const & viewportRect,
|
|||
m_type = types.m_types[0];
|
||||
m_distance = ResultDistance(viewportRect.Center(), m_rect.Center());
|
||||
m_direction = ResultDirection(viewportRect.Center(), m_rect.Center());
|
||||
m_searchRank = feature.GetSearchRank();
|
||||
m_searchRank = feature::GetSearchRank(feature);
|
||||
}
|
||||
|
||||
IntermediateResult::IntermediateResult(m2::RectD const & viewportRect,
|
||||
|
|
Loading…
Add table
Reference in a new issue