mirror of
https://codeberg.org/comaps/comaps
synced 2026-01-05 12:13:54 +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:
@@ -24,7 +24,6 @@
|
||||
|
||||
#include <boost/iterator/transform_iterator.hpp>
|
||||
|
||||
|
||||
namespace search
|
||||
{
|
||||
using namespace std;
|
||||
@@ -103,18 +102,15 @@ double const STREET_CONNECTION_LENGTH_M = 100.0;
|
||||
int const HN_NEARBY_DISTANCE = 4;
|
||||
double const STREET_CONNECTION_MAX_ANGLE = math::pi / 2.0;
|
||||
size_t const HN_COUNT_FOR_ODD_TEST = 16;
|
||||
//double const HN_MIN_READ_OFFSET_M = 50.0;
|
||||
//int const HN_NEARBY_INDEX_RANGE = 5;
|
||||
// double const HN_MIN_READ_OFFSET_M = 50.0;
|
||||
// int const HN_NEARBY_INDEX_RANGE = 5;
|
||||
double const HN_MAX_CONNECTION_DIST_M = 300.0;
|
||||
|
||||
class StreetCreator
|
||||
{
|
||||
public:
|
||||
explicit StreetCreator(Street * st) : m_street(st) {}
|
||||
void operator () (m2::PointD const & pt) const
|
||||
{
|
||||
m_street->m_points.push_back(pt);
|
||||
}
|
||||
void operator()(m2::PointD const & pt) const { m_street->m_points.push_back(pt); }
|
||||
|
||||
private:
|
||||
Street * m_street;
|
||||
@@ -133,12 +129,12 @@ double GetDistanceMeters(m2::PointD const & p1, m2::PointD const & p2)
|
||||
pair<double, double> GetConnectionAngleAndDistance(bool & isBeg, Street const * s1, Street const * s2)
|
||||
{
|
||||
m2::PointD const & p1 = isBeg ? s1->m_points.front() : s1->m_points.back();
|
||||
m2::PointD const & p0 = isBeg ? s1->m_points[1] : s1->m_points[s1->m_points.size()-2];
|
||||
m2::PointD const & p0 = isBeg ? s1->m_points[1] : s1->m_points[s1->m_points.size() - 2];
|
||||
|
||||
double const d0 = p1.SquaredLength(s2->m_points.front());
|
||||
double const d2 = p1.SquaredLength(s2->m_points.back());
|
||||
isBeg = (d0 < d2);
|
||||
m2::PointD const & p2 = isBeg ? s2->m_points[1] : s2->m_points[s2->m_points.size()-2];
|
||||
m2::PointD const & p2 = isBeg ? s2->m_points[1] : s2->m_points[s2->m_points.size() - 2];
|
||||
|
||||
return make_pair(ang::GetShortestDistance(ang::AngleTo(p0, p1), ang::AngleTo(p1, p2)), min(d0, d2));
|
||||
}
|
||||
@@ -166,10 +162,8 @@ public:
|
||||
bool operator()(MergedStreet const & st) const
|
||||
{
|
||||
for (size_t i = 0; i < st.m_cont.size(); ++i)
|
||||
{
|
||||
if (m_streets.count(st.m_cont[i]) > 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -280,10 +274,7 @@ public:
|
||||
House const * GetNearbyCandidate() const { return (HasBestMatch() ? 0 : m_results[3].house); }
|
||||
|
||||
private:
|
||||
bool IsBetter(int ind, double dist) const
|
||||
{
|
||||
return m_results[ind].house == 0 || m_results[ind].score > dist;
|
||||
}
|
||||
bool IsBetter(int ind, double dist) const { return m_results[ind].house == 0 || m_results[ind].score > dist; }
|
||||
|
||||
ParsedNumber m_number;
|
||||
bool m_isOdd = false;
|
||||
@@ -412,9 +403,10 @@ struct Competitiors
|
||||
uint32_t m_chainIndex;
|
||||
double m_score;
|
||||
Competitiors(uint32_t candidateIndex, uint32_t chainIndex, double score)
|
||||
: m_candidateIndex(candidateIndex), m_chainIndex(chainIndex), m_score(score)
|
||||
{
|
||||
}
|
||||
: m_candidateIndex(candidateIndex)
|
||||
, m_chainIndex(chainIndex)
|
||||
, m_score(score)
|
||||
{}
|
||||
bool operator<(Competitiors const & c) const { return m_score < c.m_score; }
|
||||
};
|
||||
|
||||
@@ -452,10 +444,8 @@ void ProccessHouses(vector<HouseProjection const *> const & st, ResultAccumulato
|
||||
ASSERT_LESS(used.size(), numeric_limits<uint32_t>::max(), ());
|
||||
uint32_t const count = static_cast<uint32_t>(used.size());
|
||||
for (uint32_t i = 0; i < count; ++i)
|
||||
{
|
||||
if (!used[i] && st[i]->m_house->GetIntNumber() == candidateHouseNumber)
|
||||
candidates.push_back(i);
|
||||
}
|
||||
|
||||
bool shouldAddHouseToQueue = false;
|
||||
vector<Competitiors> comp;
|
||||
@@ -470,12 +460,10 @@ void ProccessHouses(vector<HouseProjection const *> const & st, ResultAccumulato
|
||||
{
|
||||
double dist = numeric_limits<double>::max();
|
||||
for (size_t k = 0; k < houseChains[j].houses.size(); ++k)
|
||||
{
|
||||
if (abs(houseChains[j].houses[k]->m_house->GetIntNumber() -
|
||||
st[candidates[i]]->m_house->GetIntNumber()) <= HN_NEARBY_DISTANCE)
|
||||
if (abs(houseChains[j].houses[k]->m_house->GetIntNumber() - st[candidates[i]]->m_house->GetIntNumber()) <=
|
||||
HN_NEARBY_DISTANCE)
|
||||
dist = min(dist, GetDistanceMeters(houseChains[j].houses[k]->m_house->GetPosition(),
|
||||
st[candidates[i]]->m_house->GetPosition()));
|
||||
}
|
||||
if (dist < HN_MAX_CONNECTION_DIST_M)
|
||||
comp.push_back(Competitiors(candidates[i], static_cast<uint32_t>(j), dist));
|
||||
}
|
||||
@@ -582,8 +570,7 @@ struct GreaterSecond
|
||||
}
|
||||
};
|
||||
|
||||
void ProduceVoting(vector<ResultAccumulator> const & acc, vector<HouseResult> & res,
|
||||
MergedStreet const & st)
|
||||
void ProduceVoting(vector<ResultAccumulator> const & acc, vector<HouseResult> & res, MergedStreet const & st)
|
||||
{
|
||||
buffer_vector<pair<House const *, size_t>, 4> voting;
|
||||
|
||||
@@ -600,12 +587,10 @@ void ProduceVoting(vector<ResultAccumulator> const & acc, vector<HouseResult> &
|
||||
// Emit results with equal best score.
|
||||
size_t const score = voting[0].second;
|
||||
for (size_t i = 0; i < voting.size(); ++i)
|
||||
{
|
||||
if (score == voting[i].second)
|
||||
res.push_back(HouseResult(voting[i].first, &st));
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -625,9 +610,7 @@ ParsedNumber::ParsedNumber(string const & number, bool american) : m_fullN(numbe
|
||||
switch (number[curr])
|
||||
{
|
||||
case ' ':
|
||||
case '\t':
|
||||
++curr;
|
||||
break;
|
||||
case '\t': ++curr; break;
|
||||
case ',':
|
||||
case ';':
|
||||
++curr;
|
||||
@@ -672,11 +655,8 @@ ParsedNumber::ParsedNumber(string const & number, bool american) : m_fullN(numbe
|
||||
{
|
||||
if (abs(m_endN - m_startN) >= 2 * HN_NEARBY_DISTANCE)
|
||||
m_endN = -1;
|
||||
else
|
||||
{
|
||||
if (m_startN > m_endN)
|
||||
std::swap(m_startN, m_endN);
|
||||
}
|
||||
else if (m_startN > m_endN)
|
||||
std::swap(m_startN, m_endN);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -748,16 +728,21 @@ void Street::Reverse()
|
||||
reverse(m_points.begin(), m_points.end());
|
||||
}
|
||||
|
||||
void Street::SortHousesProjection() { sort(m_houses.begin(), m_houses.end(), &LessStreetDistance); }
|
||||
void Street::SortHousesProjection()
|
||||
{
|
||||
sort(m_houses.begin(), m_houses.end(), &LessStreetDistance);
|
||||
}
|
||||
|
||||
HouseDetector::HouseDetector(DataSource const & dataSource)
|
||||
: m_loader(dataSource), m_streetNum(0)
|
||||
HouseDetector::HouseDetector(DataSource const & dataSource) : m_loader(dataSource), m_streetNum(0)
|
||||
{
|
||||
// Default value for conversions.
|
||||
SetMetersToMercator(mercator::Bounds::kDegreesInMeter);
|
||||
}
|
||||
|
||||
HouseDetector::~HouseDetector() { ClearCaches(); }
|
||||
HouseDetector::~HouseDetector()
|
||||
{
|
||||
ClearCaches();
|
||||
}
|
||||
|
||||
void HouseDetector::SetMetersToMercator(double factor)
|
||||
{
|
||||
@@ -858,10 +843,10 @@ int HouseDetector::LoadStreets(vector<FeatureID> const & ids)
|
||||
|
||||
// Do clear cache if we have elements that are present in the one set,
|
||||
// but not in the other one (set's order is irrelevant).
|
||||
size_t const count = set_intersection(make_transform_iterator(m_id2st.begin(), f),
|
||||
make_transform_iterator(m_id2st.end(), f), ids.begin(),
|
||||
ids.end(), CounterIterator())
|
||||
.GetCount();
|
||||
size_t const count =
|
||||
set_intersection(make_transform_iterator(m_id2st.begin(), f), make_transform_iterator(m_id2st.end(), f),
|
||||
ids.begin(), ids.end(), CounterIterator())
|
||||
.GetCount();
|
||||
|
||||
if (count < min(ids.size(), m_id2st.size()))
|
||||
{
|
||||
@@ -926,9 +911,9 @@ int HouseDetector::MergeStreets()
|
||||
{
|
||||
LOG(LDEBUG, ("MergeStreets() called", m_id2st.size()));
|
||||
|
||||
//#ifdef DEBUG
|
||||
// KMLFileGuard file("dbg_merged_streets.kml");
|
||||
//#endif
|
||||
// #ifdef DEBUG
|
||||
// KMLFileGuard file("dbg_merged_streets.kml");
|
||||
// #endif
|
||||
|
||||
for (auto it = m_id2st.begin(); it != m_id2st.end(); ++it)
|
||||
{
|
||||
@@ -944,16 +929,16 @@ int HouseDetector::MergeStreets()
|
||||
// Put longer streets first (for better house scoring).
|
||||
sort(m_streets.begin(), m_streets.end(), MergedStreet::GreaterLength());
|
||||
|
||||
//#ifdef DEBUG
|
||||
// char const * arrColor[] = { "FFFF0000", "FF00FFFF", "FFFFFF00", "FF0000FF", "FF00FF00",
|
||||
// "FFFF00FF" };
|
||||
// #ifdef DEBUG
|
||||
// char const * arrColor[] = { "FFFF0000", "FF00FFFF", "FFFFFF00", "FF0000FF", "FF00FF00",
|
||||
// "FFFF00FF" };
|
||||
|
||||
// // Write to kml from short to long to get the longest one at the top.
|
||||
// for (int i = int(m_streets.size()) - 1; i >= 0; --i)
|
||||
// {
|
||||
// Streets2KML(file.GetStream(), m_streets[i], arrColor[i % ARRAY_SIZE(arrColor)]);
|
||||
// }
|
||||
//#endif
|
||||
// #endif
|
||||
|
||||
LOG(LDEBUG, ("MergeStreets() result", m_streetNum));
|
||||
return m_streetNum;
|
||||
@@ -1002,10 +987,8 @@ void MergedStreet::FinishReadingHouses()
|
||||
for (size_t i = 0; i < m_cont.size(); ++i)
|
||||
{
|
||||
if (i != 0)
|
||||
{
|
||||
for (size_t j = 0; j < m_cont[i]->m_houses.size(); ++j)
|
||||
m_cont[i]->m_houses[j].m_streetDistance += length;
|
||||
}
|
||||
|
||||
length += m_cont[i]->m_length;
|
||||
m_cont[i]->m_housesRead = true;
|
||||
@@ -1094,14 +1077,12 @@ void HouseDetector::ReadHouse(FeatureType & f, Street * st, ProjectionCalculator
|
||||
auto const it = m_id2house.find(f.GetID());
|
||||
bool const isNew = it == m_id2house.end();
|
||||
|
||||
m2::PointD const pt =
|
||||
isNew ? f.GetLimitRect(FeatureType::BEST_GEOMETRY).Center() : it->second->GetPosition();
|
||||
m2::PointD const pt = isNew ? f.GetLimitRect(FeatureType::BEST_GEOMETRY).Center() : it->second->GetPosition();
|
||||
|
||||
HouseProjection pr;
|
||||
if (calc.GetProjection(pt, pr) && pr.m_distMeters <= m_houseOffsetM)
|
||||
{
|
||||
pr.m_streetDistance =
|
||||
st->GetPrefixLength(pr.m_segIndex) + st->m_points[pr.m_segIndex].Length(pr.m_proj);
|
||||
pr.m_streetDistance = st->GetPrefixLength(pr.m_segIndex) + st->m_points[pr.m_segIndex].Length(pr.m_proj);
|
||||
|
||||
House * p;
|
||||
if (isNew)
|
||||
@@ -1129,9 +1110,8 @@ void HouseDetector::ReadHouses(Street * st)
|
||||
// offsetMeters));
|
||||
|
||||
ProjectionOnStreetCalculator calc(st->m_points);
|
||||
m_loader.ForEachInRect(st->GetLimitRect(m_houseOffsetM), [this, &st, &calc](FeatureType & ft) {
|
||||
ReadHouse<ProjectionOnStreetCalculator>(ft, st, calc);
|
||||
});
|
||||
m_loader.ForEachInRect(st->GetLimitRect(m_houseOffsetM), [this, &st, &calc](FeatureType & ft)
|
||||
{ ReadHouse<ProjectionOnStreetCalculator>(ft, st, calc); });
|
||||
|
||||
st->m_length = st->GetLength();
|
||||
st->SortHousesProjection();
|
||||
@@ -1145,10 +1125,8 @@ void HouseDetector::ReadAllHouses(double offsetMeters)
|
||||
ReadHouses(e.second);
|
||||
|
||||
for (auto & st : m_streets)
|
||||
{
|
||||
if (!st.IsHousesRead())
|
||||
st.FinishReadingHouses();
|
||||
}
|
||||
}
|
||||
|
||||
void HouseDetector::ClearCaches()
|
||||
@@ -1171,7 +1149,6 @@ void HouseDetector::ClearUnusedStreets(vector<FeatureID> const & ids)
|
||||
{
|
||||
set<Street *> streets;
|
||||
for (auto it = m_id2st.begin(); it != m_id2st.end();)
|
||||
{
|
||||
if (!binary_search(ids.begin(), ids.end(), it->first))
|
||||
{
|
||||
streets.insert(it->second);
|
||||
@@ -1179,11 +1156,9 @@ void HouseDetector::ClearUnusedStreets(vector<FeatureID> const & ids)
|
||||
}
|
||||
else
|
||||
++it;
|
||||
}
|
||||
|
||||
m_end2st.erase(remove_if(m_end2st.begin(), m_end2st.end(), HasSecond(streets)), m_end2st.end());
|
||||
m_streets.erase(remove_if(m_streets.begin(), m_streets.end(), HasStreet(streets)),
|
||||
m_streets.end());
|
||||
m_streets.erase(remove_if(m_streets.begin(), m_streets.end(), HasStreet(streets)), m_streets.end());
|
||||
|
||||
for_each(streets.begin(), streets.end(), base::DeleteFunctor());
|
||||
}
|
||||
@@ -1206,7 +1181,7 @@ void HouseDetector::GetHouseForName(string const & houseNumber, vector<HouseResu
|
||||
|
||||
vector<ResultAccumulator> acc(3, ResultAccumulator(houseNumber));
|
||||
|
||||
int offsets[] = { 25, 50, 100, 200, 500 };
|
||||
int offsets[] = {25, 50, 100, 200, 500};
|
||||
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
@@ -1227,7 +1202,7 @@ void HouseDetector::GetHouseForName(string const & houseNumber, vector<HouseResu
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
end:
|
||||
ProduceVoting(acc, res, m_streets[i]);
|
||||
|
||||
for (size_t j = 0; j < acc.size(); ++j)
|
||||
@@ -1238,7 +1213,10 @@ end:
|
||||
res.erase(unique(res.begin(), res.end()), res.end());
|
||||
}
|
||||
|
||||
string DebugPrint(HouseProjection const & p) { return p.m_house->GetNumber(); }
|
||||
string DebugPrint(HouseProjection const & p)
|
||||
{
|
||||
return p.m_house->GetNumber();
|
||||
}
|
||||
|
||||
string DebugPrint(HouseResult const & r)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user