[traffxml] Use m2::PointF for junctions

Signed-off-by: x7z4w <x7z4w@noreply.codeberg.org>
This commit is contained in:
x7z4w
2025-11-08 18:16:59 +00:00
parent a9700156db
commit b8f532b1d8
3 changed files with 30 additions and 56 deletions

View File

@@ -150,6 +150,12 @@ public:
{ {
size_t operator()(Point const & p) const { return math::Hash(p.x, p.y); } size_t operator()(Point const & p) const { return math::Hash(p.x, p.y); }
}; };
template <typename U>
operator Point<U>() const
{
return Point<U>(x, y);
}
}; };
using PointF = Point<float>; using PointF = Point<float>;

View File

@@ -624,18 +624,13 @@ double RoutingTraffDecoder::TraffEstimator::CalcOffroad(ms::LatLon const & from,
* *
* Returns: reduced offroad weight from table, or default offroad weight if not found * Returns: reduced offroad weight from table, or default offroad weight if not found
*/ */
auto const getOffroadFromJunction = [defaultWeight](ms::LatLon const & refPoint, auto const getOffroadFromJunction = [defaultWeight](ms::LatLon const & refPoint, ms::LatLon const & roadPoint,
ms::LatLon const & roadPoint, std::map<m2::PointF, double> const & junctions)
std::map<m2::PointD, double> const & junctions)
{ {
m2::PointD m2RoadPoint = mercator::FromLatLon(roadPoint); m2::PointF m2RoadPoint = mercator::FromLatLon(roadPoint);
auto it = junctions.find(m2RoadPoint); auto it = junctions.find(m2RoadPoint);
if (it != junctions.end()) if (it != junctions.end())
return it->second; return it->second;
// TODO this is likely an inefficient way to return near-matches
for (auto & [point, weight] : junctions)
if (m2RoadPoint.EqualDxDy(point, kMwmPointAccuracy))
return weight;
return defaultWeight; return defaultWeight;
}; };
@@ -1267,8 +1262,7 @@ void RoutingTraffDecoder::GetJunctionPointCandidates()
} }
} }
void RoutingTraffDecoder::GetJunctionPointCandidates(Point const & point, void RoutingTraffDecoder::GetJunctionPointCandidates(Point const & point, std::map<m2::PointF, double> & junctions)
std::map<m2::PointD, double> & junctions)
{ {
m2::PointD const m2Point = mercator::FromLatLon(point.m_coordinates); m2::PointD const m2Point = mercator::FromLatLon(point.m_coordinates);
std::map<m2::PointD, JunctionCandidateInfo> pointCandidates; std::map<m2::PointD, JunctionCandidateInfo> pointCandidates;
@@ -1495,10 +1489,8 @@ std::vector<std::string> ParseRef(std::string const & ref)
return res; return res;
} }
void TruncateStart(std::vector<routing::RouteSegment> & rsegments, void TruncateStart(std::vector<routing::RouteSegment> & rsegments, routing::Checkpoints const & checkpoints,
routing::Checkpoints const & checkpoints, size_t & start, double & startSaving, std::map<m2::PointF, double> const & junctions)
size_t & start, double & startSaving,
std::map<m2::PointD, double> const & junctions)
{ {
if (rsegments.empty()) if (rsegments.empty())
return; return;
@@ -1510,25 +1502,14 @@ void TruncateStart(std::vector<routing::RouteSegment> & rsegments,
* Examine end point of segment: for a junction, take weight from table; else calculate it as * Examine end point of segment: for a junction, take weight from table; else calculate it as
* direct distance multiplied with offroad penalty; calculate saving based on that. * direct distance multiplied with offroad penalty; calculate saving based on that.
*/ */
auto it = junctions.find(rsegments[i].GetJunction().GetPoint()); m2::PointF point = rsegments[i].GetJunction().GetPoint();
auto it = junctions.find(point);
if (it != junctions.end()) if (it != junctions.end())
newStartSaving = rsegments[i].GetTimeFromBeginningSec() - it->second; newStartSaving = rsegments[i].GetTimeFromBeginningSec() - it->second;
else else
{ newStartSaving = rsegments[i].GetTimeFromBeginningSec() -
bool matched = false; (mercator::DistanceOnEarth(checkpoints.GetStart(), point) * kOffroadPenalty);
// TODO this is likely an inefficient way to return near-matches
for (auto & [point, weight] : junctions)
if (rsegments[i].GetJunction().GetPoint().EqualDxDy(point, kMwmPointAccuracy))
{
newStartSaving = rsegments[i].GetTimeFromBeginningSec() - weight;
matched = true;
break;
}
if (!matched)
newStartSaving = rsegments[i].GetTimeFromBeginningSec()
- (mercator::DistanceOnEarth(checkpoints.GetStart(), rsegments[i].GetJunction().GetPoint())
* kOffroadPenalty);
}
if (newStartSaving > startSaving) if (newStartSaving > startSaving)
{ {
start = i + 1; // add 1 because we are ditching this segment and keeping the next one start = i + 1; // add 1 because we are ditching this segment and keeping the next one
@@ -1537,10 +1518,8 @@ void TruncateStart(std::vector<routing::RouteSegment> & rsegments,
} }
} }
void TruncateEnd(std::vector<routing::RouteSegment> & rsegments, void TruncateEnd(std::vector<routing::RouteSegment> & rsegments, routing::Checkpoints const & checkpoints, size_t & end,
routing::Checkpoints const & checkpoints, double & endSaving, double const endWeight, std::map<m2::PointF, double> const & junctions)
size_t & end, double & endSaving, double const endWeight,
std::map<m2::PointD, double> const & junctions)
{ {
for (size_t i = 0; i < rsegments.size(); i++) for (size_t i = 0; i < rsegments.size(); i++)
{ {
@@ -1549,25 +1528,14 @@ void TruncateEnd(std::vector<routing::RouteSegment> & rsegments,
* Examine end point of segment: for a junction, take weight from table; else calculate it as * Examine end point of segment: for a junction, take weight from table; else calculate it as
* direct distance multiplied with offroad penalty; calculate saving based on that. * direct distance multiplied with offroad penalty; calculate saving based on that.
*/ */
auto it = junctions.find(rsegments[i].GetJunction().GetPoint()); m2::PointF point = rsegments[i].GetJunction().GetPoint();
auto it = junctions.find(point);
if (it != junctions.end()) if (it != junctions.end())
newEndSaving = endWeight - rsegments[i].GetTimeFromBeginningSec() - it->second; newEndSaving = endWeight - rsegments[i].GetTimeFromBeginningSec() - it->second;
else else
{ newEndSaving = endWeight - rsegments[i].GetTimeFromBeginningSec() -
bool matched = false; (mercator::DistanceOnEarth(point, checkpoints.GetFinish()) * kOffroadPenalty);
// TODO this is likely an inefficient way to return near-matches
for (auto & [point, weight] : junctions)
if (rsegments[i].GetJunction().GetPoint().EqualDxDy(point, kMwmPointAccuracy))
{
newEndSaving = endWeight - rsegments[i].GetTimeFromBeginningSec() - weight;
matched = true;
break;
}
if (!matched)
newEndSaving = endWeight - rsegments[i].GetTimeFromBeginningSec()
- (mercator::DistanceOnEarth(rsegments[i].GetJunction().GetPoint(), checkpoints.GetFinish())
* kOffroadPenalty);
}
if (newEndSaving > endSaving) if (newEndSaving > endSaving)
{ {
end = i; end = i;

View File

@@ -507,7 +507,7 @@ private:
* @param junctions Receives a list of junction candidates with their weight * @param junctions Receives a list of junction candidates with their weight
*/ */
void GetJunctionPointCandidates(Point const & point, void GetJunctionPointCandidates(Point const & point,
std::map<m2::PointD, double> & junctions); std::map<m2::PointF, double> & junctions);
/** /**
* @brief Mutex for access to shared members. * @brief Mutex for access to shared members.
@@ -530,7 +530,7 @@ private:
* If the list is empty, no junction alignment at the `from` point will be done and decoding * If the list is empty, no junction alignment at the `from` point will be done and decoding
* relies solely on point coordinates. * relies solely on point coordinates.
*/ */
std::map<m2::PointD, double> m_startJunctions; std::map<m2::PointF, double> m_startJunctions;
/** /**
* @brief Junction points near end of location, with their associated offroad weight. * @brief Junction points near end of location, with their associated offroad weight.
@@ -538,7 +538,7 @@ private:
* If the list is empty, no junction alignment at the `to` point will be done and decoding * If the list is empty, no junction alignment at the `to` point will be done and decoding
* relies solely on point coordinates. * relies solely on point coordinates.
*/ */
std::map<m2::PointD, double> m_endJunctions; std::map<m2::PointF, double> m_endJunctions;
/** /**
* @brief Radius around reference points in which to search for junctions. * @brief Radius around reference points in which to search for junctions.
@@ -601,7 +601,7 @@ std::vector<std::string> ParseRef(std::string const & ref);
void TruncateStart(std::vector<routing::RouteSegment> & rsegments, void TruncateStart(std::vector<routing::RouteSegment> & rsegments,
routing::Checkpoints const & checkpoints, routing::Checkpoints const & checkpoints,
size_t & start, double & startSaving, size_t & start, double & startSaving,
std::map<m2::PointD, double> const & junctions); std::map<m2::PointF, double> const & junctions);
/** /**
* @brief Calculates the segments to truncate at the start of the route. * @brief Calculates the segments to truncate at the start of the route.
@@ -621,5 +621,5 @@ void TruncateStart(std::vector<routing::RouteSegment> & rsegments,
void TruncateEnd(std::vector<routing::RouteSegment> & rsegments, void TruncateEnd(std::vector<routing::RouteSegment> & rsegments,
routing::Checkpoints const & checkpoints, routing::Checkpoints const & checkpoints,
size_t & end, double & endSaving, double const endWeight, size_t & end, double & endSaving, double const endWeight,
std::map<m2::PointD, double> const & junctions); std::map<m2::PointF, double> const & junctions);
} // namespace traffxml } // namespace traffxml