5 #include <marnav/math/floatingpoint.hpp>
11 /// Returns the degrees of this angle. This value is always positive.
12 uint32_t angle::degrees() const noexcept
14 auto a
= std::abs(get());
16 return static_cast<uint32_t>(a
);
19 /// Returns the minutes of this angle. This value is always positive
20 /// and is between 0 and 59.
21 uint32_t angle::minutes() const noexcept
23 auto a
= std::abs(get());
27 return static_cast<uint32_t>(a
);
30 /// Returns the seconds of this angle.
31 double angle::seconds() const noexcept
33 auto a
= std::abs(get());
42 void swap(angle
& a
, angle
& b
) noexcept
{ std::swap(a
.value
, b
.value
); }
44 bool operator==(const angle
& a
, const angle
& b
) noexcept
46 return (&a
== &b
) || math::is_same(a
.value
, b
.value
, angle::epsilon
);
49 bool operator!=(const angle
& a
, const angle
& b
) noexcept
{ return !(a
== b
); }
51 /// Constructs a latitude with the specified angle in degrees.
52 latitude::latitude(double deg
)
58 /// Initializes the object with the specified angle.
59 /// Corrects the stored value according to the specified hemisphere.
61 /// @param[in] degrees Angle in degrees.
62 /// @param[in] h Hemisphere
63 latitude::latitude(double degrees
, hemisphere h
)
69 case hemisphere::north
:
70 if (hem() == hemisphere::south
)
73 case hemisphere::south
:
74 if (hem() == hemisphere::north
)
80 latitude::latitude(uint32_t d
, uint32_t m
, uint32_t s
, hemisphere h
)
81 : angle((static_cast<double>(d
) + static_cast<double>(m
) / 60.0
82 + static_cast<double>(s
) / 3600.0)
83 * ((h
== hemisphere::south
) ? -1.0 : 1.0))
88 bool operator==(const latitude
& a
, const latitude
& b
) noexcept
90 return (&a
== &b
) || math::is_same(a
.get(), b
.get(), angle::epsilon
);
93 bool operator!=(const latitude
& a
, const latitude
& b
) noexcept
{ return !(a
== b
); }
95 void latitude::check(double a
)
97 if ((a
< min
) || (a
> max
))
98 throw std::invalid_argument
{"invalid value for nmea::latitude"};
101 std::string
to_string(latitude::hemisphere h
)
104 case latitude::hemisphere::north
:
106 case latitude::hemisphere::south
:
112 /// Constructs a longitude with the specified angle in degrees.
113 longitude::longitude(double deg
)
119 /// Initializes the object with the specified angle.
120 /// Corrects the stored value according to the specified hemisphere.
122 /// @param[in] degrees Angle in degrees.
123 /// @param[in] h Hemisphere
124 longitude::longitude(double degrees
, hemisphere h
)
130 case hemisphere::east
:
131 if (hem() == hemisphere::west
)
134 case hemisphere::west
:
135 if (hem() == hemisphere::east
)
141 longitude::longitude(uint32_t d
, uint32_t m
, uint32_t s
, hemisphere h
)
142 : angle((static_cast<double>(d
) + static_cast<double>(m
) / 60.0
143 + static_cast<double>(s
) / 3600.0)
144 * ((h
== hemisphere::east
) ? +1.0 : -1.0))
149 bool operator==(const longitude
& a
, const longitude
& b
) noexcept
151 return (&a
== &b
) || math::is_same(a
.get(), b
.get(), angle::epsilon
);
154 bool operator!=(const longitude
& a
, const longitude
& b
) noexcept
{ return !(a
== b
); }
156 void longitude::check(double a
)
158 if ((a
< min
) || (a
> max
))
159 throw std::invalid_argument
{"invalid value for nmea::longitude"};
162 std::string
to_string(longitude::hemisphere h
)
165 case longitude::hemisphere::east
:
167 case longitude::hemisphere::west
: