Skip to content

Commit

Permalink
facilities: minimize rounding issues by using tenth_microdegree
Browse files Browse the repository at this point in the history
  • Loading branch information
riebl committed Oct 21, 2024
1 parent d21df9e commit c93410c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions vanetza/facilities/cam_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace facilities
using vanetza::units::Angle;

static const auto microdegree = units::degree * units::si::micro;
static const auto tenth_microdegree = units::si::deci * microdegree;

bool similar_heading(Angle a, Angle b, Angle limit)
{
Expand Down
22 changes: 13 additions & 9 deletions vanetza/facilities/detail/reference_position.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ namespace vanetza
namespace facilities
{

static_assert(Longitude_oneMicrodegreeEast == 10, "Longitude is an integer number of tenth microdegrees");
static_assert(Latitude_oneMicrodegreeNorth == 10, "Latitude is an integer number of tenth microdegrees");

units::Length distance(const ASN1_PREFIXED(ReferencePosition_t)& a, const ASN1_PREFIXED(ReferencePosition_t)& b)
{
using geonet::GeodeticPosition;
Expand All @@ -18,12 +21,12 @@ units::Length distance(const ASN1_PREFIXED(ReferencePosition_t)& a, const ASN1_P
auto length = units::Length::from_value(std::numeric_limits<double>::quiet_NaN());
if (is_available(a) && is_available(b)) {
GeodeticPosition geo_a {
GeoAngle { a.latitude / Latitude_oneMicrodegreeNorth * microdegree },
GeoAngle { a.longitude / Longitude_oneMicrodegreeEast * microdegree }
GeoAngle { a.latitude * tenth_microdegree },
GeoAngle { a.longitude * tenth_microdegree }
};
GeodeticPosition geo_b {
GeoAngle { b.latitude / Latitude_oneMicrodegreeNorth * microdegree },
GeoAngle { b.longitude / Longitude_oneMicrodegreeEast * microdegree }
GeoAngle { b.latitude * tenth_microdegree },
GeoAngle { b.longitude * tenth_microdegree }
};
length = geonet::distance(geo_a, geo_b);
}
Expand All @@ -38,8 +41,8 @@ units::Length distance(const ASN1_PREFIXED(ReferencePosition_t)& a, units::GeoAn
auto length = units::Length::from_value(std::numeric_limits<double>::quiet_NaN());
if (is_available(a)) {
GeodeticPosition geo_a {
GeoAngle { a.latitude / Latitude_oneMicrodegreeNorth * microdegree },
GeoAngle { a.longitude / Longitude_oneMicrodegreeEast * microdegree }
GeoAngle { a.latitude * tenth_microdegree },
GeoAngle { a.longitude * tenth_microdegree }
};
GeodeticPosition geo_b { lat, lon };
length = geonet::distance(geo_a, geo_b);
Expand All @@ -52,9 +55,10 @@ bool is_available(const ASN1_PREFIXED(ReferencePosition)& pos)
return pos.latitude != ASN1_PREFIXED(Latitude_unavailable) && pos.longitude != ASN1_PREFIXED(Longitude_unavailable);
}

void copy(const PositionFix& position, ASN1_PREFIXED(ReferencePosition)& reference_position) {
reference_position.longitude = round(position.longitude, microdegree) * Longitude_oneMicrodegreeEast;
reference_position.latitude = round(position.latitude, microdegree) * Latitude_oneMicrodegreeNorth;
void copy(const PositionFix& position, ASN1_PREFIXED(ReferencePosition)& reference_position)
{
reference_position.longitude = round(position.longitude, tenth_microdegree);
reference_position.latitude = round(position.latitude, tenth_microdegree);
if (std::isfinite(position.confidence.semi_major.value())
&& std::isfinite(position.confidence.semi_minor.value()))
{
Expand Down

0 comments on commit c93410c

Please sign in to comment.