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
00100 Vec3f strToVec3f(const QStringList& s);
00101 Vec3f strToVec3f(const QString& s);
00102
00106 QString vec3fToHtmlColor(const Vec3f& v);
00107
00110 Vec3f htmlColorToVec3f(const QString& c);
00111
00116 void spheToRect(double lng, double lat, Vec3d& v);
00117
00122 void spheToRect(float lng, float lat, Vec3f& v);
00123
00128 void rectToSphe(double *lng, double *lat, const Vec3d& v);
00129
00134 void rectToSphe(float *lng, float *lat, const Vec3d& v);
00135
00140 void rectToSphe(float *lng, float *lat, const Vec3f& v);
00141
00162 double getDecAngle(const QString& str);
00163
00165 bool isPowerOfTwo(int value);
00166
00168 int getBiggerPowerOfTwo(int value);
00169
00171 double asinh(double z);
00172
00174
00176 void getDateFromJulianDay(double julianDay, int *year, int *month, int *day);
00177
00179 void getTimeFromJulianDay(double julianDay, int *hour, int *minute, int *second);
00180
00183 bool getDateTimeFromISO8601String(const QString& iso8601Date, int* y, int* m, int* d, int* h, int* min, float* s);
00184
00187 QString julianDayToISO8601String(double jd);
00188
00191 double getJulianDayFromISO8601String(const QString& iso8601Date, bool* ok);
00192
00195 QString localeDateString(int year, int month, int day, int dayOfWeek, QString fmt);
00196
00199 QString localeDateString(int year, int month, int day, int dayOfWeek);
00200
00203 double getJDFromSystem();
00204
00208 double qTimeToJDFraction(const QTime& time);
00209
00211 QTime jdFractionToQTime(double jd);
00212
00214 float getGMTShiftFromQT(double jd);
00215
00219 double qDateTimeToJd(const QDateTime& dateTime);
00220
00224 QDateTime jdToQDateTime(const double& jd);
00225
00226 bool getJDFromDate(double* newjd, int y, int m, int d, int h, int min, int s);
00227
00228 int numberOfDaysInMonthInYear(int month, int year);
00229 bool changeDateTimeForRollover(int oy, int om, int od, int oh, int omin, int os,
00230 int* ry, int* rm, int* rd, int* rh, int* rmin, int* rs);
00231
00233 void debugQVariantMap(const QVariant& m, const QString& indent="", const QString& key="");
00234
00235
00238 inline float fastAcos(float x)
00239 {
00240 return M_PI_2 - (x + x*x*x * (1.f/6.f + x*x * (3.f/40.f + 5.f/112.f * x*x)) );
00241 }
00242
00244 inline float fastExp(float x)
00245 {
00246 return (x>=0)?
00247 (1.f + x*(1.f+ x/2.f*(1.f+ x/3.f*(1.f+x/4.f*(1.f+x/5.f))))):
00248 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)))));
00249 }
00250 }
00251
00252 #endif // _STELUTILS_HPP_