Returns true if left place is worse than right place.
| 52 | |
| 53 | // Returns true if left place is worse than right place. |
| 54 | bool IsWorsePlace(FeaturePlace const & left, FeaturePlace const & right) |
| 55 | { |
| 56 | // Capital type should be always better. |
| 57 | bool const lCapital = left.IsRealCapital(); |
| 58 | bool const rCapital = right.IsRealCapital(); |
| 59 | if (lCapital != rCapital) |
| 60 | return rCapital; |
| 61 | |
| 62 | double constexpr kRankCoeff = 1.0; |
| 63 | double constexpr kLangsCountCoeff = 1.0; |
| 64 | double constexpr kAreaCoeff = 0.05; |
| 65 | double constexpr kIsCapitalCoeff = 0.1; |
| 66 | double constexpr kIsNodeCoeff = 0.15; |
| 67 | double constexpr kIsAreaTooBigCoeff = -0.5; |
| 68 | |
| 69 | auto const normalizeRank = [](uint8_t rank) |
| 70 | { return static_cast<double>(rank) / static_cast<double>(std::numeric_limits<uint8_t>::max()); }; |
| 71 | |
| 72 | auto const normalizeLangsCount = [](uint8_t langsCount) |
| 73 | { return static_cast<double>(langsCount) / static_cast<double>(localisation::kMaxSupportedLanguages); }; |
| 74 | |
| 75 | auto const normalizeArea = [](double area) |
| 76 | { |
| 77 | // We need to compare areas to choose bigger feature from multipolygonal features. |
| 78 | // |kMaxAreaM2| should be greater than cities exclaves (like airports or Zelenograd for Moscow). |
| 79 | double const kMaxAreaM2 = 4e8; |
| 80 | area = math::Clamp(area, 0.0, kMaxAreaM2); |
| 81 | return area / kMaxAreaM2; |
| 82 | }; |
| 83 | |
| 84 | auto const isAreaTooBig = [](ftypes::LocalityType type, double area) |
| 85 | { |
| 86 | // 100*100 km. There are few such big cities in the world (Beijing, Tokyo). These cities are |
| 87 | // well-maped and have node which we want to prefer because relation boundaries may include big |
| 88 | // exclaves and/or have bad center: https://www.openstreetmap.org/relation/1543125. |
| 89 | if (type == ftypes::LocalityType::City) |
| 90 | return area > 1e10; |
| 91 | |
| 92 | /// @todo By VNG: It doesn't work with updated heuristic when collecting boundaries. |
| 93 | /// Should connect (by name) Node and Way places to select best boundary (like with Relations). |
| 94 | /// @see Relation_Wiki test. |
| 95 | /* |
| 96 | // ~14*14 km |
| 97 | if (type == ftypes::LocalityType::Town) |
| 98 | return area > 2e8; |
| 99 | |
| 100 | // 10*10 km |
| 101 | if (type == ftypes::LocalityType::Village) |
| 102 | return area > 1e8; |
| 103 | */ |
| 104 | |
| 105 | return false; |
| 106 | }; |
| 107 | |
| 108 | static_assert(kRankCoeff >= 0, ""); |
| 109 | static_assert(kLangsCountCoeff >= 0, ""); |
| 110 | static_assert(kAreaCoeff >= 0, ""); |
| 111 | static_assert(kIsCapitalCoeff >= 0, ""); |
no test coverage detected