2018-10-11 18:19:35 +02:00
|
|
|
#include "common/util.h"
|
2018-01-20 20:13:56 +01:00
|
|
|
#include "angularunits.h"
|
|
|
|
|
2018-01-22 00:28:58 +01:00
|
|
|
static double sDMS2deg(double val)
|
|
|
|
{
|
|
|
|
double angle;
|
2018-01-25 00:19:11 +01:00
|
|
|
const char *decimal;
|
2018-01-22 00:28:58 +01:00
|
|
|
|
2018-01-25 00:19:11 +01:00
|
|
|
QString qstr(QString::number(qAbs(val), 'f', 7));
|
2018-03-01 19:06:34 +01:00
|
|
|
QByteArray ba = qstr.toLatin1();
|
|
|
|
const char *str = ba.constData();
|
2018-01-25 00:19:11 +01:00
|
|
|
decimal = strrchr(str, '.');
|
2021-01-17 19:33:06 +01:00
|
|
|
int deg = Util::str2int(str, decimal - str);
|
|
|
|
int min = Util::str2int(decimal + 1, 2);
|
|
|
|
int sec = Util::str2int(decimal + 3, 2);
|
|
|
|
int f = Util::str2int(decimal + 5, 3);
|
2018-01-22 00:28:58 +01:00
|
|
|
|
2018-01-25 20:49:01 +01:00
|
|
|
angle = deg + min/60.0 + sec/3600.0 + (f/1000.0)/3600.0;
|
2018-01-22 00:28:58 +01:00
|
|
|
|
|
|
|
return (val < 0) ? -angle : angle;
|
|
|
|
}
|
|
|
|
|
|
|
|
static double deg2sDMS(double val)
|
|
|
|
{
|
|
|
|
double aval = qAbs(val);
|
|
|
|
|
|
|
|
int deg = aval;
|
|
|
|
double r1 = aval - deg;
|
|
|
|
|
|
|
|
int min = r1 * 60.0;
|
|
|
|
double r2 = r1 - (min / 60.0);
|
|
|
|
|
|
|
|
int sec = r2 * 3600.0;
|
|
|
|
double r3 = r2 - (sec / 3600.0);
|
|
|
|
int f = (int)(r3 * 3600.0 * 1000.0);
|
|
|
|
|
2018-01-25 20:49:01 +01:00
|
|
|
QString str(QString("%1.%2%3%4").arg(deg).arg(min, 2, 10, QChar('0'))
|
|
|
|
.arg(sec, 2, 10, QChar('0')).arg(f, 3, 10, QChar('0')));
|
|
|
|
|
|
|
|
return (val < 0) ? -str.toDouble() : str.toDouble();
|
2018-01-22 00:28:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
AngularUnits::AngularUnits(int code) : _code(code)
|
2018-01-20 20:13:56 +01:00
|
|
|
{
|
|
|
|
switch (code) {
|
|
|
|
case 9101:
|
|
|
|
_f = 180.0 / M_PI;
|
|
|
|
break;
|
|
|
|
case 9102:
|
|
|
|
case 9107:
|
|
|
|
case 9108:
|
|
|
|
case 9110:
|
|
|
|
case 9122:
|
|
|
|
_f = 1.0;
|
|
|
|
break;
|
|
|
|
case 9103:
|
|
|
|
_f = 1 / 60.0;
|
|
|
|
break;
|
|
|
|
case 9104:
|
|
|
|
_f = 1 / 3600.0;
|
|
|
|
break;
|
|
|
|
case 9105:
|
|
|
|
_f = 180.0 / 200.0;
|
|
|
|
break;
|
|
|
|
case 9106:
|
|
|
|
_f = 180.0 / 200.0;
|
|
|
|
break;
|
|
|
|
case 9109:
|
|
|
|
_f = 180.0 / (M_PI * 1000000.0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_f = NAN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-22 00:28:58 +01:00
|
|
|
double AngularUnits::toDegrees(double val) const
|
|
|
|
{
|
|
|
|
return (_code == 9110) ? sDMS2deg(val) : val * _f;
|
|
|
|
}
|
|
|
|
|
|
|
|
double AngularUnits::fromDegrees(double val) const
|
|
|
|
{
|
|
|
|
return (_code == 9110) ? deg2sDMS(val) : val / _f;
|
|
|
|
}
|
|
|
|
|
2018-02-13 23:03:18 +01:00
|
|
|
#ifndef QT_NO_DEBUG
|
2018-01-20 20:13:56 +01:00
|
|
|
QDebug operator<<(QDebug dbg, const AngularUnits &au)
|
|
|
|
{
|
|
|
|
dbg.nospace() << "AngularUnits(" << deg2rad(au._f) << ")";
|
2018-01-21 11:19:46 +01:00
|
|
|
return dbg.space();
|
2018-01-20 20:13:56 +01:00
|
|
|
}
|
2018-02-13 23:03:18 +01:00
|
|
|
#endif // QT_NO_DEBUG
|