forked from organicmaps/organicmaps
PR fixes.
This commit is contained in:
parent
eb1eae4123
commit
74eba830c9
4 changed files with 31 additions and 30 deletions
|
@ -272,7 +272,8 @@ Route::IterT Route::FindProjection(m2::RectD const & posRect, double predictDist
|
|||
|
||||
double Route::GetDistanceOnPolyline(IterT const & it1, IterT const & it2) const
|
||||
{
|
||||
ASSERT(it1.IsValid() && it2.IsValid(), ());
|
||||
ASSERT(it1.IsValid(), ());
|
||||
ASSERT(it2.IsValid(), ());
|
||||
ASSERT_LESS_OR_EQUAL(it1.m_ind, it2.m_ind, ());
|
||||
ASSERT_LESS(it1.m_ind, m_poly.GetSize(), ());
|
||||
ASSERT_LESS(it2.m_ind, m_poly.GetSize(), ());
|
||||
|
@ -290,9 +291,9 @@ void Route::Update()
|
|||
if (m_routingSettings.m_keepPedestrianInfo)
|
||||
{
|
||||
vector<m2::PointD> points;
|
||||
auto distf = m2::DistanceToLineSquare<m2::PointD>();
|
||||
auto distFn = m2::DistanceToLineSquare<m2::PointD>();
|
||||
// TODO (ldargunov) Rewrite dist f to distance in meters and avoid 0.00000 constants.
|
||||
SimplifyNearOptimal(20, m_poly.Begin(), m_poly.End(), 0.00000001, distf,
|
||||
SimplifyNearOptimal(20, m_poly.Begin(), m_poly.End(), 0.00000001, distFn,
|
||||
MakeBackInsertFunctor(points));
|
||||
m_pedestrianFollower = RouteFollower(points.begin(), points.end());
|
||||
}
|
||||
|
|
|
@ -30,8 +30,8 @@ public:
|
|||
explicit Route(string const & router)
|
||||
: m_router(router), m_routingSettings(GetCarRoutingSettings()) {}
|
||||
|
||||
template <class IterT>
|
||||
Route(string const & router, IterT beg, IterT end)
|
||||
template <class TIter>
|
||||
Route(string const & router, TIter beg, TIter end)
|
||||
: m_router(router), m_routingSettings(GetCarRoutingSettings()), m_poly(beg, end)
|
||||
{
|
||||
Update();
|
||||
|
@ -41,7 +41,7 @@ public:
|
|||
|
||||
void Swap(Route & rhs);
|
||||
|
||||
template <class IterT> void SetGeometry(IterT beg, IterT end)
|
||||
template <class TIter> void SetGeometry(TIter beg, TIter end)
|
||||
{
|
||||
m2::PolylineD(beg, end).Swap(m_poly);
|
||||
Update();
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace
|
|||
double constexpr kPedestrianEdgeSwitchMeters = 5.0;
|
||||
} // namespace
|
||||
|
||||
double RouteFollower::GetDistanceOnPolyline(IterT const & it1, IterT const & it2) const
|
||||
double RouteFollower::GetDistanceOnPolyline(Iter const & it1, Iter const & it2) const
|
||||
{
|
||||
ASSERT(it1.IsValid() && it2.IsValid(), ());
|
||||
ASSERT_LESS_OR_EQUAL(it1.m_ind, it2.m_ind, ());
|
||||
|
@ -51,14 +51,14 @@ void RouteFollower::Update()
|
|||
m_segProj[i].SetBounds(p1, p2);
|
||||
}
|
||||
|
||||
m_current = IterT(m_poly.Front(), 0);
|
||||
m_current = Iter(m_poly.Front(), 0);
|
||||
}
|
||||
|
||||
template <class DistanceF>
|
||||
RouteFollower::IterT RouteFollower::GetClosestProjection(m2::RectD const & posRect,
|
||||
DistanceF const & distFn) const
|
||||
template <class DistanceFn>
|
||||
RouteFollower::Iter RouteFollower::GetClosestProjection(m2::RectD const & posRect,
|
||||
DistanceFn const & distFn) const
|
||||
{
|
||||
IterT res;
|
||||
Iter res;
|
||||
double minDist = numeric_limits<double>::max();
|
||||
|
||||
m2::PointD const currPos = posRect.Center();
|
||||
|
@ -70,7 +70,7 @@ RouteFollower::IterT RouteFollower::GetClosestProjection(m2::RectD const & posRe
|
|||
if (!posRect.IsPointInside(pt))
|
||||
continue;
|
||||
|
||||
IterT it(pt, i);
|
||||
Iter it(pt, i);
|
||||
double const dp = distFn(it);
|
||||
if (dp < minDist)
|
||||
{
|
||||
|
@ -82,25 +82,25 @@ RouteFollower::IterT RouteFollower::GetClosestProjection(m2::RectD const & posRe
|
|||
return res;
|
||||
}
|
||||
|
||||
RouteFollower::IterT RouteFollower::FindProjection(m2::RectD const & posRect,
|
||||
RouteFollower::Iter RouteFollower::FindProjection(m2::RectD const & posRect,
|
||||
double predictDistance) const
|
||||
{
|
||||
ASSERT(m_current.IsValid(), ());
|
||||
ASSERT_LESS(m_current.m_ind, m_poly.GetSize() - 1, ());
|
||||
|
||||
IterT res;
|
||||
Iter res;
|
||||
if (predictDistance >= 0.0)
|
||||
{
|
||||
res = GetClosestProjection(posRect, [&](IterT const & it)
|
||||
{
|
||||
res = GetClosestProjection(posRect, [&](Iter const & it)
|
||||
{
|
||||
return fabs(GetDistanceOnPolyline(m_current, it) - predictDistance);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
m2::PointD const currPos = posRect.Center();
|
||||
res = GetClosestProjection(posRect, [&](IterT const & it)
|
||||
{
|
||||
res = GetClosestProjection(posRect, [&](Iter const & it)
|
||||
{
|
||||
return MercatorBounds::DistanceOnEarth(it.m_pt, currPos);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -11,8 +11,8 @@ class RouteFollower
|
|||
{
|
||||
public:
|
||||
RouteFollower() {}
|
||||
template <class IterT>
|
||||
RouteFollower(IterT begin, IterT end)
|
||||
template <class TIter>
|
||||
RouteFollower(TIter begin, TIter end)
|
||||
: m_poly(begin, end)
|
||||
{
|
||||
Update();
|
||||
|
@ -20,34 +20,34 @@ public:
|
|||
|
||||
void Swap(RouteFollower & rhs);
|
||||
|
||||
struct IterT
|
||||
struct Iter
|
||||
{
|
||||
m2::PointD m_pt;
|
||||
size_t m_ind;
|
||||
|
||||
IterT(m2::PointD pt, size_t ind) : m_pt(pt), m_ind(ind) {}
|
||||
IterT() : m_ind(-1) {}
|
||||
Iter(m2::PointD pt, size_t ind) : m_pt(pt), m_ind(ind) {}
|
||||
Iter() : m_ind(-1) {}
|
||||
|
||||
bool IsValid() const { return m_ind != -1; }
|
||||
};
|
||||
|
||||
IterT GetCurrentIter() { return m_current; }
|
||||
Iter GetCurrentIter() { return m_current; }
|
||||
|
||||
IterT FindProjection(m2::RectD const & posRect, double predictDistance = -1.0) const;
|
||||
Iter FindProjection(m2::RectD const & posRect, double predictDistance = -1.0) const;
|
||||
|
||||
void GetCurrentDirectionPoint(m2::PointD & pt) const;
|
||||
|
||||
private:
|
||||
template <class DistanceF>
|
||||
IterT GetClosestProjection(m2::RectD const & posRect, DistanceF const & distFn) const;
|
||||
template <class DistanceFn>
|
||||
Iter GetClosestProjection(m2::RectD const & posRect, DistanceFn const & distFn) const;
|
||||
|
||||
void Update();
|
||||
|
||||
double GetDistanceOnPolyline(IterT const & it1, IterT const & it2) const;
|
||||
double GetDistanceOnPolyline(Iter const & it1, Iter const & it2) const;
|
||||
|
||||
m2::PolylineD m_poly;
|
||||
|
||||
mutable IterT m_current;
|
||||
mutable Iter m_current;
|
||||
/// Precalculated info for fast projection finding.
|
||||
vector<m2::ProjectionToSection<m2::PointD>> m_segProj;
|
||||
/// Accumulated cache of segments length in meters.
|
||||
|
|
Loading…
Add table
Reference in a new issue