~ubuntu-branches/ubuntu/precise/stellarium/precise

« back to all changes in this revision

Viewing changes to src/core/StelUtils.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Howard
  • Date: 2010-02-15 20:48:39 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20100215204839-u3qgbv60rho997yk
Tags: 0.10.3-0ubuntu1
* New upstream release.
  - fixes intel rendering bug (LP: #480553)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Stellarium
3
3
 * Copyright (C) 2002 Fabien Chereau
4
 
 * 
 
4
 *
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.
9
 
 * 
 
9
 *
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.
14
 
 * 
 
14
 *
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.
21
21
#define _STELUTILS_HPP_
22
22
 
23
23
#include "VecMath.hpp"
24
 
#include "fixx11h.h"
25
24
 
26
25
#include <QVariantMap>
27
26
#include <QDateTime>
37
36
//! @namespace StelUtils contains general purpose utility functions.
38
37
namespace StelUtils
39
38
{
 
39
        //! Return the full name of stellarium, i.e. "stellarium 0.9.0"
 
40
        QString getApplicationName();
 
41
 
 
42
        //! Return the version of stellarium, i.e. "0.9.0"
 
43
        QString getApplicationVersion();
40
44
 
41
45
        //! Convert an angle in hms format to radian.
42
46
        //! @param h hour component
44
48
        //!     @param s second component
45
49
        //! @return angle in radian
46
50
        double hmsToRad(unsigned int h, unsigned int m, double s);
47
 
                           
 
51
 
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);
54
 
        
 
58
 
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);
61
 
        
 
65
 
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);
69
73
 
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);
74
 
        
 
78
 
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);
79
 
        
 
83
 
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);
85
 
        
 
89
 
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);
91
 
        
 
95
 
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);
98
 
        
 
102
 
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);
107
 
                
 
111
 
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);
113
 
        
 
117
 
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);
119
 
        
 
123
 
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
131
135
 
132
136
        //! Convert a string longitude, latitude, RA or Declination angle
133
137
        //! to radians.
134
 
        //! @param str the angle in format something like these: 
 
138
        //! @param str the angle in format something like these:
135
139
        //! - +53d  51'21.6"
136
140
        //! - +53d51'21.6"
137
141
        //! - -1d  10'31.8"
144
148
        //! - 12h 14m 6s
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);
153
 
        
 
157
 
154
158
        //! Check if a number is a power of 2.
155
159
        bool isPowerOfTwo(int value);
156
 
        
 
160
 
157
161
        //! Return the first power of two bigger than the given value.
158
162
        int getBiggerPowerOfTwo(int value);
159
 
        
 
163
 
160
164
        //! Return the inverse sinus hyperbolic of z.
161
165
        double asinh(double z);
162
 
        
 
166
 
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);
167
171
 
186
190
        double getJDFromSystem(void);
187
191
 
188
192
        //! Convert a time of day to the fraction of a Julian Day.
189
 
        //! Note that a Julian Day starts at 12:00, not 0:00, and 
 
193
        //! Note that a Julian Day starts at 12:00, not 0:00, and
190
194
        //! so 12:00 == 0.0 and 0:00 == 0.5
191
195
        double qTimeToJDFraction(const QTime& time);
192
196
 
210
214
 
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);
214
218
 
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="");
217
 
        
 
221
 
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);
 
224
 
 
225
        /// Compute acos(x)
 
226
        //! The taylor serie is not accurate around x=1 and x=-1
 
227
        inline float fastAcos(float x)
 
228
        {
 
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)) );
 
230
        }
 
231
 
 
232
        //! Compute exp(x) for small exponents x
 
233
        inline float fastExp(float x)
 
234
        {
 
235
                return (x>=0)?
 
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)))));
 
238
        }
220
239
}
221
240
 
222
241
#endif // _STELUTILS_HPP_