diff options
author | Maxim Pimenov <m@maps.me> | 2019-05-29 21:00:59 +0300 |
---|---|---|
committer | Tatiana Yan <tatiana.kondakova@gmail.com> | 2019-05-30 13:45:16 +0300 |
commit | 6187c6182e8881c1729dba07b18ff34995aa2081 (patch) | |
tree | b44d0d21e8f63c9272fec64f4349be91fe12ebad /storage | |
parent | 68cb47979ed8e32d1ac6b48b0e0030242b985b7d (diff) |
[data] [storage] [generator] Removed the Vatican City mwm.
This commit removes "data/borders/Vatican City.poly" which
means that we won't generate the "Vatican City.mwm" anymore.
This mwm wasn't present in countries.txt and wasn't downloadable
via the app. The city itself is included in Italy_Lazio.mwm, so
the deleted mwm file was redundant anyway.
Several tests against this situation are added.
Diffstat (limited to 'storage')
-rw-r--r-- | storage/country_info_getter.cpp | 28 | ||||
-rw-r--r-- | storage/country_info_getter.hpp | 7 | ||||
-rw-r--r-- | storage/storage.hpp | 14 | ||||
-rw-r--r-- | storage/storage_tests/country_info_getter_tests.cpp | 79 | ||||
-rw-r--r-- | storage/storage_tests/helpers.cpp | 6 | ||||
-rw-r--r-- | storage/storage_tests/helpers.hpp | 2 | ||||
-rw-r--r-- | storage/storage_tests/storage_tests.cpp | 6 |
7 files changed, 104 insertions, 38 deletions
diff --git a/storage/country_info_getter.cpp b/storage/country_info_getter.cpp index 0d6d9515ba..cb5531871a 100644 --- a/storage/country_info_getter.cpp +++ b/storage/country_info_getter.cpp @@ -220,6 +220,20 @@ std::unique_ptr<CountryInfoGetter> CountryInfoReader::CreateCountryInfoReaderObs return std::unique_ptr<CountryInfoReader>(); } +void CountryInfoReader::LoadRegionsFromDisk(size_t id, std::vector<m2::RegionD> & regions) const +{ + regions.clear(); + ReaderSource<ModelReaderPtr> src(m_reader.GetReader(strings::to_string(id))); + + uint32_t const count = ReadVarUint<uint32_t>(src); + for (size_t i = 0; i < count; ++i) + { + std::vector<m2::PointD> points; + serial::LoadOuterPath(src, serial::GeometryCodingParams(), points); + regions.emplace_back(std::move(points)); + } +} + CountryInfoReader::CountryInfoReader(ModelReaderPtr polyR, ModelReaderPtr countryR) : CountryInfoGetter(true), m_reader(polyR), m_cache(3 /* logCacheSize */) @@ -259,20 +273,6 @@ std::result_of_t<Fn(std::vector<m2::RegionD>)> CountryInfoReader::WithRegion(siz return fn(regions); } -void CountryInfoReader::LoadRegionsFromDisk(size_t id, std::vector<m2::RegionD> & regions) const -{ - regions.clear(); - ReaderSource<ModelReaderPtr> src(m_reader.GetReader(strings::to_string(id))); - - uint32_t const count = ReadVarUint<uint32_t>(src); - for (size_t i = 0; i < count; ++i) - { - std::vector<m2::PointD> points; - serial::LoadOuterPath(src, serial::GeometryCodingParams(), points); - regions.emplace_back(std::move(points)); - } -} - bool CountryInfoReader::BelongsToRegion(m2::PointD const & pt, size_t id) const { if (!m_countries[id].m_rect.IsPointInside(pt)) diff --git a/storage/country_info_getter.hpp b/storage/country_info_getter.hpp index 0084f6c170..b98269916c 100644 --- a/storage/country_info_getter.hpp +++ b/storage/country_info_getter.hpp @@ -48,6 +48,8 @@ public: // Returns true if there's at least one region with id equal to |countryId|. bool BelongsToAnyRegion(CountryId const & countryId, RegionIdVec const & regions) const; + std::vector<CountryDef> const & GetCountries() const { return m_countries; } + protected: // Returns identifier of the first country containing |pt| or |kInvalidId| if there is none. RegionId FindFirstCountry(m2::PointD const & pt) const; @@ -150,6 +152,9 @@ public: static std::unique_ptr<CountryInfoGetter> CreateCountryInfoReaderObsolete( Platform const & platform); + // Loads all regions for country number |id| from |m_reader|. + void LoadRegionsFromDisk(size_t id, std::vector<m2::RegionD> & regions) const; + protected: CountryInfoReader(ModelReaderPtr polyR, ModelReaderPtr countryR); @@ -162,8 +167,6 @@ protected: template <typename Fn> std::result_of_t<Fn(std::vector<m2::RegionD>)> WithRegion(size_t id, Fn && fn) const; - void LoadRegionsFromDisk(size_t id, std::vector<m2::RegionD> & regions) const; - FilesContainerR m_reader; mutable base::Cache<uint32_t, std::vector<m2::RegionD>> m_cache; mutable std::mutex m_cacheMutex; diff --git a/storage/storage.hpp b/storage/storage.hpp index dd36b1a2a0..d799cd2d1d 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -736,8 +736,8 @@ void Storage::ForEachInSubtree(CountryId const & root, ToDo && toDo) const ASSERT(false, ("CountryId =", root, "not found in m_countries.")); return; } - rootNode->ForEachInSubtree([&toDo](CountryTree::Node const & container) { - Country const & value = container.Value(); + rootNode->ForEachInSubtree([&toDo](CountryTree::Node const & node) { + Country const & value = node.Value(); toDo(value.Name(), value.GetSubtreeMwmCounter() != 1 /* groupNode. */); }); } @@ -772,13 +772,13 @@ void Storage::ForEachAncestorExceptForTheRoot(std::vector<CountryTree::Node cons // may be more than one. It means |childId| is present in the country tree more than once. for (auto const & node : nodes) { - node->ForEachAncestorExceptForTheRoot([&](CountryTree::Node const & container) { - CountryId const ancestorId = container.Value().Name(); - if (visitedAncestors.find(&container) != visitedAncestors.end()) + node->ForEachAncestorExceptForTheRoot([&](CountryTree::Node const & node) { + CountryId const ancestorId = node.Value().Name(); + if (visitedAncestors.find(&node) != visitedAncestors.end()) return; // The node was visited before because countryId is present in the tree more // than once. - visitedAncestors.insert(&container); - toDo(ancestorId, container); + visitedAncestors.insert(&node); + toDo(ancestorId, node); }); } } diff --git a/storage/storage_tests/country_info_getter_tests.cpp b/storage/storage_tests/country_info_getter_tests.cpp index 17edfdda10..8509b1fc28 100644 --- a/storage/storage_tests/country_info_getter_tests.cpp +++ b/storage/storage_tests/country_info_getter_tests.cpp @@ -3,6 +3,7 @@ #include "storage/storage_tests/helpers.hpp" #include "storage/country.hpp" +#include "storage/country_decl.hpp" #include "storage/country_info_getter.hpp" #include "storage/storage.hpp" @@ -13,6 +14,7 @@ #include "platform/mwm_version.hpp" #include "platform/platform.hpp" +#include "base/assert.hpp" #include "base/logging.hpp" #include <map> @@ -36,7 +38,7 @@ bool IsEmptyName(map<string, CountryInfo> const & id2info, string const & id) UNIT_TEST(CountryInfoGetter_GetByPoint_Smoke) { - auto const getter = CreateCountryInfoGetter(); + auto const getter = CreateCountryInfoGetterObsolete(); CountryInfo info; @@ -53,7 +55,7 @@ UNIT_TEST(CountryInfoGetter_GetByPoint_Smoke) UNIT_TEST(CountryInfoGetter_GetRegionsCountryIdByRect_Smoke) { - auto const getter = CreateCountryInfoGetter(); + auto const getter = CreateCountryInfoGetterObsolete(); m2::PointD const p = MercatorBounds::FromLatLon(53.9022651, 27.5618818); @@ -123,7 +125,7 @@ UNIT_TEST(CountryInfoGetter_ValidName_Smoke) UNIT_TEST(CountryInfoGetter_SomeRects) { - auto const getter = CreateCountryInfoGetter(); + auto const getter = CreateCountryInfoGetterObsolete(); m2::RectD rects[3]; getter->CalcUSALimitRect(rects); @@ -137,7 +139,7 @@ UNIT_TEST(CountryInfoGetter_SomeRects) UNIT_TEST(CountryInfoGetter_HitsInRadius) { - auto const getter = CreateCountryInfoGetterMigrate(); + auto const getter = CreateCountryInfoGetter(); CountriesVec results; getter->GetRegionsCountryId(MercatorBounds::FromLatLon(56.1702, 28.1505), results); TEST_EQUAL(results.size(), 3, ()); @@ -148,7 +150,7 @@ UNIT_TEST(CountryInfoGetter_HitsInRadius) UNIT_TEST(CountryInfoGetter_HitsOnLongLine) { - auto const getter = CreateCountryInfoGetterMigrate(); + auto const getter = CreateCountryInfoGetter(); CountriesVec results; getter->GetRegionsCountryId(MercatorBounds::FromLatLon(62.2507, -102.0753), results); TEST_EQUAL(results.size(), 2, ()); @@ -159,7 +161,7 @@ UNIT_TEST(CountryInfoGetter_HitsOnLongLine) UNIT_TEST(CountryInfoGetter_HitsInTheMiddleOfNowhere) { - auto const getter = CreateCountryInfoGetterMigrate(); + auto const getter = CreateCountryInfoGetter(); CountriesVec results; getter->GetRegionsCountryId(MercatorBounds::FromLatLon(62.2900, -103.9423), results); TEST_EQUAL(results.size(), 1, ()); @@ -169,7 +171,7 @@ UNIT_TEST(CountryInfoGetter_HitsInTheMiddleOfNowhere) UNIT_TEST(CountryInfoGetter_GetLimitRectForLeafSingleMwm) { - auto const getter = CreateCountryInfoGetterMigrate(); + auto const getter = CreateCountryInfoGetter(); Storage storage(COUNTRIES_FILE); if (!version::IsSingleMwm(storage.GetCurrentDataVersion())) return; @@ -183,7 +185,7 @@ UNIT_TEST(CountryInfoGetter_GetLimitRectForLeafSingleMwm) UNIT_TEST(CountryInfoGetter_GetLimitRectForLeafTwoComponentMwm) { - auto const getter = CreateCountryInfoGetter(); + auto const getter = CreateCountryInfoGetterObsolete(); Storage storage(COUNTRIES_FILE); if (version::IsSingleMwm(storage.GetCurrentDataVersion())) return; @@ -194,3 +196,64 @@ UNIT_TEST(CountryInfoGetter_GetLimitRectForLeafTwoComponentMwm) TEST(AlmostEqualRectsAbs(boundingBox, expectedBoundingBox), ()); } + +UNIT_TEST(CountryInfoGetter_RegionRects) +{ + auto const getterRaw = CountryInfoReader::CreateCountryInfoReader(GetPlatform()); + CHECK(getterRaw != nullptr, ()); + CountryInfoReader const * const getter = static_cast<CountryInfoReader const *>(getterRaw.get()); + + Storage storage(COUNTRIES_FILE); + + auto const & countries = getter->GetCountries(); + + for (size_t i = 0; i < countries.size(); ++i) + { + vector<m2::RegionD> regions; + getter->LoadRegionsFromDisk(i, regions); + + m2::RectD rect; + for (auto const & region : regions) + region.ForEachPoint([&](m2::PointD const & point) { rect.Add(point); }); + + TEST(AlmostEqualRectsAbs(rect, countries[i].m_rect), (rect, countries[i].m_rect)); + } +} + +// This is a test for consistency between data/countries.txt and data/packed_polygons.bin. +UNIT_TEST(CountryInfoGetter_Countries_And_Polygons) +{ + auto const getterRaw = CountryInfoReader::CreateCountryInfoReader(GetPlatform()); + CHECK(getterRaw != nullptr, ()); + CountryInfoReader const * const getter = static_cast<CountryInfoReader const *>(getterRaw.get()); + + Storage storage(COUNTRIES_FILE); + + double const kRectSize = 10; + + auto const & countries = getter->GetCountries(); + + // Set is used here because disputed territories may occur as leaves several times. + set<CountryId> storageLeaves; + storage.ForEachInSubtree(storage.GetRootId(), [&](CountryId const & countryId, bool groupNode) { + if (!groupNode) + storageLeaves.insert(countryId); + }); + + TEST_EQUAL(countries.size(), storageLeaves.size(), ()); + + for (size_t defId = 0; defId < countries.size(); ++defId) + { + auto const & countryDef = countries[defId]; + TEST_GREATER(storageLeaves.count(countryDef.m_countryId), 0, (countryDef.m_countryId)); + + auto const & p = countryDef.m_rect.Center(); + auto const rect = MercatorBounds::RectByCenterXYAndSizeInMeters(p.x, p.y, kRectSize, kRectSize); + auto vec = getter->GetRegionsCountryIdByRect(rect, false /* rough */); + for (auto const & countryId : vec) + { + // This call fails a CHECK if |countryId| is not found. + storage.GetCountryFile(countryId); + } + } +} diff --git a/storage/storage_tests/helpers.cpp b/storage/storage_tests/helpers.cpp index 2f92714b29..a35cabc14d 100644 --- a/storage/storage_tests/helpers.cpp +++ b/storage/storage_tests/helpers.cpp @@ -8,19 +8,19 @@ namespace storage { -unique_ptr<CountryInfoGetter> CreateCountryInfoGetter() +unique_ptr<CountryInfoGetter> CreateCountryInfoGetterObsolete() { return CountryInfoReader::CreateCountryInfoReaderObsolete(GetPlatform()); } -unique_ptr<storage::CountryInfoGetter> CreateCountryInfoGetterMigrate() +unique_ptr<storage::CountryInfoGetter> CreateCountryInfoGetter() { return CountryInfoReader::CreateCountryInfoReader(GetPlatform()); } bool AlmostEqualRectsAbs(const m2::RectD & r1, const m2::RectD & r2) { - double constexpr kEpsilon = 1e-3; + double constexpr kEpsilon = 1e-2; return base::AlmostEqualAbs(r1.maxX(), r2.maxX(), kEpsilon) && base::AlmostEqualAbs(r1.maxY(), r2.maxY(), kEpsilon) && base::AlmostEqualAbs(r1.minX(), r2.minX(), kEpsilon) diff --git a/storage/storage_tests/helpers.hpp b/storage/storage_tests/helpers.hpp index c8fbdffafb..7a0dbdde6f 100644 --- a/storage/storage_tests/helpers.hpp +++ b/storage/storage_tests/helpers.hpp @@ -8,8 +8,8 @@ namespace storage { class CountryInfoGetter; +unique_ptr<CountryInfoGetter> CreateCountryInfoGetterObsolete(); unique_ptr<CountryInfoGetter> CreateCountryInfoGetter(); -unique_ptr<CountryInfoGetter> CreateCountryInfoGetterMigrate(); bool AlmostEqualRectsAbs(const m2::RectD & r1, const m2::RectD & r2); } // namespace storage diff --git a/storage/storage_tests/storage_tests.cpp b/storage/storage_tests/storage_tests.cpp index c90be4d58e..4e173d0a6a 100644 --- a/storage/storage_tests/storage_tests.cpp +++ b/storage/storage_tests/storage_tests.cpp @@ -1187,8 +1187,8 @@ UNIT_CLASS_TEST(StorageTest, DownloadedMap) UNIT_CLASS_TEST(StorageTest, IsPointCoveredByDownloadedMaps) { bool const isSingleMwm = version::IsSingleMwm(storage.GetCurrentDataVersion()); - auto const countryInfoGetter = isSingleMwm ? CreateCountryInfoGetterMigrate() - : CreateCountryInfoGetter(); + auto const countryInfoGetter = + isSingleMwm ? CreateCountryInfoGetter() : CreateCountryInfoGetterObsolete(); ASSERT(countryInfoGetter, ()); string const uruguayId = string("Uruguay"); m2::PointD const montevideoUruguay = MercatorBounds::FromLatLon(-34.8094, -56.1558); @@ -1554,7 +1554,7 @@ UNIT_CLASS_TEST(StorageTest, CalcLimitRect) if (!version::IsSingleMwm(storage.GetCurrentDataVersion())) return; - auto const countryInfoGetter = CreateCountryInfoGetterMigrate(); + auto const countryInfoGetter = CreateCountryInfoGetter(); ASSERT(countryInfoGetter, ()); m2::RectD const boundingBox = storage::CalcLimitRect("Algeria", storage, *countryInfoGetter); |