Format all C++ and Java code via clang-format

Signed-off-by: Konstantin Pastbin <konstantin.pastbin@gmail.com>
This commit is contained in:
Konstantin Pastbin
2025-08-17 14:32:37 +07:00
parent 9f0290c0ec
commit bfffa1fff4
2169 changed files with 56441 additions and 64188 deletions

View File

@@ -34,22 +34,19 @@ std::pair<uint64_t, uint64_t> AddressEnricher::RawEntryBase::GetHNRange() const
if (f.m_type != Token::TYPE_NUMBER || t.m_type != Token::TYPE_NUMBER)
return kInvalidRange;
return { ToUInt(f.m_value), ToUInt(t.m_value) };
return {ToUInt(f.m_value), ToUInt(t.m_value)};
}
std::string DebugPrint(AddressEnricher::Stats const & s)
{
return
"{ m_noStreet = " + std::to_string(s.m_noStreet) +
"; m_existInterpol = " + std::to_string(s.m_existInterpol) +
"; m_existSingle = " + std::to_string(s.m_existSingle) +
"; m_enoughAddrs = " + std::to_string(s.m_enoughAddrs) +
"; m_addedSingle = " + std::to_string(s.m_addedSingle) +
"; m_addedBegEnd = " + std::to_string(s.m_addedBegEnd) +
"; m_addedInterpol = " + std::to_string(s.m_addedInterpol) + " }";
return "{ m_noStreet = " + std::to_string(s.m_noStreet) + "; m_existInterpol = " + std::to_string(s.m_existInterpol) +
"; m_existSingle = " + std::to_string(s.m_existSingle) +
"; m_enoughAddrs = " + std::to_string(s.m_enoughAddrs) +
"; m_addedSingle = " + std::to_string(s.m_addedSingle) +
"; m_addedBegEnd = " + std::to_string(s.m_addedBegEnd) +
"; m_addedInterpol = " + std::to_string(s.m_addedInterpol) + " }";
}
AddressEnricher::AddressEnricher()
{
auto const & cl = classif();
@@ -223,7 +220,7 @@ AddressEnricher::FoundT AddressEnricher::Match(Entry & e) const
std::vector<m2::ParametrizedSegment<m2::PointD>> eSegs;
eSegs.reserve(e.m_points.size() - 1);
for (size_t i = 1; i < e.m_points.size(); ++i)
eSegs.emplace_back(e.m_points[i-1], e.m_points[i]);
eSegs.emplace_back(e.m_points[i - 1], e.m_points[i]);
/// @todo Check nodes distance for now. Should make more honest algo.
auto const isClose = [&e, &eSegs](feature::FeatureBuilder const & fb)
@@ -237,9 +234,7 @@ AddressEnricher::FoundT AddressEnricher::Match(Entry & e) const
auto const ll = mercator::ToLatLon(p);
auto const check = [&ll](m2::PointD const & p)
{
return ms::DistanceOnEarth(ll, mercator::ToLatLon(p)) < kDistanceThresholdM;
};
{ return ms::DistanceOnEarth(ll, mercator::ToLatLon(p)) < kDistanceThresholdM; };
if (!eSegs.empty())
{
@@ -268,7 +263,7 @@ AddressEnricher::FoundT AddressEnricher::Match(Entry & e) const
// First of all - compare street's name.
strings::UniString fbStreetKey = search::GetNormalizedStreetName(params.GetStreet());
std::string streetName; // original street's name, valid if isStreet == true
std::string streetName; // original street's name, valid if isStreet == true
if (isStreet)
{
// Fancy object, highway=pedestrian with addr: https://www.openstreetmap.org/way/415336229
@@ -323,7 +318,7 @@ AddressEnricher::FoundT AddressEnricher::Match(Entry & e) const
auto const & geom = fb.GetOuterGeometry();
for (size_t i = 1; i < geom.size(); ++i)
{
m2::ParametrizedSegment<m2::PointD> seg(geom[i-1], geom[i]);
m2::ParametrizedSegment<m2::PointD> seg(geom[i - 1], geom[i]);
/// @todo Calculate e.m_points LL once?
for (auto const & p : e.m_points)
if (mercator::DistanceOnEarth(p, seg.ClosestPointTo(p)) < kDistanceThresholdM)
@@ -349,8 +344,8 @@ AddressEnricher::FoundT AddressEnricher::Match(Entry & e) const
size_t const i = hnRange.find(':');
CHECK(i != std::string::npos, (hnRange));
uint64_t left, right;
CHECK(strings::to_uint(hnRange.substr(0, i), left) &&
strings::to_uint(hnRange.substr(i + 1), right), (hnRange));
CHECK(strings::to_uint(hnRange.substr(0, i), left) && strings::to_uint(hnRange.substr(i + 1), right),
(hnRange));
res.interpol = !(left >= range.second || right <= range.first);
}
@@ -360,4 +355,4 @@ AddressEnricher::FoundT AddressEnricher::Match(Entry & e) const
return res;
}
} // namespace generator
} // namespace generator

View File

@@ -32,7 +32,8 @@ public:
std::pair<uint64_t, uint64_t> GetHNRange() const;
/// @}
template <class TSink> void Save(TSink & sink) const
template <class TSink>
void Save(TSink & sink) const
{
rw::Write(sink, m_from);
rw::Write(sink, m_to);
@@ -42,7 +43,8 @@ public:
WriteToSink(sink, static_cast<uint8_t>(m_interpol));
}
template <class TSource> void Load(TSource & src)
template <class TSource>
void Load(TSource & src)
{
rw::Read(src, m_from);
rw::Read(src, m_to);
@@ -62,7 +64,7 @@ public:
void AddSrc(feature::FeatureBuilder && fb);
using TFBCollectFn = std::function<void (feature::FeatureBuilder &&)>;
using TFBCollectFn = std::function<void(feature::FeatureBuilder &&)>;
void ProcessRawEntries(std::string const & path, TFBCollectFn const & fn);
// Public for tests.
@@ -99,4 +101,4 @@ private:
std::map<feature::InterpolType, uint32_t> m_interpolType;
};
} // namespace generator
} // namespace generator

View File

@@ -25,7 +25,9 @@ UNIT_TEST(TigerParser_Smoke)
TEST(tiger::ParseLine("9587;9619;all;;Platte;MO;64152;LINESTRING(-94.691917 39.210393,-94.692370 39.210351)", e), ());
e = {};
TEST(tiger::ParseLine("698;600;all;Boston St;Berkeley;WV;25401;LINESTRING(-77.970484 39.464604,-77.970540 39.464630)", e), ());
TEST(tiger::ParseLine("698;600;all;Boston St;Berkeley;WV;25401;LINESTRING(-77.970484 39.464604,-77.970540 39.464630)",
e),
());
TEST_EQUAL(e.m_from, "600", ());
TEST_EQUAL(e.m_to, "698", ());
TEST_EQUAL(e.m_street, "Boston St", ());
@@ -33,10 +35,14 @@ UNIT_TEST(TigerParser_Smoke)
TEST_EQUAL(e.m_interpol, feature::InterpolType::Any, ());
TEST_EQUAL(e.m_geom.size(), 1, ());
TEST(ms::LatLon((39.464604 + 39.464630) / 2.0, (-77.970484 -77.970540) / 2.0).EqualDxDy(e.m_geom.back(), kEpsLL), ());
TEST(ms::LatLon((39.464604 + 39.464630) / 2.0, (-77.970484 - 77.970540) / 2.0).EqualDxDy(e.m_geom.back(), kEpsLL),
());
e = {};
TEST(tiger::ParseLine("798;700;all;Boston St;Berkeley;WV;25401;LINESTRING(-77.968929 39.463906,-77.969118 39.463990,-77.969427 39.464129,-77.969946 39.464353,-77.970027 39.464389)", e), ());
TEST(tiger::ParseLine("798;700;all;Boston St;Berkeley;WV;25401;LINESTRING(-77.968929 39.463906,-77.969118 "
"39.463990,-77.969427 39.464129,-77.969946 39.464353,-77.970027 39.464389)",
e),
());
TEST_EQUAL(e.m_from, "700", ());
TEST_EQUAL(e.m_to, "798", ());
TEST_EQUAL(e.m_street, "Boston St", ());
@@ -47,7 +53,11 @@ UNIT_TEST(TigerParser_Smoke)
TEST(ms::LatLon(39.463906, -77.968929).EqualDxDy(e.m_geom.back(), kEpsLL), ());
TEST(ms::LatLon(39.464389, -77.970027).EqualDxDy(e.m_geom.front(), kEpsLL), ());
TEST(tiger::ParseLine("0;98;even;Austin Ln;Mifflin;PA;17044;LINESTRING(-77.634119 40.597239,-77.634200 40.597288,-77.634679 40.598169,-77.634835 40.598393,-77.635116 40.598738,-77.635518 40.599388,-77.635718 40.599719,-77.635833 40.599871,-77.635856 40.599920)", e), ());
TEST(tiger::ParseLine("0;98;even;Austin Ln;Mifflin;PA;17044;LINESTRING(-77.634119 40.597239,-77.634200 "
"40.597288,-77.634679 40.598169,-77.634835 40.598393,-77.635116 40.598738,-77.635518 "
"40.599388,-77.635718 40.599719,-77.635833 40.599871,-77.635856 40.599920)",
e),
());
TEST_EQUAL(e.m_from, "0", ());
TEST_EQUAL(e.m_to, "98", ());
}
@@ -55,6 +65,7 @@ UNIT_TEST(TigerParser_Smoke)
class TmpDir
{
std::string const m_path = "./addrs";
public:
std::string const & Get() const { return m_path; }
@@ -63,10 +74,7 @@ public:
(void)Platform::RmDirRecursively(m_path);
TEST(Platform::MkDirChecked(m_path), ());
}
~TmpDir()
{
TEST(Platform::RmDirRecursively(m_path), ());
}
~TmpDir() { TEST(Platform::RmDirRecursively(m_path), ()); }
};
UNIT_TEST(Processor_Smoke)
@@ -160,7 +168,9 @@ UNIT_CLASS_TEST(TestFixture, Generator_Smoke)
{
std::stringstream ss;
ss << "698;600;all;Boston St;Berkeley;WV;25401;LINESTRING(-77.970484 39.464604,-77.970540 39.464630)" << "\n"
<< "798;700;all;Boston St;Berkeley;WV;25401;LINESTRING(-77.968929 39.463906,-77.969118 39.463990,-77.969427 39.464129,-77.969946 39.464353,-77.970027 39.464389)" << "\n";
<< "798;700;all;Boston St;Berkeley;WV;25401;LINESTRING(-77.968929 39.463906,-77.969118 39.463990,-77.969427 "
"39.464129,-77.969946 39.464353,-77.970027 39.464389)"
<< "\n";
Parse(ss);
@@ -170,7 +180,8 @@ UNIT_CLASS_TEST(TestFixture, Generator_Smoke)
UNIT_CLASS_TEST(TestFixture, Generator_Filter_SF1)
{
std::stringstream ss;
ss << "601;699;all;Francisco St;San Francisco;CA;94133;LINESTRING(-122.416189 37.804256,-122.416526 37.804215)" << "\n";
ss << "601;699;all;Francisco St;San Francisco;CA;94133;LINESTRING(-122.416189 37.804256,-122.416526 37.804215)"
<< "\n";
Parse(ss);
@@ -190,8 +201,10 @@ UNIT_CLASS_TEST(TestFixture, Generator_Filter_NY)
UNIT_CLASS_TEST(TestFixture, Generator_Filter_SF2)
{
std::stringstream ss;
ss << "744;752;all;Francisco St;San Francisco;CA;94133;LINESTRING(-122.417593 37.804248,-122.417686 37.804236)" << "\n"
<< "754;798;even;Francisco St;San Francisco;CA;94133;LINESTRING(-122.417933 37.804205,-122.418204 37.804171)" << "\n";
ss << "744;752;all;Francisco St;San Francisco;CA;94133;LINESTRING(-122.417593 37.804248,-122.417686 37.804236)"
<< "\n"
<< "754;798;even;Francisco St;San Francisco;CA;94133;LINESTRING(-122.417933 37.804205,-122.418204 37.804171)"
<< "\n";
Parse(ss);
@@ -201,8 +214,12 @@ UNIT_CLASS_TEST(TestFixture, Generator_Filter_SF2)
UNIT_CLASS_TEST(TestFixture, Generator_Street_Name)
{
std::stringstream ss;
ss << "599;501;odd;Seventh St;Marshall;MN;56757;LINESTRING(-96.878165 48.451707,-96.878047 48.451722,-96.877150 48.451844,-96.877034 48.451860)" << "\n"
<< "598;500;even;Seventh St;Marshall;MN;56757;LINESTRING(-96.878214 48.451868,-96.878097 48.451884,-96.877200 48.452006,-96.877084 48.452022)" << "\n";
ss << "599;501;odd;Seventh St;Marshall;MN;56757;LINESTRING(-96.878165 48.451707,-96.878047 48.451722,-96.877150 "
"48.451844,-96.877034 48.451860)"
<< "\n"
<< "598;500;even;Seventh St;Marshall;MN;56757;LINESTRING(-96.878214 48.451868,-96.878097 48.451884,-96.877200 "
"48.452006,-96.877084 48.452022)"
<< "\n";
Parse(ss);
@@ -240,4 +257,4 @@ UNIT_CLASS_TEST(TestFixture, Generator_Street_Name)
TEST_EQUAL(count, 2, ());
}
} // namespace addr_parser_tests
} // namespace addr_parser_tests

View File

@@ -8,16 +8,15 @@
#include <iostream>
DEFINE_string(data_path, "./data", "Data path with 'borders' folder inside");
DEFINE_string(output_path, "", "Output files path");
DEFINE_uint64(threads_count, 0, "Desired number of threads. 0 - number of threads is set automatically");
MAIN_WITH_ERROR_HANDLING([](int argc, char ** argv)
{
std::string usage("Tiger addresses processor. Sample usage:\n");
gflags::SetUsageMessage(usage + "tar -xOzf tiger-nominatim-preprocessed-latest.csv.tar.gz | " + argv[0] + " --output_path=... ");
gflags::SetUsageMessage(usage + "tar -xOzf tiger-nominatim-preprocessed-latest.csv.tar.gz | " + argv[0] +
" --output_path=... ");
gflags::ParseCommandLineFlags(&argc, &argv, true);

View File

@@ -10,7 +10,6 @@
#include "defines.hpp"
namespace addr_generator
{
@@ -18,8 +17,7 @@ Processor::Processor(std::string const & dataPath, std::string const & outputPat
: m_affiliation(dataPath, true /* haveBordersForWholeWorld */)
, m_workers(numThreads)
, m_outputPath(outputPath)
{
}
{}
FileWriter & Processor::GetWriter(std::string const & country)
{
@@ -90,4 +88,4 @@ void Processor::Run(std::istream & is)
LOG(LINFO, ("Total entries:", total, "Incomplete:", incomplete));
}
} // namespace addr_generator
} // namespace addr_generator

View File

@@ -29,4 +29,4 @@ public:
void Run(std::istream & is);
};
} // namespace addr_generator
} // namespace addr_generator

View File

@@ -30,7 +30,7 @@ void ParseGeometry(std::string_view s, std::vector<ms::LatLon> & geom)
CHECK(i != std::string_view::npos, (s));
CHECK(to_double(s.substr(0, i), last.m_lon), (s));
CHECK(to_double(s.substr(i+1), last.m_lat), (s));
CHECK(to_double(s.substr(i + 1), last.m_lat), (s));
if (!skipPoint())
geom.push_back(last);
@@ -42,7 +42,7 @@ void ParseGeometry(std::string_view s, std::vector<ms::LatLon> & geom)
if (geom.size() == 1)
{
// Set one middle point address.
back = ms::LatLon{ (back.m_lat + last.m_lat) / 2.0, (back.m_lon + last.m_lon) / 2.0 };
back = ms::LatLon{(back.m_lat + last.m_lat) / 2.0, (back.m_lon + last.m_lon) / 2.0};
}
else
{
@@ -71,15 +71,21 @@ bool ParseLine(std::string_view line, AddressEntry & e)
if (std::count(line.begin(), line.end(), ';') != 7)
return false;
TokenizeIterator<SimpleDelimiter, std::string_view::const_iterator, true /* KeepEmptyTokens */> it(
line.begin(), line.end(), ";");
TokenizeIterator<SimpleDelimiter, std::string_view::const_iterator, true /* KeepEmptyTokens */> it(line.begin(),
line.end(), ";");
e.m_from = *it; ++it;
e.m_to = *it; ++it;
e.m_interpol = ParseInterpolation(*it); ++it;
e.m_street = *it; ++it;
++it; ++it;
e.m_postcode = *it; ++it;
e.m_from = *it;
++it;
e.m_to = *it;
++it;
e.m_interpol = ParseInterpolation(*it);
++it;
e.m_street = *it;
++it;
++it;
++it;
e.m_postcode = *it;
++it;
ParseGeometry(*it, e.m_geom);
if (e.m_interpol == feature::InterpolType::None || e.m_geom.empty())
@@ -99,7 +105,7 @@ bool ParseLine(std::string_view line, AddressEntry & e)
return true;
}
} // namespace tiger
} // namespace tiger
namespace feature
{
@@ -114,4 +120,4 @@ std::string DebugPrint(InterpolType type)
}
UNREACHABLE();
}
} // namespace feature
} // namespace feature

View File

@@ -18,9 +18,9 @@ struct AddressEntry : public generator::AddressEnricher::RawEntryBase
void ParseGeometry(std::string_view s, std::vector<ms::LatLon> & geom);
feature::InterpolType ParseInterpolation(std::string_view s);
bool ParseLine(std::string_view line, AddressEntry & e);
} // namespace tiger
} // namespace tiger
namespace feature
{
std::string DebugPrint(InterpolType type);
} // namespace feature
} // namespace feature

View File

@@ -24,7 +24,7 @@ uint64_t GetOsmID(FeatureBuilder const & fb)
AddressesHolder::AddressInfo FromFB(FeatureBuilder const & fb)
{
auto const & params = fb.GetParams();
return { params.house.Get(), std::string(params.GetStreet()), std::string(params.GetPostcode()), {} };
return {params.house.Get(), std::string(params.GetStreet()), std::string(params.GetPostcode()), {}};
}
// Current stats:
@@ -35,8 +35,7 @@ void LogWarning(std::string const & msg, uint64_t id)
{
LOG(LWARNING, ("addr:interpolation: " + msg, id));
}
} // namespace
} // namespace
std::string AddressesHolder::AddressInfo::FormatRange() const
{
@@ -81,7 +80,6 @@ std::string AddressesHolder::AddressInfo::FormatRange() const
}
}
void AddressesHolder::Add(FeatureBuilder const & fb)
{
CHECK(fb.IsPoint(), ());
@@ -160,11 +158,7 @@ void AddressesHolder::Deserialize(std::string const & filePath)
}
}
AddressesCollector::AddressesCollector(std::string const & filename)
: CollectorInterface(filename)
{
}
AddressesCollector::AddressesCollector(std::string const & filename) : CollectorInterface(filename) {}
std::shared_ptr<CollectorInterface> AddressesCollector::Clone(IDRInterfacePtr const & cache) const
{
@@ -231,4 +225,4 @@ void AddressesCollector::MergeInto(AddressesCollector & collector) const
collector.m_interpolWays.emplace(e.first, e.second);
}
} // namespace generator
} // namespace generator

View File

@@ -12,7 +12,7 @@ public:
struct AddressInfo
{
std::string m_house, m_street, m_postcode;
std::string m_house2; // end point house number for the 2nd stage
std::string m_house2; // end point house number for the 2nd stage
std::string FormatRange() const;
};
@@ -64,4 +64,4 @@ public:
void MergeInto(AddressesCollector & collector) const;
};
} // namespace generator
} // namespace generator

View File

@@ -9,10 +9,9 @@
#include <functional>
#include "std/boost_geometry.hpp"
#include <boost/geometry/geometries/register/ring.hpp>
#include <boost/geometry/geometries/register/point.hpp>
#include <boost/geometry/geometries/register/ring.hpp>
#include "std/boost_geometry.hpp"
BOOST_GEOMETRY_REGISTER_POINT_2D(m2::PointD, double, boost::geometry::cs::cartesian, x, y)
BOOST_GEOMETRY_REGISTER_RING(std::vector<m2::PointD>)
@@ -34,16 +33,16 @@ template <typename T>
m2::RectD GetLimitRect(T && t)
{
using Type = RemoveCvrefT<T>;
if constexpr(std::is_same_v<Type, FeatureBuilder>)
if constexpr (std::is_same_v<Type, FeatureBuilder>)
return t.GetLimitRect();
if constexpr(std::is_same_v<Type, std::vector<m2::PointD>>)
if constexpr (std::is_same_v<Type, std::vector<m2::PointD>>)
{
m2::RectD r;
for (auto const & p : t)
r.Add(p);
return r;
}
if constexpr(std::is_same_v<Type, m2::PointD>)
if constexpr (std::is_same_v<Type, m2::PointD>)
return m2::RectD(t, t);
UNREACHABLE();
@@ -53,11 +52,11 @@ template <typename T, typename F>
bool ForAnyPoint(T && t, F && f)
{
using Type = RemoveCvrefT<T>;
if constexpr(std::is_same_v<Type, FeatureBuilder>)
if constexpr (std::is_same_v<Type, FeatureBuilder>)
return t.ForAnyPoint(f);
if constexpr(std::is_same_v<Type, std::vector<m2::PointD>>)
if constexpr (std::is_same_v<Type, std::vector<m2::PointD>>)
return base::AnyOf(t, f);
if constexpr(std::is_same_v<Type, m2::PointD>)
if constexpr (std::is_same_v<Type, m2::PointD>)
return f(t);
UNREACHABLE();
@@ -67,9 +66,9 @@ template <typename T, typename F>
void ForEachPoint(T && t, F && f)
{
using Type = RemoveCvrefT<T>;
if constexpr(std::is_same_v<Type, FeatureBuilder>)
if constexpr (std::is_same_v<Type, FeatureBuilder>)
t.ForEachPoint(std::forward<F>(f));
else if constexpr(std::is_same_v<Type, m2::PointD>)
else if constexpr (std::is_same_v<Type, m2::PointD>)
f(std::forward<T>(t));
else
UNREACHABLE();
@@ -77,16 +76,13 @@ void ForEachPoint(T && t, F && f)
// An implementation for CountriesFilesAffiliation class.
template <typename T>
std::vector<std::string> GetAffiliations(T const & t,
borders::CountryPolygonsCollection const & countryPolygonsTree,
std::vector<std::string> GetAffiliations(T const & t, borders::CountryPolygonsCollection const & countryPolygonsTree,
bool haveBordersForWholeWorld)
{
std::vector<std::string> countries;
std::vector<std::reference_wrapper<borders::CountryPolygons const>> countriesContainer;
countryPolygonsTree.ForEachCountryInRect(GetLimitRect(t), [&](auto const & countryPolygons)
{
countriesContainer.emplace_back(countryPolygons);
});
countryPolygonsTree.ForEachCountryInRect(
GetLimitRect(t), [&](auto const & countryPolygons) { countriesContainer.emplace_back(countryPolygons); });
// todo(m.andrianov): We need to explore this optimization better. There is a hypothesis: some
// elements belong to a rectangle, but do not belong to the exact boundary.
@@ -99,10 +95,7 @@ std::vector<std::string> GetAffiliations(T const & t,
for (borders::CountryPolygons const & countryPolygons : countriesContainer)
{
auto const need = ForAnyPoint(t, [&](auto const & point)
{
return countryPolygons.Contains(point);
});
auto const need = ForAnyPoint(t, [&](auto const & point) { return countryPolygons.Contains(point); });
if (need)
countries.emplace_back(countryPolygons.GetName());
@@ -119,23 +112,19 @@ CountriesFilesIndexAffiliation::Box MakeBox(m2::RectD const & rect)
return {rect.LeftBottom(), rect.RightTop()};
}
std::optional<std::string> IsOneCountryForLimitRect(m2::RectD const & limitRect,
IndexSharedPtr const & index)
std::optional<std::string> IsOneCountryForLimitRect(m2::RectD const & limitRect, IndexSharedPtr const & index)
{
borders::CountryPolygons const * country = nullptr;
std::vector<CountriesFilesIndexAffiliation::Value> values;
auto const bbox = MakeBox(limitRect);
boost::geometry::index::query(*index, boost::geometry::index::covers(bbox),
std::back_inserter(values));
boost::geometry::index::query(*index, boost::geometry::index::covers(bbox), std::back_inserter(values));
for (auto const & v : values)
{
for (borders::CountryPolygons const & c : v.second)
{
if (!country)
country = &c;
else if (country != &c)
return {};
}
}
return country ? country->GetName() : std::optional<std::string>{};
}
@@ -145,10 +134,10 @@ std::vector<std::string> GetHonestAffiliations(T && t, IndexSharedPtr const & in
{
std::vector<std::string> affiliations;
std::unordered_set<borders::CountryPolygons const *> countires;
ForEachPoint(t, [&](auto const & point) {
ForEachPoint(t, [&](auto const & point)
{
std::vector<CountriesFilesIndexAffiliation::Value> values;
boost::geometry::index::query(*index, boost::geometry::index::covers(point),
std::back_inserter(values));
boost::geometry::index::query(*index, boost::geometry::index::covers(point), std::back_inserter(values));
for (auto const & v : values)
{
if (v.second.size() == 1)
@@ -160,10 +149,8 @@ std::vector<std::string> GetHonestAffiliations(T && t, IndexSharedPtr const & in
else
{
for (borders::CountryPolygons const & cp : v.second)
{
if (cp.Contains(point) && countires.insert(&cp).second)
affiliations.emplace_back(cp.GetName());
}
}
}
});
@@ -182,8 +169,7 @@ std::vector<std::string> GetAffiliations(T && t, IndexSharedPtr const & index)
CountriesFilesAffiliation::CountriesFilesAffiliation(std::string const & borderPath, bool haveBordersForWholeWorld)
: m_countryPolygonsTree(borders::GetOrCreateCountryPolygonsTree(borderPath))
, m_haveBordersForWholeWorld(haveBordersForWholeWorld)
{
}
{}
std::vector<std::string> CountriesFilesAffiliation::GetAffiliations(FeatureBuilder const & fb) const
{
@@ -222,8 +208,7 @@ CountriesFilesIndexAffiliation::CountriesFilesIndexAffiliation(std::string const
return;
}
auto const net = generator::cells_merger::MakeNet(0.2 /* step */,
mercator::Bounds::kMinX, mercator::Bounds::kMinY,
auto const net = generator::cells_merger::MakeNet(0.2 /* step */, mercator::Bounds::kMinX, mercator::Bounds::kMinY,
mercator::Bounds::kMaxX, mercator::Bounds::kMaxY);
auto const index = BuildIndex(net);
m_index = index;
@@ -240,8 +225,8 @@ std::vector<std::string> CountriesFilesIndexAffiliation::GetAffiliations(m2::Poi
return affiliation::GetAffiliations(point, m_index);
}
std::shared_ptr<CountriesFilesIndexAffiliation::Tree>
CountriesFilesIndexAffiliation::BuildIndex(const std::vector<m2::RectD> & net)
std::shared_ptr<CountriesFilesIndexAffiliation::Tree> CountriesFilesIndexAffiliation::BuildIndex(
std::vector<m2::RectD> const & net)
{
std::unordered_map<borders::CountryPolygons const *, std::vector<m2::RectD>> countriesRects;
std::mutex countriesRectsMutex;
@@ -252,11 +237,11 @@ CountriesFilesIndexAffiliation::BuildIndex(const std::vector<m2::RectD> & net)
base::ComputationalThreadPool pool(numThreads);
for (auto const & rect : net)
{
pool.SubmitWork([&, rect]() {
pool.SubmitWork([&, rect]()
{
std::vector<std::reference_wrapper<borders::CountryPolygons const>> countries;
m_countryPolygonsTree.ForEachCountryInRect(rect, [&](auto const & country) {
countries.emplace_back(country);
});
m_countryPolygonsTree.ForEachCountryInRect(rect,
[&](auto const & country) { countries.emplace_back(country); });
if (m_haveBordersForWholeWorld && countries.size() == 1)
{
borders::CountryPolygons const & country = countries.front();
@@ -269,7 +254,8 @@ CountriesFilesIndexAffiliation::BuildIndex(const std::vector<m2::RectD> & net)
std::vector<std::reference_wrapper<borders::CountryPolygons const>> interCountries;
for (borders::CountryPolygons const & cp : countries)
{
cp.ForAnyPolygon([&](auto const & polygon) {
cp.ForAnyPolygon([&](auto const & polygon)
{
if (!boost::geometry::intersects(polygon.Data(), box))
return false;
interCountries.emplace_back(cp);
@@ -297,7 +283,8 @@ CountriesFilesIndexAffiliation::BuildIndex(const std::vector<m2::RectD> & net)
base::ComputationalThreadPool pool(numThreads);
for (auto & pair : countriesRects)
{
pool.SubmitWork([&, countryPtr{pair.first}, rects{std::move(pair.second)}]() mutable {
pool.SubmitWork([&, countryPtr{pair.first}, rects{std::move(pair.second)}]() mutable
{
generator::cells_merger::CellsMerger merger(std::move(rects));
auto const merged = merger.Merge();
for (auto const & rect : merged)
@@ -312,10 +299,7 @@ CountriesFilesIndexAffiliation::BuildIndex(const std::vector<m2::RectD> & net)
return std::make_shared<Tree>(treeCells);
}
SingleAffiliation::SingleAffiliation(std::string const & filename)
: m_filename(filename)
{
}
SingleAffiliation::SingleAffiliation(std::string const & filename) : m_filename(filename) {}
std::vector<std::string> SingleAffiliation::GetAffiliations(FeatureBuilder const &) const
{
@@ -327,8 +311,7 @@ bool SingleAffiliation::HasCountryByName(std::string const & name) const
return name == m_filename;
}
std::vector<std::string>
SingleAffiliation::GetAffiliations(m2::PointD const &) const
std::vector<std::string> SingleAffiliation::GetAffiliations(m2::PointD const &) const
{
return {m_filename};
}

View File

@@ -20,7 +20,6 @@ public:
virtual std::vector<std::string> GetAffiliations(m2::PointD const & point) const = 0;
virtual bool HasCountryByName(std::string const & name) const = 0;
};
class CountriesFilesAffiliation : public AffiliationInterface

View File

@@ -35,10 +35,7 @@ public:
explicit SrtmGetter(std::string const & srtmDir) : m_srtmManager(srtmDir) {}
// AltitudeGetter overrides:
Altitude GetAltitude(m2::PointD const & p) override
{
return m_srtmManager.GetAltitude(mercator::ToLatLon(p));
}
Altitude GetAltitude(m2::PointD const & p) override { return m_srtmManager.GetAltitude(mercator::ToLatLon(p)); }
void PrintStatsAndPurge() override
{
@@ -56,18 +53,18 @@ public:
struct FeatureAltitude
{
FeatureAltitude(uint32_t featureId, geometry::Altitudes && altitudes)
: m_featureId(featureId), m_altitudes(std::move(altitudes))
{
}
: m_featureId(featureId)
, m_altitudes(std::move(altitudes))
{}
uint32_t m_featureId;
feature::Altitudes m_altitudes;
};
explicit Processor(AltitudeGetter & altitudeGetter)
: m_minAltitude(geometry::kInvalidAltitude), m_altitudeGetter(altitudeGetter)
{
}
: m_minAltitude(geometry::kInvalidAltitude)
, m_altitudeGetter(altitudeGetter)
{}
void operator()(FeatureType & f, uint32_t id)
{
@@ -75,8 +72,7 @@ public:
CHECK_EQUAL(id, m_altitudeAvailabilityBuilder.size(), ());
bool hasAltitude = false;
SCOPE_GUARD(altitudeAvailabilityBuilding,
[&]() { m_altitudeAvailabilityBuilder.push_back(hasAltitude); });
SCOPE_GUARD(altitudeAvailabilityBuilding, [&]() { m_altitudeAvailabilityBuilder.push_back(hasAltitude); });
if (!routing::IsRoad(feature::TypesHolder(f)))
return;

View File

@@ -39,8 +39,7 @@ template <class ToDo>
void ForEachCountry(std::string const & baseDir, ToDo && toDo)
{
std::string const bordersDir = base::JoinPath(baseDir, BORDERS_DIR);
CHECK(Platform::IsFileExistsByFullPath(bordersDir),
("Cannot read borders directory", bordersDir));
CHECK(Platform::IsFileExistsByFullPath(bordersDir), ("Cannot read borders directory", bordersDir));
Platform::FilesList files;
Platform::GetFilesByExt(bordersDir, BORDERS_EXTENSION, files);
@@ -58,9 +57,7 @@ void ForEachCountry(std::string const & baseDir, ToDo && toDo)
class PackedBordersGenerator
{
public:
explicit PackedBordersGenerator(std::string const & baseDir) : m_writer(baseDir + PACKED_POLYGONS_FILE)
{
}
explicit PackedBordersGenerator(std::string const & baseDir) : m_writer(baseDir + PACKED_POLYGONS_FILE) {}
void operator()(std::string name, PolygonsList && borders)
{
@@ -138,9 +135,7 @@ bool ReadPolygon(std::istream & stream, Polygon & poly, std::string const & file
bool CountryPolygons::Contains(m2::PointD const & point) const
{
return m_polygons.ForAnyInRect(m2::RectD(point, point), [&](auto const & rgn)
{
return rgn.Contains(point, ContainsCompareFn(GetContainsEpsilon()));
});
{ return rgn.Contains(point, ContainsCompareFn(GetContainsEpsilon())); });
}
bool LoadBorders(std::string const & borderFile, PolygonsList & outBorders)
@@ -165,8 +160,7 @@ bool LoadBorders(std::string const & borderFile, PolygonsList & outBorders)
return true;
}
bool GetBordersRect(std::string const & baseDir, std::string const & country,
m2::RectD & bordersRect)
bool GetBordersRect(std::string const & baseDir, std::string const & country, m2::RectD & bordersRect)
{
auto const bordersFile = base::JoinPath(baseDir, BORDERS_DIR, country + BORDERS_EXTENSION);
if (!Platform::IsFileExistsByFullPath(bordersFile))

View File

@@ -14,7 +14,7 @@
#include <unordered_set>
#include <vector>
#define BORDERS_DIR "borders/"
#define BORDERS_DIR "borders/"
#define BORDERS_EXTENSION ".poly"
namespace borders
@@ -44,9 +44,9 @@ class CountryPolygons
public:
CountryPolygons() = default;
explicit CountryPolygons(std::string && name, PolygonsTree && regions)
: m_name(std::move(name)), m_polygons(std::move(regions))
{
}
: m_name(std::move(name))
, m_polygons(std::move(regions))
{}
std::string const & GetName() const { return m_name; }
bool IsEmpty() const { return m_polygons.IsEmpty(); }
@@ -61,16 +61,12 @@ public:
double m_eps, m_squareEps;
public:
explicit ContainsCompareFn(double eps) : m_eps(eps), m_squareEps(eps*eps) {}
explicit ContainsCompareFn(double eps) : m_eps(eps), m_squareEps(eps * eps) {}
bool EqualPoints(m2::PointD const & p1, m2::PointD const & p2) const
{
return AlmostEqualAbs(p1.x, p2.x, m_eps) &&
AlmostEqualAbs(p1.y, p2.y, m_eps);
}
bool EqualZeroSquarePrecision(double val) const
{
return AlmostEqualAbs(val, 0.0, m_squareEps);
return AlmostEqualAbs(p1.x, p2.x, m_eps) && AlmostEqualAbs(p1.y, p2.y, m_eps);
}
bool EqualZeroSquarePrecision(double val) const { return AlmostEqualAbs(val, 0.0, m_squareEps); }
};
static double GetContainsEpsilon() { return 1.0E-4; }
@@ -108,9 +104,7 @@ public:
auto const & inserted = res.first->second;
inserted.ForEachPolygon([&inserted, this](Polygon const & polygon)
{
m_regionsTree.Add(inserted, polygon.GetRect());
});
{ m_regionsTree.Add(inserted, polygon.GetRect()); });
}
size_t GetSize() const { return m_countryPolygonsMap.size(); }
@@ -126,10 +120,7 @@ public:
});
}
bool HasRegionByName(std::string const & name) const
{
return m_countryPolygonsMap.count(name) != 0;
}
bool HasRegionByName(std::string const & name) const { return m_countryPolygonsMap.count(name) != 0; }
CountryPolygons const & GetRegionByName(std::string const & name) const
{
@@ -139,7 +130,7 @@ public:
}
private:
m4::Tree<std::reference_wrapper<const CountryPolygons>> m_regionsTree;
m4::Tree<std::reference_wrapper<CountryPolygons const>> m_regionsTree;
std::unordered_map<std::string, CountryPolygons> m_countryPolygonsMap;
};
@@ -148,8 +139,7 @@ using PolygonsList = std::vector<Polygon>;
/// @return false if borderFile can't be opened
bool LoadBorders(std::string const & borderFile, PolygonsList & outBorders);
bool GetBordersRect(std::string const & baseDir, std::string const & country,
m2::RectD & bordersRect);
bool GetBordersRect(std::string const & baseDir, std::string const & country, m2::RectD & bordersRect);
bool LoadCountriesList(std::string const & baseDir, CountryPolygonsCollection & countries);

View File

@@ -28,8 +28,7 @@ BoundaryPostcodesEnricher::BoundaryPostcodesEnricher(std::string const & boundar
CHECK(!postcode.empty() && !geometry.empty(), ());
m_boundaryPostcodes.emplace_back(std::move(postcode), std::move(geometry));
m_boundariesTree.Add(m_boundaryPostcodes.size() - 1,
m_boundaryPostcodes.back().second.GetRect());
m_boundariesTree.Add(m_boundaryPostcodes.size() - 1, m_boundaryPostcodes.back().second.GetRect());
}
}

View File

@@ -23,7 +23,7 @@ using std::pair, std::string, std::unordered_map, std::vector;
DECLARE_EXCEPTION(ParsingError, RootException);
static void ParseFeatureToBrand(json_t * root, string const & field, GeoObjectId::Type type,
vector<pair<GeoObjectId, uint32_t>> & result)
vector<pair<GeoObjectId, uint32_t>> & result)
{
auto arr = base::GetJSONOptionalField(root, field);
if (arr == nullptr)
@@ -42,8 +42,7 @@ static void ParseFeatureToBrand(json_t * root, string const & field, GeoObjectId
}
}
void ParseTranslations(json_t * root, std::set<string> const & keys,
unordered_map<uint32_t, string> & idToKey)
void ParseTranslations(json_t * root, std::set<string> const & keys, unordered_map<uint32_t, string> & idToKey)
{
string const empty;
auto getKey = [&](string & translation) -> string const &

View File

@@ -18,8 +18,7 @@
namespace generator
{
CamerasInfoCollector::CamerasInfoCollector(std::string const & dataFilePath,
std::string const & camerasInfoPath,
CamerasInfoCollector::CamerasInfoCollector(std::string const & dataFilePath, std::string const & camerasInfoPath,
std::string const & osmIdsToFeatureIdsPath)
{
routing::OsmIdToFeatureIds osmIdToFeatureIds;
@@ -90,8 +89,8 @@ void CamerasInfoCollector::Serialize(FileWriter & writer) const
camera.Serialize(writer, prevFeatureId);
}
bool CamerasInfoCollector::ParseIntermediateInfo(
std::string const & camerasInfoPath, routing::OsmIdToFeatureIds const & osmIdToFeatureIds)
bool CamerasInfoCollector::ParseIntermediateInfo(std::string const & camerasInfoPath,
routing::OsmIdToFeatureIds const & osmIdToFeatureIds)
{
FileReader reader(camerasInfoPath);
ReaderSource<FileReader> src(reader);
@@ -131,8 +130,8 @@ bool CamerasInfoCollector::ParseIntermediateInfo(
if (relatedWaysNumber > std::numeric_limits<uint8_t>::max())
{
badCamera = true;
LOG(LERROR, ("Number of related to camera ways should be interval from 0 to 255.",
"lat(", lat, "), lon(", lon, ")"));
LOG(LERROR,
("Number of related to camera ways should be interval from 0 to 255.", "lat(", lat, "), lon(", lon, ")"));
}
std::vector<routing::SpeedCameraMwmPosition> ways;
@@ -159,8 +158,7 @@ bool CamerasInfoCollector::ParseIntermediateInfo(
return true;
}
void CamerasInfoCollector::Camera::FindClosestSegment(FrozenDataSource const & dataSource,
MwmSet::MwmId const & mwmId)
void CamerasInfoCollector::Camera::FindClosestSegment(FrozenDataSource const & dataSource, MwmSet::MwmId const & mwmId)
{
if (!m_data.m_ways.empty() && FindClosestSegmentInInnerWays(dataSource, mwmId))
return;
@@ -168,7 +166,6 @@ void CamerasInfoCollector::Camera::FindClosestSegment(FrozenDataSource const & d
FindClosestSegmentWithGeometryIndex(dataSource);
}
bool CamerasInfoCollector::Camera::FindClosestSegmentInInnerWays(FrozenDataSource const & dataSource,
MwmSet::MwmId const & mwmId)
{
@@ -201,7 +198,8 @@ void CamerasInfoCollector::Camera::FindClosestSegmentWithGeometryIndex(FrozenDat
double bestCoef = 0.0;
// Look at each segment of roads and find the closest.
auto const updateClosestFeatureCallback = [&](FeatureType & ft) {
auto const updateClosestFeatureCallback = [&](FeatureType & ft)
{
if (ft.GetGeomType() != feature::GeomType::Line)
return;
@@ -243,30 +241,32 @@ void CamerasInfoCollector::Camera::FindClosestSegmentWithGeometryIndex(FrozenDat
}
};
dataSource.ForEachInRect(
updateClosestFeatureCallback,
mercator::RectByCenterXYAndSizeInMeters(m_data.m_center, kSearchCameraRadiusMeters),
scales::GetUpperScale());
dataSource.ForEachInRect(updateClosestFeatureCallback,
mercator::RectByCenterXYAndSizeInMeters(m_data.m_center, kSearchCameraRadiusMeters),
scales::GetUpperScale());
if (found)
m_data.m_ways.emplace_back(bestFeatureId, bestSegmentId, bestCoef);
}
std::optional<std::pair<double, uint32_t>> CamerasInfoCollector::Camera::FindMyself(
uint32_t wayFeatureId, FrozenDataSource const & dataSource, MwmSet::MwmId const & mwmId) const
std::optional<std::pair<double, uint32_t>> CamerasInfoCollector::Camera::FindMyself(uint32_t wayFeatureId,
FrozenDataSource const & dataSource,
MwmSet::MwmId const & mwmId) const
{
double coef = 0.0;
bool isRoad = true;
uint32_t result = 0;
bool cannotFindMyself = false;
auto const readFeature = [&](FeatureType & ft) {
auto const readFeature = [&](FeatureType & ft)
{
bool found = false;
isRoad = routing::IsRoad(feature::TypesHolder(ft));
if (!isRoad)
return;
auto const findPoint = [&result, &found, this](m2::PointD const & pt) {
auto const findPoint = [&result, &found, this](m2::PointD const & pt)
{
if (found)
return;
@@ -317,14 +317,12 @@ std::optional<std::pair<double, uint32_t>> CamerasInfoCollector::Camera::FindMys
return {};
}
void CamerasInfoCollector::Camera::Serialize(FileWriter & writer,
uint32_t & prevFeatureId) const
void CamerasInfoCollector::Camera::Serialize(FileWriter & writer, uint32_t & prevFeatureId) const
{
routing::SerializeSpeedCamera(writer, m_data, prevFeatureId);
}
void BuildCamerasInfo(std::string const & dataFilePath,
std::string const & camerasInfoPath,
void BuildCamerasInfo(std::string const & dataFilePath, std::string const & camerasInfoPath,
std::string const & osmIdsToFeatureIdsPath)
{
LOG(LINFO, ("Generating cameras info for", dataFilePath));

View File

@@ -32,8 +32,7 @@ private:
Camera(m2::PointD const & center, uint8_t maxSpeed, std::vector<routing::SpeedCameraMwmPosition> && ways)
: m_data(center, maxSpeed, std::move(ways))
{
}
{}
void ParseDirection()
{
@@ -56,8 +55,7 @@ private:
// Returns empty object, if current feature - |wayId| is not the car road.
// Otherwise returns id of segment from feature with id - |wayId|, which starts (or ends) at camera's
// center and coefficient - where it placed at the segment: 0.0 (or 1.0).
std::optional<std::pair<double, uint32_t>> FindMyself(uint32_t wayFeatureId,
FrozenDataSource const & dataSource,
std::optional<std::pair<double, uint32_t>> FindMyself(uint32_t wayFeatureId, FrozenDataSource const & dataSource,
MwmSet::MwmId const & mwmId) const;
void Serialize(FileWriter & writer, uint32_t & prevFeatureId) const;
@@ -68,8 +66,7 @@ private:
inline static double constexpr kMaxDistFromCameraToClosestSegmentMeters = 20.0;
inline static double constexpr kSearchCameraRadiusMeters = 10.0;
bool ParseIntermediateInfo(std::string const & camerasInfoPath,
routing::OsmIdToFeatureIds const & osmIdToFeatureIds);
bool ParseIntermediateInfo(std::string const & camerasInfoPath, routing::OsmIdToFeatureIds const & osmIdToFeatureIds);
std::vector<Camera> m_cameras;
};

View File

@@ -11,18 +11,16 @@ namespace
double GetMinX(std::vector<m2::RectD> const & cells)
{
CHECK(!cells.empty(), ());
auto const minElementX =
std::min_element(std::cbegin(cells), std::cend(cells),
[](auto const & l, auto const & r) { return l.minX() < r.minX(); });
auto const minElementX = std::min_element(std::cbegin(cells), std::cend(cells),
[](auto const & l, auto const & r) { return l.minX() < r.minX(); });
return minElementX->minX();
}
double GetMinY(std::vector<m2::RectD> const & cells)
{
CHECK(!cells.empty(), ());
auto const minElementY =
std::min_element(std::cbegin(cells), std::cend(cells),
[](auto const & l, auto const & r) { return l.minY() < r.minY(); });
auto const minElementY = std::min_element(std::cbegin(cells), std::cend(cells),
[](auto const & l, auto const & r) { return l.minY() < r.minY(); });
return minElementY->minY();
}
} // namespace
@@ -70,10 +68,9 @@ void CellsMerger::CalcSum()
if (!Has(x, y))
continue;
auto & cell = Get(x, y);
cell.SetBottomLeft(
std::min({TryGet(x - 1, y).GetBottomLeft(), TryGet(x, y - 1).GetBottomLeft(),
TryGet(x - 1, y - 1).GetBottomLeft()}) +
1);
cell.SetBottomLeft(std::min({TryGet(x - 1, y).GetBottomLeft(), TryGet(x, y - 1).GetBottomLeft(),
TryGet(x - 1, y - 1).GetBottomLeft()}) +
1);
}
}
// Bottom right
@@ -84,10 +81,9 @@ void CellsMerger::CalcSum()
if (!Has(x, y))
continue;
auto & cell = Get(x, y);
cell.SetBottomRight(
std::min({TryGet(x + 1, y).GetBottomRight(), TryGet(x, y - 1).GetBottomRight(),
TryGet(x + 1, y - 1).GetBottomRight()}) +
1);
cell.SetBottomRight(std::min({TryGet(x + 1, y).GetBottomRight(), TryGet(x, y - 1).GetBottomRight(),
TryGet(x + 1, y - 1).GetBottomRight()}) +
1);
}
}
// Top left
@@ -98,9 +94,9 @@ void CellsMerger::CalcSum()
if (!Has(x, y))
continue;
auto & cell = Get(x, y);
cell.SetTopLeft(std::min({TryGet(x - 1, y).GetTopLeft(), TryGet(x, y + 1).GetTopLeft(),
TryGet(x - 1, y + 1).GetTopLeft()}) +
1);
cell.SetTopLeft(
std::min({TryGet(x - 1, y).GetTopLeft(), TryGet(x, y + 1).GetTopLeft(), TryGet(x - 1, y + 1).GetTopLeft()}) +
1);
}
}
// Top right
@@ -127,10 +123,12 @@ CellWrapper & CellsMerger::Get(m2::PointI const & xy)
return it->second;
}
CellWrapper & CellsMerger::Get(int32_t x, int32_t y) { return Get({x, y}); }
CellWrapper & CellsMerger::Get(int32_t x, int32_t y)
{
return Get({x, y});
}
CellWrapper const & CellsMerger::TryGet(int32_t x, int32_t y,
CellWrapper const & defaultValue) const
CellWrapper const & CellsMerger::TryGet(int32_t x, int32_t y, CellWrapper const & defaultValue) const
{
auto const it = m_matrix.find({x, y});
return it == std::cend(m_matrix) ? defaultValue : it->second;
@@ -144,16 +142,12 @@ m2::PointI CellsMerger::FindBigSquare(m2::PointI const & xy, m2::PointI const &
{
auto const xMinMax = std::minmax(currXy.x, xy.x);
for (int32_t x = xMinMax.first; x <= xMinMax.second; ++x)
{
if (!Has({x, currXy.y}))
return prevXy;
}
auto const yMinMax = std::minmax(currXy.y, xy.y);
for (int32_t y = yMinMax.first; y <= yMinMax.second; ++y)
{
if (!Has({currXy.x, y}))
return prevXy;
}
prevXy = currXy;
currXy += direction;
}
@@ -163,16 +157,14 @@ std::optional<m2::PointI> CellsMerger::FindDirection(m2::PointI const & startXy)
{
std::array<std::pair<size_t, m2::PointI>, 4> directionsWithWeight;
std::array<m2::PointI, 4> const directions{{{1, 1}, {-1, 1}, {1, -1}, {-1, -1}}};
base::Transform(directions, std::begin(directionsWithWeight),
[&](auto const & direction) {
return std::make_pair(
TryGet(startXy.x + direction.x, startXy.y).GetSum() +
TryGet(startXy.x, startXy.y + direction.y).GetSum() +
TryGet(startXy.x + direction.x, startXy.y + direction.y).GetSum(),
direction);
});
auto const direction =
std::max_element(std::cbegin(directionsWithWeight), std::cend(directionsWithWeight))->second;
base::Transform(directions, std::begin(directionsWithWeight), [&](auto const & direction)
{
return std::make_pair(TryGet(startXy.x + direction.x, startXy.y).GetSum() +
TryGet(startXy.x, startXy.y + direction.y).GetSum() +
TryGet(startXy.x + direction.x, startXy.y + direction.y).GetSum(),
direction);
});
auto const direction = std::max_element(std::cbegin(directionsWithWeight), std::cend(directionsWithWeight))->second;
return Has(startXy + direction) ? direction : std::optional<m2::PointI>{};
}
@@ -181,15 +173,19 @@ void CellsMerger::Remove(m2::PointI const & minXy, m2::PointI const & maxXy)
auto const xMinMax = std::minmax(minXy.x, maxXy.x);
auto const yMinMax = std::minmax(minXy.y, maxXy.y);
for (int32_t x = xMinMax.first; x <= xMinMax.second; ++x)
{
for (int32_t y = yMinMax.first; y <= yMinMax.second; ++y)
m_matrix.erase({x, y});
}
}
bool CellsMerger::Has(int32_t x, int32_t y) const { return m_matrix.count({x, y}) != 0; }
bool CellsMerger::Has(int32_t x, int32_t y) const
{
return m_matrix.count({x, y}) != 0;
}
bool CellsMerger::Has(const m2::PointI & xy) const { return Has(xy.x, xy.y); }
bool CellsMerger::Has(m2::PointI const & xy) const
{
return Has(xy.x, xy.y);
}
std::optional<m2::PointI> CellsMerger::FindMax() const
{

View File

@@ -58,8 +58,7 @@ private:
bool Has(m2::PointI const & xy) const;
CellWrapper & Get(m2::PointI const & xy);
CellWrapper & Get(int32_t x, int32_t y);
CellWrapper const & TryGet(int32_t x, int32_t y,
CellWrapper const & defaultValue = CellWrapper::kEmpty) const;
CellWrapper const & TryGet(int32_t x, int32_t y, CellWrapper const & defaultValue = CellWrapper::kEmpty) const;
void CalcSum();
std::optional<m2::PointI> FindMax() const;

View File

@@ -35,10 +35,7 @@ bool BuildCentersTableFromDataFile(std::string const & filename, bool forceRebui
FeaturesVector const features(rcont, header, table.get(), nullptr);
builder.SetGeometryParams(header.GetBounds());
features.ForEach([&](FeatureType & ft, uint32_t featureId)
{
builder.Put(featureId, feature::GetCenter(ft));
});
features.ForEach([&](FeatureType & ft, uint32_t featureId) { builder.Put(featureId, feature::GetCenter(ft)); });
}
{

View File

@@ -2,9 +2,9 @@
#include "defines.hpp"
#include "indexer/features_vector.hpp"
#include "indexer/classificator.hpp"
#include "indexer/feature_visibility.hpp"
#include "indexer/features_vector.hpp"
#include "base/logging.hpp"
@@ -44,4 +44,4 @@ void ReadFeatures(std::string const & fName)
LOG(LINFO, ("OK"));
}
} // namespace check_model
} // namespace check_model

View File

@@ -10,8 +10,7 @@
namespace generator
{
// todo(@m) Make test ids a new source in base::GeoObjectId?
using OsmIdToBoundariesTable =
base::ClusteringMap<base::GeoObjectId, indexer::CityBoundary>;
using OsmIdToBoundariesTable = base::ClusteringMap<base::GeoObjectId, indexer::CityBoundary>;
using TestIdToBoundariesTable = base::ClusteringMap<uint64_t, indexer::CityBoundary>;
bool BuildCitiesBoundaries(std::string const & dataPath, OsmIdToBoundariesTable & table);

View File

@@ -13,7 +13,8 @@ CitiesBoundariesChecker::CitiesBoundariesChecker(CitiesBoundaries const & cities
bool CitiesBoundariesChecker::InCity(m2::PointD const & point) const
{
bool result = false;
m_tree.ForEachInRect(m2::RectD(point, point), [&](indexer::CityBoundary const & cityBoundary) {
m_tree.ForEachInRect(m2::RectD(point, point), [&](indexer::CityBoundary const & cityBoundary)
{
if (result)
return;

View File

@@ -11,8 +11,8 @@
#include "search/localities_source.hpp"
#include "search/mwm_context.hpp"
#include "coding/files_container.hpp"
#include "coding/file_writer.hpp"
#include "coding/files_container.hpp"
#include "base/cancellable.hpp"
#include "base/checked_cast.hpp"
@@ -44,7 +44,8 @@ void WriteCitiesIdsSectionToFile(std::string const & dataPath,
{
indexer::FeatureIdToGeoObjectIdBimapMem map;
auto const localities = generator::GetLocalities(dataPath);
localities.ForEach([&](uint64_t fid64) {
localities.ForEach([&](uint64_t fid64)
{
auto const fid = base::checked_cast<uint32_t>(fid64);
auto const it = mapping.find(fid);
if (it == mapping.end())
@@ -58,10 +59,9 @@ void WriteCitiesIdsSectionToFile(std::string const & dataPath,
auto const hasOldOsmId = map.GetValue(fid, oldOsmId);
auto const hasOldFid = map.GetKey(osmId, oldFid);
LOG(LWARNING,
("Could not add the pair (", fid, ",", osmId,
") to the cities ids section; old fid:", (hasOldFid ? DebugPrint(oldFid) : "none"),
"old osmId:", (hasOldOsmId ? DebugPrint(oldOsmId) : "none")));
LOG(LWARNING, ("Could not add the pair (", fid, ",", osmId,
") to the cities ids section; old fid:", (hasOldFid ? DebugPrint(oldFid) : "none"),
"old osmId:", (hasOldOsmId ? DebugPrint(oldOsmId) : "none")));
}
});
@@ -73,8 +73,7 @@ void WriteCitiesIdsSectionToFile(std::string const & dataPath,
indexer::FeatureIdToGeoObjectIdSerDes::Serialize(*sink, map);
auto const pos1 = sink->Pos();
LOG(LINFO,
("Serialized cities ids. Number of entries:", map.Size(), "Size in bytes:", pos1 - pos0));
LOG(LINFO, ("Serialized cities ids. Number of entries:", map.Size(), "Size in bytes:", pos1 - pos0));
}
} // namespace

View File

@@ -23,8 +23,7 @@ namespace routing_builder
using generator::CitiesBoundariesChecker;
using std::string, std::vector;
void LoadCitiesBoundariesGeometry(string const & boundariesPath,
CitiesBoundariesChecker::CitiesBoundaries & result)
void LoadCitiesBoundariesGeometry(string const & boundariesPath, CitiesBoundariesChecker::CitiesBoundaries & result)
{
if (!Platform::IsFileExistsByFullPath(boundariesPath))
{
@@ -44,8 +43,8 @@ void LoadCitiesBoundariesGeometry(string const & boundariesPath,
{
++points;
double const radiusM = ftypes::GetRadiusByPopulationForRouting(loc.GetPopulation(), loc.GetPlace());
result.emplace_back(ms::CreateCircleGeometryOnEarth(
mercator::ToLatLon(loc.m_center), radiusM, 30.0 /* angleStepDegree */));
result.emplace_back(
ms::CreateCircleGeometryOnEarth(mercator::ToLatLon(loc.m_center), radiusM, 30.0 /* angleStepDegree */));
}
else
{
@@ -63,7 +62,6 @@ void LoadCitiesBoundariesGeometry(string const & boundariesPath,
/// according to |table|.
vector<uint32_t> CalcRoadFeatureIds(string const & dataPath, string const & boundariesPath)
{
CitiesBoundariesChecker::CitiesBoundaries citiesBoundaries;
LoadCitiesBoundariesGeometry(boundariesPath, citiesBoundaries);
CitiesBoundariesChecker const checker(citiesBoundaries);
@@ -80,10 +78,8 @@ vector<uint32_t> CalcRoadFeatureIds(string const & dataPath, string const & boun
size_t inCityPointsCounter = 0;
size_t const count = ft.GetPointsCount();
for (size_t i = 0; i < count; ++i)
{
if (checker.InCity(ft.GetPoint(i)))
++inCityPointsCounter;
}
// Our approximation of boundary overestimates it, because of different
// bounding boxes (in order to increase performance). So we don't want

View File

@@ -14,7 +14,8 @@ namespace generator
{
// The class ClustersFinder finds clusters of objects for which IsSameFunc returns true.
// RadiusFunc should return the same radius for all objects in one cluster.
template <class T> class ClustersFinder
template <class T>
class ClustersFinder
{
public:
using PtrT = T const *;
@@ -22,7 +23,9 @@ public:
using IsSameFunc = std::function<bool(T const &, T const &)>;
ClustersFinder(std::vector<T> const & container, RadiusFunc radiusFunc, IsSameFunc isSameFunc)
: m_container(container), m_radiusFunc(std::move(radiusFunc)), m_isSameFunc(std::move(isSameFunc))
: m_container(container)
, m_radiusFunc(std::move(radiusFunc))
, m_isSameFunc(std::move(isSameFunc))
{
for (auto const & e : m_container)
m_tree.Add(&e);
@@ -78,10 +81,7 @@ private:
{
m2::RectD bbox;
auto const dist = m_radiusFunc(*p);
GetLimitRect(*p).ForEachCorner([&](auto const & p)
{
bbox.Add(mercator::RectByCenterXYAndSizeInMeters(p, dist));
});
GetLimitRect(*p).ForEachCorner([&](auto const & p) { bbox.Add(mercator::RectByCenterXYAndSizeInMeters(p, dist)); });
return bbox;
}
@@ -93,7 +93,8 @@ private:
/// @return Vector of equal place clusters, like pointers from input \a container.
template <class T, class RadiusFnT, class IsSameFnT>
std::vector<std::vector<T const *>> GetClusters(std::vector<T> const & container, RadiusFnT && radiusFunc, IsSameFnT && isSameFunc)
std::vector<std::vector<T const *>> GetClusters(std::vector<T> const & container, RadiusFnT && radiusFunc,
IsSameFnT && isSameFunc)
{
return ClustersFinder<T>(container, std::forward<RadiusFnT>(radiusFunc), std::forward<IsSameFnT>(isSameFunc)).Find();
}

View File

@@ -15,7 +15,6 @@
#include <functional>
#include <thread>
namespace coastlines_generator
{
using RegionT = m2::RegionI;
@@ -53,9 +52,12 @@ class DoAddToTree : public FeatureEmitterIFace
public:
explicit DoAddToTree(CoastlineFeaturesGenerator & rMain)
: m_rMain(rMain), m_notMergedCoastsCount(0), m_totalNotMergedCoastsPoints(0) {}
: m_rMain(rMain)
, m_notMergedCoastsCount(0)
, m_totalNotMergedCoastsPoints(0)
{}
virtual void operator() (feature::FeatureBuilder const & fb)
virtual void operator()(feature::FeatureBuilder const & fb)
{
if (fb.IsGeometryClosed())
m_rMain.AddRegionToTree(fb);
@@ -64,30 +66,20 @@ public:
base::GeoObjectId const firstWay = fb.GetFirstOsmId();
base::GeoObjectId const lastWay = fb.GetLastOsmId();
if (firstWay == lastWay)
LOG(LINFO, ("Not merged coastline, way", firstWay.GetSerialId(), "(", fb.GetPointsCount(),
"points)"));
LOG(LINFO, ("Not merged coastline, way", firstWay.GetSerialId(), "(", fb.GetPointsCount(), "points)"));
else
LOG(LINFO, ("Not merged coastline, ways", firstWay.GetSerialId(), "to",
lastWay.GetSerialId(), "(", fb.GetPointsCount(), "points)"));
LOG(LINFO, ("Not merged coastline, ways", firstWay.GetSerialId(), "to", lastWay.GetSerialId(), "(",
fb.GetPointsCount(), "points)"));
++m_notMergedCoastsCount;
m_totalNotMergedCoastsPoints += fb.GetPointsCount();
}
}
bool HasNotMergedCoasts() const
{
return m_notMergedCoastsCount != 0;
}
bool HasNotMergedCoasts() const { return m_notMergedCoastsCount != 0; }
size_t GetNotMergedCoastsCount() const
{
return m_notMergedCoastsCount;
}
size_t GetNotMergedCoastsCount() const { return m_notMergedCoastsCount; }
size_t GetNotMergedCoastsPoints() const
{
return m_totalNotMergedCoastsPoints;
}
size_t GetNotMergedCoastsPoints() const { return m_totalNotMergedCoastsPoints; }
};
class DoDifference
@@ -129,8 +121,8 @@ public:
m_res[i].ForEachPoint([&points](PointT const & p)
{
points.push_back(PointUToPointD(
m2::PointU(static_cast<uint32_t>(p.x), static_cast<uint32_t>(p.y)), kPointCoordBits));
points.push_back(
PointUToPointD(m2::PointU(static_cast<uint32_t>(p.x), static_cast<uint32_t>(p.y)), kPointCoordBits));
});
fb.AddPolygon(std::move(points));
@@ -139,8 +131,7 @@ public:
};
} // namespace coastlines_generator
CoastlineFeaturesGenerator::CoastlineFeaturesGenerator()
: m_merger(kPointCoordBits) {}
CoastlineFeaturesGenerator::CoastlineFeaturesGenerator() : m_merger(kPointCoordBits) {}
void CoastlineFeaturesGenerator::AddRegionToTree(feature::FeatureBuilder const & fb)
{
@@ -206,13 +197,10 @@ protected:
Context & m_ctx;
TIndex const & m_index;
RegionInCellSplitter(Context & ctx,TIndex const & index)
: m_ctx(ctx), m_index(index)
{}
RegionInCellSplitter(Context & ctx, TIndex const & index) : m_ctx(ctx), m_index(index) {}
public:
static bool Process(size_t numThreads, size_t baseScale, TIndex const & index,
TProcessResultFunc funcResult)
static bool Process(size_t numThreads, size_t baseScale, TIndex const & index, TProcessResultFunc funcResult)
{
/// @todo Replace with base::ComputationalThreadPool
@@ -246,8 +234,8 @@ public:
using namespace coastlines_generator;
// create rect region
PointT arr[] = {D2I(m2::PointD(minX, minY)), D2I(m2::PointD(minX, maxY)),
D2I(m2::PointD(maxX, maxY)), D2I(m2::PointD(maxX, minY))};
PointT arr[] = {D2I(m2::PointD(minX, minY)), D2I(m2::PointD(minX, maxY)), D2I(m2::PointD(maxX, maxY)),
D2I(m2::PointD(maxX, minY))};
RegionT rectR(arr, arr + ARRAY_SIZE(arr));
// Do 'and' with all regions and accumulate the result, including bound region.
@@ -269,7 +257,7 @@ public:
while (true)
{
std::unique_lock lock(m_ctx.mutexTasks);
m_ctx.listCondVar.wait(lock, [&]{return (!m_ctx.listTasks.empty() || m_ctx.inWork == 0);});
m_ctx.listCondVar.wait(lock, [&] { return (!m_ctx.listTasks.empty() || m_ctx.inWork == 0); });
if (m_ctx.listTasks.empty())
break;
@@ -283,10 +271,8 @@ public:
lock.lock();
// return to queue not ready cells
if (!done)
{
for (int8_t i = 0; i < TCell::MAX_CHILDREN; ++i)
m_ctx.listTasks.push_back(currentCell.Child(i));
}
--m_ctx.inWork;
m_ctx.listCondVar.notify_all();
}
@@ -300,23 +286,24 @@ std::vector<feature::FeatureBuilder> CoastlineFeaturesGenerator::GetFeatures(siz
std::vector<feature::FeatureBuilder> features;
std::mutex featuresMutex;
RegionInCellSplitter::Process(maxThreads, RegionInCellSplitter::kStartLevel, m_tree,
RegionInCellSplitter::Process(
maxThreads, RegionInCellSplitter::kStartLevel, m_tree,
[&](RegionInCellSplitter::TCell const & cell, coastlines_generator::DoDifference & cellData)
{
feature::FeatureBuilder fb;
fb.SetCoastCell(cell.ToInt64(RegionInCellSplitter::kHighLevel + 1));
{
feature::FeatureBuilder fb;
fb.SetCoastCell(cell.ToInt64(RegionInCellSplitter::kHighLevel + 1));
cellData.AssignGeometry(fb);
fb.SetArea();
fb.AddType(coastType);
cellData.AssignGeometry(fb);
fb.SetArea();
fb.AddType(coastType);
// Should represent non-empty geometry
CHECK_GREATER(fb.GetPolygonsCount(), 0, ());
CHECK_GREATER_OR_EQUAL(fb.GetPointsCount(), 3, ());
// Should represent non-empty geometry
CHECK_GREATER(fb.GetPolygonsCount(), 0, ());
CHECK_GREATER_OR_EQUAL(fb.GetPointsCount(), 3, ());
std::lock_guard lock(featuresMutex);
features.emplace_back(std::move(fb));
});
std::lock_guard lock(featuresMutex);
features.emplace_back(std::move(fb));
});
return features;
}

View File

@@ -2,8 +2,8 @@
#include "generator/feature_merger.hpp"
#include "geometry/tree4d.hpp"
#include "geometry/region2d.hpp"
#include "geometry/tree4d.hpp"
#include <vector>
@@ -35,4 +35,4 @@ namespace coastlines_generator
{
/// @param[in] poly Closed polygon where poly.frotn() == poly.back() like in FeatureBuilder.
m2::RegionI CreateRegionI(std::vector<m2::PointD> const & poly);
} // namespace coastlines_generator
} // namespace coastlines_generator

View File

@@ -9,26 +9,16 @@ template <typename T>
class CollectionBase
{
public:
void Append(T const & collector)
{
m_collection.push_back(collector);
}
void Append(T const & collector) { m_collection.push_back(collector); }
void AddCollection(CollectionBase<T> const & collection)
{
std::copy(std::begin(collection.m_collection), std::end(collection.m_collection),
std::back_inserter(m_collection));
std::copy(std::begin(collection.m_collection), std::end(collection.m_collection), std::back_inserter(m_collection));
}
std::vector<T> const & GetCollection() const
{
return m_collection;
}
std::vector<T> const & GetCollection() const { return m_collection; }
bool Empty() const
{
return m_collection.empty();
}
bool Empty() const { return m_collection.empty(); }
protected:
std::vector<T> m_collection;

View File

@@ -14,8 +14,7 @@ BoundaryPostcodeCollector::BoundaryPostcodeCollector(std::string const & filenam
: CollectorInterface(filename)
, m_cache(cache)
, m_featureMakerSimple(cache)
{
}
{}
std::shared_ptr<CollectorInterface> BoundaryPostcodeCollector::Clone(IDRInterfacePtr const & cache) const
{

View File

@@ -59,8 +59,7 @@ void BuildingPartsCollector::BuildingParts::Write(FileWriter & writer, BuildingP
}
// static
BuildingPartsCollector::BuildingParts BuildingPartsCollector::BuildingParts::Read(
ReaderSource<FileReader> & src)
BuildingPartsCollector::BuildingParts BuildingPartsCollector::BuildingParts::Read(ReaderSource<FileReader> & src)
{
BuildingParts bp;
auto const first = base::GeoObjectId(ReadPrimitiveFromSource<uint64_t>(src));
@@ -78,8 +77,7 @@ BuildingPartsCollector::BuildingPartsCollector(std::string const & filename, IDR
: CollectorInterface(filename)
, m_cache(cache)
, m_writer(std::make_unique<FileWriter>(GetTmpFilename()))
{
}
{}
std::shared_ptr<CollectorInterface> BuildingPartsCollector::Clone(IDRInterfacePtr const & cache) const
{
@@ -107,8 +105,7 @@ void BuildingPartsCollector::CollectFeature(feature::FeatureBuilder const & fb,
}
}
std::vector<base::GeoObjectId> BuildingPartsCollector::FindAllBuildingParts(
base::GeoObjectId const & id)
std::vector<base::GeoObjectId> BuildingPartsCollector::FindAllBuildingParts(base::GeoObjectId const & id)
{
std::vector<base::GeoObjectId> buildingParts;
RelationElement relation;
@@ -119,16 +116,12 @@ std::vector<base::GeoObjectId> BuildingPartsCollector::FindAllBuildingParts(
}
for (auto const & v : relation.m_ways)
{
if (v.second == "part")
buildingParts.emplace_back(base::MakeOsmWay(v.first));
}
for (auto const & v : relation.m_relations)
{
if (v.second == "part")
buildingParts.emplace_back(base::MakeOsmRelation(v.first));
}
return buildingParts;
}
@@ -143,22 +136,23 @@ base::GeoObjectId BuildingPartsCollector::FindTopRelation(base::GeoObjectId elId
if (elId.GetType() == base::GeoObjectId::Type::ObsoleteOsmWay)
{
m_cache->ForEachRelationByWayCached(serialId, wrapper);
it = base::FindIf(elements, [&](auto const & idRelation) {
return idRelation.second.GetWayRole(serialId) == "outline";
});
it = base::FindIf(elements,
[&](auto const & idRelation) { return idRelation.second.GetWayRole(serialId) == "outline"; });
}
else if (elId.GetType() == base::GeoObjectId::Type::ObsoleteOsmRelation)
{
m_cache->ForEachRelationByRelationCached(serialId, wrapper);
it = base::FindIf(elements, [&](auto const & idRelation) {
return idRelation.second.GetRelationRole(serialId) == "outline";
});
it = base::FindIf(
elements, [&](auto const & idRelation) { return idRelation.second.GetRelationRole(serialId) == "outline"; });
}
return it != std::end(elements) ? base::MakeOsmRelation(it->first) : base::GeoObjectId();
}
void BuildingPartsCollector::Finish() { m_writer.reset(); }
void BuildingPartsCollector::Finish()
{
m_writer.reset();
}
void BuildingPartsCollector::Save()
{
@@ -197,8 +191,7 @@ BuildingToBuildingPartsMap::BuildingToBuildingPartsMap(std::string const & filen
auto const buildingParts = BuildingPartsCollector::BuildingParts::Read(src);
m_buildingParts.insert(std::end(m_buildingParts), std::begin(buildingParts.m_buildingParts),
std::end(buildingParts.m_buildingParts));
m_outlineToBuildingPart.emplace_back(buildingParts.m_id,
std::move(buildingParts.m_buildingParts));
m_outlineToBuildingPart.emplace_back(buildingParts.m_id, std::move(buildingParts.m_buildingParts));
}
m_outlineToBuildingPart.shrink_to_fit();
@@ -212,12 +205,10 @@ bool BuildingToBuildingPartsMap::HasBuildingPart(base::GeoObjectId const & id)
return std::binary_search(std::cbegin(m_buildingParts), std::cend(m_buildingParts), id);
}
std::vector<base::GeoObjectId> const & BuildingToBuildingPartsMap::GetBuildingPartsByOutlineId(
CompositeId const & id)
std::vector<base::GeoObjectId> const & BuildingToBuildingPartsMap::GetBuildingPartsByOutlineId(CompositeId const & id)
{
auto const it =
std::lower_bound(std::cbegin(m_outlineToBuildingPart), std::cend(m_outlineToBuildingPart), id,
[](auto const & lhs, auto const & rhs) { return lhs.first < rhs; });
auto const it = std::lower_bound(std::cbegin(m_outlineToBuildingPart), std::cend(m_outlineToBuildingPart), id,
[](auto const & lhs, auto const & rhs) { return lhs.first < rhs; });
if (it != std::cend(m_outlineToBuildingPart) && it->first == id)
return it->second;

View File

@@ -26,7 +26,6 @@
#include <algorithm>
namespace routing_builder
{
@@ -82,12 +81,10 @@ CameraCollector::CameraInfo CameraCollector::CameraInfo::Read(ReaderSource<FileR
// static
void CameraCollector::CameraInfo::Write(FileWriter & writer, CameraInfo const & camera)
{
uint32_t const lat =
DoubleToUint32(camera.m_lat, ms::LatLon::kMinLat, ms::LatLon::kMaxLat, kPointCoordBits);
uint32_t const lat = DoubleToUint32(camera.m_lat, ms::LatLon::kMinLat, ms::LatLon::kMaxLat, kPointCoordBits);
WriteToSink(writer, lat);
uint32_t const lon =
DoubleToUint32(camera.m_lon, ms::LatLon::kMinLon, ms::LatLon::kMaxLon, kPointCoordBits);
uint32_t const lon = DoubleToUint32(camera.m_lon, ms::LatLon::kMinLon, ms::LatLon::kMaxLon, kPointCoordBits);
WriteToSink(writer, lon);
WriteToSink(writer, camera.m_speedKmPH);
@@ -159,9 +156,9 @@ void CameraCollector::OrderCollectedData()
}
CameraCollector::CameraCollector(std::string const & filename, IDRInterfacePtr cache)
: generator::CollectorInterface(filename), m_cache(std::move(cache))
{
}
: generator::CollectorInterface(filename)
, m_cache(std::move(cache))
{}
std::shared_ptr<generator::CollectorInterface> CameraCollector::Clone(IDRInterfacePtr const & cache) const
{

View File

@@ -28,7 +28,6 @@ class TestCameraCollector;
/// for more details about input string.
std::optional<double> GetMaxSpeedKmPH(std::string const & maxSpeedString);
class CameraCollector : public generator::CollectorInterface
{
friend class TestCameraCollector;
@@ -72,7 +71,8 @@ protected:
void FillCameraInWays();
template <typename Fn> void ForEachCamera(Fn && toDo)
template <typename Fn>
void ForEachCamera(Fn && toDo)
{
for (auto & p : m_speedCameras)
toDo(p.second);

View File

@@ -17,7 +17,9 @@ namespace generator
{
// This class allows you to work with a group of collectors as with one.
class CollectorCollection : public CollectionBase<std::shared_ptr<CollectorInterface>>, public CollectorInterface
class CollectorCollection
: public CollectionBase<std::shared_ptr<CollectorInterface>>
, public CollectorInterface
{
public:
// CollectorInterface overrides:

View File

@@ -82,8 +82,8 @@ private:
};
} // namespace generator
#define IMPLEMENT_COLLECTOR_IFACE(className) \
void Merge(CollectorInterface const & ci) override \
{ \
dynamic_cast<className const &>(ci).MergeInto(*this); \
#define IMPLEMENT_COLLECTOR_IFACE(className) \
void Merge(CollectorInterface const & ci) override \
{ \
dynamic_cast<className const &>(ci).MergeInto(*this); \
}

View File

@@ -10,9 +10,9 @@ namespace generator
using namespace feature;
MiniRoundaboutCollector::MiniRoundaboutCollector(std::string const & filename, IDRInterfacePtr cache)
: generator::CollectorInterface(filename), m_cache(std::move(cache))
{
}
: generator::CollectorInterface(filename)
, m_cache(std::move(cache))
{}
std::shared_ptr<generator::CollectorInterface> MiniRoundaboutCollector::Clone(IDRInterfacePtr const & cache) const
{
@@ -39,8 +39,7 @@ void MiniRoundaboutCollector::Collect(OsmElement const & element)
}
}
void MiniRoundaboutCollector::CollectFeature(FeatureBuilder const & feature,
OsmElement const & element)
void MiniRoundaboutCollector::CollectFeature(FeatureBuilder const & feature, OsmElement const & element)
{
if (MiniRoundaboutInfo::IsProcessRoad(feature))
m_roads.AddWay(element);

View File

@@ -31,10 +31,8 @@ protected:
void ForEachMiniRoundabout(Fn && toDo)
{
for (auto & p : m_miniRoundabouts)
{
if (m_miniRoundaboutsExceptions.count(p.first) == 0)
toDo(p.second);
}
}
private:

View File

@@ -28,10 +28,10 @@ PlaceBoundariesHolder::Locality::Locality(std::string const & placeType, OsmElem
, m_name(elem.GetTag("name"))
, m_population(osm_element::GetPopulation(elem))
, m_place(ftypes::LocalityFromString(placeType))
{
}
{}
template <class Sink> void PlaceBoundariesHolder::Locality::Serialize(Sink & sink) const
template <class Sink>
void PlaceBoundariesHolder::Locality::Serialize(Sink & sink) const
{
CHECK(TestValid(), ());
@@ -49,7 +49,8 @@ template <class Sink> void PlaceBoundariesHolder::Locality::Serialize(Sink & sin
rw::WriteVectorOfPOD(sink, e);
}
template <class Source> void PlaceBoundariesHolder::Locality::Deserialize(Source & src)
template <class Source>
void PlaceBoundariesHolder::Locality::Deserialize(Source & src)
{
m_place = static_cast<LocalityType>(ReadPrimitiveFromSource<int8_t>(src));
m_placeFromNode = static_cast<LocalityType>(ReadPrimitiveFromSource<int8_t>(src));
@@ -228,8 +229,8 @@ int PlaceBoundariesHolder::GetIndex(IDType id) const
return -1;
}
PlaceBoundariesHolder::Locality const *
PlaceBoundariesHolder::GetBestBoundary(std::vector<IDType> const & ids, m2::PointD const & center) const
PlaceBoundariesHolder::Locality const * PlaceBoundariesHolder::GetBestBoundary(std::vector<IDType> const & ids,
m2::PointD const & center) const
{
Locality const * bestLoc = nullptr;
@@ -311,8 +312,7 @@ void PlaceBoundariesBuilder::Save(std::string const & fileName)
for (auto const & relID : ids)
{
auto const & loc = m_id2loc[relID];
if ((best == nullptr || loc.IsBetterBoundary(*best, e.second.m_name)) &&
loc.IsInBoundary(e.second.m_center))
if ((best == nullptr || loc.IsBetterBoundary(*best, e.second.m_name)) && loc.IsInBoundary(e.second.m_center))
{
best = &loc;
bestID = relID;
@@ -348,22 +348,20 @@ void PlaceBoundariesBuilder::Save(std::string const & fileName)
// Add remaining localities.
for (auto & e : m_id2loc)
{
if (e.second.IsHonestCity())
holder.Add(e.first, std::move(e.second), IDType());
}
holder.Serialize(fileName);
}
// RoutingCityBoundariesCollector ------------------------------------------------------------------
RoutingCityBoundariesCollector::RoutingCityBoundariesCollector(std::string const & filename, IDRInterfacePtr const & cache)
RoutingCityBoundariesCollector::RoutingCityBoundariesCollector(std::string const & filename,
IDRInterfacePtr const & cache)
: CollectorInterface(filename)
, m_cache(cache)
, m_featureMakerSimple(cache)
{
}
{}
std::shared_ptr<CollectorInterface> RoutingCityBoundariesCollector::Clone(IDRInterfacePtr const & cache) const
{
@@ -425,9 +423,7 @@ void RoutingCityBoundariesCollector::Collect(OsmElement const & elem)
{
switch (fb.GetGeomType())
{
case GeomType::Point:
loc.m_center = fb.GetKeyPoint();
break;
case GeomType::Point: loc.m_center = fb.GetKeyPoint(); break;
case GeomType::Area:
/// @todo Move geometry or make parsing geometry without FeatureBuilder class.
loc.m_boundary.push_back(fb.GetOuterGeometry());

View File

@@ -20,8 +20,10 @@ public:
Locality(std::string const & placeType, OsmElement const & elem);
// Used in cpp module only.
template <class Sink> void Serialize(Sink & sink) const;
template <class Source> void Deserialize(Source & src);
template <class Sink>
void Serialize(Sink & sink) const;
template <class Source>
void Deserialize(Source & src);
/// @param[in] placeName Original Node place's name if available to match.
/// @return Is this boundary better than rhs.
@@ -69,7 +71,8 @@ public:
void Add(IDType id, Locality && loc, IDType nodeID);
/// @note Mutable function!
template <class FnT> void ForEachLocality(FnT && fn)
template <class FnT>
void ForEachLocality(FnT && fn)
{
for (auto & loc : m_data)
fn(loc);

View File

@@ -14,8 +14,7 @@
namespace generator
{
CollectorTag::CollectorTag(std::string const & filename, std::string const & tagKey,
Validator const & validator)
CollectorTag::CollectorTag(std::string const & filename, std::string const & tagKey, Validator const & validator)
: CollectorInterface(filename)
, m_tagKey(tagKey)
, m_validator(validator)
@@ -49,7 +48,10 @@ void CollectorTag::Save()
CHECK(base::CopyFileX(GetTmpFilename(), GetFilename()), ());
}
void CollectorTag::OrderCollectedData() { OrderTextFileByLine(GetFilename()); }
void CollectorTag::OrderCollectedData()
{
OrderTextFileByLine(GetFilename());
}
void CollectorTag::MergeInto(CollectorTag & collector) const
{

View File

@@ -23,8 +23,7 @@ class CollectorTag : public CollectorInterface
public:
using Validator = std::function<bool(std::string const & tagValue)>;
explicit CollectorTag(std::string const & filename, std::string const & tagKey,
Validator const & validator);
explicit CollectorTag(std::string const & filename, std::string const & tagKey, Validator const & validator);
// CollectorInterface overrides:
std::shared_ptr<CollectorInterface> Clone(IDRInterfacePtr const & = {}) const override;

View File

@@ -45,8 +45,7 @@
#include <gflags/gflags.h>
DEFINE_string(node_storage, "map",
"Type of storage for intermediate points representation. Available: raw, map, mem.");
DEFINE_string(node_storage, "map", "Type of storage for intermediate points representation. Available: raw, map, mem.");
DEFINE_string(user_resource_path, "", "User defined resource path for classificator.txt and etc.");
DEFINE_string(maps_build_path, "",
"Directory of any of the previous map generations. It is assumed that it will "
@@ -56,7 +55,8 @@ DEFINE_bool(popularity, false, "Build complexes for calculation of popularity of
DEFINE_string(output, "", "Output filename");
DEFINE_bool(debug, false, "Debug mode.");
MAIN_WITH_ERROR_HANDLING([](int argc, char ** argv) {
MAIN_WITH_ERROR_HANDLING([](int argc, char ** argv)
{
CHECK(IsLittleEndian(), ("Only little-endian architectures are supported."));
Platform & pl = GetPlatform();
@@ -86,15 +86,9 @@ MAIN_WITH_ERROR_HANDLING([](int argc, char ** argv) {
std::shared_ptr<generator::FilterInterface> filter = std::make_shared<generator::FilterComplex>();
if (FLAGS_debug)
{
print = static_cast<std::string (*)(generator::HierarchyEntry const &)>(generator::DebugPrint);
}
else
{
print = [](auto const & entry) {
return generator::hierarchy::HierarchyEntryToCsvString(entry);
};
}
print = [](auto const & entry) { return generator::hierarchy::HierarchyEntryToCsvString(entry); };
generator::RawGenerator rawGenerator(genInfo, threadsCount);
auto processor = CreateProcessor(generator::ProcessorType::Complex, rawGenerator.GetQueue(),
@@ -102,15 +96,14 @@ MAIN_WITH_ERROR_HANDLING([](int argc, char ** argv) {
generator::cache::IntermediateDataObjectsCache objectsCache;
auto const cache = std::make_shared<generator::cache::IntermediateData>(objectsCache, genInfo);
auto translator = CreateTranslator(generator::TranslatorType::Complex, processor, cache, genInfo);
auto finalProcessor = std::make_shared<generator::ComplexFinalProcessor>(
genInfo.m_tmpDir, FLAGS_output, threadsCount);
auto finalProcessor =
std::make_shared<generator::ComplexFinalProcessor>(genInfo.m_tmpDir, FLAGS_output, threadsCount);
finalProcessor->SetPrintFunction(print);
finalProcessor->SetGetMainTypeFunction(getMainType);
finalProcessor->SetGetNameFunction(generator::hierarchy::GetName);
finalProcessor->SetFilter(filter);
finalProcessor->UseBuildingPartsInfo(
genInfo.GetIntermediateFileName(BUILDING_PARTS_MAPPING_FILE));
finalProcessor->UseBuildingPartsInfo(genInfo.GetIntermediateFileName(BUILDING_PARTS_MAPPING_FILE));
if (FLAGS_popularity)
{

View File

@@ -18,7 +18,8 @@ bool IsComplex(tree_node::types::Ptr<HierarchyEntry> const & tree)
{
size_t constexpr kNumRequiredTypes = 3;
return tree_node::CountIf(tree, [&](auto const & e) {
return tree_node::CountIf(tree, [&](auto const & e)
{
auto const & isAttraction = ftypes::AttractionsChecker::Instance();
return isAttraction(e.m_type);
}) >= kNumRequiredTypes;
@@ -32,13 +33,12 @@ storage::CountryId GetCountry(tree_node::types::Ptr<HierarchyEntry> const & tree
ComplexLoader::ComplexLoader(std::string const & filename)
{
auto trees = hierarchy::LoadHierachy(filename);
base::EraseIf(trees, [](auto const & e){ return !IsComplex(e); });
base::EraseIf(trees, [](auto const & e) { return !IsComplex(e); });
for (auto const & tree : trees)
m_forests[GetCountry(tree)].Append(tree);
}
tree_node::Forest<HierarchyEntry> const & ComplexLoader::GetForest(
storage::CountryId const & country) const
tree_node::Forest<HierarchyEntry> const & ComplexLoader::GetForest(storage::CountryId const & country) const
{
static tree_node::Forest<HierarchyEntry> const kEmpty;
auto const it = m_forests.find(country);
@@ -48,10 +48,10 @@ tree_node::Forest<HierarchyEntry> const & ComplexLoader::GetForest(
std::unordered_set<CompositeId> ComplexLoader::GetIdsSet() const
{
std::unordered_set<CompositeId> set;
ForEach([&](auto const &, auto const & forest) {
forest.ForEachTree([&](auto const & tree) {
tree_node::ForEach(tree, [&](auto const & entry) { set.emplace(entry.m_id); });
});
ForEach([&](auto const &, auto const & forest)
{
forest.ForEachTree([&](auto const & tree)
{ tree_node::ForEach(tree, [&](auto const & entry) { set.emplace(entry.m_id); }); });
});
return set;
}

View File

@@ -54,13 +54,10 @@ storage::CountryId GetCountry(tree_node::types::Ptr<HierarchyEntry> const & tree
ComplexLoader const & GetOrCreateComplexLoader(std::string const & filename);
template <typename Fn>
tree_node::Forest<complex::Ids> TraformToIdsForest(
tree_node::Forest<HierarchyEntry> const & forest, Fn && fn)
tree_node::Forest<complex::Ids> TraformToIdsForest(tree_node::Forest<HierarchyEntry> const & forest, Fn && fn)
{
tree_node::Forest<complex::Ids> res;
forest.ForEachTree([&](auto const & tree) {
res.Append(tree_node::TransformToTree(tree, std::forward<Fn>(fn)));
});
forest.ForEachTree([&](auto const & tree) { res.Append(tree_node::TransformToTree(tree, std::forward<Fn>(fn))); });
return res;
}
} // namespace generator

View File

@@ -14,14 +14,11 @@ CompositeId::CompositeId(std::string const & str)
}
CompositeId::CompositeId(base::GeoObjectId mainId, base::GeoObjectId additionalId)
: m_mainId(mainId), m_additionalId(additionalId)
{
}
: m_mainId(mainId)
, m_additionalId(additionalId)
{}
CompositeId::CompositeId(base::GeoObjectId mainId)
: CompositeId(mainId, base::GeoObjectId() /* additionalId */)
{
}
CompositeId::CompositeId(base::GeoObjectId mainId) : CompositeId(mainId, base::GeoObjectId() /* additionalId */) {}
bool CompositeId::operator<(CompositeId const & other) const
{

View File

@@ -34,9 +34,6 @@ namespace std
template <>
struct hash<generator::CompositeId>
{
size_t operator()(generator::CompositeId const & id) const
{
return math::Hash(id.m_mainId, id.m_additionalId);
}
size_t operator()(generator::CompositeId const & id) const { return math::Hash(id.m_mainId, id.m_additionalId); }
};
} // namespace std

View File

@@ -18,19 +18,17 @@ namespace generator
{
// CrossMwmOsmWaysCollector ------------------------------------------------------------------------
CrossMwmOsmWaysCollector::CrossMwmOsmWaysCollector(
std::string intermediateDir, AffiliationInterfacePtr affiliation)
: m_intermediateDir(std::move(intermediateDir)), m_affiliation(std::move(affiliation))
{
}
CrossMwmOsmWaysCollector::CrossMwmOsmWaysCollector(std::string intermediateDir, AffiliationInterfacePtr affiliation)
: m_intermediateDir(std::move(intermediateDir))
, m_affiliation(std::move(affiliation))
{}
std::shared_ptr<CollectorInterface> CrossMwmOsmWaysCollector::Clone(IDRInterfacePtr const &) const
{
return std::make_shared<CrossMwmOsmWaysCollector>(m_intermediateDir, m_affiliation);
}
void CrossMwmOsmWaysCollector::CollectFeature(feature::FeatureBuilder const & fb,
OsmElement const & element)
void CrossMwmOsmWaysCollector::CollectFeature(feature::FeatureBuilder const & fb, OsmElement const & element)
{
if (element.m_type != OsmElement::EntityType::Way)
return;
@@ -84,26 +82,18 @@ void CrossMwmOsmWaysCollector::CollectFeature(feature::FeatureBuilder const & fb
// And belongs to both. So we consider such segment as cross mwm segment.
// So the condition that segment certainly lies inside of mwm is:
// both points inside and both points belong to only this mwm.
if (prevPointIn && curPointIn &&
pointsAffiliationsNumber[i] == 1 && pointsAffiliationsNumber[i - 1] == 1)
{
if (prevPointIn && curPointIn && pointsAffiliationsNumber[i] == 1 && pointsAffiliationsNumber[i - 1] == 1)
continue;
}
bool forwardIsEnter;
if (prevPointIn != curPointIn)
{
forwardIsEnter = curPointIn;
}
else if (pointsAffiliationsNumber[i - 1] != 1)
forwardIsEnter = curPointIn;
else if (pointsAffiliationsNumber[i] != 1)
forwardIsEnter = !prevPointIn;
else
{
if (pointsAffiliationsNumber[i - 1] != 1)
forwardIsEnter = curPointIn;
else if (pointsAffiliationsNumber[i] != 1)
forwardIsEnter = !prevPointIn;
else
UNREACHABLE();
}
UNREACHABLE();
prevPointIn = curPointIn;
crossMwmSegments.emplace_back(i - 1 /* segmentId */, forwardIsEnter);
}
@@ -171,8 +161,8 @@ void CrossMwmOsmWaysCollector::CrossMwmInfo::Dump(CrossMwmInfo const & info, std
}
// static
std::set<CrossMwmOsmWaysCollector::CrossMwmInfo>
CrossMwmOsmWaysCollector::CrossMwmInfo::LoadFromFileToSet(std::string const & path)
std::set<CrossMwmOsmWaysCollector::CrossMwmInfo> CrossMwmOsmWaysCollector::CrossMwmInfo::LoadFromFileToSet(
std::string const & path)
{
std::ifstream input(path);
if (!input)

View File

@@ -21,8 +21,7 @@ public:
struct SegmentInfo
{
SegmentInfo() = default;
SegmentInfo(uint32_t id, bool forwardIsEnter)
: m_segmentId(id), m_forwardIsEnter(forwardIsEnter) {}
SegmentInfo(uint32_t id, bool forwardIsEnter) : m_segmentId(id), m_forwardIsEnter(forwardIsEnter) {}
uint32_t m_segmentId = 0;
bool m_forwardIsEnter = false;
@@ -30,7 +29,9 @@ public:
explicit CrossMwmInfo(uint64_t osmId) : m_osmId(osmId) {}
CrossMwmInfo(uint64_t osmId, std::vector<SegmentInfo> crossMwmSegments)
: m_osmId(osmId), m_crossMwmSegments(std::move(crossMwmSegments)) {}
: m_osmId(osmId)
, m_crossMwmSegments(std::move(crossMwmSegments))
{}
bool operator<(CrossMwmInfo const & rhs) const;

View File

@@ -6,8 +6,8 @@
#include "platform/platform.hpp"
#include "coding/files_container.hpp"
#include "coding/file_writer.hpp"
#include "coding/files_container.hpp"
#include "coding/string_utf8_multilang.hpp"
#include "base/file_name_utils.hpp"
@@ -78,23 +78,22 @@ std::string DescriptionsCollectionBuilderStat::LangStatisticsToString() const
if (m_langsStat[code] == 0)
continue;
stream << StringUtf8Multilang::GetLangByCode(static_cast<int8_t>(code))
<< ":" << m_langsStat[code] << " ";
stream << StringUtf8Multilang::GetLangByCode(static_cast<int8_t>(code)) << ":" << m_langsStat[code] << " ";
}
return stream.str();
}
void DescriptionsCollector::operator() (FeatureType & ft, uint32_t featureId)
void DescriptionsCollector::operator()(FeatureType & ft, uint32_t featureId)
{
// auto const & attractionsChecker = ftypes::AttractionsChecker::Instance();
// if (!attractionsChecker(ft))
// return;
// auto const & attractionsChecker = ftypes::AttractionsChecker::Instance();
// if (!attractionsChecker(ft))
// return;
(*this)(ft.GetMetadata().GetWikiURL(), featureId);
}
void DescriptionsCollector::operator() (std::string const & wikiUrl, uint32_t featureId)
void DescriptionsCollector::operator()(std::string const & wikiUrl, uint32_t featureId)
{
descriptions::LangMeta langsMeta;
@@ -127,7 +126,7 @@ void DescriptionsCollector::operator() (std::string const & wikiUrl, uint32_t fe
else
m_stat.IncNumberWikidataIds();
m_collection.m_features.push_back({ featureId, std::move(langsMeta) });
m_collection.m_features.push_back({featureId, std::move(langsMeta)});
}
// static
@@ -143,8 +142,7 @@ std::string DescriptionsCollector::MakePathForWikipedia(std::string const & wiki
}
// static
std::string DescriptionsCollector::MakePathForWikidata(std::string const & wikipediaDir,
std::string const & wikidataId)
std::string DescriptionsCollector::MakePathForWikidata(std::string const & wikipediaDir, std::string const & wikidataId)
{
return base::JoinPath(wikipediaDir, "wikidata", wikidataId);
}
@@ -217,10 +215,8 @@ void DescriptionsSectionBuilder::BuildSection(std::string const & mwmFile, Descr
{
auto const & stat = collector.m_stat;
size_t const size = stat.GetTotalSize();
LOG(LINFO, ("Wiki descriptions for", mwmFile,
"Wikipedia urls =", stat.GetNumberOfWikipediaUrls(),
"Wikidata ids =", stat.GetNumberOfWikidataIds(),
"Total number of pages =", stat.GetNumberOfPages(),
LOG(LINFO, ("Wiki descriptions for", mwmFile, "Wikipedia urls =", stat.GetNumberOfWikipediaUrls(),
"Wikidata ids =", stat.GetNumberOfWikidataIds(), "Total number of pages =", stat.GetNumberOfPages(),
"Total size of added pages (before writing to section) =", size, "bytes"));
if (size == 0)
{
@@ -240,9 +236,7 @@ void DescriptionsSectionBuilder::BuildSection(std::string const & mwmFile, Descr
sectionSize = writer->Pos() - sectionSize;
}
LOG(LINFO, ("Section", DESCRIPTIONS_FILE_TAG, "is built.",
"Disk size =", sectionSize, "bytes",
"Compression ratio =", size / double(sectionSize),
stat.LangStatisticsToString()));
LOG(LINFO, ("Section", DESCRIPTIONS_FILE_TAG, "is built.", "Disk size =", sectionSize, "bytes",
"Compression ratio =", size / double(sectionSize), stat.LangStatisticsToString()));
}
} // namespace generator

View File

@@ -33,7 +33,7 @@ public:
DescriptionsCollectionBuilderStat()
{
CHECK_EQUAL(m_langsStat.size(), StringUtf8Multilang::kMaxSupportedLanguages , ());
CHECK_EQUAL(m_langsStat.size(), StringUtf8Multilang::kMaxSupportedLanguages, ());
}
std::string LangStatisticsToString() const;
@@ -67,11 +67,13 @@ class DescriptionsCollector
public:
DescriptionsCollector(std::string const & wikipediaDir, std::string const & mwmFile,
std::string const & idToWikidataPath = {})
: m_wikidataHelper(mwmFile, idToWikidataPath), m_wikipediaDir(wikipediaDir), m_mwmFile(mwmFile)
: m_wikidataHelper(mwmFile, idToWikidataPath)
, m_wikipediaDir(wikipediaDir)
, m_mwmFile(mwmFile)
{}
void operator() (FeatureType & ft, uint32_t featureId);
void operator() (std::string const & wikiUrl, uint32_t featureId);
void operator()(FeatureType & ft, uint32_t featureId);
void operator()(std::string const & wikiUrl, uint32_t featureId);
static std::string MakePathForWikipedia(std::string const & wikipediaDir, std::string wikipediaUrl);
static std::string MakePathForWikidata(std::string const & wikipediaDir, std::string const & wikidataId);

View File

@@ -4,8 +4,8 @@
#include "indexer/classificator.hpp"
#include "indexer/feature_processor.hpp"
#include "indexer/trie_reader.hpp"
#include "indexer/search_string_utils.hpp"
#include "indexer/trie_reader.hpp"
#include "coding/string_utf8_multilang.hpp"
@@ -50,167 +50,161 @@ struct SearchTokensCollector
uint32_t m_currentCount;
};
class TypesCollector
class TypesCollector
{
vector<uint32_t> m_currFeatureTypes;
public:
typedef std::map<vector<uint32_t>, size_t> value_type;
value_type m_stats;
size_t m_namesCount;
size_t m_totalCount;
TypesCollector() : m_namesCount(0), m_totalCount(0) {}
void operator()(FeatureType & f, uint32_t)
{
vector<uint32_t> m_currFeatureTypes;
++m_totalCount;
auto const primary = f.GetReadableName();
if (!primary.empty())
++m_namesCount;
public:
typedef std::map<vector<uint32_t>, size_t> value_type;
value_type m_stats;
size_t m_namesCount;
size_t m_totalCount;
m_currFeatureTypes.clear();
f.ForEachType([this](uint32_t type) { m_currFeatureTypes.push_back(type); });
CHECK(!m_currFeatureTypes.empty(), ("Feature without any type???"));
TypesCollector() : m_namesCount(0), m_totalCount(0) {}
auto found = m_stats.insert(make_pair(m_currFeatureTypes, 1));
if (!found.second)
found.first->second++;
}
};
void operator()(FeatureType & f, uint32_t)
template <class T>
static bool SortFunc(T const & first, T const & second)
{
return first.second > second.second;
}
void DumpTypes(string const & fPath)
{
TypesCollector doClass;
feature::ForEachFeature(fPath, doClass);
typedef pair<vector<uint32_t>, size_t> stats_elem_type;
typedef vector<stats_elem_type> vec_to_sort;
vec_to_sort vecToSort(doClass.m_stats.begin(), doClass.m_stats.end());
sort(vecToSort.begin(), vecToSort.end(), &SortFunc<stats_elem_type>);
for (auto const & el : vecToSort)
{
cout << el.second << " ";
for (uint32_t i : el.first)
cout << classif().GetFullObjectName(i) << " ";
cout << endl;
}
cout << "Total features: " << doClass.m_totalCount << endl;
cout << "Features with names: " << doClass.m_namesCount << endl;
}
///////////////////////////////////////////////////////////////////
typedef std::map<int8_t, std::map<strings::UniString, pair<unsigned int, string>>> TokensContainerT;
class PrefixesCollector
{
public:
TokensContainerT m_stats;
void operator()(int8_t langCode, std::string_view name)
{
CHECK(!name.empty(), ("Feature name is empty"));
auto const tokens = search::NormalizeAndTokenizeString(name);
for (size_t i = 1; i < tokens.size(); ++i)
{
++m_totalCount;
auto const primary = f.GetReadableName();
if (!primary.empty())
++m_namesCount;
m_currFeatureTypes.clear();
f.ForEachType([this](uint32_t type)
strings::UniString s;
for (size_t numTokens = 0; numTokens < i; ++numTokens)
{
m_currFeatureTypes.push_back(type);
});
CHECK(!m_currFeatureTypes.empty(), ("Feature without any type???"));
auto found = m_stats.insert(make_pair(m_currFeatureTypes, 1));
if (!found.second)
found.first->second++;
s.append(tokens[numTokens].begin(), tokens[numTokens].end());
s.push_back(' ');
}
auto [iter, found] = m_stats[langCode].emplace(s, std::make_pair(1U, name));
if (!found)
iter->second.first++;
}
};
template <class T>
static bool SortFunc(T const & first, T const & second)
{
return first.second > second.second;
}
void DumpTypes(string const & fPath)
void operator()(FeatureType & f, uint32_t) { f.ForEachName(*this); }
};
static size_t constexpr MIN_OCCURRENCE = 3;
void Print(int8_t langCode, TokensContainerT::mapped_type const & container)
{
typedef pair<strings::UniString, pair<unsigned int, string>> NameElemT;
typedef vector<NameElemT> VecToSortT;
VecToSortT v(container.begin(), container.end());
std::sort(v.begin(), v.end(), &SortFunc<NameElemT>);
// do not display prefixes with low occurrences
if (v[0].second.first > MIN_OCCURRENCE)
{
TypesCollector doClass;
feature::ForEachFeature(fPath, doClass);
cout << "Language code: " << StringUtf8Multilang::GetLangByCode(langCode) << endl;
typedef pair<vector<uint32_t>, size_t> stats_elem_type;
typedef vector<stats_elem_type> vec_to_sort;
vec_to_sort vecToSort(doClass.m_stats.begin(), doClass.m_stats.end());
sort(vecToSort.begin(), vecToSort.end(), &SortFunc<stats_elem_type>);
for (auto const & el : vecToSort)
for (auto const & el : v)
{
cout << el.second << " ";
for (uint32_t i : el.first)
cout << classif().GetFullObjectName(i) << " ";
cout << endl;
if (el.second.first <= MIN_OCCURRENCE)
break;
cout << el.second.first << " " << strings::ToUtf8(el.first);
cout << " \"" << el.second.second << "\"" << endl;
}
cout << "Total features: " << doClass.m_totalCount << endl;
cout << "Features with names: " << doClass.m_namesCount << endl;
}
}
///////////////////////////////////////////////////////////////////
void DumpPrefixes(string const & fPath)
{
PrefixesCollector doClass;
feature::ForEachFeature(fPath, doClass);
for (auto const & [langCode, container] : doClass.m_stats)
Print(langCode, container);
}
typedef std::map<int8_t, std::map<strings::UniString, pair<unsigned int, string> > > TokensContainerT;
class PrefixesCollector
void DumpSearchTokens(string const & fPath, size_t maxTokensToShow)
{
using Value = Uint64IndexValue;
FilesContainerR container(std::make_unique<FileReader>(fPath));
feature::DataHeader header(container);
auto const trieRoot = trie::ReadTrie<ModelReaderPtr, ValueList<Value>>(container.GetReader(SEARCH_INDEX_FILE_TAG),
SingleValueSerializer<Value>());
SearchTokensCollector<Value> f;
trie::ForEachRef(*trieRoot, f, strings::UniString());
f.Finish();
for (size_t i = 0; i < std::min(maxTokensToShow, f.m_tokens.size()); ++i)
{
public:
TokensContainerT m_stats;
auto const & s = f.m_tokens[i].second;
cout << f.m_tokens[i].first << " " << strings::ToUtf8(s) << endl;
}
}
void operator()(int8_t langCode, std::string_view name)
void DumpFeatureNames(string const & fPath, string const & lang)
{
int8_t const langIndex = StringUtf8Multilang::GetLangIndex(lang);
feature::ForEachFeature(fPath, [&](FeatureType & f, uint32_t)
{
f.ForEachName([&](int8_t langCode, std::string_view name)
{
CHECK(!name.empty(), ("Feature name is empty"));
auto const tokens = search::NormalizeAndTokenizeString(name);
for (size_t i = 1; i < tokens.size(); ++i)
{
strings::UniString s;
for (size_t numTokens = 0; numTokens < i; ++numTokens)
{
s.append(tokens[numTokens].begin(), tokens[numTokens].end());
s.push_back(' ');
}
auto [iter, found] = m_stats[langCode].emplace(s, std::make_pair(1U, name));
if (!found)
iter->second.first++;
}
}
void operator()(FeatureType & f, uint32_t)
{
f.ForEachName(*this);
}
};
static size_t constexpr MIN_OCCURRENCE = 3;
void Print(int8_t langCode, TokensContainerT::mapped_type const & container)
{
typedef pair<strings::UniString, pair<unsigned int, string> > NameElemT;
typedef vector<NameElemT> VecToSortT;
VecToSortT v(container.begin(), container.end());
std::sort(v.begin(), v.end(), &SortFunc<NameElemT>);
// do not display prefixes with low occurrences
if (v[0].second.first > MIN_OCCURRENCE)
{
cout << "Language code: " << StringUtf8Multilang::GetLangByCode(langCode) << endl;
for (auto const & el : v)
{
if (el.second.first <= MIN_OCCURRENCE)
break;
cout << el.second.first << " " << strings::ToUtf8(el.first);
cout << " \"" << el.second.second << "\"" << endl;
}
}
}
void DumpPrefixes(string const & fPath)
{
PrefixesCollector doClass;
feature::ForEachFeature(fPath, doClass);
for (auto const & [langCode, container] : doClass.m_stats)
Print(langCode, container);
}
void DumpSearchTokens(string const & fPath, size_t maxTokensToShow)
{
using Value = Uint64IndexValue;
FilesContainerR container(std::make_unique<FileReader>(fPath));
feature::DataHeader header(container);
auto const trieRoot = trie::ReadTrie<ModelReaderPtr, ValueList<Value>>(
container.GetReader(SEARCH_INDEX_FILE_TAG), SingleValueSerializer<Value>());
SearchTokensCollector<Value> f;
trie::ForEachRef(*trieRoot, f, strings::UniString());
f.Finish();
for (size_t i = 0; i < std::min(maxTokensToShow, f.m_tokens.size()); ++i)
{
auto const & s = f.m_tokens[i].second;
cout << f.m_tokens[i].first << " " << strings::ToUtf8(s) << endl;
}
}
void DumpFeatureNames(string const & fPath, string const & lang)
{
int8_t const langIndex = StringUtf8Multilang::GetLangIndex(lang);
feature::ForEachFeature(fPath, [&](FeatureType & f, uint32_t)
{
f.ForEachName([&](int8_t langCode, std::string_view name)
{
CHECK(!name.empty(), ("Feature name is empty"));
if (langIndex == StringUtf8Multilang::kUnsupportedLanguageCode)
cout << StringUtf8Multilang::GetLangByCode(langCode) << ' ' << name << endl;
else if (langCode == langIndex)
cout << name << endl;
});
if (langIndex == StringUtf8Multilang::kUnsupportedLanguageCode)
cout << StringUtf8Multilang::GetLangByCode(langCode) << ' ' << name << endl;
else if (langCode == langIndex)
cout << name << endl;
});
}
} // namespace features_dumper
});
}
} // namespace features_dumper

View File

@@ -4,16 +4,16 @@
namespace features_dumper
{
void DumpTypes(std::string const & fPath);
void DumpPrefixes(std::string const & fPath);
void DumpTypes(std::string const & fPath);
void DumpPrefixes(std::string const & fPath);
// Writes top maxTokensToShow tokens sorted by their
// frequency, i.e. by the number of features in
// an mwm that contain the token in their name.
void DumpSearchTokens(std::string const & fPath, size_t maxTokensToShow);
// Writes top maxTokensToShow tokens sorted by their
// frequency, i.e. by the number of features in
// an mwm that contain the token in their name.
void DumpSearchTokens(std::string const & fPath, size_t maxTokensToShow);
// Writes the names of all features in the locale provided by lang
// (e.g. "en", "ru", "sv"). If the locale is not recognized, writes all names
// preceded by their locales.
void DumpFeatureNames(std::string const & fPath, std::string const & lang);
}
// Writes the names of all features in the locale provided by lang
// (e.g. "en", "ru", "sv"). If the locale is not recognized, writes all names
// preceded by their locales.
void DumpFeatureNames(std::string const & fPath, std::string const & lang);
} // namespace features_dumper

View File

@@ -6,16 +6,14 @@
namespace generator
{
template <typename T, typename... Args>
std::enable_if_t<std::is_constructible<T, Args...>::value, std::shared_ptr<T>>
create(Args&&... args)
std::enable_if_t<std::is_constructible<T, Args...>::value, std::shared_ptr<T>> create(Args &&... args)
{
return std::make_shared<T>(std::forward<Args>(args)...);
}
// impossible to construct
template <typename T, typename... Args>
std::enable_if_t<!std::is_constructible<T, Args...>::value, std::shared_ptr<T>>
create(Args&&... )
std::enable_if_t<!std::is_constructible<T, Args...>::value, std::shared_ptr<T>> create(Args &&...)
{
return nullptr;
}

View File

@@ -39,9 +39,7 @@ bool IsEqual(m2::PointD const & p1, m2::PointD const & p2)
bool IsEqual(m2::RectD const & r1, m2::RectD const & r2)
{
return (IsEqual(r1.minX(), r2.minX()) &&
IsEqual(r1.minY(), r2.minY()) &&
IsEqual(r1.maxX(), r2.maxX()) &&
return (IsEqual(r1.minX(), r2.minX()) && IsEqual(r1.minY(), r2.minY()) && IsEqual(r1.maxX(), r2.maxX()) &&
IsEqual(r1.maxY(), r2.maxY()));
}
@@ -52,10 +50,7 @@ bool IsEqual(std::vector<m2::PointD> const & v1, std::vector<m2::PointD> const &
}
} // namespace
FeatureBuilder::FeatureBuilder()
: m_coastCell(-1)
{
}
FeatureBuilder::FeatureBuilder() : m_coastCell(-1) {}
bool FeatureBuilder::IsGeometryClosed() const
{
@@ -76,14 +71,10 @@ m2::PointD FeatureBuilder::GetKeyPoint() const
{
switch (GetGeomType())
{
case GeomType::Point:
return m_center;
case GeomType::Point: return m_center;
case GeomType::Line:
case GeomType::Area:
return GetGeometryCenter();
default:
CHECK(false, ());
return m2::PointD();
case GeomType::Area: return GetGeometryCenter();
default: CHECK(false, ()); return m2::PointD();
}
}
@@ -128,7 +119,7 @@ void FeatureBuilder::AssignArea(PointSeq && outline, Geometry const & holes)
for (PointSeq const & points : holes)
{
ASSERT ( !points.empty(), (*this) );
ASSERT(!points.empty(), (*this));
size_t j = 0;
size_t const count = points.size();
@@ -222,10 +213,8 @@ bool FeatureBuilder::PreSerialize()
auto const & types = GetTypes();
if (ftypes::IsMotorwayJunctionChecker::Instance()(types) ||
(m_params.name.IsEmpty() &&
(ftypes::IsPostPoiChecker::Instance()(types) ||
ftypes::IsRailwaySubwayEntranceChecker::Instance()(types) ||
ftypes::IsEntranceChecker::Instance()(types) ||
ftypes::IsAerowayGateChecker::Instance()(types) ||
(ftypes::IsPostPoiChecker::Instance()(types) || ftypes::IsRailwaySubwayEntranceChecker::Instance()(types) ||
ftypes::IsEntranceChecker::Instance()(types) || ftypes::IsAerowayGateChecker::Instance()(types) ||
ftypes::IsPlatformChecker::Instance()(types))))
{
m_params.name.AddString(StringUtf8Multilang::kDefaultCode, m_params.ref);
@@ -253,11 +242,8 @@ bool FeatureBuilder::PreSerialize()
if (!m_params.ref.empty())
{
auto const & types = GetTypes();
if (m_params.name.IsEmpty() &&
(ftypes::IsPlatformChecker::Instance()(types)))
{
if (m_params.name.IsEmpty() && (ftypes::IsPlatformChecker::Instance()(types)))
m_params.name.AddString(StringUtf8Multilang::kDefaultCode, m_params.ref);
}
m_params.ref.clear();
}
@@ -265,8 +251,7 @@ bool FeatureBuilder::PreSerialize()
m_params.rank = 0;
break;
default:
return false;
default: return false;
}
// Stats shows that 1706197 POIs out of 2258011 have name == brand.
@@ -298,7 +283,7 @@ bool FeatureBuilder::PreSerializeAndRemoveUselessNamesForIntermediate()
// Clear name for features with invisible texts.
// AlexZ: Commented this line to enable captions on subway exits, which
// are not drawn but should be visible in balloons and search results
//RemoveNameIfInvisible();
// RemoveNameIfInvisible();
RemoveUselessNames();
return true;
@@ -312,7 +297,7 @@ void FeatureBuilder::RemoveUselessNames()
// AFAIR, they were very messy in search because they contain places' names.
auto const typeRemover = [](uint32_t type)
{
static TypeSetChecker const checkBoundary({ "boundary", "administrative" });
static TypeSetChecker const checkBoundary({"boundary", "administrative"});
return checkBoundary.IsEqual(type);
};
@@ -367,10 +352,8 @@ bool FeatureBuilder::operator==(FeatureBuilder const & fb) const
return false;
for (auto i = m_polygons.cbegin(), j = fb.m_polygons.cbegin(); i != m_polygons.cend(); ++i, ++j)
{
if (!IsEqual(*i, *j))
return false;
}
return true;
}
@@ -380,8 +363,8 @@ bool FeatureBuilder::IsExactEq(FeatureBuilder const & fb) const
if (m_params.GetGeomType() == GeomType::Point && m_center != fb.m_center)
return false;
return (m_polygons == fb.m_polygons && m_limitRect == fb.m_limitRect &&
m_osmIds == fb.m_osmIds && m_params == fb.m_params && m_coastCell == fb.m_coastCell);
return (m_polygons == fb.m_polygons && m_limitRect == fb.m_limitRect && m_osmIds == fb.m_osmIds &&
m_params == fb.m_params && m_coastCell == fb.m_coastCell);
}
void FeatureBuilder::SerializeForIntermediate(Buffer & data) const
@@ -485,7 +468,7 @@ void FeatureBuilder::SerializeAccuratelyForIntermediate(Buffer & data) const
Buffer tmp(data);
FeatureBuilder fb;
fb.DeserializeAccuratelyFromIntermediate(tmp);
ASSERT ( fb == *this, ("Source feature: ", *this, "Deserialized feature: ", fb) );
ASSERT(fb == *this, ("Source feature: ", *this, "Deserialized feature: ", fb));
#endif
}
@@ -522,9 +505,15 @@ void FeatureBuilder::DeserializeAccuratelyFromIntermediate(Buffer & data)
CHECK(IsValid(), (*this));
}
void FeatureBuilder::AddOsmId(base::GeoObjectId id) { m_osmIds.push_back(id); }
void FeatureBuilder::AddOsmId(base::GeoObjectId id)
{
m_osmIds.push_back(id);
}
void FeatureBuilder::SetOsmId(base::GeoObjectId id) { m_osmIds.assign(1, id); }
void FeatureBuilder::SetOsmId(base::GeoObjectId id)
{
m_osmIds.assign(1, id);
}
base::GeoObjectId FeatureBuilder::GetFirstOsmId() const
{
@@ -597,10 +586,8 @@ bool FeatureBuilder::IsDrawableInRange(int lowScale, int highScale) const
{
auto const types = GetTypesHolder();
while (lowScale <= highScale)
{
if (IsDrawableForIndex(types, m_limitRect, lowScale++))
return true;
}
return false;
}
@@ -636,8 +623,7 @@ bool FeatureBuilder::PreSerializeAndRemoveUselessNamesForMwm(SupportingData cons
return true;
}
void FeatureBuilder::SerializeForMwm(SupportingData & data,
serial::GeometryCodingParams const & params) const
void FeatureBuilder::SerializeForMwm(SupportingData & data, serial::GeometryCodingParams const & params) const
{
data.m_buffer.clear();
@@ -654,7 +640,7 @@ void FeatureBuilder::SerializeForMwm(SupportingData & data,
uint8_t trgCount = base::asserted_cast<uint8_t>(data.m_innerTrg.size());
if (trgCount > 0)
{
ASSERT_GREATER ( trgCount, 2, () );
ASSERT_GREATER(trgCount, 2, ());
trgCount -= 2;
}
@@ -735,10 +721,8 @@ bool FeatureBuilder::IsValid() const
return false;
for (auto const & points : geom)
{
if (points.size() < 3)
return false;
}
}
return true;
@@ -756,9 +740,8 @@ std::string DebugPrint(FeatureBuilder const & fb)
default: out << "ERROR: unknown geometry type"; break;
}
out << " " << DebugPrint(mercator::ToLatLon(fb.GetLimitRect()))
<< " " << DebugPrint(fb.GetParams())
<< " " << fb.DebugPrintIDs();
out << " " << DebugPrint(mercator::ToLatLon(fb.GetLimitRect())) << " " << DebugPrint(fb.GetParams()) << " "
<< fb.DebugPrintIDs();
return out.str();
}

View File

@@ -70,10 +70,7 @@ public:
bool IsGeometryClosed() const;
static m2::PointD GetGeometryCenter(PointSeq const & pts);
m2::PointD GetGeometryCenter() const
{
return GetGeometryCenter(GetOuterGeometry());
}
m2::PointD GetGeometryCenter() const { return GetGeometryCenter(GetOuterGeometry()); }
m2::PointD GetKeyPoint() const;
size_t GetPointsCount() const;
size_t GetPolygonsCount() const { return m_polygons.size(); }
@@ -89,10 +86,8 @@ public:
else
{
for (auto const & points : m_polygons)
{
for (auto const & pt : points)
toDo(pt);
}
}
}
@@ -103,10 +98,8 @@ public:
return toDo(m_center);
for (auto const & points : m_polygons)
{
if (base::AnyOf(points, std::forward<ToDo>(toDo)))
return true;
}
return false;
}
@@ -236,24 +229,16 @@ using TypeSerializationVersion = typename std::underlying_type<SerializationVers
struct MinSize
{
auto static const kSerializationVersion =
static_cast<TypeSerializationVersion>(SerializationVersion::MinSize);
auto static const kSerializationVersion = static_cast<TypeSerializationVersion>(SerializationVersion::MinSize);
static void Serialize(FeatureBuilder const & fb, FeatureBuilder::Buffer & data)
{
fb.SerializeForIntermediate(data);
}
static void Serialize(FeatureBuilder const & fb, FeatureBuilder::Buffer & data) { fb.SerializeForIntermediate(data); }
static void Deserialize(FeatureBuilder & fb, FeatureBuilder::Buffer & data)
{
fb.DeserializeFromIntermediate(data);
}
static void Deserialize(FeatureBuilder & fb, FeatureBuilder::Buffer & data) { fb.DeserializeFromIntermediate(data); }
};
struct MaxAccuracy
{
auto static const kSerializationVersion =
static_cast<TypeSerializationVersion>(SerializationVersion::MinSize);
auto static const kSerializationVersion = static_cast<TypeSerializationVersion>(SerializationVersion::MinSize);
static void Serialize(FeatureBuilder const & fb, FeatureBuilder::Buffer & data)
{
@@ -321,10 +306,8 @@ std::vector<FeatureBuilder> ReadAllDatRawFormat(std::string const & fileName)
// Happens in tests when World or Country file is empty (no valid Features to emit).
if (Platform::IsFileExistsByFullPath(fileName))
{
ForEachFeatureRawFormat<SerializationPolicy>(fileName, [&](FeatureBuilder && fb, uint64_t)
{
fbs.emplace_back(std::move(fb));
});
ForEachFeatureRawFormat<SerializationPolicy>(
fileName, [&](FeatureBuilder && fb, uint64_t) { fbs.emplace_back(std::move(fb)); });
}
return fbs;
}
@@ -333,12 +316,11 @@ template <class SerializationPolicy = serialization_policy::MaxAccuracy, class W
class FeatureBuilderWriter
{
public:
explicit FeatureBuilderWriter(std::string const & filename,
bool mangleName = false,
explicit FeatureBuilderWriter(std::string const & filename, bool mangleName = false,
FileWriter::Op op = FileWriter::Op::OP_WRITE_TRUNCATE)
: m_filename(filename)
, m_mangleName(mangleName)
, m_writer(std::make_unique<Writer>(m_mangleName ? m_filename + "_" : m_filename, op))
, m_writer(std::make_unique<Writer>(m_mangleName ? m_filename + "_" : m_filename, op))
{
// TODO(maksimandrianov): I would like to support the verification of serialization versions,
// but this requires reworking of FeatureCollector class and its derived classes. It is in
@@ -346,11 +328,9 @@ public:
// static_cast<serialization_policy::TypeSerializationVersion>(SerializationPolicy::kSerializationVersion));
}
explicit FeatureBuilderWriter(std::string const & filename,
FileWriter::Op op)
explicit FeatureBuilderWriter(std::string const & filename, FileWriter::Op op)
: FeatureBuilderWriter(filename, false /* mangleName */, op)
{
}
{}
~FeatureBuilderWriter()
{
@@ -363,10 +343,7 @@ public:
}
}
void Write(FeatureBuilder const & fb)
{
Write(*m_writer, fb);
}
void Write(FeatureBuilder const & fb) { Write(*m_writer, fb); }
template <typename Sink>
static void Write(Sink & writer, FeatureBuilder const & fb)

View File

@@ -8,9 +8,10 @@ class FeatureBuilder;
class FeatureEmitterIFace
{
// Disable deletion via this interface, because some dtors in derived classes are noexcept(false).
protected:
~FeatureEmitterIFace() = default;
public:
virtual void operator() (feature::FeatureBuilder const &) = 0;
virtual void operator()(feature::FeatureBuilder const &) = 0;
};

View File

@@ -5,9 +5,9 @@
#include "generator/intermediate_data.hpp"
#include "generator/intermediate_elements.hpp"
#include "geometry/mercator.hpp"
#include "indexer/cell_id.hpp"
#include "indexer/data_header.hpp"
#include "geometry/mercator.hpp"
#include "coding/varint.hpp"
@@ -27,9 +27,9 @@
namespace feature
{
FeaturesCollector::FeaturesCollector(std::string const & fName, FileWriter::Op op)
: m_dataFile(fName, op), m_writeBuffer(kBufferSize)
{
}
: m_dataFile(fName, op)
, m_writeBuffer(kBufferSize)
{}
FeaturesCollector::~FeaturesCollector()
{
@@ -77,7 +77,8 @@ void FeaturesCollector::Write(char const * src, size_t size)
m_writePosition += part_size;
size -= part_size;
src += part_size;
} while (size > 0);
}
while (size > 0);
}
uint32_t FeaturesCollector::WriteFeatureBase(std::vector<char> const & bytes, FeatureBuilder const & fb)
@@ -104,7 +105,9 @@ uint32_t FeaturesCollector::Collect(FeatureBuilder const & fb)
FeaturesAndRawGeometryCollector::FeaturesAndRawGeometryCollector(std::string const & featuresFileName,
std::string const & rawGeometryFileName)
: FeaturesCollector(featuresFileName), m_rawGeometryFileStream(rawGeometryFileName) {}
: FeaturesCollector(featuresFileName)
, m_rawGeometryFileStream(rawGeometryFileName)
{}
FeaturesAndRawGeometryCollector::~FeaturesAndRawGeometryCollector()
{
@@ -128,8 +131,7 @@ uint32_t FeaturesAndRawGeometryCollector::Collect(FeatureBuilder const & fb)
{
uint64_t numPoints = points.size();
m_rawGeometryFileStream.Write(&numPoints, sizeof(numPoints));
m_rawGeometryFileStream.Write(points.data(),
sizeof(FeatureBuilder::PointSeq::value_type) * points.size());
m_rawGeometryFileStream.Write(points.data(), sizeof(FeatureBuilder::PointSeq::value_type) * points.size());
}
return featureId;
}

View File

@@ -52,8 +52,7 @@ class FeaturesAndRawGeometryCollector : public FeaturesCollector
size_t m_rawGeometryCounter = 0;
public:
FeaturesAndRawGeometryCollector(std::string const & featuresFileName,
std::string const & rawGeometryFileName);
FeaturesAndRawGeometryCollector(std::string const & featuresFileName, std::string const & rawGeometryFileName);
~FeaturesAndRawGeometryCollector() override;
uint32_t Collect(FeatureBuilder const & f) override;

View File

@@ -12,9 +12,7 @@ namespace feature
CalculateMidPoints::CalculateMidPoints()
{
m_minDrawableScaleFn = [](FeatureBuilder const & fb)
{
return GetMinDrawableScale(fb.GetTypesHolder(), fb.GetLimitRect());
};
{ return GetMinDrawableScale(fb.GetTypesHolder(), fb.GetLimitRect()); };
}
void CalculateMidPoints::operator()(FeatureBuilder const & ft, uint64_t pos)

View File

@@ -25,7 +25,7 @@ class CalculateMidPoints
{
public:
using CellAndOffset = std::pair<uint64_t, uint64_t>;
using MinDrawableScaleFn = std::function<int (FeatureBuilder const & fb)>;
using MinDrawableScaleFn = std::function<int(FeatureBuilder const & fb)>;
CalculateMidPoints();
@@ -68,10 +68,8 @@ public:
// p is close to the borders of |m_rect|, in which case returns a very large number.
double operator()(m2::PointD const & a, m2::PointD const & b, m2::PointD const & p) const
{
if (AlmostEqualAbs(p.x, m_rect.minX(), m_eps) ||
AlmostEqualAbs(p.x, m_rect.maxX(), m_eps) ||
AlmostEqualAbs(p.y, m_rect.minY(), m_eps) ||
AlmostEqualAbs(p.y, m_rect.maxY(), m_eps))
if (AlmostEqualAbs(p.x, m_rect.minX(), m_eps) || AlmostEqualAbs(p.x, m_rect.maxX(), m_eps) ||
AlmostEqualAbs(p.y, m_rect.minY(), m_eps) || AlmostEqualAbs(p.y, m_rect.maxY(), m_eps))
{
// Points near rect should be in a result simplified vector.
return std::numeric_limits<double>::max();

View File

@@ -11,7 +11,6 @@
#include "geometry/mercator.hpp"
namespace generator
{
using namespace feature;
@@ -24,8 +23,7 @@ std::shared_ptr<FeatureMakerBase> FeatureMakerSimple::Clone() const
void FeatureMakerSimple::ParseParams(FeatureBuilderParams & params, OsmElement & p) const
{
auto const & cl = classif();
ftype::GetNameAndType(&p, params,
[&cl] (uint32_t type) { return cl.IsTypeValid(type); },
ftype::GetNameAndType(&p, params, [&cl](uint32_t type) { return cl.IsTypeValid(type); },
[this](OsmElement const * p) { return GetOrigin(*p); });
}
@@ -59,10 +57,8 @@ std::optional<m2::PointD> FeatureMakerSimple::GetOrigin(OsmElement const & e) co
return {};
}
for (auto const & m : e.m_members)
{
if (m.m_type == OsmElement::EntityType::Node)
return ReadNode(m.m_ref);
}
for (auto const & m : e.m_members)
{
@@ -149,17 +145,12 @@ bool FeatureMakerSimple::BuildFromRelation(OsmElement & p, FeatureBuilderParams
m_queue.push(std::move(fb));
};
helper.GetOuter().ForEachArea(true /* collectID */, [&](auto && pts, auto && ids)
{
createFB(std::move(pts), ids);
});
helper.GetOuter().ForEachArea(true /* collectID */, [&](auto && pts, auto && ids) { createFB(std::move(pts), ids); });
return size != m_queue.size();
}
FeatureMaker::FeatureMaker(IDRInterfacePtr const & cache)
: FeatureMakerSimple(cache)
FeatureMaker::FeatureMaker(IDRInterfacePtr const & cache) : FeatureMakerSimple(cache)
{
m_placeClass = classif().GetTypeByPath({"place"});
}
@@ -171,8 +162,7 @@ std::shared_ptr<FeatureMakerBase> FeatureMaker::Clone() const
void FeatureMaker::ParseParams(FeatureBuilderParams & params, OsmElement & p) const
{
ftype::GetNameAndType(&p, params, &feature::IsUsefulType,
[this](OsmElement const * p) { return GetOrigin(*p); });
ftype::GetNameAndType(&p, params, &feature::IsUsefulType, [this](OsmElement const * p) { return GetOrigin(*p); });
}
bool FeatureMaker::BuildFromRelation(OsmElement & p, FeatureBuilderParams const & params)

View File

@@ -2,14 +2,13 @@
#include "generator/feature_maker_base.hpp"
struct OsmElement;
namespace generator
{
// FeatureMakerSimple is suitable for most cases for simple features.
// It filters features for bad geometry only.
class FeatureMakerSimple: public FeatureMakerBase
class FeatureMakerSimple : public FeatureMakerBase
{
public:
using FeatureMakerBase::FeatureMakerBase;

View File

@@ -17,14 +17,10 @@ bool FeatureMakerBase::Add(OsmElement & element)
ParseParams(params, element);
switch (element.m_type)
{
case OsmElement::EntityType::Node:
return BuildFromNode(element, params);
case OsmElement::EntityType::Way:
return BuildFromWay(element, params);
case OsmElement::EntityType::Relation:
return BuildFromRelation(element, params);
default:
return false;
case OsmElement::EntityType::Node: return BuildFromNode(element, params);
case OsmElement::EntityType::Way: return BuildFromWay(element, params);
case OsmElement::EntityType::Relation: return BuildFromRelation(element, params);
default: return false;
}
}

View File

@@ -8,8 +8,7 @@
using namespace feature;
MergedFeatureBuilder::MergedFeatureBuilder(FeatureBuilder const & fb)
: FeatureBuilder(fb), m_isRound(false)
MergedFeatureBuilder::MergedFeatureBuilder(FeatureBuilder const & fb) : FeatureBuilder(fb), m_isRound(false)
{
m_params.FinishAddingTypes();
}
@@ -60,18 +59,15 @@ void MergedFeatureBuilder::AppendFeature(MergedFeatureBuilder const & fb, bool f
CalcRect(fbG.begin(), fbG.end() - 1, m_limitRect);
}
}
else if (toBack)
{
thisG.insert(thisG.end(), fbG.rbegin() + 1, fbG.rend());
CalcRect(fbG.rbegin() + 1, fbG.rend(), m_limitRect);
}
else
{
if (toBack)
{
thisG.insert(thisG.end(), fbG.rbegin() + 1, fbG.rend());
CalcRect(fbG.rbegin() + 1, fbG.rend(), m_limitRect);
}
else
{
thisG.insert(thisG.begin(), fbG.rbegin(), fbG.rend() - 1);
CalcRect(fbG.rbegin(), fbG.rend() - 1, m_limitRect);
}
thisG.insert(thisG.begin(), fbG.rbegin(), fbG.rend() - 1);
CalcRect(fbG.rbegin(), fbG.rend() - 1, m_limitRect);
}
}
@@ -100,7 +96,7 @@ std::pair<m2::PointD, bool> MergedFeatureBuilder::GetKeyPoint(size_t i) const
i -= sz;
// 4. return last point
ASSERT_EQUAL ( i, 0, () );
ASSERT_EQUAL(i, 0, ());
return std::make_pair(LastPoint(), true);
}
@@ -115,27 +111,23 @@ double MergedFeatureBuilder::GetSquaredLength() const
double sqLen = 0.0;
for (size_t i = 1; i < poly.size(); ++i)
sqLen += poly[i-1].SquaredLength(poly[i]);
sqLen += poly[i - 1].SquaredLength(poly[i]);
return sqLen;
}
FeatureMergeProcessor::Key FeatureMergeProcessor::GetKey(m2::PointD const & p)
{
return PointToInt64Obsolete(p, m_coordBits);
}
FeatureMergeProcessor::FeatureMergeProcessor(uint32_t coordBits)
: m_coordBits(coordBits)
FeatureMergeProcessor::FeatureMergeProcessor(uint32_t coordBits) : m_coordBits(coordBits) {}
void FeatureMergeProcessor::operator()(FeatureBuilder const & fb)
{
this->operator()(new MergedFeatureBuilder(fb));
}
void FeatureMergeProcessor::operator() (FeatureBuilder const & fb)
{
this->operator() (new MergedFeatureBuilder(fb));
}
void FeatureMergeProcessor::operator() (MergedFeatureBuilder * p)
void FeatureMergeProcessor::operator()(MergedFeatureBuilder * p)
{
Key const k1 = GetKey(p->FirstPoint());
Key const k2 = GetKey(p->LastPoint());
@@ -166,7 +158,8 @@ void FeatureMergeProcessor::Remove(Key key, MergedFeatureBuilder const * p)
{
MergedFeatureBuilders & v = i->second;
v.erase(remove(v.begin(), v.end(), p), v.end());
if (v.empty()) m_map.erase(i);
if (v.empty())
m_map.erase(i);
}
}
@@ -180,7 +173,7 @@ void FeatureMergeProcessor::Remove(MergedFeatureBuilder const * p)
Remove(k2, p);
else
{
ASSERT ( p->IsRound(), () );
ASSERT(p->IsRound(), ());
p->ForEachMiddlePoints(std::bind(&FeatureMergeProcessor::Remove1, this, std::placeholders::_1, p));
}
@@ -276,7 +269,8 @@ void FeatureMergeProcessor::DoMerge(FeatureEmitterIFace & emitter)
}
// Delete if the feature was removed from map.
if (isRemoved) delete p;
if (isRemoved)
delete p;
}
if (m_last.NotEmpty())
@@ -292,7 +286,8 @@ uint32_t FeatureTypesProcessor::GetType(char const * arr[], size_t n)
void FeatureTypesProcessor::CorrectType(uint32_t & t) const
{
if (m_dontNormalize.count(t) > 0) return;
if (m_dontNormalize.count(t) > 0)
return;
// 1. get normalized type:
// highway-motorway-bridge => highway-motorway
@@ -309,7 +304,7 @@ void FeatureTypesProcessor::SetMappingTypes(char const * arr1[2], char const * a
m_mapping[GetType(arr1, 2)] = GetType(arr2, 2);
}
MergedFeatureBuilder * FeatureTypesProcessor::operator() (FeatureBuilder const & fb)
MergedFeatureBuilder * FeatureTypesProcessor::operator()(FeatureBuilder const & fb)
{
MergedFeatureBuilder * p = new MergedFeatureBuilder(fb);
@@ -340,22 +335,13 @@ protected:
public:
int m_lowScale, m_upScale;
TypeCheckBase(int lowScale, int upScale)
: m_lowScale(lowScale), m_upScale(upScale)
{
}
TypeCheckBase(int lowScale, int upScale) : m_lowScale(lowScale), m_upScale(upScale) {}
using RangeT = std::pair<int, int>;
static RangeT GetScaleRange(uint32_t type)
{
return feature::GetDrawableScaleRange(type);
}
static RangeT GetScaleRange(uint32_t type) { return feature::GetDrawableScaleRange(type); }
static bool IsEmptyRange(RangeT const & range) { return range.first == -1; }
bool IsBadRange(RangeT const & range) const
{
return (range.first > m_upScale || range.second < m_lowScale);
}
bool IsBadRange(RangeT const & range) const { return (range.first > m_upScale || range.second < m_lowScale); }
};
class TypeCheckWorld : public TypeCheckBase
@@ -363,12 +349,10 @@ class TypeCheckWorld : public TypeCheckBase
public:
bool m_isRegion = false;
TypeCheckWorld() : TypeCheckBase(0, scales::GetUpperWorldScale())
{
}
TypeCheckWorld() : TypeCheckBase(0, scales::GetUpperWorldScale()) {}
/// @return true If |type| should be removed.
bool operator() (uint32_t type)
bool operator()(uint32_t type)
{
// Keep place=region types in World.mwm for search, even when they are not visible.
if (type == GetRegionType())
@@ -385,12 +369,10 @@ public:
class TypeCheckCountry : public TypeCheckBase
{
public:
TypeCheckCountry() : TypeCheckBase(scales::GetUpperWorldScale() + 1, scales::GetUpperStyleScale())
{
}
TypeCheckCountry() : TypeCheckBase(scales::GetUpperWorldScale() + 1, scales::GetUpperStyleScale()) {}
/// @return true If |type| should be removed.
bool operator() (uint32_t type) const
bool operator()(uint32_t type) const
{
// Do not keep place=region in countries.
if (type == GetRegionType())
@@ -427,4 +409,4 @@ bool PreprocessForCountryMap(FeatureBuilder & fb)
{
return !fb.RemoveTypesIf(TypeCheckCountry());
}
} // namespace feature
} // namespace feature

View File

@@ -1,7 +1,7 @@
#pragma once
#include "generator/feature_emitter_iface.hpp"
#include "generator/feature_builder.hpp"
#include "generator/feature_emitter_iface.hpp"
#include <map>
#include <set>
@@ -35,16 +35,18 @@ public:
inline bool PopAnyType(uint32_t & type) { return m_params.PopAnyType(type); }
template <class ToDo> void ForEachChangeTypes(ToDo toDo)
template <class ToDo>
void ForEachChangeTypes(ToDo toDo)
{
for_each(m_params.m_types.begin(), m_params.m_types.end(), toDo);
m_params.FinishAddingTypes();
}
template <class ToDo> void ForEachMiddlePoints(ToDo toDo) const
template <class ToDo>
void ForEachMiddlePoints(ToDo toDo) const
{
PointSeq const & poly = GetOuterGeometry();
for (size_t i = 1; i < poly.size()-1; ++i)
for (size_t i = 1; i < poly.size() - 1; ++i)
toDo(poly[i]);
}
@@ -58,7 +60,7 @@ public:
/// Feature merger.
class FeatureMergeProcessor
{
using Key = int64_t ;
using Key = int64_t;
Key GetKey(m2::PointD const & p);
MergedFeatureBuilder m_last;
@@ -70,10 +72,7 @@ class FeatureMergeProcessor
void Insert(m2::PointD const & pt, MergedFeatureBuilder * p);
void Remove(Key key, MergedFeatureBuilder const * p);
inline void Remove1(m2::PointD const & pt, MergedFeatureBuilder const * p)
{
Remove(GetKey(pt), p);
}
inline void Remove1(m2::PointD const & pt, MergedFeatureBuilder const * p) { Remove(GetKey(pt), p); }
void Remove(MergedFeatureBuilder const * p);
uint8_t m_coordBits;
@@ -81,13 +80,12 @@ class FeatureMergeProcessor
public:
FeatureMergeProcessor(uint32_t coordBits);
void operator() (feature::FeatureBuilder const & fb);
void operator() (MergedFeatureBuilder * p);
void operator()(feature::FeatureBuilder const & fb);
void operator()(MergedFeatureBuilder * p);
void DoMerge(FeatureEmitterIFace & emitter);
};
/// Feature types corrector.
class FeatureTypesProcessor
{
@@ -101,9 +99,10 @@ class FeatureTypesProcessor
class do_change_types
{
FeatureTypesProcessor const & m_pr;
public:
do_change_types(FeatureTypesProcessor const & pr) : m_pr(pr) {}
void operator() (uint32_t & t) { m_pr.CorrectType(t); }
void operator()(uint32_t & t) { m_pr.CorrectType(t); }
};
public:
@@ -111,19 +110,20 @@ public:
void SetMappingTypes(char const * arr1[2], char const * arr2[2]);
/// Leave original types, for example: boundary-administrative-2.
template <size_t N> void SetDontNormalizeType(char const * (&arr)[N])
template <size_t N>
void SetDontNormalizeType(char const * (&arr)[N])
{
m_dontNormalize.insert(GetType(arr, N));
}
MergedFeatureBuilder * operator() (feature::FeatureBuilder const & fb);
MergedFeatureBuilder * operator()(feature::FeatureBuilder const & fb);
};
namespace feature
{
/// @return false If fb became invalid (no any suitable types).
//@{
bool PreprocessForWorldMap(FeatureBuilder & fb);
bool PreprocessForCountryMap(FeatureBuilder & fb);
//@}
}
/// @return false If fb became invalid (no any suitable types).
//@{
bool PreprocessForWorldMap(FeatureBuilder & fb);
bool PreprocessForCountryMap(FeatureBuilder & fb);
//@}
} // namespace feature

View File

@@ -63,8 +63,8 @@ void LayerBase::Add(std::shared_ptr<LayerBase> next)
void RepresentationLayer::Handle(FeatureBuilder & fb)
{
// if (m_complexFeaturesMixer)
// m_complexFeaturesMixer->Process([&](FeatureBuilder & fb){ LayerBase::Handle(fb); }, fb);
// if (m_complexFeaturesMixer)
// m_complexFeaturesMixer->Process([&](FeatureBuilder & fb){ LayerBase::Handle(fb); }, fb);
auto const sourceType = fb.GetMostGenericOsmId().GetType();
auto const geomType = fb.GetGeomType();
@@ -73,9 +73,7 @@ void RepresentationLayer::Handle(FeatureBuilder & fb)
auto const params = fb.GetParams();
switch (sourceType)
{
case base::GeoObjectId::Type::ObsoleteOsmNode:
LayerBase::Handle(fb);
break;
case base::GeoObjectId::Type::ObsoleteOsmNode: LayerBase::Handle(fb); break;
case base::GeoObjectId::Type::ObsoleteOsmWay:
{
switch (geomType)
@@ -104,12 +102,8 @@ void RepresentationLayer::Handle(FeatureBuilder & fb)
}
break;
}
case GeomType::Line:
LayerBase::Handle(fb);
break;
default:
UNREACHABLE();
break;
case GeomType::Line: LayerBase::Handle(fb); break;
default: UNREACHABLE(); break;
}
break;
}
@@ -117,22 +111,14 @@ void RepresentationLayer::Handle(FeatureBuilder & fb)
{
switch (geomType)
{
case GeomType::Area:
HandleArea(fb, params);
break;
case GeomType::Area: HandleArea(fb, params); break;
// We transform place relations into points (see BuildFromRelation).
case GeomType::Point:
LayerBase::Handle(fb);
break;
default:
UNREACHABLE();
break;
case GeomType::Point: LayerBase::Handle(fb); break;
default: UNREACHABLE(); break;
}
break;
}
default:
UNREACHABLE();
break;
default: UNREACHABLE(); break;
}
}
@@ -185,31 +171,22 @@ void RepresentationCoastlineLayer::Handle(FeatureBuilder & fb)
auto const geomType = fb.GetGeomType();
switch (sourceType)
{
case base::GeoObjectId::Type::ObsoleteOsmNode:
break;
case base::GeoObjectId::Type::ObsoleteOsmNode: break;
case base::GeoObjectId::Type::ObsoleteOsmWay:
{
switch (geomType)
{
case GeomType::Area:
case GeomType::Line:
LayerBase::Handle(fb);
break;
default:
UNREACHABLE();
break;
case GeomType::Line: LayerBase::Handle(fb); break;
default: UNREACHABLE(); break;
}
break;
}
case base::GeoObjectId::Type::ObsoleteOsmRelation:
break;
default:
UNREACHABLE();
break;
case base::GeoObjectId::Type::ObsoleteOsmRelation: break;
default: UNREACHABLE(); break;
}
}
void PrepareCoastlineFeatureLayer::Handle(FeatureBuilder & fb)
{
if (fb.IsArea())
@@ -225,10 +202,7 @@ void PrepareCoastlineFeatureLayer::Handle(FeatureBuilder & fb)
LayerBase::Handle(fb);
}
WorldLayer::WorldLayer(std::string const & popularityFilename)
: m_filter(popularityFilename)
{
}
WorldLayer::WorldLayer(std::string const & popularityFilename) : m_filter(popularityFilename) {}
void WorldLayer::Handle(FeatureBuilder & fb)
{

View File

@@ -50,7 +50,7 @@ public:
private:
void HandleArea(feature::FeatureBuilder & fb, FeatureBuilderParams const & params);
//std::shared_ptr<ComplexFeaturesMixer> m_complexFeaturesMixer;
// std::shared_ptr<ComplexFeaturesMixer> m_complexFeaturesMixer;
};
// Responsibility of class PrepareFeatureLayer is the removal of unused types and names,
@@ -112,7 +112,7 @@ class AffiliationsFeatureLayer : public LayerBase
{
public:
AffiliationsFeatureLayer(size_t bufferSize, AffiliationInterfacePtr affiliation,
std::shared_ptr<FeatureProcessorQueue> queue)
std::shared_ptr<FeatureProcessorQueue> queue)
: m_bufferSize(bufferSize)
, m_affiliation(std::move(affiliation))
, m_queue(std::move(queue))

View File

@@ -44,16 +44,13 @@ int32_t Coord2RoughCoord(double d)
struct RoughPoint
{
explicit RoughPoint(m2::PointD const & point)
: x(Coord2RoughCoord(point.x)), y(Coord2RoughCoord(point.y))
{
}
explicit RoughPoint(m2::PointD const & point) : x(Coord2RoughCoord(point.x)), y(Coord2RoughCoord(point.y)) {}
int32_t x;
int32_t y;
};
bool operator< (RoughPoint const & l, RoughPoint const & r)
bool operator<(RoughPoint const & l, RoughPoint const & r)
{
if (l.x != r.x)
return l.x < r.x;
@@ -61,8 +58,7 @@ bool operator< (RoughPoint const & l, RoughPoint const & r)
}
template <typename Cont>
void PrintCont(Cont const & cont, std::string const & title, std::string const & msgText1,
std::string const & msgText2)
void PrintCont(Cont const & cont, std::string const & title, std::string const & msgText1, std::string const & msgText2)
{
std::cout << std::endl << title << std::endl;
for (auto const & a : cont)
@@ -78,13 +74,15 @@ void WriteCSV(Cont const & cont, std::string const & fileName)
}
/// \returns y = k * x + b. It's the expected altitude in meters.
double GetY(double k, double b, double x) { return k * x + b; }
double GetY(double k, double b, double x)
{
return k * x + b;
}
/// \brief Calculates factors |k| and |b| of a line using linear least squares method.
/// \returns false in case of error (e.g. if the line is parallel to the vertical axis)
/// and true otherwise.
bool LinearLeastSquaresFactors(std::vector<double> const & xs, std::vector<double> const & ys, double & k,
double & b)
bool LinearLeastSquaresFactors(std::vector<double> const & xs, std::vector<double> const & ys, double & k, double & b)
{
double constexpr kEpsilon = 1e-6;
size_t const n = xs.size();
@@ -154,8 +152,7 @@ public:
, m_emptyRoadCount(0)
, m_roadPointCount(0)
, m_notRoadCount(0)
{
}
{}
void operator()(FeatureType & f, uint32_t const & id)
{
@@ -196,8 +193,7 @@ public:
continue;
}
// Feature segment length.
double const segmentLengthMeters =
mercator::DistanceOnEarth(f.GetPoint(i - 1), f.GetPoint(i));
double const segmentLengthMeters = mercator::DistanceOnEarth(f.GetPoint(i - 1), f.GetPoint(i));
distFromStartMeters += segmentLengthMeters;
pointDists[i] = distFromStartMeters;
}
@@ -272,8 +268,7 @@ public:
for (uint32_t i = 1; i + 1 < numPoints; ++i)
{
int32_t const deviation =
static_cast<geometry::Altitude>(GetY(k, startAltitude, pointDists[i])) -
pointAltitudes[i];
static_cast<geometry::Altitude>(GetY(k, startAltitude, pointDists[i])) - pointAltitudes[i];
m_diffFromLinear[deviation]++;
}
@@ -337,8 +332,7 @@ int main(int argc, char ** argv)
PrintCont(processor.m_featureLength, "Feature length.", " feature(s) with length ", " meter(s)");
WriteCSV(processor.m_featureLength, "feature_length.csv");
PrintCont(processor.m_segLength, "Feature segment length.", " segment(s) with length ",
" meter(s)");
PrintCont(processor.m_segLength, "Feature segment length.", " segment(s) with length ", " meter(s)");
PrintCont(processor.m_featureWave, "Wave factor", " feature(s) with wave factor ", "");
WriteCSV(processor.m_featureWave, "feature_wave.csv");
@@ -352,8 +346,7 @@ int main(int argc, char ** argv)
PrintCont(processor.m_diffFromLinear, "Altitude deviation of internal feature points from linear model.",
" internal feature point(s) deviate from linear model with ", " meter(s)");
PrintCont(processor.m_leastSquaresDiff,
"Altitude deviation of feature points from least squares line.",
PrintCont(processor.m_leastSquaresDiff, "Altitude deviation of feature points from least squares line.",
" internal feature point(s) deviate from linear model with ", " meter(s)");
using std::cout, std::endl;

View File

@@ -35,7 +35,6 @@
#include <memory>
#include <vector>
namespace feature
{
@@ -58,7 +57,8 @@ public:
m_trgFile.push_back(std::make_unique<TmpFile>(info.GetIntermediateFileName(name, TRIANGLE_FILE_TAG + postfix)));
}
m_addrFile = std::make_unique<FileWriter>(info.GetIntermediateFileName(name + DATA_FILE_EXTENSION, TEMP_ADDR_EXTENSION));
m_addrFile =
std::make_unique<FileWriter>(info.GetIntermediateFileName(name + DATA_FILE_EXTENSION, TEMP_ADDR_EXTENSION));
}
void Finish() override
@@ -104,8 +104,7 @@ public:
header.m_featuresOffset = base::asserted_cast<uint32_t>(w->Pos() - startOffset);
ReaderSource<ModelReaderPtr> src(std::make_unique<FileReader>(m_dataFile.GetName()));
rw::ReadAndWrite(src, *w);
header.m_featuresSize =
base::asserted_cast<uint32_t>(w->Pos() - header.m_featuresOffset - startOffset);
header.m_featuresSize = base::asserted_cast<uint32_t>(w->Pos() - header.m_featuresOffset - startOffset);
auto const endOffset = w->Pos();
w->Seek(startOffset);
@@ -134,8 +133,7 @@ public:
m_metadataBuilder.Freeze(*w);
}
if (m_header.GetType() == DataHeader::MapType::Country ||
m_header.GetType() == DataHeader::MapType::World)
if (m_header.GetType() == DataHeader::MapType::Country || m_header.GetType() == DataHeader::MapType::World)
{
FileWriter osm2ftWriter(m_filename + OSM2FEATURE_FILE_EXTENSION);
m_osm2ft.Write(osm2ftWriter);
@@ -219,8 +217,8 @@ public:
}
else
{
LOG(LDEBUG, ("Area: too small or degenerate 1st (outer) polygon of", polys.size(),
", points count", points.size(), "at scale", i, DebugPrint(fb)));
LOG(LDEBUG, ("Area: too small or degenerate 1st (outer) polygon of", polys.size(), ", points count",
points.size(), "at scale", i, DebugPrint(fb)));
continue;
}
@@ -239,8 +237,8 @@ public:
}
else
{
LOG(LDEBUG, ("Area: too small or degenerate 2nd+ (inner) polygon of", polys.size(),
", points count", points.size(), "at scale", i, DebugPrint(fb)));
LOG(LDEBUG, ("Area: too small or degenerate 2nd+ (inner) polygon of", polys.size(), ", points count",
points.size(), "at scale", i, DebugPrint(fb)));
}
}
@@ -255,11 +253,8 @@ public:
/// @todo Probably, we should store and index OSM's short_name tag.
if (indexer::SynonymsHolder::CanApply(fb.GetTypes()))
{
int8_t const langs[] = {
StringUtf8Multilang::kDefaultCode,
StringUtf8Multilang::kEnglishCode,
StringUtf8Multilang::kInternationalCode
};
int8_t const langs[] = {StringUtf8Multilang::kDefaultCode, StringUtf8Multilang::kEnglishCode,
StringUtf8Multilang::kInternationalCode};
bool added = false;
for (int8_t lang : langs)
@@ -314,9 +309,9 @@ private:
class TmpFile
{
std::unique_ptr<FileWriter> m_writer;
public:
explicit TmpFile(std::string const & filePath)
: m_writer(std::make_unique<FileWriter>(filePath)) {}
explicit TmpFile(std::string const & filePath) : m_writer(std::make_unique<FileWriter>(filePath)) {}
FileWriter & GetWriter() { return *m_writer; }
@@ -371,10 +366,7 @@ bool GenerateFinalFeatures(feature::GenerateInfo const & info, std::string const
LOG(LINFO, ("Calculating middle points"));
// Store cellIds for middle points.
CalculateMidPoints midPoints;
ForEachFeatureRawFormat(srcFilePath, [&midPoints](FeatureBuilder const & fb, uint64_t pos)
{
midPoints(fb, pos);
});
ForEachFeatureRawFormat(srcFilePath, [&midPoints](FeatureBuilder const & fb, uint64_t pos) { midPoints(fb, pos); });
// Sort features by their middle point.
midPoints.Sort();

View File

@@ -6,8 +6,8 @@
#include <cstddef>
#include <optional>
#include <utility>
#include <string>
#include <utility>
#include <vector>
namespace generator
@@ -16,9 +16,10 @@ size_t static const kAffiliationsBufferSize = 512;
struct ProcessedData
{
explicit ProcessedData(feature::FeatureBuilder::Buffer && buffer,
std::vector<std::string> && affiliations)
: m_buffer(std::move(buffer)), m_affiliations(std::move(affiliations)) {}
explicit ProcessedData(feature::FeatureBuilder::Buffer && buffer, std::vector<std::string> && affiliations)
: m_buffer(std::move(buffer))
, m_affiliations(std::move(affiliations))
{}
feature::FeatureBuilder::Buffer m_buffer;
std::vector<std::string> m_affiliations;

View File

@@ -14,11 +14,11 @@ std::shared_ptr<FilterInterface> FilterCollection::Clone() const
bool FilterCollection::IsAccepted(OsmElement const & element) const
{
return base::AllOf(m_collection, [&] (auto const & filter) { return filter->IsAccepted(element); });
return base::AllOf(m_collection, [&](auto const & filter) { return filter->IsAccepted(element); });
}
bool FilterCollection::IsAccepted(feature::FeatureBuilder const & feature) const
{
return base::AllOf(m_collection, [&] (auto const & filter) { return filter->IsAccepted(feature); });
return base::AllOf(m_collection, [&](auto const & filter) { return filter->IsAccepted(feature); });
}
} // namespace generator

View File

@@ -6,7 +6,9 @@
namespace generator
{
// This class allows you to work with a group of filters as with one.
class FilterCollection : public CollectionBase<std::shared_ptr<FilterInterface>>, public FilterInterface
class FilterCollection
: public CollectionBase<std::shared_ptr<FilterInterface>>
, public FilterInterface
{
public:
// FilterInterface overrides:

View File

@@ -22,10 +22,7 @@ public:
return true;
}
bool Contains(T const & key) const
{
return base::IsExist(m_vec, key);
}
bool Contains(T const & key) const { return base::IsExist(m_vec, key); }
private:
std::vector<T> m_vec;
@@ -36,10 +33,9 @@ namespace generator
{
bool FilterData::IsMatch(Tags const & elementTags, Tags const & tags)
{
return base::AllOf(tags, [&](OsmElement::Tag const & t) {
auto const it = base::FindIf(elementTags, [&](OsmElement::Tag const & tag) {
return tag.m_key == t.m_key;
});
return base::AllOf(tags, [&](OsmElement::Tag const & t)
{
auto const it = base::FindIf(elementTags, [&](OsmElement::Tag const & tag) { return tag.m_key == t.m_key; });
return it == std::end(elementTags) ? false : t.m_value == "*" || it->m_value == t.m_value;
});
}
@@ -149,8 +145,7 @@ bool FilterElements::ParseTags(json_t * json, FilterData & fdata)
return true;
}
FilterElements::FilterElements(std::string const & filename)
: m_filename(filename)
FilterElements::FilterElements(std::string const & filename) : m_filename(filename)
{
std::ifstream stream(m_filename);
std::string str((std::istreambuf_iterator<char>(stream)), std::istreambuf_iterator<char>());
@@ -179,7 +174,7 @@ bool FilterElements::NeedSkip(OsmElement const & element) const
}
}
bool FilterElements::NeedSkip(OsmElement const & element, FilterData const & fdata) const
bool FilterElements::NeedSkip(OsmElement const & element, FilterData const & fdata) const
{
return fdata.NeedSkipWithId(element.m_id) || fdata.NeedSkipWithTags(element.Tags());
}

View File

@@ -71,7 +71,7 @@ private:
class FilterElements : public FilterInterface
{
public:
explicit FilterElements(const std::string & filename);
explicit FilterElements(std::string const & filename);
// FilterInterface overrides:
std::shared_ptr<FilterInterface> Clone() const override;

View File

@@ -31,9 +31,7 @@ bool FilterWorld::IsAccepted(feature::FeatureBuilder const & fb) const
if (m_isCityTownVillage(fb.GetTypes()))
return false;
return (IsGoodScale(fb) ||
IsPopularAttraction(fb, m_popularityFilename) ||
IsInternationalAirport(fb));
return (IsGoodScale(fb) || IsPopularAttraction(fb, m_popularityFilename) || IsInternationalAirport(fb));
}
// static

View File

@@ -1,6 +1,6 @@
#include "generator/final_processor_cities.hpp"
#include "generator/final_processor_utils.hpp"
#include "generator/filter_world.hpp"
#include "generator/final_processor_utils.hpp"
#include "generator/place_processor.hpp"
#include <mutex>
@@ -8,14 +8,13 @@
namespace generator
{
FinalProcessorCities::FinalProcessorCities(AffiliationInterfacePtr const & affiliation,
std::string const & mwmPath, size_t threadsCount)
FinalProcessorCities::FinalProcessorCities(AffiliationInterfacePtr const & affiliation, std::string const & mwmPath,
size_t threadsCount)
: FinalProcessorIntermediateMwmInterface(FinalProcessorPriority::Places)
, m_temporaryMwmPath(mwmPath)
, m_affiliation(affiliation)
, m_threadsCount(threadsCount)
{
}
{}
void FinalProcessorCities::Process()
{
@@ -52,10 +51,8 @@ void FinalProcessorCities::Process()
FeatureBuilderWriter writer(base::JoinPath(m_temporaryMwmPath, WORLD_FILE_NAME DATA_FILE_EXTENSION_TMP),
FileWriter::Op::OP_APPEND);
for (auto const & fb : result)
{
if (FilterWorld::IsGoodScale(fb))
writer.Write(fb);
}
}
if (!m_boundariesOutFile.empty())
@@ -65,4 +62,4 @@ void FinalProcessorCities::Process()
}
}
} // namespace generator
} // namespace generator

View File

@@ -8,8 +8,8 @@ namespace generator
class FinalProcessorCities : public FinalProcessorIntermediateMwmInterface
{
public:
FinalProcessorCities(AffiliationInterfacePtr const & affiliation,
std::string const & mwmPath, size_t threadsCount = 1);
FinalProcessorCities(AffiliationInterfacePtr const & affiliation, std::string const & mwmPath,
size_t threadsCount = 1);
void SetCityBoundariesFiles(std::string const & collectorFile, std::string const & boundariesOutFile)
{
@@ -25,4 +25,4 @@ private:
size_t m_threadsCount;
};
} // namespace generator
} // namespace generator

View File

@@ -3,16 +3,15 @@
#include "generator/feature_builder.hpp"
#include "generator/feature_generator.hpp"
namespace generator
{
using namespace feature;
CoastlineFinalProcessor::CoastlineFinalProcessor(std::string const & filename, size_t threadsCount)
: FinalProcessorIntermediateMwmInterface(FinalProcessorPriority::WorldCoasts)
, m_filename(filename), m_threadsCount(threadsCount)
{
}
, m_filename(filename)
, m_threadsCount(threadsCount)
{}
void CoastlineFinalProcessor::SetCoastlinesFilenames(std::string const & geomFilename,
std::string const & rawGeomFilename)
@@ -23,10 +22,8 @@ void CoastlineFinalProcessor::SetCoastlinesFilenames(std::string const & geomFil
void CoastlineFinalProcessor::Process()
{
ForEachFeatureRawFormat<serialization_policy::MaxAccuracy>(m_filename, [this](FeatureBuilder const & fb, uint64_t)
{
m_generator.Process(fb);
});
ForEachFeatureRawFormat<serialization_policy::MaxAccuracy>(
m_filename, [this](FeatureBuilder const & fb, uint64_t) { m_generator.Process(fb); });
FeaturesAndRawGeometryCollector collector(m_coastlineGeomFilename, m_coastlineRawGeomFilename);
// Check and stop if some coasts were not merged.

View File

@@ -12,8 +12,7 @@ class CoastlineFinalProcessor : public FinalProcessorIntermediateMwmInterface
public:
CoastlineFinalProcessor(std::string const & filename, size_t threadsCount);
void SetCoastlinesFilenames(std::string const & geomFilename,
std::string const & rawGeomFilename);
void SetCoastlinesFilenames(std::string const & geomFilename, std::string const & rawGeomFilename);
// FinalProcessorIntermediateMwmInterface overrides:
void Process() override;

View File

@@ -13,14 +13,13 @@ using namespace feature;
namespace generator
{
ComplexFinalProcessor::ComplexFinalProcessor(std::string const & mwmTmpPath,
std::string const & outFilename, size_t threadsCount)
ComplexFinalProcessor::ComplexFinalProcessor(std::string const & mwmTmpPath, std::string const & outFilename,
size_t threadsCount)
: FinalProcessorIntermediateMwmInterface(FinalProcessorPriority::Complex)
, m_mwmTmpPath(mwmTmpPath)
, m_outFilename(outFilename)
, m_threadsCount(threadsCount)
{
}
{}
void ComplexFinalProcessor::SetGetMainTypeFunction(hierarchy::GetMainTypeFn const & getMainType)
{
@@ -42,8 +41,7 @@ void ComplexFinalProcessor::SetPrintFunction(hierarchy::PrintFn const & printFun
m_printFunction = printFunction;
}
void ComplexFinalProcessor::UseCentersEnricher(std::string const & mwmPath,
std::string const & osm2ftPath)
void ComplexFinalProcessor::UseCentersEnricher(std::string const & mwmPath, std::string const & osm2ftPath)
{
m_useCentersEnricher = true;
m_mwmPath = mwmPath;
@@ -70,7 +68,8 @@ void ComplexFinalProcessor::Process()
std::mutex mutex;
std::vector<HierarchyEntry> allLines;
ForEachMwmTmp(m_mwmTmpPath, [&](auto const & name, auto const & path) {
ForEachMwmTmp(m_mwmTmpPath, [&](auto const & name, auto const & path)
{
// https://wiki.openstreetmap.org/wiki/Simple_3D_buildings
// An object with tag 'building:part' is a part of a relation with outline 'building' or
// is contained in an object with tag 'building'. We will split data and work with
@@ -87,7 +86,8 @@ void ComplexFinalProcessor::Process()
auto trees = hierarchy::BuildHierarchy(std::move(fbs), m_getMainType, m_filter);
// We remove tree roots with tag 'building:part'.
base::EraseIf(trees, [](auto const & node) {
base::EraseIf(trees, [](auto const & node)
{
static auto const & buildingPartChecker = ftypes::IsBuildingPartChecker::Instance();
return buildingPartChecker(node->GetData().GetTypes());
});
@@ -104,7 +104,8 @@ void ComplexFinalProcessor::Process()
// In the end we add objects, which were saved by the collector.
if (m_buildingToParts)
{
hierarchy::AddChildrenTo(trees, [&](auto const & compositeId) {
hierarchy::AddChildrenTo(trees, [&](auto const & compositeId)
{
auto const & ids = m_buildingToParts->GetBuildingPartsByOutlineId(compositeId);
std::vector<hierarchy::HierarchyPlace> places;
places.reserve(ids.size());
@@ -138,23 +139,22 @@ void ComplexFinalProcessor::Process()
WriteLines(allLines);
}
std::unordered_map<base::GeoObjectId, FeatureBuilder>
ComplexFinalProcessor::RemoveRelationBuildingParts(std::vector<FeatureBuilder> & fbs)
std::unordered_map<base::GeoObjectId, FeatureBuilder> ComplexFinalProcessor::RemoveRelationBuildingParts(
std::vector<FeatureBuilder> & fbs)
{
CHECK(m_buildingToParts, ());
auto it = std::partition(std::begin(fbs), std::end(fbs), [&](auto const & fb) {
return !m_buildingToParts->HasBuildingPart(fb.GetMostGenericOsmId());
});
auto it = std::partition(std::begin(fbs), std::end(fbs), [&](auto const & fb)
{ return !m_buildingToParts->HasBuildingPart(fb.GetMostGenericOsmId()); });
std::unordered_map<base::GeoObjectId, FeatureBuilder> buildingParts;
buildingParts.reserve(static_cast<size_t>(std::distance(it, std::end(fbs))));
std::transform(it, std::end(fbs), std::inserter(buildingParts, std::begin(buildingParts)),
[](auto && fb) {
auto const id = fb.GetMostGenericOsmId();
return std::make_pair(id, std::move(fb));
});
std::transform(it, std::end(fbs), std::inserter(buildingParts, std::begin(buildingParts)), [](auto && fb)
{
auto const id = fb.GetMostGenericOsmId();
return std::make_pair(id, std::move(fb));
});
fbs.resize(static_cast<size_t>(std::distance(std::begin(fbs), it)));
return buildingParts;

View File

@@ -21,8 +21,7 @@ namespace generator
class ComplexFinalProcessor : public FinalProcessorIntermediateMwmInterface
{
public:
ComplexFinalProcessor(std::string const & mwmTmpPath, std::string const & outFilename,
size_t threadsCount);
ComplexFinalProcessor(std::string const & mwmTmpPath, std::string const & outFilename, size_t threadsCount);
void SetGetMainTypeFunction(hierarchy::GetMainTypeFn const & getMainType);
void SetFilter(std::shared_ptr<FilterInterface> const & filter);
@@ -36,8 +35,7 @@ public:
void Process() override;
private:
std::unique_ptr<hierarchy::HierarchyEntryEnricher> CreateEnricher(
std::string const & countryName) const;
std::unique_ptr<hierarchy::HierarchyEntryEnricher> CreateEnricher(std::string const & countryName) const;
void WriteLines(std::vector<HierarchyEntry> const & lines);
std::unordered_map<base::GeoObjectId, feature::FeatureBuilder> RemoveRelationBuildingParts(
std::vector<feature::FeatureBuilder> & fbs);

View File

@@ -1,7 +1,7 @@
#include "generator/final_processor_country.hpp"
#include "generator/addresses_collector.hpp"
#include "generator/address_enricher.hpp"
#include "generator/addresses_collector.hpp"
#include "generator/affiliation.hpp"
#include "generator/coastlines_generator.hpp"
#include "generator/feature_builder.hpp"
@@ -20,13 +20,12 @@
#include "geometry/mercator.hpp"
#include "geometry/region2d/binary_operators.hpp"
namespace generator
{
using namespace feature;
CountryFinalProcessor::CountryFinalProcessor(AffiliationInterfacePtr affiliations,
std::string const & temporaryMwmPath, size_t threadsCount)
CountryFinalProcessor::CountryFinalProcessor(AffiliationInterfacePtr affiliations, std::string const & temporaryMwmPath,
size_t threadsCount)
: FinalProcessorIntermediateMwmInterface(FinalProcessorPriority::CountriesOrWorld)
, m_temporaryMwmPath(temporaryMwmPath)
, m_affiliations(std::move(affiliations))
@@ -42,7 +41,7 @@ bool CountryFinalProcessor::IsCountry(std::string const & filename)
void CountryFinalProcessor::Process()
{
//Order();
// Order();
/// @todo Make "straight-way" processing. There is no need to make many functions and
/// many read-write FeatureBuilder ops here.
@@ -64,10 +63,10 @@ void CountryFinalProcessor::Process()
if (!m_isolinesPath.empty())
AddIsolines();
//DropProhibitedSpeedCameras();
// DropProhibitedSpeedCameras();
ProcessBuildingParts();
//Finish();
// Finish();
}
/*
@@ -133,15 +132,11 @@ void CountryFinalProcessor::ProcessRoundabouts()
// Adds new way features generated from mini-roundabout nodes with those nodes ids.
// Transforms points on roads to connect them with these new roundabout junctions.
transformer.ProcessRoundabouts([&writer](FeatureBuilder const & fb)
{
writer.Write(fb);
});
transformer.ProcessRoundabouts([&writer](FeatureBuilder const & fb) { writer.Write(fb); });
}, m_threadsCount);
}
bool DoesBuildingConsistOfParts(FeatureBuilder const & fbBuilding,
m4::Tree<m2::RegionI> const & buildingPartsKDTree)
bool DoesBuildingConsistOfParts(FeatureBuilder const & fbBuilding, m4::Tree<m2::RegionI> const & buildingPartsKDTree)
{
m2::RegionI building;
m2::MultiRegionI partsUnion;
@@ -204,7 +199,7 @@ bool DoesBuildingConsistOfParts(FeatureBuilder const & fbBuilding,
uint64_t const isectArea = m2::Area(m2::IntersectRegions(building, partsUnion));
// That doesn't work with *very* degenerated polygons like https://www.openstreetmap.org/way/629725974.
//CHECK(isectArea * 0.95 <= buildingArea, (isectArea, buildingArea, fbBuilding.DebugPrintIDs()));
// CHECK(isectArea * 0.95 <= buildingArea, (isectArea, buildingArea, fbBuilding.DebugPrintIDs()));
// Consider building as consisting of parts if the building footprint is covered with parts at least by 90%.
return isectArea >= 0.9 * buildingArea;
@@ -236,9 +231,7 @@ void CountryFinalProcessor::ProcessBuildingParts()
FeatureBuilderWriter<serialization_policy::MaxAccuracy> writer(path, true /* mangleName */);
ForEachFeatureRawFormat<serialization_policy::MaxAccuracy>(path, [&](FeatureBuilder && fb, uint64_t)
{
if (fb.IsArea() &&
buildingChecker(fb.GetTypes()) &&
DoesBuildingConsistOfParts(fb, buildingPartsKDTree))
if (fb.IsArea() && buildingChecker(fb.GetTypes()) && DoesBuildingConsistOfParts(fb, buildingPartsKDTree))
{
fb.AddType(buildingHasPartsChecker.GetType());
fb.GetParams().FinishAddingTypes();
@@ -280,10 +273,8 @@ void CountryFinalProcessor::AddAddresses()
AddressEnricher enricher;
// Collect existing addresses and streets.
ForEachFeatureRawFormat<serialization_policy::MaxAccuracy>(path, [&](FeatureBuilder && fb, uint64_t)
{
enricher.AddSrc(std::move(fb));
});
ForEachFeatureRawFormat<serialization_policy::MaxAccuracy>(
path, [&](FeatureBuilder && fb, uint64_t) { enricher.AddSrc(std::move(fb)); });
// Append new addresses.
FeatureBuilderWriter<serialization_policy::MaxAccuracy> writer(path, FileWriter::Op::OP_APPEND);

View File

@@ -10,41 +10,22 @@ namespace generator
class CountryFinalProcessor : public FinalProcessorIntermediateMwmInterface
{
public:
CountryFinalProcessor(AffiliationInterfacePtr affiliations,
std::string const & temporaryMwmPath, size_t threadsCount);
CountryFinalProcessor(AffiliationInterfacePtr affiliations, std::string const & temporaryMwmPath,
size_t threadsCount);
void SetCoastlines(std::string const & coastlineGeomFilename,
std::string const & worldCoastsFilename)
void SetCoastlines(std::string const & coastlineGeomFilename, std::string const & worldCoastsFilename)
{
m_coastlineGeomFilename = coastlineGeomFilename;
m_worldCoastsFilename = worldCoastsFilename;
}
void SetFakeNodes(std::string const & filename)
{
m_fakeNodesFilename = filename;
}
void SetMiniRoundabouts(std::string const & filename)
{
m_miniRoundaboutsFilename = filename;
}
void SetAddrInterpolation(std::string const & filename)
{
m_addrInterpolFilename = filename;
}
void SetFakeNodes(std::string const & filename) { m_fakeNodesFilename = filename; }
void SetMiniRoundabouts(std::string const & filename) { m_miniRoundaboutsFilename = filename; }
void SetAddrInterpolation(std::string const & filename) { m_addrInterpolFilename = filename; }
void SetIsolinesDir(std::string const & dir)
{
m_isolinesPath = dir;
}
void SetAddressesDir(std::string const & dir)
{
m_addressPath = dir;
}
void SetIsolinesDir(std::string const & dir) { m_isolinesPath = dir; }
void SetAddressesDir(std::string const & dir) { m_addressPath = dir; }
void SetCityBoundariesFiles(std::string const & collectorFile)
{
m_boundariesCollectorFile = collectorFile;
}
void SetCityBoundariesFiles(std::string const & collectorFile) { m_boundariesCollectorFile = collectorFile; }
// FinalProcessorIntermediateMwmInterface overrides:
void Process() override;
@@ -52,14 +33,14 @@ public:
void ProcessBuildingParts();
private:
//void Order();
// void Order();
void ProcessCoastline();
void ProcessRoundabouts();
void AddFakeNodes();
void AddIsolines();
void AddAddresses();
void DropProhibitedSpeedCameras();
//void Finish();
// void Finish();
bool IsCountry(std::string const & filename);

View File

@@ -20,18 +20,12 @@ enum class FinalProcessorPriority : uint8_t
class FinalProcessorIntermediateMwmInterface
{
public:
explicit FinalProcessorIntermediateMwmInterface(FinalProcessorPriority priority)
: m_priority(priority)
{
}
explicit FinalProcessorIntermediateMwmInterface(FinalProcessorPriority priority) : m_priority(priority) {}
virtual ~FinalProcessorIntermediateMwmInterface() = default;
virtual void Process() = 0;
bool operator<(FinalProcessorIntermediateMwmInterface const & other) const
{
return m_priority < other.m_priority;
}
bool operator<(FinalProcessorIntermediateMwmInterface const & other) const { return m_priority < other.m_priority; }
protected:
FinalProcessorPriority m_priority;

View File

@@ -24,11 +24,13 @@ bool Less(FeatureBuilder const & lhs, FeatureBuilder const & rhs)
auto const lKeyPoint = lhs.GetKeyPoint();
auto const rKeyPoint = rhs.GetKeyPoint();
return std::tie(lGeomType, lId, lPointsCount, lKeyPoint) <
std::tie(rGeomType, rId, rPointsCount, rKeyPoint);
return std::tie(lGeomType, lId, lPointsCount, lKeyPoint) < std::tie(rGeomType, rId, rPointsCount, rKeyPoint);
}
void Order(std::vector<FeatureBuilder> & fbs) { std::sort(std::begin(fbs), std::end(fbs), Less); }
void Order(std::vector<FeatureBuilder> & fbs)
{
std::sort(std::begin(fbs), std::end(fbs), Less);
}
void OrderTextFileByLine(std::string const & filename)
{
@@ -50,8 +52,7 @@ void OrderTextFileByLine(std::string const & filename)
}
std::vector<std::vector<std::string>> GetAffiliations(std::vector<FeatureBuilder> const & fbs,
AffiliationInterface const & affiliation,
size_t threadsCount)
AffiliationInterface const & affiliation, size_t threadsCount)
{
base::ComputationalThreadPool pool(threadsCount);
std::vector<std::future<std::vector<std::string>>> futuresAffiliations;

View File

@@ -33,23 +33,21 @@ void ForEachMwmTmp(std::string const & temporaryMwmPath, ToDo && toDo, size_t th
}
}
std::vector<std::vector<std::string>> GetAffiliations(
std::vector<feature::FeatureBuilder> const & fbs,
feature::AffiliationInterface const & affiliation, size_t threadsCount);
std::vector<std::vector<std::string>> GetAffiliations(std::vector<feature::FeatureBuilder> const & fbs,
feature::AffiliationInterface const & affiliation,
size_t threadsCount);
// Writes |fbs| to countries mwm.tmp files. Returns affiliations - country matches for |fbs|.
template <class SerializationPolicy = feature::serialization_policy::MaxAccuracy>
std::vector<std::vector<std::string>> AppendToMwmTmp(std::vector<feature::FeatureBuilder> const & fbs,
feature::AffiliationInterface const & affiliation,
std::string const & temporaryMwmPath, size_t threadsCount = 1)
feature::AffiliationInterface const & affiliation,
std::string const & temporaryMwmPath, size_t threadsCount = 1)
{
auto affiliations = GetAffiliations(fbs, affiliation, threadsCount);
std::unordered_map<std::string, std::vector<size_t>> countryToFbsIndexes;
for (size_t i = 0; i < fbs.size(); ++i)
{
for (auto const & country : affiliations[i])
countryToFbsIndexes[country].emplace_back(i);
}
base::ComputationalThreadPool pool(threadsCount);
for (auto && p : countryToFbsIndexes)

View File

@@ -14,11 +14,9 @@ WorldFinalProcessor::WorldFinalProcessor(std::string const & temporaryMwmPath,
std::string const & coastlineGeomFilename)
: FinalProcessorIntermediateMwmInterface(FinalProcessorPriority::CountriesOrWorld)
, m_temporaryMwmPath(temporaryMwmPath)
, m_worldTmpFilename(base::JoinPath(m_temporaryMwmPath, WORLD_FILE_NAME) +
DATA_FILE_EXTENSION_TMP)
, m_worldTmpFilename(base::JoinPath(m_temporaryMwmPath, WORLD_FILE_NAME) + DATA_FILE_EXTENSION_TMP)
, m_coastlineGeomFilename(coastlineGeomFilename)
{
}
{}
void WorldFinalProcessor::Process()
{

View File

@@ -16,10 +16,7 @@ public:
/// @param[in] coastGeomFilename Can be empty if you don't care about cutting borders by water.
WorldFinalProcessor(std::string const & temporaryMwmPath, std::string const & coastGeomFilename);
void SetPopularPlaces(std::string const & filename)
{
m_popularPlacesFilename = filename;
}
void SetPopularPlaces(std::string const & filename) { m_popularPlacesFilename = filename; }
// FinalProcessorIntermediateMwmInterface overrides:
void Process() override;

View File

@@ -13,7 +13,10 @@ uint32_t const OsmID2FeatureID::kHeaderMagic;
OsmID2FeatureID::OsmID2FeatureID() : m_version(Version::V1) {}
OsmID2FeatureID::Version OsmID2FeatureID::GetVersion() const { return m_version; }
OsmID2FeatureID::Version OsmID2FeatureID::GetVersion() const
{
return m_version;
}
bool OsmID2FeatureID::ReadFromFile(std::string const & filename)
{
@@ -25,8 +28,7 @@ bool OsmID2FeatureID::ReadFromFile(std::string const & filename)
}
catch (FileReader::Exception const & e)
{
LOG(LERROR, ("Exception while reading osm id to feature id mapping from file", filename,
". Msg:", e.Msg()));
LOG(LERROR, ("Exception while reading osm id to feature id mapping from file", filename, ". Msg:", e.Msg()));
return false;
}
@@ -60,4 +62,3 @@ std::vector<uint32_t> OsmID2FeatureID::GetFeatureIds(base::GeoObjectId mainId) c
return ids;
}
} // namespace generator

View File

@@ -96,20 +96,17 @@ struct GenerateInfo
LOG(LCRITICAL, ("Incorrect node_storage type:", type));
}
std::string GetTmpFileName(std::string const & fileName,
std::string const & ext = DATA_FILE_EXTENSION_TMP) const
std::string GetTmpFileName(std::string const & fileName, std::string const & ext = DATA_FILE_EXTENSION_TMP) const
{
return base::JoinPath(m_tmpDir, fileName + ext);
}
std::string GetTargetFileName(std::string const & fileName,
std::string const & ext = DATA_FILE_EXTENSION) const
std::string GetTargetFileName(std::string const & fileName, std::string const & ext = DATA_FILE_EXTENSION) const
{
return base::JoinPath(m_targetDir, fileName + ext);
}
std::string GetIntermediateFileName(std::string const & fileName,
std::string const & ext = "") const
std::string GetIntermediateFileName(std::string const & fileName, std::string const & ext = "") const
{
return base::JoinPath(m_intermediateDir, fileName + ext);
}

View File

@@ -39,8 +39,8 @@ struct CountryFeaturesCounters
CountryFeaturesCounters() = default;
constexpr CountryFeaturesCounters(int64_t fbs, int64_t geometryPoints, int64_t point, int64_t line,
int64_t area, int64_t poi, int64_t cityTownOrVillage)
constexpr CountryFeaturesCounters(int64_t fbs, int64_t geometryPoints, int64_t point, int64_t line, int64_t area,
int64_t poi, int64_t cityTownOrVillage)
: m_fbs(fbs)
, m_geometryPoints(geometryPoints)
, m_point(point)
@@ -48,28 +48,27 @@ struct CountryFeaturesCounters
, m_area(area)
, m_poi(poi)
, m_cityTownOrVillage(cityTownOrVillage)
{
}
{}
CountryFeaturesCounters operator+(CountryFeaturesCounters const & rhs) const
{
return CountryFeaturesCounters(m_fbs + rhs.m_fbs, m_geometryPoints + rhs.m_geometryPoints,
m_point + rhs.m_point, m_line + rhs.m_line, m_area + rhs.m_area,
m_poi + rhs.m_poi, m_cityTownOrVillage + rhs.m_cityTownOrVillage);
return CountryFeaturesCounters(m_fbs + rhs.m_fbs, m_geometryPoints + rhs.m_geometryPoints, m_point + rhs.m_point,
m_line + rhs.m_line, m_area + rhs.m_area, m_poi + rhs.m_poi,
m_cityTownOrVillage + rhs.m_cityTownOrVillage);
}
CountryFeaturesCounters operator-(CountryFeaturesCounters const & rhs) const
{
return CountryFeaturesCounters(m_fbs - rhs.m_fbs, m_geometryPoints - rhs.m_geometryPoints,
m_point - rhs.m_point, m_line - rhs.m_line, m_area - rhs.m_area,
m_poi - rhs.m_poi, m_cityTownOrVillage - rhs.m_cityTownOrVillage);
return CountryFeaturesCounters(m_fbs - rhs.m_fbs, m_geometryPoints - rhs.m_geometryPoints, m_point - rhs.m_point,
m_line - rhs.m_line, m_area - rhs.m_area, m_poi - rhs.m_poi,
m_cityTownOrVillage - rhs.m_cityTownOrVillage);
}
bool operator==(CountryFeaturesCounters const & rhs) const
{
return m_fbs == rhs.m_fbs && m_geometryPoints == rhs.m_geometryPoints &&
m_point == rhs.m_point && m_line == rhs.m_line && m_area == rhs.m_area &&
m_poi == rhs.m_poi && m_cityTownOrVillage == rhs.m_cityTownOrVillage;
return m_fbs == rhs.m_fbs && m_geometryPoints == rhs.m_geometryPoints && m_point == rhs.m_point &&
m_line == rhs.m_line && m_area == rhs.m_area && m_poi == rhs.m_poi &&
m_cityTownOrVillage == rhs.m_cityTownOrVillage;
}
bool operator!=(CountryFeaturesCounters const & rhs) const { return !(*this == rhs); }
@@ -79,9 +78,9 @@ struct CountryFeatureResults
{
CountryFeatureResults() = default;
CountryFeatureResults(CountryFeaturesCounters actual, CountryFeaturesCounters expected)
: m_actual(actual), m_expected(expected)
{
}
: m_actual(actual)
, m_expected(expected)
{}
CountryFeaturesCounters m_actual;
CountryFeaturesCounters m_expected;
@@ -93,9 +92,8 @@ void TestAndLogCountryFeatures(std::map<std::string, CountryFeatureResults> cons
{
if (result.second.m_actual != result.second.m_expected)
{
LOG(LINFO, ("Unexpectad result for", result.first, "actual:", result.second.m_actual,
"expected:", result.second.m_expected,
"the difference is:", result.second.m_actual - result.second.m_expected));
LOG(LINFO, ("Unexpectad result for", result.first, "actual:", result.second.m_actual, "expected:",
result.second.m_expected, "the difference is:", result.second.m_actual - result.second.m_expected));
}
}
@@ -115,45 +113,45 @@ std::string DebugPrint(CountryFeaturesCounters const & cnt)
return out.str();
}
CountryFeaturesCounters constexpr kWorldCounters(945 /* fbs */, 364406 /* geometryPoints */,
334 /* point */, 598 /* line */, 13 /* area */,
428 /* poi */, 172 /* cityTownOrVillage */);
CountryFeaturesCounters constexpr kWorldCounters(945 /* fbs */, 364406 /* geometryPoints */, 334 /* point */,
598 /* line */, 13 /* area */, 428 /* poi */,
172 /* cityTownOrVillage */);
CountryFeaturesCounters constexpr kNorthAucklandCounters(
1812144 /* fbs */, 12195444 /* geometryPoints */, 1007580 /* point */, 205448 /* line */,
599116 /* area */, 212424 /* poi */, 521 /* cityTownOrVillage */);
CountryFeaturesCounters constexpr kNorthAucklandCounters(1812144 /* fbs */, 12195444 /* geometryPoints */,
1007580 /* point */, 205448 /* line */, 599116 /* area */,
212424 /* poi */, 521 /* cityTownOrVillage */);
CountryFeaturesCounters constexpr kNorthWellingtonCounters(
797814 /* fbs */, 7771530 /* geometryPoints */, 460560 /* point */, 86978 /* line */,
250276 /* area */, 95863 /* poi */, 297 /* cityTownOrVillage */);
CountryFeaturesCounters constexpr kNorthWellingtonCounters(797814 /* fbs */, 7771530 /* geometryPoints */,
460560 /* point */, 86978 /* line */, 250276 /* area */,
95863 /* poi */, 297 /* cityTownOrVillage */);
CountryFeaturesCounters constexpr kSouthCanterburyCounters(
637239 /* fbs */, 6984183 /* geometryPoints */, 397964 /* point */, 81688 /* line */,
157587 /* area */, 89690 /* poi */, 331 /* cityTownOrVillage */);
CountryFeaturesCounters constexpr kSouthCanterburyCounters(637239 /* fbs */, 6984183 /* geometryPoints */,
397964 /* point */, 81688 /* line */, 157587 /* area */,
89690 /* poi */, 331 /* cityTownOrVillage */);
CountryFeaturesCounters constexpr kSouthSouthlandCounters(
340644 /* fbs */, 5342380 /* geometryPoints */, 186000 /* point */, 40118 /* line */,
114526 /* area */, 40671 /* poi */, 297 /* cityTownOrVillage */);
CountryFeaturesCounters constexpr kSouthSouthlandCounters(340644 /* fbs */, 5342380 /* geometryPoints */,
186000 /* point */, 40118 /* line */, 114526 /* area */,
40671 /* poi */, 297 /* cityTownOrVillage */);
CountryFeaturesCounters constexpr kSouthSouthlandMixedNodesCounters(
2 /* fbs */, 2 /* geometryPoints */, 2 /* point */, 0 /* line */, 0 /* area */, 0 /* poi */,
0 /* cityTownOrVillage */);
CountryFeaturesCounters constexpr kSouthSouthlandMixedNodesCounters(2 /* fbs */, 2 /* geometryPoints */, 2 /* point */,
0 /* line */, 0 /* area */, 0 /* poi */,
0 /* cityTownOrVillage */);
CountryFeaturesCounters constexpr kNorthAucklandComplexFeaturesCounters(
288 /* fbs */, 16119 /* geometryPoints */, 0 /* point */, 252 /* line */, 36 /* area */,
0 /* poi */, 0 /* cityTownOrVillage */);
CountryFeaturesCounters constexpr kNorthAucklandComplexFeaturesCounters(288 /* fbs */, 16119 /* geometryPoints */,
0 /* point */, 252 /* line */, 36 /* area */,
0 /* poi */, 0 /* cityTownOrVillage */);
CountryFeaturesCounters constexpr kNorthWellingtonComplexFeaturesCounters(
254 /* fbs */, 18434 /* geometryPoints */, 0 /* point */, 244 /* line */, 10 /* area */,
0 /* poi */, 0 /* cityTownOrVillage */);
CountryFeaturesCounters constexpr kNorthWellingtonComplexFeaturesCounters(254 /* fbs */, 18434 /* geometryPoints */,
0 /* point */, 244 /* line */, 10 /* area */,
0 /* poi */, 0 /* cityTownOrVillage */);
CountryFeaturesCounters constexpr kSouthCanterburyComplexFeaturesCounters(
1037 /* fbs */, 73854 /* geometryPoints */, 0 /* point */, 1016 /* line */, 21 /* area */,
0 /* poi */, 0 /* cityTownOrVillage */);
CountryFeaturesCounters constexpr kSouthCanterburyComplexFeaturesCounters(1037 /* fbs */, 73854 /* geometryPoints */,
0 /* point */, 1016 /* line */, 21 /* area */,
0 /* poi */, 0 /* cityTownOrVillage */);
CountryFeaturesCounters constexpr kSouthSouthlandComplexFeaturesCounters(
1252 /* fbs */, 141706 /* geometryPoints */, 0 /* point */, 1245 /* line */, 7 /* area */,
0 /* poi */, 0 /* cityTownOrVillage */);
CountryFeaturesCounters constexpr kSouthSouthlandComplexFeaturesCounters(1252 /* fbs */, 141706 /* geometryPoints */,
0 /* point */, 1245 /* line */, 7 /* area */,
0 /* poi */, 0 /* cityTownOrVillage */);
class FeatureIntegrationTests
{
@@ -172,19 +170,14 @@ public:
CHECK(Platform::RmDirRecursively(m_testPath), ());
CHECK(Platform::RemoveFileIfExists(m_mixedNodesFilenames.first), ());
CHECK(Platform::RemoveFileIfExists(m_mixedTagsFilenames.first), ());
CHECK_EQUAL(
std::rename(m_mixedNodesFilenames.second.c_str(), m_mixedNodesFilenames.first.c_str()), 0,
());
CHECK_EQUAL(
std::rename(m_mixedTagsFilenames.second.c_str(), m_mixedTagsFilenames.first.c_str()), 0,
());
CHECK_EQUAL(std::rename(m_mixedNodesFilenames.second.c_str(), m_mixedNodesFilenames.first.c_str()), 0, ());
CHECK_EQUAL(std::rename(m_mixedTagsFilenames.second.c_str(), m_mixedTagsFilenames.first.c_str()), 0, ());
}
void BuildCoasts()
{
auto const worldCoastsGeom = m_genInfo.GetIntermediateFileName(WORLD_COASTS_FILE_NAME ".geom");
auto const worldCoastsRawGeom =
m_genInfo.GetIntermediateFileName(WORLD_COASTS_FILE_NAME ".rawgeom");
auto const worldCoastsRawGeom = m_genInfo.GetIntermediateFileName(WORLD_COASTS_FILE_NAME ".rawgeom");
CHECK(!Platform::IsFileExistsByFullPath(worldCoastsGeom), ());
CHECK(!Platform::IsFileExistsByFullPath(worldCoastsRawGeom), ());
@@ -235,8 +228,7 @@ public:
void BuildCountries()
{
m_genInfo.m_emitCoasts = true;
m_genInfo.m_citiesBoundariesFilename =
m_genInfo.GetIntermediateFileName("citiesboundaries.bin");
m_genInfo.m_citiesBoundariesFilename = m_genInfo.GetIntermediateFileName("citiesboundaries.bin");
auto const northAuckland = m_genInfo.GetTmpFileName("New Zealand North_Auckland");
auto const northWellington = m_genInfo.GetTmpFileName("New Zealand North_Wellington");
@@ -265,8 +257,7 @@ public:
void BuildCountriesWithComplex()
{
m_genInfo.m_emitCoasts = true;
m_genInfo.m_citiesBoundariesFilename =
m_genInfo.GetIntermediateFileName("citiesboundaries.bin");
m_genInfo.m_citiesBoundariesFilename = m_genInfo.GetIntermediateFileName("citiesboundaries.bin");
m_genInfo.m_complexHierarchyFilename = base::JoinPath(m_testPath, "hierarchy.csv");
auto const northAuckland = m_genInfo.GetTmpFileName("New Zealand North_Auckland");
@@ -282,26 +273,21 @@ public:
TEST(rawGenerator.Execute(), ());
std::map<std::string, CountryFeatureResults> results;
results["kNorthAucklandCounters + kNorthAucklandComplexFeaturesCounters"] =
CountryFeatureResults(GetCountersForCountry(northAuckland),
kNorthAucklandCounters + kNorthAucklandComplexFeaturesCounters);
results["kNorthWellingtonCounters + kNorthWellingtonComplexFeaturesCounters"] =
CountryFeatureResults(GetCountersForCountry(northWellington),
kNorthWellingtonCounters + kNorthWellingtonComplexFeaturesCounters);
results["kSouthCanterburyCounters + kSouthCanterburyComplexFeaturesCounters"] =
CountryFeatureResults(GetCountersForCountry(southCanterbury),
kSouthCanterburyCounters + kSouthCanterburyComplexFeaturesCounters);
results["kSouthSouthlandCounters + kSouthSouthlandComplexFeaturesCounters"] =
CountryFeatureResults(GetCountersForCountry(southSouthland),
kSouthSouthlandCounters + kSouthSouthlandComplexFeaturesCounters);
results["kNorthAucklandCounters + kNorthAucklandComplexFeaturesCounters"] = CountryFeatureResults(
GetCountersForCountry(northAuckland), kNorthAucklandCounters + kNorthAucklandComplexFeaturesCounters);
results["kNorthWellingtonCounters + kNorthWellingtonComplexFeaturesCounters"] = CountryFeatureResults(
GetCountersForCountry(northWellington), kNorthWellingtonCounters + kNorthWellingtonComplexFeaturesCounters);
results["kSouthCanterburyCounters + kSouthCanterburyComplexFeaturesCounters"] = CountryFeatureResults(
GetCountersForCountry(southCanterbury), kSouthCanterburyCounters + kSouthCanterburyComplexFeaturesCounters);
results["kSouthSouthlandCounters + kSouthSouthlandComplexFeaturesCounters"] = CountryFeatureResults(
GetCountersForCountry(southSouthland), kSouthSouthlandCounters + kSouthSouthlandComplexFeaturesCounters);
TestAndLogCountryFeatures(results);
}
void CheckMixedTagsAndNodes()
{
m_genInfo.m_emitCoasts = true;
m_genInfo.m_citiesBoundariesFilename =
m_genInfo.GetIntermediateFileName("citiesboundaries.bin");
m_genInfo.m_citiesBoundariesFilename = m_genInfo.GetIntermediateFileName("citiesboundaries.bin");
auto const northAuckland = m_genInfo.GetTmpFileName("New Zealand North_Auckland");
auto const northWellington = m_genInfo.GetTmpFileName("New Zealand North_Wellington");
@@ -325,9 +311,8 @@ public:
CountryFeatureResults(GetCountersForCountry(northWellington), kNorthWellingtonCounters);
results["kSouthCanterburyCounters"] =
CountryFeatureResults(GetCountersForCountry(southCanterbury), kSouthCanterburyCounters);
results["kSouthSouthlandCounters + kSouthSouthlandMixedNodesCounters"] =
CountryFeatureResults(GetCountersForCountry(southSouthland),
kSouthSouthlandCounters + kSouthSouthlandMixedNodesCounters);
results["kSouthSouthlandCounters + kSouthSouthlandMixedNodesCounters"] = CountryFeatureResults(
GetCountersForCountry(southSouthland), kSouthSouthlandCounters + kSouthSouthlandMixedNodesCounters);
results["kWorldCounters"] = CountryFeatureResults(GetCountersForCountry(world), kWorldCounters);
TestAndLogCountryFeatures(results);
@@ -336,8 +321,7 @@ public:
void CheckGeneratedData()
{
m_genInfo.m_emitCoasts = true;
m_genInfo.m_citiesBoundariesFilename =
m_genInfo.GetIntermediateFileName("citiesboundaries.bin");
m_genInfo.m_citiesBoundariesFilename = m_genInfo.GetIntermediateFileName("citiesboundaries.bin");
auto const cameraToWays = m_genInfo.GetIntermediateFileName(CAMERAS_TO_WAYS_FILENAME);
auto const cityBoundaries = m_genInfo.GetIntermediateFileName(CITY_BOUNDARIES_COLLECTOR_FILENAME);
auto const maxSpeeds = m_genInfo.GetIntermediateFileName(MAXSPEEDS_FILENAME);
@@ -345,9 +329,8 @@ public:
auto const restrictions = m_genInfo.GetIntermediateFileName(RESTRICTIONS_FILENAME);
auto const roadAccess = m_genInfo.GetIntermediateFileName(ROAD_ACCESS_FILENAME);
for (auto const & generatedFile :
{cameraToWays, cityBoundaries, maxSpeeds, metalines, restrictions, roadAccess,
m_genInfo.m_citiesBoundariesFilename})
for (auto const & generatedFile : {cameraToWays, cityBoundaries, maxSpeeds, metalines, restrictions, roadAccess,
m_genInfo.m_citiesBoundariesFilename})
{
CHECK(!Platform::IsFileExistsByFullPath(generatedFile), (generatedFile));
}
@@ -385,9 +368,9 @@ public:
}
private:
CountryFeaturesCounters GetCountersForCountry(
std::string const & path, std::function<void(feature::FeatureBuilder const &)> const & fn =
[](feature::FeatureBuilder const &) {})
CountryFeaturesCounters GetCountersForCountry(std::string const & path,
std::function<void(feature::FeatureBuilder const &)> const & fn =
[](feature::FeatureBuilder const &) {})
{
CHECK(Platform::IsFileExistsByFullPath(path), ());
auto const fbs = feature::ReadAllDatRawFormat(path);
@@ -449,12 +432,8 @@ private:
m_mixedTagsFilenames.first = base::JoinPath(platform.ResourcesDir(), MIXED_TAGS_FILE);
m_mixedTagsFilenames.second = base::JoinPath(platform.ResourcesDir(), MIXED_TAGS_FILE "_");
CHECK_EQUAL(
std::rename(m_mixedNodesFilenames.first.c_str(), m_mixedNodesFilenames.second.c_str()), 0,
());
CHECK_EQUAL(
std::rename(m_mixedTagsFilenames.first.c_str(), m_mixedTagsFilenames.second.c_str()), 0,
());
CHECK_EQUAL(std::rename(m_mixedNodesFilenames.first.c_str(), m_mixedNodesFilenames.second.c_str()), 0, ());
CHECK_EQUAL(std::rename(m_mixedTagsFilenames.first.c_str(), m_mixedTagsFilenames.second.c_str()), 0, ());
}
void WriteToFile(std::string const & filename, std::string const & data)

View File

@@ -18,10 +18,9 @@ namespace
{
platform::LocalCountryFile MakeFile(std::string name, int64_t version)
{
return { GetPlatform().WritableDir() + std::to_string(version),
platform::CountryFile(std::move(name)), version };
return {GetPlatform().WritableDir() + std::to_string(version), platform::CountryFile(std::move(name)), version};
}
} // namespace
} // namespace
UNIT_TEST(CrossMwmWeights)
{
@@ -43,7 +42,7 @@ UNIT_TEST(CrossMwmWeights)
builder.DeserializeTransitions(VehicleType::Car, reader);
builder.DeserializeWeights(reader);
//std::vector<connector::Weight> weights(connector.GetNumEnters() * connector.GetNumExits());
// std::vector<connector::Weight> weights(connector.GetNumEnters() * connector.GetNumExits());
using IdxWeightT = std::pair<uint32_t, uint32_t>;
std::vector<IdxWeightT> idx2weight;
@@ -54,7 +53,7 @@ UNIT_TEST(CrossMwmWeights)
{
uint32_t const idx = connector.GetWeightIndex(enterIdx, exitIdx);
uint32_t const weight = connector.GetWeight(enterIdx, exitIdx);
//weights[idx] = weight;
// weights[idx] = weight;
if (weight > 0)
idx2weight.emplace_back(idx, weight);

View File

@@ -48,12 +48,9 @@ class TestAffiliation : public feature::AffiliationInterface
std::vector<std::string> GetAffiliations(feature::FeatureBuilder const & fb) const override { return {}; }
std::vector<std::string> GetAffiliations(m2::PointD const & point) const override { return {}; }
bool HasCountryByName(std::string const & name) const override
{
return !name.starts_with("World");
}
bool HasCountryByName(std::string const & name) const override { return !name.starts_with("World"); }
};
} // namespace
} // namespace
UNIT_TEST(CountryFinalProcessor_ProcessBuildingParts)
{

View File

@@ -23,8 +23,8 @@ namespace
class AffiliationTests
{
public:
static const std::string kOne;
static const std::string kTwo;
static std::string const kOne;
static std::string const kTwo;
static constexpr m2::PointD kPointInsideOne1{3.0, 3.0};
static constexpr m2::PointD kPointInsideOne2{4.0, 4.0};
@@ -89,8 +89,8 @@ private:
};
// static
const std::string AffiliationTests::kOne = "One";
const std::string AffiliationTests::kTwo = "Two";
std::string const AffiliationTests::kOne = "One";
std::string const AffiliationTests::kTwo = "Two";
bool Test(std::vector<std::string> && res, std::set<std::string> const & answ)
{
@@ -104,41 +104,29 @@ bool Test(std::vector<std::string> && res, std::set<std::string> const & answ)
void TestCountriesAffiliationInsideBorders(feature::AffiliationInterface const & affiliation)
{
TEST(Test(affiliation.GetAffiliations(AffiliationTests::kPointInsideOne1),
{AffiliationTests::kOne}),
());
TEST(Test(affiliation.GetAffiliations(AffiliationTests::kPointInsideOne2),
{AffiliationTests::kOne}),
());
TEST(Test(affiliation.GetAffiliations(AffiliationTests::kPointOnBorderOne),
{AffiliationTests::kOne}),
());
TEST(Test(affiliation.GetAffiliations(AffiliationTests::kPointInsideTwo1),
{AffiliationTests::kTwo}),
());
TEST(Test(affiliation.GetAffiliations(AffiliationTests::kPointInsideTwo2),
{AffiliationTests::kTwo}),
());
TEST(Test(affiliation.GetAffiliations(AffiliationTests::kPointInsideOne1), {AffiliationTests::kOne}), ());
TEST(Test(affiliation.GetAffiliations(AffiliationTests::kPointInsideOne2), {AffiliationTests::kOne}), ());
TEST(Test(affiliation.GetAffiliations(AffiliationTests::kPointOnBorderOne), {AffiliationTests::kOne}), ());
TEST(Test(affiliation.GetAffiliations(AffiliationTests::kPointInsideTwo1), {AffiliationTests::kTwo}), ());
TEST(Test(affiliation.GetAffiliations(AffiliationTests::kPointInsideTwo2), {AffiliationTests::kTwo}), ());
TEST(Test(affiliation.GetAffiliations(AffiliationTests::kPointInsideOneAndTwo1),
{AffiliationTests::kOne, AffiliationTests::kTwo}),
());
TEST(Test(affiliation.GetAffiliations(AffiliationTests::kPointInsideOneAndTwo2),
{AffiliationTests::kOne, AffiliationTests::kTwo}),
());
TEST(Test(affiliation.GetAffiliations(AffiliationTests::kPointOnBorderTwo),
{AffiliationTests::kTwo}),
());
TEST(Test(affiliation.GetAffiliations(AffiliationTests::kPointOnBorderTwo), {AffiliationTests::kTwo}), ());
TEST(Test(affiliation.GetAffiliations(AffiliationTests::MakeLineFb(
{AffiliationTests::kPointInsideOne1, AffiliationTests::kPointInsideOne2})),
TEST(Test(affiliation.GetAffiliations(
AffiliationTests::MakeLineFb({AffiliationTests::kPointInsideOne1, AffiliationTests::kPointInsideOne2})),
{AffiliationTests::kOne}),
());
TEST(Test(affiliation.GetAffiliations(AffiliationTests::MakeLineFb(
{AffiliationTests::kPointInsideTwo1, AffiliationTests::kPointInsideTwo2})),
TEST(Test(affiliation.GetAffiliations(
AffiliationTests::MakeLineFb({AffiliationTests::kPointInsideTwo1, AffiliationTests::kPointInsideTwo2})),
{AffiliationTests::kTwo}),
());
TEST(Test(affiliation.GetAffiliations(AffiliationTests::MakeLineFb(
{AffiliationTests::kPointInsideOne1, AffiliationTests::kPointInsideTwo1})),
TEST(Test(affiliation.GetAffiliations(
AffiliationTests::MakeLineFb({AffiliationTests::kPointInsideOne1, AffiliationTests::kPointInsideTwo1})),
{AffiliationTests::kOne, AffiliationTests::kTwo}),
());
}
@@ -159,16 +147,12 @@ void TestCountriesFilesAffiliation(std::string const & borderPath)
TestCountriesAffiliationInsideBorders(affiliation);
TEST(Test(affiliation.GetAffiliations(AffiliationTests::kPointInsideOneBoundingBox),
{AffiliationTests::kOne}),
());
TEST(Test(affiliation.GetAffiliations(AffiliationTests::kPointInsideTwoBoundingBox),
{AffiliationTests::kTwo}),
());
TEST(Test(affiliation.GetAffiliations(AffiliationTests::kPointInsideOneBoundingBox), {AffiliationTests::kOne}), ());
TEST(Test(affiliation.GetAffiliations(AffiliationTests::kPointInsideTwoBoundingBox), {AffiliationTests::kTwo}), ());
}
}
} // namespace
} // namespace
UNIT_CLASS_TEST(AffiliationTests, SingleAffiliationTests)
{
@@ -179,8 +163,8 @@ UNIT_CLASS_TEST(AffiliationTests, SingleAffiliationTests)
TEST(Test(affiliation.GetAffiliations(AffiliationTests::kPointInsideOneAndTwo1), {kName}), ());
TEST(Test(affiliation.GetAffiliations(AffiliationTests::MakeLineFb(
{AffiliationTests::kPointInsideOne1, AffiliationTests::kPointInsideTwo1})),
TEST(Test(affiliation.GetAffiliations(
AffiliationTests::MakeLineFb({AffiliationTests::kPointInsideOne1, AffiliationTests::kPointInsideTwo1})),
{kName}),
());
@@ -190,14 +174,12 @@ UNIT_CLASS_TEST(AffiliationTests, SingleAffiliationTests)
UNIT_CLASS_TEST(AffiliationTests, CountriesFilesAffiliationTests)
{
TestCountriesFilesAffiliation<feature::CountriesFilesAffiliation>(
AffiliationTests::GetBorderPath());
TestCountriesFilesAffiliation<feature::CountriesFilesAffiliation>(AffiliationTests::GetBorderPath());
}
UNIT_CLASS_TEST(AffiliationTests, CountriesFilesIndexAffiliationTests)
{
TestCountriesFilesAffiliation<feature::CountriesFilesIndexAffiliation>(
AffiliationTests::GetBorderPath());
TestCountriesFilesAffiliation<feature::CountriesFilesIndexAffiliation>(AffiliationTests::GetBorderPath());
}
UNIT_TEST(Lithuania_Belarus_Border)
@@ -211,11 +193,11 @@ UNIT_TEST(Lithuania_Belarus_Border)
for (auto const country : {"Lithuania_East", "Belarus_Hrodna Region"})
{
std::vector<m2::RegionD> regions;
LoadBorders(bordersDir + country + BORDERS_EXTENSION, regions);
LoadBorders(bordersDir + country + BORDERS_EXTENSION, regions);
TEST_EQUAL(regions.size(), 1, ());
bool found = false;
for (auto const eps : { 1.0E-5, 5.0E-5, 1.0E-4 })
for (auto const eps : {1.0E-5, 5.0E-5, 1.0E-4})
{
if (regions[0].Contains(point, CountryPolygons::ContainsCompareFn(eps)))
{

View File

@@ -83,8 +83,7 @@ public:
auto const it = m_altitudes.find(g.m_point);
if (it != m_altitudes.cend())
{
CHECK_EQUAL(it->second, g.m_altitude,
("Point", it->first, "is set with two different altitudes."));
CHECK_EQUAL(it->second, g.m_altitude, ("Point", it->first, "is set with two different altitudes."));
continue;
}
m_altitudes[g.m_point] = g.m_altitude;
@@ -104,7 +103,6 @@ public:
}
private:
TMockAltitudes m_altitudes;
};
@@ -130,9 +128,8 @@ void BuildMwmWithoutAltitudes(std::vector<TPoint3DList> const & roads, LocalCoun
builder.Add(generator::tests_support::TestStreet(ExtractPoints(geom3D), std::string(), std::string()));
}
void TestAltitudes(DataSource const & dataSource, MwmSet::MwmId const & mwmId,
std::string const & mwmPath, bool hasAltitudeExpected,
AltitudeGetter & expectedAltitudes)
void TestAltitudes(DataSource const & dataSource, MwmSet::MwmId const & mwmId, std::string const & mwmPath,
bool hasAltitudeExpected, AltitudeGetter & expectedAltitudes)
{
auto const handle = dataSource.GetMwmHandleById(mwmId);
TEST(handle.IsAlive(), ());
@@ -157,8 +154,7 @@ void TestAltitudes(DataSource const & dataSource, MwmSet::MwmId const & mwmId,
{
geometry::Altitude const fromGetter = expectedAltitudes.GetAltitude(f.GetPoint(i));
geometry::Altitude const expected =
(fromGetter == geometry::kInvalidAltitude ? geometry::kDefaultAltitudeMeters
: fromGetter);
(fromGetter == geometry::kInvalidAltitude ? geometry::kDefaultAltitudeMeters : fromGetter);
TEST_EQUAL(expected, altitudes[i], ("A wrong altitude"));
}
};
@@ -175,8 +171,7 @@ void TestAltitudesBuilding(std::vector<TPoint3DList> const & roads, bool hasAlti
// Building mwm without altitude section.
LocalCountryFile country(testDirFullPath, CountryFile(kTestMwm), 1);
ScopedDir testScopedDir(kTestDir);
ScopedFile testScopedMwm(base::JoinPath(kTestDir, kTestMwm + DATA_FILE_EXTENSION),
ScopedFile::Mode::Create);
ScopedFile testScopedMwm(base::JoinPath(kTestDir, kTestMwm + DATA_FILE_EXTENSION), ScopedFile::Mode::Create);
BuildMwmWithoutAltitudes(roads, country);

View File

@@ -18,16 +18,16 @@ using platform::tests_support::ScopedFile;
char const kBrandsJson[] =
"{\n"
"\"nodes\": {\n"
"\"2132500347\": 13,\n"
"\"5321137826\": 12\n"
"\"2132500347\": 13,\n"
"\"5321137826\": 12\n"
"},\n"
"\"ways\": {\n"
"\"440527172\": 13,\n"
"\"149816366\": 12\n"
"\"440527172\": 13,\n"
"\"149816366\": 12\n"
"},\n"
"\"relations\": {\n"
"\"6018309\": 13,\n"
"\"6228042\": 12\n"
"\"6018309\": 13,\n"
"\"6228042\": 12\n"
"}\n"
"}";
@@ -36,13 +36,13 @@ char const kBrandTranslationsJson[] =
"\"12\": {\n"
"\"en\": [\"subway\"],\n"
"\"ru\": [\"\u0441\u0430\u0431\u0432\u044d\u0439\",\n"
"\"\u0441\u0430\u0431\u0432\u0435\u0439\"]\n"
"},\n"
"\"\u0441\u0430\u0431\u0432\u0435\u0439\"]\n"
"},\n"
"\"13\": {\n"
"\"en\": [\"mcdonalds\",\"mc donalds\"],\n"
"\"ru\": [\"\u043c\u0430\u043a\u0434\u043e\u043d\u0430\u043b\u044c\u0434\u0441\",\n"
"\"\u043c\u0430\u043a\u0434\u043e\u043d\u0430\u043b\u0434\u0441\"]\n"
"}\n"
"\"\u043c\u0430\u043a\u0434\u043e\u043d\u0430\u043b\u0434\u0441\"]\n"
"}\n"
"}";
UNIT_TEST(LoadBrands)
@@ -52,11 +52,11 @@ UNIT_TEST(LoadBrands)
std::unordered_map<GeoObjectId, std::string> brands;
TEST(LoadBrands(brandsFile.GetFullPath(), translationsFile.GetFullPath(), brands), ());
TEST_EQUAL(brands[GeoObjectId(GeoObjectId::Type::ObsoleteOsmNode, 2132500347)], "mcdonalds", ());
TEST_EQUAL(brands[GeoObjectId(GeoObjectId::Type::ObsoleteOsmWay, 440527172)], "mcdonalds", ());
TEST_EQUAL(brands[GeoObjectId(GeoObjectId::Type::ObsoleteOsmRelation, 6018309)], "mcdonalds", ());
TEST_EQUAL(brands[GeoObjectId(GeoObjectId::Type::ObsoleteOsmNode, 5321137826)], "subway", ());
TEST_EQUAL(brands[GeoObjectId(GeoObjectId::Type::ObsoleteOsmWay, 149816366)], "subway", ());
TEST_EQUAL(brands[GeoObjectId(GeoObjectId::Type::ObsoleteOsmRelation, 6228042)], "subway", ());
TEST_EQUAL(brands[GeoObjectId(GeoObjectId::Type::ObsoleteOsmNode, 2132500347)], "mcdonalds", ());
TEST_EQUAL(brands[GeoObjectId(GeoObjectId::Type::ObsoleteOsmWay, 440527172)], "mcdonalds", ());
TEST_EQUAL(brands[GeoObjectId(GeoObjectId::Type::ObsoleteOsmRelation, 6018309)], "mcdonalds", ());
TEST_EQUAL(brands[GeoObjectId(GeoObjectId::Type::ObsoleteOsmNode, 5321137826)], "subway", ());
TEST_EQUAL(brands[GeoObjectId(GeoObjectId::Type::ObsoleteOsmWay, 149816366)], "subway", ());
TEST_EQUAL(brands[GeoObjectId(GeoObjectId::Type::ObsoleteOsmRelation, 6228042)], "subway", ());
}
} // namespace brands_loader_test

View File

@@ -13,8 +13,8 @@
#include "generator/translator.hpp"
#include "indexer/classificator_loader.hpp"
#include "indexer/map_style_reader.hpp"
#include "indexer/map_style.hpp"
#include "indexer/map_style_reader.hpp"
#include "platform/platform.hpp"
#include "platform/platform_tests_support/scoped_dir.hpp"
@@ -25,7 +25,6 @@
#include "defines.hpp"
namespace routing_builder
{
using namespace generator;
@@ -58,10 +57,7 @@ public:
return {};
}
void Merge(TranslatorInterface const &) override
{
CHECK(false, ());
}
void Merge(TranslatorInterface const &) override { CHECK(false, ()); }
protected:
using Translator::Translator;
@@ -105,7 +101,8 @@ public:
// Test load this data from cached file.
generator::cache::IntermediateDataObjectsCache objectsCache;
auto cache = std::make_shared<generator::cache::IntermediateData>(objectsCache, genInfo);
auto collector = std::make_shared<CameraCollector>(genInfo.GetIntermediateFileName(CAMERAS_TO_WAYS_FILENAME), cache->GetCache());
auto collector =
std::make_shared<CameraCollector>(genInfo.GetIntermediateFileName(CAMERAS_TO_WAYS_FILENAME), cache->GetCache());
auto processor = CreateProcessor(ProcessorType::Noop);
auto translator = std::make_shared<TranslatorForTest>(processor, cache);
translator->SetCollector(collector);
@@ -131,8 +128,8 @@ UNIT_CLASS_TEST(TestCameraCollector, test_1)
{
string const osmSourceXML =
R"(<osm version="0.6" generator="osmconvert 0.8.4" timestamp="2018-07-16T02:00:00Z">
<node id="1" lat="55.779384" lon="37.3699375" version="1">)" + kSpeedCameraTag +
R"(</node><node id="2" lat="55.779304" lon="37.3699375" version="1">)" + kSpeedCameraTag +
<node id="1" lat="55.779384" lon="37.3699375" version="1">)" +
kSpeedCameraTag + R"(</node><node id="2" lat="55.779304" lon="37.3699375" version="1">)" + kSpeedCameraTag +
R"(</node><node id="3" lat="55.773084" lon="37.3699375" version="1">)" + kSpeedCameraTag +
R"(</node><node id="4" lat="55.773084" lon="37.3699375" version="1">
</node>
@@ -149,9 +146,7 @@ UNIT_CLASS_TEST(TestCameraCollector, test_1)
</way>
</osm>)";
std::set<pair<uint64_t, uint64_t>> trueAnswers = {
{1, 10}, {1, 20}, {2, 20}, {3, 20}
};
std::set<pair<uint64_t, uint64_t>> trueAnswers = {{1, 10}, {1, 20}, {2, 20}, {3, 20}};
TEST(TestCameraCollector::Test(osmSourceXML, trueAnswers), ());
}
@@ -160,8 +155,8 @@ UNIT_CLASS_TEST(TestCameraCollector, test_2)
{
string const osmSourceXML =
R"(<osm version="0.6" generator="osmconvert 0.8.4" timestamp="2018-07-16T02:00:00Z">
<node id="1" lat="55.779384" lon="37.3699375" version="1">)" + kSpeedCameraTag +
R"(</node><node id="2" lat="55.779304" lon="37.3699375" version="1">)" + kSpeedCameraTag +
<node id="1" lat="55.779384" lon="37.3699375" version="1">)" +
kSpeedCameraTag + R"(</node><node id="2" lat="55.779304" lon="37.3699375" version="1">)" + kSpeedCameraTag +
R"(</node><node id="3" lat="55.773084" lon="37.3699375" version="1">)" + kSpeedCameraTag +
R"(</node><node id="4" lat="55.773024" lon="37.3699375" version="1">)" + kSpeedCameraTag +
R"(</node><node id="5" lat="55.773014" lon="37.3699375" version="1">)" + kSpeedCameraTag +
@@ -185,9 +180,8 @@ UNIT_CLASS_TEST(TestCameraCollector, test_2)
</way>
</osm>)";
std::set<pair<uint64_t, uint64_t>> trueAnswers = {
{1, 10}, {2, 10}, {1, 20}, {3, 20}, {1, 30}, {3, 30}, {4, 30}, {5, 30}
};
std::set<pair<uint64_t, uint64_t>> trueAnswers = {{1, 10}, {2, 10}, {1, 20}, {3, 20},
{1, 30}, {3, 30}, {4, 30}, {5, 30}};
TEST(TestCameraCollector::Test(osmSourceXML, trueAnswers), ());
}
@@ -196,7 +190,8 @@ UNIT_CLASS_TEST(TestCameraCollector, test_3)
{
string const osmSourceXML =
R"(<osm version="0.6" generator="osmconvert 0.8.4" timestamp="2018-07-16T02:00:00Z">
<node id="1" lat="55.779384" lon="37.3699375" version="1">)" + kSpeedCameraTag +
<node id="1" lat="55.779384" lon="37.3699375" version="1">)" +
kSpeedCameraTag +
R"(</node><node id="2" lat="55.779384" lon="37.3699375" version="1">
</node>
<way id="10" version="1">
@@ -211,9 +206,7 @@ UNIT_CLASS_TEST(TestCameraCollector, test_3)
</way>
</osm>)";
std::set<pair<uint64_t, uint64_t>> trueAnswers = {
{1, 10}, {1, 20}
};
std::set<pair<uint64_t, uint64_t>> trueAnswers = {{1, 10}, {1, 20}};
TEST(TestCameraCollector::Test(osmSourceXML, trueAnswers), ());
}
@@ -222,7 +215,8 @@ UNIT_CLASS_TEST(TestCameraCollector, test_4)
{
string const osmSourceXML =
R"(<osm version="0.6" generator="osmconvert 0.8.4" timestamp="2018-07-16T02:00:00Z">
<node id="1" lat="55.779384" lon="37.3699375" version="1">)" + kSpeedCameraTag +
<node id="1" lat="55.779384" lon="37.3699375" version="1">)" +
kSpeedCameraTag +
R"(</node><way id="10" version="1">
<tag k="highway" v="unclassified"/>
</way>
@@ -252,4 +246,4 @@ UNIT_CLASS_TEST(TestCameraCollector, test_5)
TEST(TestCameraCollector::Test(osmSourceXML, trueAnswers), ());
}
} // namespace routing_builder
} // namespace routing_builder

View File

@@ -24,20 +24,16 @@ UNIT_TEST(CellsMerger_One)
UNIT_TEST(CellsMerger_Two)
{
generator::cells_merger::CellsMerger merger({{{0.0, 0.0}, {1.0, 1.0}},
{{1.0, 0.0}, {2.0, 1.0}}});
std::vector<m2::RectD> expected{{{0.0, 0.0}, {1.0, 1.0}},
{{1.0, 0.0}, {2.0, 1.0}}};
generator::cells_merger::CellsMerger merger({{{0.0, 0.0}, {1.0, 1.0}}, {{1.0, 0.0}, {2.0, 1.0}}});
std::vector<m2::RectD> expected{{{0.0, 0.0}, {1.0, 1.0}}, {{1.0, 0.0}, {2.0, 1.0}}};
auto const result = merger.Merge();
TEST_EQUAL(result, expected, ());
}
UNIT_TEST(CellsMerger_Four)
{
generator::cells_merger::CellsMerger merger({{{0.0, 0.0}, {1.0, 1.0}},
{{1.0, 0.0}, {2.0, 1.0}},
{{0.0, 1.0}, {1.0, 2.0}},
{{1.0, 1.0}, {2.0, 2.0}}});
generator::cells_merger::CellsMerger merger(
{{{0.0, 0.0}, {1.0, 1.0}}, {{1.0, 0.0}, {2.0, 1.0}}, {{0.0, 1.0}, {1.0, 2.0}}, {{1.0, 1.0}, {2.0, 2.0}}});
std::vector<m2::RectD> expected{{{0.0, 0.0}, {2.0, 2.0}}};
auto const result = merger.Merge();
TEST_EQUAL(result, expected, ());
@@ -45,23 +41,31 @@ UNIT_TEST(CellsMerger_Four)
UNIT_TEST(CellsMerger_Six)
{
generator::cells_merger::CellsMerger merger({{{0.0, 0.0}, {1.0, 1.0}}, {{1.0, 0.0}, {2.0, 1.0}},
{{0.0, 1.0}, {1.0, 2.0}}, {{1.0, 1.0}, {2.0, 2.0}},
{{2.0, 0.0}, {3.0, 1.0}}, {{2.0, 1.0}, {3.0, 2.0}}});
std::vector<m2::RectD> expected{{{1.0, 0.0}, {3.0, 2.0}}, {{0.0, 0.0}, {1.0, 1.0}},
{{0.0, 1.0}, {1.0, 2.0}}};
generator::cells_merger::CellsMerger merger({{{0.0, 0.0}, {1.0, 1.0}},
{{1.0, 0.0}, {2.0, 1.0}},
{{0.0, 1.0}, {1.0, 2.0}},
{{1.0, 1.0}, {2.0, 2.0}},
{{2.0, 0.0}, {3.0, 1.0}},
{{2.0, 1.0}, {3.0, 2.0}}});
std::vector<m2::RectD> expected{{{1.0, 0.0}, {3.0, 2.0}}, {{0.0, 0.0}, {1.0, 1.0}}, {{0.0, 1.0}, {1.0, 2.0}}};
auto const result = merger.Merge();
TEST_EQUAL(result, expected, ());
}
UNIT_TEST(CellsMerger_Eight)
{
generator::cells_merger::CellsMerger merger({{{0.0, 0.0}, {1.0, 1.0}}, {{1.0, 0.0}, {2.0, 1.0}},
{{0.0, 1.0}, {1.0, 2.0}}, {{1.0, 1.0}, {2.0, 2.0}},
{{2.0, 0.0}, {3.0, 1.0}}, {{2.0, 1.0}, {3.0, 2.0}},
{{3.0, 0.0}, {4.0, 1.0}}, {{3.0, 1.0}, {4.0, 2.0}}});
std::vector<m2::RectD> expected{{{1.0, 0.0}, {3.0, 2.0}}, {{0.0, 0.0}, {1.0, 1.0}},
{{0.0, 1.0}, {1.0, 2.0}}, {{3.0, 0.0}, {4.0, 1.0}},
generator::cells_merger::CellsMerger merger({{{0.0, 0.0}, {1.0, 1.0}},
{{1.0, 0.0}, {2.0, 1.0}},
{{0.0, 1.0}, {1.0, 2.0}},
{{1.0, 1.0}, {2.0, 2.0}},
{{2.0, 0.0}, {3.0, 1.0}},
{{2.0, 1.0}, {3.0, 2.0}},
{{3.0, 0.0}, {4.0, 1.0}},
{{3.0, 1.0}, {4.0, 2.0}}});
std::vector<m2::RectD> expected{{{1.0, 0.0}, {3.0, 2.0}},
{{0.0, 0.0}, {1.0, 1.0}},
{{0.0, 1.0}, {1.0, 2.0}},
{{3.0, 0.0}, {4.0, 1.0}},
{{3.0, 1.0}, {4.0, 2.0}}};
auto const result = merger.Merge();
TEST_EQUAL(result, expected, ());

Some files were not shown because too many files have changed in this diff Show More