summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkarsh Simha <akarsh@kde.org>2016-09-26 01:13:30 (GMT)
committerAkarsh Simha <akarsh@kde.org>2016-09-29 02:20:12 (GMT)
commit8fd7073964885ff9b8d21a509fa8a77cda49de52 (patch)
tree2b423326f3cb0a349498ba6dfeccf5066b61591b
parent6e4fff45e0f4e4db691da7ccb00d4932e9eb74a5 (diff)
A dms::reduceToRange() method.
Calling this on a CachingDms has no effect on the sine and cosine values, so it is okay.
-rw-r--r--Tests/auxiliary/testdms.cpp42
-rw-r--r--Tests/auxiliary/testdms.h1
-rw-r--r--kstars/auxiliary/dms.cpp12
-rw-r--r--kstars/auxiliary/dms.h10
4 files changed, 64 insertions, 1 deletions
diff --git a/Tests/auxiliary/testdms.cpp b/Tests/auxiliary/testdms.cpp
index 1dcf945..a5f5363 100644
--- a/Tests/auxiliary/testdms.cpp
+++ b/Tests/auxiliary/testdms.cpp
@@ -85,6 +85,46 @@ void TestDMS::stringCtor()
QVERIFY(h.Hours() == d.Degrees());
}
-QTEST_GUILESS_MAIN(TestDMS)
+void TestDMS::testReduceToRange() {
+ double base = 67.8;
+ double a = 360.0 * 11. + base;
+ double b = -360.0 * 12. + base;
+
+ dms d;
+ d.setD( a );
+ d.reduceToRange( dms::ZERO_TO_2PI );
+ QVERIFY( fabs( d.Degrees() - base ) < 1e-9 );
+
+ d.setD( b );
+ d.reduceToRange( dms::ZERO_TO_2PI );
+ QVERIFY( fabs( d.Degrees() - base ) < 1e-9 );
+
+ d.setD( 360.0 );
+ d.reduceToRange( dms::ZERO_TO_2PI );
+ QVERIFY( fabs( d.Degrees() - 0. ) < 1e-9 );
+
+ double c = 180.0 * 13. + base;
+ double e = 180.0 * 14. + base;
+ double f = -180.0 * 15. + base;
+ double g = -180.0 * 16. + base;
+
+ d.setD( c );
+ d.reduceToRange( dms::MINUSPI_TO_PI );
+ QVERIFY( fabs( d.Degrees() - ( base - 180.0 ) ) < 1e-9 );
+ d.setD( e );
+ d.reduceToRange( dms::MINUSPI_TO_PI );
+ QVERIFY( fabs( d.Degrees() - base ) < 1e-9 );
+
+ d.setD( f );
+ d.reduceToRange( dms::MINUSPI_TO_PI );
+ QVERIFY( fabs( d.Degrees() - ( base - 180.0 ) ) < 1e-9 );
+
+ d.setD( g );
+ d.reduceToRange( dms::MINUSPI_TO_PI );
+ QVERIFY( fabs( d.Degrees() - base ) < 1e-9 );
+
+}
+
+QTEST_GUILESS_MAIN(TestDMS)
diff --git a/Tests/auxiliary/testdms.h b/Tests/auxiliary/testdms.h
index 8e7a377..9496fe5 100644
--- a/Tests/auxiliary/testdms.h
+++ b/Tests/auxiliary/testdms.h
@@ -31,6 +31,7 @@ class TestDMS: public QObject
void explicitSexigesimalCtor();
void angleCtor();
void stringCtor();
+ void testReduceToRange();
};
diff --git a/kstars/auxiliary/dms.cpp b/kstars/auxiliary/dms.cpp
index b457be1..9e36857 100644
--- a/kstars/auxiliary/dms.cpp
+++ b/kstars/auxiliary/dms.cpp
@@ -267,6 +267,18 @@ dms dms::fromString(const QString &st, bool deg) {
// }
}
+
+void dms::reduceToRange( enum dms::AngleRanges range ) {
+ switch( range ) {
+ case MINUSPI_TO_PI:
+ D -= 360. * floor( ( D + 180. ) / 360. );
+ break;
+ case ZERO_TO_2PI:
+ default:
+ D -= 360. * floor( D / 360. );
+ }
+}
+
// M_PI is defined in math.h
const double dms::PI = M_PI;
const double dms::DegToRad = PI/180.0;
diff --git a/kstars/auxiliary/dms.h b/kstars/auxiliary/dms.h
index d4b7196..0f77cfb 100644
--- a/kstars/auxiliary/dms.h
+++ b/kstars/auxiliary/dms.h
@@ -304,6 +304,16 @@ public:
*/
const dms reduce() const;
+ /**
+ * @short an enum defining standard angle ranges
+ */
+ enum AngleRanges { ZERO_TO_2PI, MINUSPI_TO_PI };
+
+ /**
+ * @short Reduce _this_ angle to the given range
+ */
+ void reduceToRange( enum dms::AngleRanges range );
+
/** @return a nicely-formatted string representation of the angle
* in degrees, arcminutes, and arcseconds.
* @param machineReadable uses a colon separator and produces +/-dd:mm:ss format instead