CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
approx_atan2.h File Reference
#include <cstdint>
#include <cmath>
#include <limits>
#include <algorithm>

Go to the source code of this file.

Functions

template<int DEGREE>
float approx_atan2f_P (float x)
 
template<>
float approx_atan2f_P< 11 > (float x)
 
template<>
float approx_atan2f_P< 13 > (float x)
 
template<>
float approx_atan2f_P< 15 > (float x)
 
template<>
float approx_atan2f_P< 3 > (float x)
 
template<>
float approx_atan2f_P< 5 > (float x)
 
template<>
float approx_atan2f_P< 7 > (float x)
 
template<>
float approx_atan2f_P< 9 > (float x)
 
template<int DEGREE>
float approx_atan2i_P (float x)
 
template<>
float approx_atan2i_P< 11 > (float x)
 
template<>
float approx_atan2i_P< 13 > (float x)
 
template<>
float approx_atan2i_P< 15 > (float x)
 
template<>
float approx_atan2i_P< 3 > (float x)
 
template<>
float approx_atan2i_P< 5 > (float x)
 
template<>
float approx_atan2i_P< 7 > (float x)
 
template<>
float approx_atan2i_P< 9 > (float x)
 
double int2dphi (int x)
 
float int2phi (int x)
 
int phi2int (float x)
 
short phi2short (float x)
 
template<int DEGREE>
float safe_atan2f (float y, float x)
 
float short2phi (short x)
 
template<int DEGREE>
float unsafe_atan2f (float y, float x)
 
template<int DEGREE>
float unsafe_atan2f_impl (float y, float x)
 
template<int DEGREE>
int unsafe_atan2i (float y, float x)
 
template<int DEGREE>
int unsafe_atan2i_impl (float y, float x)
 

Function Documentation

template<int DEGREE>
float approx_atan2f_P ( float  x)
inline
template<>
float approx_atan2f_P< 11 > ( float  x)
inline

Definition at line 69 of file approx_atan2.h.

References x, and detailsBasic3DVector::z.

69  {
70  auto z = x*x;
71  return x * (float(-0xf.ffe82p-4) + z * (float(0x5.526c8p-4) + z * (float(-0x3.18bea8p-4) + z * (float(0x1.dce3bcp-4) + z * (float(-0xd.7a64ap-8) + z * float(0x3.000eap-8))))));
72 }
float float float z
Definition: DDAxes.h:10
template<>
float approx_atan2f_P< 13 > ( float  x)
inline

Definition at line 75 of file approx_atan2.h.

References x, and detailsBasic3DVector::z.

75  {
76  auto z = x*x;
77  return x * (float(-0xf.fffbep-4) + z * (float(0x5.54adp-4) + z * (float(-0x3.2b4df8p-4) + z * (float(0x2.1df79p-4) + z * (float(-0x1.46081p-4) + z * (float(0x8.99028p-8) + z * float(-0x1.be0bc4p-8))))))) ;
78 }
float float float z
Definition: DDAxes.h:10
template<>
float approx_atan2f_P< 15 > ( float  x)
inline

Definition at line 81 of file approx_atan2.h.

References x, and detailsBasic3DVector::z.

81  {
82  auto z = x*x;
83  return x * (float(-0xf.ffff4p-4) + z * (float(0x5.552f9p-4 + z * (float(-0x3.30f728p-4) + z * (float(0x2.39826p-4) + z * (float(-0x1.8a880cp-4) + z * (float(0xe.484d6p-8) + z * (float(-0x5.93d5p-8) + z * float(0x1.0875dcp-8)))))))));
84 }
float float float z
Definition: DDAxes.h:10
template<>
float approx_atan2f_P< 3 > ( float  x)
inline

Definition at line 46 of file approx_atan2.h.

References x.

46  {
47  return x * (float(-0xf.8eed2p-4) + x*x * float(0x3.1238p-4)) ;
48 }
Definition: DDAxes.h:10
template<>
float approx_atan2f_P< 5 > ( float  x)
inline

Definition at line 51 of file approx_atan2.h.

References x, and detailsBasic3DVector::z.

51  {
52  auto z = x*x;
53  return x * (float(-0xf.ecfc8p-4) + z * (float(0x4.9e79dp-4) + z * float(-0x1.44f924p-4) ) );
54 }
float float float z
Definition: DDAxes.h:10
template<>
float approx_atan2f_P< 7 > ( float  x)
inline

Definition at line 57 of file approx_atan2.h.

References x, and detailsBasic3DVector::z.

57  {
58  auto z = x*x;
59  return x * (float(-0xf.fcc7ap-4) + z * (float(0x5.23886p-4) + z * (float(-0x2.571968p-4) + z * float(0x9.fb05p-8) ) ) ) ;
60 }
float float float z
Definition: DDAxes.h:10
template<>
float approx_atan2f_P< 9 > ( float  x)
inline

Definition at line 63 of file approx_atan2.h.

References x, and detailsBasic3DVector::z.

63  {
64  auto z = x*x;
65  return x * (float(-0xf.ff73ep-4) + z * (float(0x5.48ee1p-4) + z * (float(-0x2.e1efe8p-4) + z * (float(0x1.5cce54p-4) + z * float(-0x5.56245p-8) ) ) ) );
66 }
float float float z
Definition: DDAxes.h:10
template<int DEGREE>
float approx_atan2i_P ( float  x)
inline
template<>
float approx_atan2i_P< 11 > ( float  x)
inline

Definition at line 155 of file approx_atan2.h.

References x, and detailsBasic3DVector::z.

155  {
156  auto z = x*x;
157  return x * (-683549696.f + z * (227369312.f + z * (-132297008.f + z * (79584144.f + z * (-35987016.f + z * 8010488.f)))));
158 }
float float float z
Definition: DDAxes.h:10
template<>
float approx_atan2i_P< 13 > ( float  x)
inline

Definition at line 161 of file approx_atan2.h.

References x, and detailsBasic3DVector::z.

161  {
162  auto z = x*x;
163  return x * (-683562624.f + z * (227746080.f + z * (-135400128.f + z * (90460848.f + z * (-54431464.f + z * (22973256.f + z * (-4657049.f)))))));
164 }
float float float z
Definition: DDAxes.h:10
template<>
float approx_atan2i_P< 15 > ( float  x)
inline

Definition at line 166 of file approx_atan2.h.

References x, and detailsBasic3DVector::z.

166  {
167  auto z = x*x;
168  return x * (-683562624.f + z * (227746080.f + z * (-135400128.f + z * (90460848.f + z * (-54431464.f + z * (22973256.f + z * (-4657049.f)))))));
169 }
float float float z
Definition: DDAxes.h:10
template<>
float approx_atan2i_P< 3 > ( float  x)
inline

Definition at line 131 of file approx_atan2.h.

References x, and detailsBasic3DVector::z.

131  {
132  auto z = x*x;
133  return x * (-664694912.f + z * 131209024.f);
134 }
float float float z
Definition: DDAxes.h:10
template<>
float approx_atan2i_P< 5 > ( float  x)
inline

Definition at line 137 of file approx_atan2.h.

References x, and detailsBasic3DVector::z.

137  {
138  auto z = x*x;
139  return x * (-680392064.f + z * (197338400.f + z * (-54233256.f)));
140 }
float float float z
Definition: DDAxes.h:10
template<>
float approx_atan2i_P< 7 > ( float  x)
inline

Definition at line 143 of file approx_atan2.h.

References x, and detailsBasic3DVector::z.

143  {
144  auto z = x*x;
145  return x * (-683027840.f + z * (219543904.f + z * (-99981040.f + z * 26649684.f)));
146 }
float float float z
Definition: DDAxes.h:10
template<>
float approx_atan2i_P< 9 > ( float  x)
inline

Definition at line 149 of file approx_atan2.h.

References x, and detailsBasic3DVector::z.

149  {
150  auto z = x*x;
151  return x * (-683473920.f + z * (225785056.f + z * (-123151184.f + z * (58210592.f + z * (-14249276.f)))));
152 }
float float float z
Definition: DDAxes.h:10
double int2dphi ( int  x)
inline

Definition at line 212 of file approx_atan2.h.

References constexpr, M_PI, and max().

212  {
213  constexpr double i2p = M_PI/( (long long)(std::numeric_limits<int>::max())+1LL );
214  return x*i2p;
215 }
const T & max(const T &a, const T &b)
#define M_PI
Definition: DDAxes.h:10
#define constexpr
float int2phi ( int  x)
inline

Definition at line 206 of file approx_atan2.h.

References constexpr, M_PI, and max().

206  {
207  constexpr float i2p = M_PI/( (long long)(std::numeric_limits<int>::max())+1LL );
208  return float(x)*i2p;
209 }
const T & max(const T &a, const T &b)
#define M_PI
Definition: DDAxes.h:10
#define constexpr
int phi2int ( float  x)
inline

Definition at line 200 of file approx_atan2.h.

References constexpr, M_PI, and max().

200  {
201  constexpr float p2i = ( (long long)(std::numeric_limits<int>::max())+1LL )/M_PI;
202  return std::round(x*p2i);
203 }
const T & max(const T &a, const T &b)
#define M_PI
Definition: DDAxes.h:10
#define constexpr
short phi2short ( float  x)
inline

Definition at line 219 of file approx_atan2.h.

References constexpr, M_PI, and max().

219  {
220  constexpr float p2i = ( (int)(std::numeric_limits<short>::max())+1 )/M_PI;
221  return std::round(x*p2i);
222 }
const T & max(const T &a, const T &b)
#define M_PI
Definition: DDAxes.h:10
#define constexpr
template<int DEGREE>
float safe_atan2f ( float  y,
float  x 
)
inline

Definition at line 112 of file approx_atan2.h.

References f, x, and detailsBasic3DVector::y.

112  {
113  return unsafe_atan2f_impl<DEGREE>( y, (y==0.f)&(x==0.f) ? 0.2f : x);
114  // return (y==0.f)&(x==0.f) ? 0.f : unsafe_atan2f_impl<DEGREE>( y, x);
115 
116 }
double f[11][100]
Definition: DDAxes.h:10
float short2phi ( short  x)
inline

Definition at line 225 of file approx_atan2.h.

References constexpr, M_PI, and max().

225  {
226  constexpr float i2p = M_PI/( (int)(std::numeric_limits<short>::max())+1 );
227  return float(x)*i2p;
228 }
const T & max(const T &a, const T &b)
#define M_PI
Definition: DDAxes.h:10
#define constexpr
template<int DEGREE>
float unsafe_atan2f ( float  y,
float  x 
)
inline

Definition at line 106 of file approx_atan2.h.

References x, and detailsBasic3DVector::y.

106  {
107  return unsafe_atan2f_impl<DEGREE>(y,x);
108 
109 }
Definition: DDAxes.h:10
template<int DEGREE>
float unsafe_atan2f_impl ( float  y,
float  x 
)
inline

Definition at line 88 of file approx_atan2.h.

References funct::abs(), angle(), constexpr, and alignCSCRings::r.

88  {
89 
90  constexpr float pi4f = 3.1415926535897932384626434/4;
91  constexpr float pi34f = 3.1415926535897932384626434*3/4;
92 
93  auto r= (std::abs(x) - std::abs(y))/(std::abs(x) + std::abs(y));
94  if (x<0) r = -r;
95 
96  auto angle = (x>=0) ? pi4f : pi34f;
97  angle += approx_atan2f_P<DEGREE>(r);
98 
99 
100  return ( (y < 0)) ? - angle : angle ;
101 
102 
103 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Definition: DDAxes.h:10
#define constexpr
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11
template<int DEGREE>
int unsafe_atan2i ( float  y,
float  x 
)
inline

Definition at line 194 of file approx_atan2.h.

References x, and detailsBasic3DVector::y.

194  {
195  return unsafe_atan2i_impl<DEGREE>(y,x);
196 
197 }
Definition: DDAxes.h:10
template<int DEGREE>
int unsafe_atan2i_impl ( float  y,
float  x 
)
inline

Definition at line 173 of file approx_atan2.h.

References funct::abs(), angle(), constexpr, max(), and alignCSCRings::r.

173  {
174 
175 
176  constexpr long long maxint = (long long)(std::numeric_limits<int>::max())+1LL;
177  constexpr int pi4 = int(maxint/4LL);
178  constexpr int pi34 = int(3LL*maxint/4LL);
179 
180  auto r= (std::abs(x) - std::abs(y))/(std::abs(x) + std::abs(y));
181  if (x<0) r = -r;
182 
183  auto angle = (x>=0) ? pi4 : pi34;
184  angle += int(approx_atan2i_P<DEGREE>(r));
185  // angle += int(std::round(approx_atan2i_P<DEGREE>(r)));
186 
187 
188  return (y < 0) ? - angle : angle ;
189 
190 
191 }
const T & max(const T &a, const T &b)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Definition: DDAxes.h:10
#define constexpr
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11