19 #ifndef SNARK_MATH_ANGLE_H_
20 #define SNARK_MATH_ANGLE_H_
22 #include <comma/math/cyclic.h>
24 namespace snark{
namespace math{
33 explicit radians(
double d ) : value( d ) {}
41 explicit degrees(
double d ) : value( d ) {}
48 template <
typename T >
49 class angle :
public comma::math::cyclic< T >
53 angle() : comma::math::cyclic< T >( comma::math::interval< T >( 0, 360 ), 0 ) {}
54 angle(
degrees d ) : comma::math::cyclic< T >( comma::math::interval< T >( 0, 360 ), static_cast< T >( d.value ) ) {}
55 angle( radians d ) : comma::math::cyclic< T >( comma::math::interval< T >( 0, 360 ), static_cast< T >( degrees( d ).value ) ) {}
56 angle(
const angle& rhs ) : comma::math::cyclic< T >( rhs.interval(), rhs() ) {}
59 T
as_degrees()
const {
return comma::math::cyclic< T >::operator()(); }
60 double as_radians()
const {
return math::radians(
degrees(comma::math::cyclic< T >::operator()()) ).value; }
64 const angle& operator-=(
const angle& rhs ) { comma::math::cyclic< T >::operator-=( rhs );
return *
this; }
66 const angle& operator-=( T t ) { comma::math::cyclic< T >::operator-=( t );
return *
this; }
67 const angle& operator*=( T t ) { comma::math::cyclic< T >::operator=( comma::math::cyclic< T >::operator()() * t );
return *
this; }
68 const angle& operator/=( T t ) { comma::math::cyclic< T >::operator=( comma::math::cyclic< T >::operator()() / t );
return *
this; }
69 angle operator+(
const angle& rhs )
const {
angle a( *
this ); a += rhs;
return a; }
70 angle operator-(
const angle& rhs )
const {
angle a( *
this ); a -= rhs;
return a; }
71 angle operator+( T rhs )
const {
angle a( *
this ); a += rhs;
return a; }
72 angle operator-( T rhs )
const {
angle a( *
this ); a -= rhs;
return a; }
73 angle operator*( T rhs )
const {
angle a( *
this ); a *= rhs;
return a; }
74 angle operator/( T rhs )
const {
angle a( *
this ); a /= rhs;
return a; }
77 T operator()()
const {
return comma::math::cyclic< T >::operator()(); }
80 inline radians::radians( degrees d ) { value = d.value *
static_cast< double >( M_PI ) / 180; }
82 inline degrees::degrees( radians d ) { value = d.value * 180 /
static_cast< double >( M_PI ); }
86 #endif // SNARK_MATH_ANGLE_H_