Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
conversions.hh
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file numeric/conversions.hh
11 /// @brief Conversions between degrees and radians
12 /// @author Stuart G. Mentzer (Stuart_Mentzer@objexx.com)
13 
14 
15 #ifndef INCLUDED_numeric_conversions_hh
16 #define INCLUDED_numeric_conversions_hh
17 
18 
19 // Package headers
20 #include <numeric/NumericTraits.hh>
21 
22 
23 namespace numeric {
24 namespace conversions {
25 
27 
28 /// @brief Radians of degrees
29 template< typename T >
30 inline
31 T
32 radians( T const & degrees )
33 {
34  return degrees * NumericTraits< T >::degrees_to_radians();
35 }
36 
37 
38 /// @brief Radians of any angle
39 template< typename T >
40 inline
41 T
42 radians( T const & angle, AngleUnit const unit )
43 {
44  if ( unit == DEGREES ) {
46  } else /* unit == RADIANS */ {
47  return angle;
48  }
49 }
50 
51 
52 /// @brief Radians from degrees
53 template< typename T >
54 inline
55 T &
57 {
58  return degrees *= NumericTraits< T >::degrees_to_radians();
59 }
60 
61 
62 /// @brief Radians from any angle
63 template< typename T >
64 inline
65 T &
66 to_radians( T & angle, AngleUnit const unit )
67 {
68  if ( unit == DEGREES ) {
70  } else /* unit == RADIANS */ {
71  return angle;
72  }
73 }
74 
75 
76 /// @brief Degrees of radians
77 template< typename T >
78 inline
79 T
80 degrees( T const & radians )
81 {
82  return radians * NumericTraits< T >::radians_to_degrees();
83 }
84 
85 
86 /// @brief Degrees of any angle
87 template< typename T >
88 inline
89 T
90 degrees( T const & angle, AngleUnit const unit )
91 {
92  if ( unit == RADIANS ) {
94  } else /* unit == DEGREES */ {
95  return angle;
96  }
97 }
98 
99 
100 /// @brief Degrees from radians
101 template< typename T >
102 inline
103 T &
105 {
106  return radians *= NumericTraits< T >::radians_to_degrees();
107 }
108 
109 
110 /// @brief Degrees from any angle
111 template< typename T >
112 inline
113 T &
114 to_degrees( T & angle, AngleUnit const unit )
115 {
116  if ( unit == RADIANS ) {
117  return angle *= NumericTraits< T >::radians_to_degrees();
118  } else /* unit == DEGREES */ {
119  return angle;
120  }
121 }
122 
123 
124 /// @brief Any angle from radians
125 template< typename T >
126 inline
127 T
128 from_radians( T const & angle, AngleUnit const unit )
129 {
130  if ( unit == DEGREES ) {
132  } else /* unit == RADIANS */ {
133  return angle;
134  }
135 }
136 
137 
138 /// @brief Any angle from radians
139 template< typename T >
140 inline
141 T
142 from_degrees( T const & angle, AngleUnit const unit )
143 {
144  if ( unit == RADIANS ) {
146  } else /* unit == DEGREES */ {
147  return angle;
148  }
149 }
150 
151 
152 } // namespace conversions
153 } // namespace numeric
154 
155 
156 #endif // INCLUDED_numeric_conversions_HH
Numeric type traits.
T from_degrees(T const &angle, AngleUnit const unit)
Any angle from radians.
Definition: conversions.hh:142
static Type degrees_to_radians()
pi/180
def angle
Definition: Equations.py:36
static Type radians_to_degrees()
180/pi
T & to_degrees(T &radians)
Degrees from radians.
Definition: conversions.hh:104
T degrees(T const &radians)
Degrees of radians.
Definition: conversions.hh:80
T from_radians(T const &angle, AngleUnit const unit)
Any angle from radians.
Definition: conversions.hh:128
T radians(T const &degrees)
Radians of degrees.
Definition: conversions.hh:32
T & to_radians(T &degrees)
Radians from degrees.
Definition: conversions.hh:56