14#include <qtskipemptyparts.h>
16#ifdef COUNT_DMS_SINCOS_CALLS
17long unsigned dms::dms_constructor_calls = 0;
18long unsigned dms::dms_with_sincos_called = 0;
19long unsigned dms::trig_function_calls = 0;
20long unsigned dms::redundant_trig_function_calls = 0;
21double dms::seconds_in_trig = 0;
24void dms::setD(
const int &d,
const int &m,
const int &s,
const int &ms)
26 D = (double)abs(d) + ((double)m + ((double)s + (double)ms / 1000.) / 60.) / 60.;
31#ifdef COUNT_DMS_SINCOS_CALLS
32 m_cosDirty = m_sinDirty =
true;
36void dms::setH(
const int &h,
const int &m,
const int &s,
const int &ms)
38 D = 15.0 * ((double)abs(h) + ((double)m + ((double)s + (double)ms / 1000.) / 60.) / 60.);
43#ifdef COUNT_DMS_SINCOS_CALLS
44 m_cosDirty = m_sinDirty =
true;
52 bool checkValue(
false), badEntry(
false), negative(
false);
54 entry.
remove(QRegExp(
"[hdms'\"°]"));
68 d = entry.
toInt(&checkValue);
79 double x = entry.
toDouble(&checkValue);
99 if (fields.count() == 1)
110 if (fields.count() == 2)
112 m = fields[1].toInt(&checkValue);
117 double mx = fields[1].toDouble(&checkValue);
133 if (fields.count() >= 3)
137 d = fields[0].toInt(&checkValue);
140 m = fields[1].toInt(&checkValue);
143 s = fields[2].toDouble(&checkValue);
149 if (fields[0].at(0) ==
'-' && d == 0)
155 double D = (double)abs(d) + (double)abs(m) / 60. + (double)fabs(s) / 3600.;
157 if (negative || d < 0 || m < 0 || s < 0)
185 int am = int(60.0 * (fabs(D) - abs(
degree())));
186 if (D < 0.0 && D > -1.0)
198 int as = int(60.0 * (60.0 * (fabs(D) - abs(
degree())) - abs(
arcmin())));
212 int as = int(1000.0 * (60.0 * (60.0 * (fabs(D) - abs(
degree())) - abs(
arcmin())) - abs(
arcsec())));
223 int hm = int(60.0 * (fabs(
Hours()) - abs(
hour())));
233 int hs = int(60.0 * (60.0 * (fabs(
Hours()) - abs(
hour())) - abs(
minute())));
243 int hs = int(1000.0 * (60.0 * (60.0 * (fabs(
Hours()) - abs(
hour())) - abs(
minute())) - abs(
second())));
256 return dms(D - 360.0 * floor(D / 360.0));
264 return (D - 360.0 * floor(D / 360.0));
269 double angleDiff = D - angle.
Degrees();
272 while (angleDiff > 360)
274 while (angleDiff < -360)
278 return dms(360 - angleDiff);
280 else if (angleDiff < -180)
281 return dms(-(360 + angleDiff));
284 return dms(angleDiff);
294 if (machineReadable || !highPrecision)
298 double half_precision = 1.0 / 7200.0;
300 half_precision = -half_precision;
315 else if (forceSign &&
Degrees() > 0.0)
328 .
arg(dd, 2, 10, zero)
329 .
arg(dm, 2, 10, zero)
330 .
arg(sec, 2,
'f', 2, zero);
334 .
arg(dd, 2, 10, zero)
335 .
arg(dm, 2, 10, zero)
336 .
arg(ds, 2, 10, zero);
339 if (!machineReadable && dd < 10)
344 return dummy.sprintf(
"%c%1d%c %02d\' %05.2f\"", pm, dd, 176, dm, sec);
347 return dummy.sprintf(
"%c%1d%c %02d\' %02d\"", pm, dd, 176, dm, ds);
350 if (!machineReadable && dd < 100)
355 return dummy.sprintf(
"%c%2d%c %02d\' %05.2f\"", pm, dd, 176, dm, sec);
358 return dummy.sprintf(
"%c%2d%c %02d\' %02d\"", pm, dd, 176, dm, ds);
360 if (machineReadable && dd < 100)
361 return dummy.sprintf(
"%c%02d:%02d:%02d", pm, dd, dm, ds);
363 if (!machineReadable)
368 return dummy.sprintf(
"%c%3d%c %02d\' %05.2f\"", pm, dd, 176, dm, sec);
371 return dummy.sprintf(
"%c%3d%c %02d\' %02d\"", pm, dd, 176, dm, ds);
374 return dummy.sprintf(
"%c%03d:%02d:%02d", pm, dd, dm, ds);
384 if (machineReadable || !highPrecision)
388 double half_precision = 15.0 / 7200.0;
396 return QString(
"%1:%2:%3").
arg(hh, 2, 10, zero)
397 .
arg(hm, 2, 10, zero)
398 .
arg(hs, 2, 10, zero);
405 .
arg(sec, 2,
'f', 2, zero);
408 return QString(
"%1h %2m %3s").
arg(hh, 2, 10, zero)
409 .
arg(hm, 2, 10, zero)
410 .
arg(hs, 2, 10, zero);
414 if (!machineReadable)
419 return dummy.sprintf(
"%02dh %02dm %05.2f",
hour(),
minute(), sec);
422 return dummy.sprintf(
"%02dh %02dm %02ds", hh, hm, hs);
425 return dummy.sprintf(
"%02d:%02d:%02d", hh, hm, hs);
454 D -= 360. * floor((D + 180.) / 360.);
457 D -= 360. * floor(D / 360.);
An angle, stored as degrees, but expressible in many ways.
static dms fromString(const QString &s, bool deg)
Static function to create a DMS object from a QString.
void reduceToRange(enum dms::AngleRanges range)
Reduce this angle to the given range.
virtual void setH(const double &x)
Sets floating-point value of angle, in hours.
const dms reduce() const
return the equivalent angle between 0 and 360 degrees.
virtual bool setFromString(const QString &s, bool isDeg=true)
Attempt to parse the string argument as a dms value, and set the dms object accordingly.
const QString toDMSString(const bool forceSign=false, const bool machineReadable=false, const bool highPrecision=false) const
const dms deltaAngle(dms angle) const
deltaAngle Return the shortest difference (path) between this angle and the supplied angle.
const QString toHMSString(const bool machineReadable=false, const bool highPrecision=false) const
AngleRanges
an enum defining standard angle ranges
dms()
Default constructor.
virtual void setD(const double &x)
Sets floating-point value of angle, in degrees.
const double & Degrees() const
KCALENDARCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalendarCore::Alarm::Ptr &)
QString arg(Args &&... args) const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QString number(double n, char format, int precision)
QString & remove(QChar ch, Qt::CaseSensitivity cs)
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
double toDouble(bool *ok) const const
int toInt(bool *ok, int base) const const
QString trimmed() const const