1
#ifndef LOCATION_SERVICE_COM_UBUNTU_LOCATION_VELOCITY_H_
2
#define LOCATION_SERVICE_COM_UBUNTU_LOCATION_VELOCITY_H_
4
#include "com/ubuntu/location/accuracy.h"
5
#include "com/ubuntu/location/units/units.h"
19
typedef units::Velocity Unit;
20
typedef units::Quantity<Unit> Quantity;
22
static inline const Quantity& min()
24
static const Quantity instance = Quantity::from_value(0.);
28
static inline const Quantity max()
30
static const Quantity instance = Quantity::from_value(std::numeric_limits<double>::max());
34
Velocity(const Quantity& value = Quantity()) : value(value)
36
if (value < Velocity::min())
37
throw std::out_of_range("");
38
if (value > Velocity::max())
39
throw std::out_of_range("");
42
inline bool operator==(const Velocity& rhs) const
44
return value == rhs.value;
47
inline bool operator!=(const Velocity& rhs) const
49
return value != rhs.value;
55
inline std::ostream& operator<<(std::ostream& out, const Velocity& velocity)
57
out << "Velocity(" << velocity.value << ")";
62
struct AccuracyTraits<Velocity>
64
static AccuracyLevel classify(const Velocity& h)
66
if (h.value > (1.f * units::MetersPerSecond))
67
return AccuracyLevel::worst;
69
if (h.value <= (1.f * units::MetersPerSecond))
70
return AccuracyLevel::best;
72
return AccuracyLevel::worst;
75
static Accuracy<Velocity> best()
77
return Accuracy<Velocity>{Velocity{Velocity::min()}};
80
static Accuracy<Velocity> worst()
82
return Accuracy<Velocity>{Velocity{2*units::MetersPerSecond}};
89
#endif // LOCATION_SERVICE_COM_UBUNTU_LOCATION_VELOCITY_H_