00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _STELUTILS_HPP_
00021 #define _STELUTILS_HPP_
00022
00023 #include "VecMath.hpp"
00024
00025 #include <QVariantMap>
00026 #include <QDateTime>
00027 #include <QString>
00028
00029
00030 #define AU 149597870.691
00031
00032 #define PARSEC 30.857e12
00033
00034 #define SPEED_OF_LIGHT 299792.458
00035
00037 namespace StelUtils
00038 {
00040 QString getApplicationName();
00041
00043 QString getApplicationVersion();
00044
00050 double hmsToRad(unsigned int h, unsigned int m, double s);
00051
00057 double dmsToRad(int d, unsigned int m, double s);
00058
00064 void radToHms(double rad, unsigned int& h, unsigned int& m, double& s);
00065
00072 void radToDms(double rad, bool& sign, unsigned int& d, unsigned int& m, double& s);
00073
00077 QString radToHmsStrAdapt(double angle);
00078
00082 QString radToHmsStr(double angle, bool decimal=false);
00083
00088 QString radToDmsStrAdapt(double angle, bool useD=false);
00089
00094 QString radToDmsStr(double angle, bool decimal=false, bool useD=false);
00095
00098 double dmsStrToRad(const QString& s);
00099
00104 Vec3f strToVec3f(const QStringList& s);
00105 Vec3f strToVec3f(const QString& s);
00106
00110 QString vec3fToHtmlColor(const Vec3f& v);
00111
00114 Vec3f htmlColorToVec3f(const QString& c);
00115
00120 void spheToRect(double lng, double lat, Vec3d& v);
00121
00126 void spheToRect(float lng, float lat, Vec3f& v);
00127
00132 void rectToSphe(double *lng, double *lat, const Vec3d& v);
00133
00138 void rectToSphe(float *lng, float *lat, const Vec3d& v);
00139
00144 void rectToSphe(float *lng, float *lat, const Vec3f& v);
00145
00166 double getDecAngle(const QString& str);
00167
00169 bool isPowerOfTwo(int value);
00170
00172 int getBiggerPowerOfTwo(int value);
00173
00175 double asinh(double z);
00176
00178
00180 void getDateFromJulianDay(double julianDay, int *year, int *month, int *day);
00181
00183 void getTimeFromJulianDay(double julianDay, int *hour, int *minute, int *second);
00184
00187 bool getDateTimeFromISO8601String(const QString& iso8601Date, int* y, int* m, int* d, int* h, int* min, float* s);
00188
00191 QString julianDayToISO8601String(double jd);
00192
00195 double getJulianDayFromISO8601String(const QString& iso8601Date, bool* ok);
00196
00199 QString localeDateString(int year, int month, int day, int dayOfWeek, QString fmt);
00200
00203 QString localeDateString(int year, int month, int day, int dayOfWeek);
00204
00207 double getJDFromSystem();
00208
00212 double qTimeToJDFraction(const QTime& time);
00213
00215 QTime jdFractionToQTime(double jd);
00216
00218 float getGMTShiftFromQT(double jd);
00219
00223 double qDateTimeToJd(const QDateTime& dateTime);
00224
00228 QDateTime jdToQDateTime(const double& jd);
00229
00230 bool getJDFromDate(double* newjd, int y, int m, int d, int h, int min, int s);
00231
00232 int numberOfDaysInMonthInYear(int month, int year);
00233 bool changeDateTimeForRollover(int oy, int om, int od, int oh, int omin, int os,
00234 int* ry, int* rm, int* rd, int* rh, int* rmin, int* rs);
00235
00237 void debugQVariantMap(const QVariant& m, const QString& indent="", const QString& key="");
00238
00239
00242 inline float fastAcos(float x)
00243 {
00244 return M_PI_2 - (x + x*x*x * (1.f/6.f + x*x * (3.f/40.f + 5.f/112.f * x*x)) );
00245 }
00246
00248 inline float fastExp(float x)
00249 {
00250 return (x>=0)?
00251 (1.f + x*(1.f+ x/2.f*(1.f+ x/3.f*(1.f+x/4.f*(1.f+x/5.f))))):
00252 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)))));
00253 }
00254 }
00255
00256 #endif // _STELUTILS_HPP_