mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-20 13:23:59 +00:00
Format all C++ and Java code via clang-format
Signed-off-by: Konstantin Pastbin <konstantin.pastbin@gmail.com>
This commit is contained in:
@@ -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};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user