[traffic] Comparison operators for TrafficImpact, TraffLocation and Point

Signed-off-by: mvglasow <michael -at- vonglasow.com>
This commit is contained in:
mvglasow
2025-05-16 18:32:47 +03:00
parent a39bdee0d1
commit e2aff53291
2 changed files with 59 additions and 0 deletions

View File

@@ -159,6 +159,21 @@ bool IsoTime::operator> (IsoTime & rhs)
return t_lhs > t_rhs;
}
bool operator==(TrafficImpact const & lhs, TrafficImpact const & rhs)
{
if ((lhs.m_speedGroup == traffic::SpeedGroup::TempBlock)
&& (rhs.m_speedGroup == traffic::SpeedGroup::TempBlock))
return true;
return (lhs.m_speedGroup == rhs.m_speedGroup)
&& (lhs.m_maxspeed == rhs.m_maxspeed)
&& (lhs.m_delayMins == rhs.m_delayMins);
}
bool operator==(Point const & lhs, Point const & rhs)
{
return lhs.m_coordinates == rhs.m_coordinates;
}
openlr::LocationReferencePoint Point::ToLrp()
{
openlr::LocationReferencePoint result;
@@ -166,6 +181,15 @@ openlr::LocationReferencePoint Point::ToLrp()
return result;
}
bool operator==(TraffLocation const & lhs, TraffLocation const & rhs)
{
return (lhs.m_from == rhs.m_from)
&& (lhs.m_at == rhs.m_at)
&& (lhs.m_via == rhs.m_via)
&& (lhs.m_notVia == rhs.m_notVia)
&& (lhs.m_to == rhs.m_to);
}
openlr::LinearLocationReference TraffLocation::ToLinearLocationReference(bool backwards)
{
openlr::LinearLocationReference locationReference;

View File

@@ -226,6 +226,17 @@ enum class EventType
*/
struct TrafficImpact
{
/**
* @brief Whether two `TrafficImpact` instances are equal.
*
* Instances are considered equal if both have a speed group of `TempBlock`, in which case other
* members are not compared. Otherwise, they are equal if, and only if, all three members hold
* identical values between both instances.
*/
// Non-member friend as member operators do not work with std::optional
friend bool operator==(TrafficImpact const & lhs, TrafficImpact const & rhs);
friend bool operator!=(TrafficImpact const & lhs, TrafficImpact const & rhs) { return !(lhs == rhs); }
/**
* @brief The speed group for the affected segments, or `traffic::SpeedGroup::Unknown` if unknown.
*/
@@ -244,6 +255,15 @@ struct TrafficImpact
struct Point
{
/**
* @brief Whether two points are equal.
*
* Two points are equal if, and only if, their coordinates are. Other attributes are not compared.
*/
// Non-member friend as member operators do not work with std::optional
friend bool operator==(Point const & lhs, Point const & rhs);
friend bool operator!=(Point const & lhs, Point const & rhs) { return !(lhs == rhs); }
/**
* @brief Converts the point to an OpenLR location reference point.
*
@@ -262,6 +282,21 @@ struct Point
struct TraffLocation
{
/**
* @brief Whether two locations are equal.
*
* Two locations are equal if, and only if, they contain the same points in the same roles.
*
* @todo Road class and ramps are not compared, though these values are used by the decoder. Not
* comparing these values could lead to two seemingly equal locations resolving to a different
* path. However, given that comparison only takes place between messages with identical IDs
* (indicating both refer to the same event at the same location), such a situation is highly
* unlikely to occur in practice.
*/
// Non-member friend as member operators do not work with std::optional
friend bool operator==(TraffLocation const & lhs, TraffLocation const & rhs);
friend bool operator!=(TraffLocation const & lhs, TraffLocation const & rhs) { return !(lhs == rhs); }
/**
* @brief Converts the location to an OpenLR linear location reference.
*