3
3
* Copyright (C) 2002 Fabien Chereau
5
5
* This program is free software; you can redistribute it and/or
6
6
* modify it under the terms of the GNU General Public License
7
7
* as published by the Free Software Foundation; either version 2
8
8
* of the License, or (at your option) any later version.
10
10
* This program is distributed in the hope that it will be useful,
11
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
13
* GNU General Public License for more details.
15
15
* You should have received a copy of the GNU General Public License
16
16
* along with this program; if not, write to the Free Software
17
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
44
48
//! @param s second component
45
49
//! @return angle in radian
46
50
double hmsToRad(unsigned int h, unsigned int m, double s);
48
52
//! Convert an angle in +-dms format to radian.
49
53
//! @param d degree component
50
54
//! @param m arcmin component
51
55
//! @param s arcsec component
52
56
//! @return angle in radian
53
57
double dmsToRad(int d, unsigned int m, double s);
55
59
//! Convert an angle in radian to hms format.
56
60
//! @param rad input angle in radian
57
61
//! @param h hour component
58
62
//! @param m minute component
59
63
//! @param s second component
60
64
void radToHms(double rad, unsigned int& h, unsigned int& m, double& s);
62
66
//! Convert an angle in radian to +-dms format.
63
67
//! @param rad input angle in radian
64
68
//! @param sign true if positive, false otherwise
65
69
//! @param d degree component
66
70
//! @param m minute component
67
71
//! @param s second component
68
void radToDms(double rad, bool& sign, unsigned int& d, unsigned int& m, double& s);
72
void radToDms(double rad, bool& sign, unsigned int& d, unsigned int& m, double& s);
70
74
//! Convert an angle in radian to a hms formatted string.
71
75
//! If the second, minute part is == 0, it is not output
72
76
//! @param angle input angle in radian
73
77
QString radToHmsStrAdapt(double angle);
75
79
//! Convert an angle in radian to a hms formatted string.
76
80
//! @param angle input angle in radian
77
81
//! @param decimal output decimal second value
78
82
QString radToHmsStr(double angle, bool decimal=false);
80
84
//! Convert an angle in radian to a dms formatted string.
81
85
//! If the second, minute part is == 0, it is not output
82
86
//! @param angle input angle in radian
83
87
//! @param useD Define if letter "d" must be used instead of deg sign
84
88
QString radToDmsStrAdapt(double angle, bool useD=false);
86
90
//! Convert an angle in radian to a dms formatted string.
87
91
//! @param angle input angle in radian
88
92
//! @param useD Define if letter "d" must be used instead of deg sign
89
93
//! @param decimal output decimal second value
90
94
QString radToDmsStr(double angle, bool decimal=false, bool useD=false);
92
96
//! Obtains a Vec3f from a string.
93
97
//! @param s the string describing the Vector with the form "x,y,z"
94
98
//! @return The corresponding vector
95
99
//! @deprecated Use the >> operator from Vec3f class
96
100
Vec3f strToVec3f(const QStringList& s);
97
101
Vec3f strToVec3f(const QString& s);
99
103
//! Converts a Vec3f to HTML color notation.
100
104
//! @param v The vector
101
105
//! @return The string in HTML color notation "#rrggbb".
104
108
//! Converts a color in HTML notation to a Vec3f.
105
109
//! @param c The HTML spec color string
106
110
Vec3f htmlColorToVec3f(const QString& c);
108
112
//! Convert from spherical coordinates to Rectangular direction.
109
113
//! @param lng longitude in radian
110
114
//! @param lat latitude in radian
111
115
//! @param v the resulting 3D unit vector
112
116
void spheToRect(double lng, double lat, Vec3d& v);
114
118
//! Convert from spherical coordinates to Rectangular direction.
115
119
//! @param lng longitude in radian
116
120
//! @param lat latitude in radian
117
121
//! @param v the resulting 3D unti vector
118
122
void spheToRect(float lng, float lat, Vec3f& v);
120
124
//! Convert from spherical coordinates to Rectangular direction.
121
125
//! @param lng double* to store longitude in radian
122
126
//! @param lat double* to store latitude in radian
145
149
//! The degree separator may be a degree symbol (\\xBA) in addition
146
150
//! to a 'd' or 'D'.
147
//! @return the angle in radians.
151
//! @return the angle in radians.
148
152
//! Latitude: North are positive, South are negative.
149
153
//! Longitude: East is positive, West is negative.
150
//! Note: if there is a N, S, E or W suffix, any leading + or -
154
//! Note: if there is a N, S, E or W suffix, any leading + or -
151
155
//! characters are ignored.
152
156
double getDecAngle(const QString& str);
154
158
//! Check if a number is a power of 2.
155
159
bool isPowerOfTwo(int value);
157
161
//! Return the first power of two bigger than the given value.
158
162
int getBiggerPowerOfTwo(int value);
160
164
//! Return the inverse sinus hyperbolic of z.
161
165
double asinh(double z);
163
167
///////////////////////////////////////////////////
164
// New Qt based General Calendar Functions.
168
// New Qt based General Calendar Functions.
165
169
//! Make from julianDay a year, month, day for the Julian Date julianDay represents.
166
170
void getDateFromJulianDay(double julianDay, int *year, int *month, int *day);
211
215
int numberOfDaysInMonthInYear(int month, int year);
212
216
bool changeDateTimeForRollover(int oy, int om, int od, int oh, int omin, int os,
213
int* ry, int* rm, int* rd, int* rh, int* rmin, int* rs);
217
int* ry, int* rm, int* rd, int* rh, int* rmin, int* rs);
215
219
//! Output a QVariantMap to qDebug(). Formats like a tree where there are nested objects.
216
220
void debugQVariantMap(const QVariant& m, const QString& indent="", const QString& key="");
218
222
//! Use RegExp for final to parse a QString to six ints, use in the event QDateTime cannot handle the date.
219
223
QList<int> getIntsFromISO8601String(const QString& iso8601Date);
226
//! The taylor serie is not accurate around x=1 and x=-1
227
inline float fastAcos(float x)
229
return M_PI_2 - (x + x*x*x * (1.f/6.f + x*x * (3.f/40.f + 5.f/112.f * x*x)) );
232
//! Compute exp(x) for small exponents x
233
inline float fastExp(float x)
236
(1.f + x*(1.f+ x/2.f*(1.f+ x/3.f*(1.f+x/4.f*(1.f+x/5.f))))):
237
1.f / (1.f -x*(1.f -x/2.f*(1.f- x/3.f*(1.f-x/4.f*(1.f-x/5.f)))));
222
241
#endif // _STELUTILS_HPP_