summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkarsh Simha <akarsh@kde.org>2016-09-25 11:08:03 (GMT)
committerAkarsh Simha <akarsh@kde.org>2016-09-28 22:16:22 (GMT)
commit786e4fcc5397fa8a9dcbb54c670410b687f000db (patch)
treed39dbc65c24b7048106788673b357604f795aa6d
parent69caa284c81f86204ff4b37b4670c5bb927cb223 (diff)
Make EquatorialToHorizontal faster by a number of improvements
1. Cache trigonometric values for RA, Dec and RA0, Dec0 Warning: This might negatively affect performance of updateCoords(), which is another MAJOR bottleneck in KStars 2. Avoid calling sincos() on HourAngle -- instead just compute it using CachingDms subtraction operator. 3. Avoid cos( AltRad ) computation. Instead use cos x = sqrt(1 - sin(x)^2) The result is an improvement of EquatorialToHorizontal() average run-time from ~ 567 ns to ~ 341 ns per call. Note: I would have expected a more significant improvement, but it might be improved once we remove profiling instrumentation from dms and CachingDms.
-rw-r--r--kstars/skyobjects/skypoint.cpp6
-rw-r--r--kstars/skyobjects/skypoint.h12
2 files changed, 10 insertions, 8 deletions
diff --git a/kstars/skyobjects/skypoint.cpp b/kstars/skyobjects/skypoint.cpp
index b0d894a..73fc33a 100644
--- a/kstars/skyobjects/skypoint.cpp
+++ b/kstars/skyobjects/skypoint.cpp
@@ -74,7 +74,7 @@ void SkyPoint::EquatorialToHorizontal( const CachingDms *LST, const CachingDms *
double sindec, cosdec, sinlat, coslat, sinHA, cosHA;
double sinAlt, cosAlt;
- dms HourAngle = (*LST) - ra();
+ CachingDms HourAngle = (*LST) - ra(); // Using CachingDms subtraction operator to find cos/sin of HourAngle without calling sincos()
lat->SinCos( sinlat, coslat );
dec().SinCos( sindec, cosdec );
@@ -82,7 +82,9 @@ void SkyPoint::EquatorialToHorizontal( const CachingDms *LST, const CachingDms *
sinAlt = sindec*sinlat + cosdec*coslat*cosHA;
AltRad = asin( sinAlt );
- cosAlt = cos( AltRad );
+
+ // cosAlt = cos( AltRad );
+ cosAlt = sqrt( 1 - sinAlt * sinAlt ); // Avoid trigonometric function. Return value of asin is always in [-pi/2, pi/2] and in this domain cosine is always non-negative, so we can use this.
double arg = ( sindec - sinlat*sinAlt )/( coslat*cosAlt );
if ( arg <= -1.0 ) AzRad = dms::PI;
diff --git a/kstars/skyobjects/skypoint.h b/kstars/skyobjects/skypoint.h
index af937d4..7978f57 100644
--- a/kstars/skyobjects/skypoint.h
+++ b/kstars/skyobjects/skypoint.h
@@ -172,16 +172,16 @@ public:
//// =========================
/** @return a pointer to the catalog Right Ascension. */
- inline const dms& ra0() const { return RA0; }
+ inline const CachingDms& ra0() const { return RA0; }
/** @return a pointer to the catalog Declination. */
- inline const dms& dec0() const { return Dec0; }
+ inline const CachingDms& dec0() const { return Dec0; }
/** @returns a pointer to the current Right Ascension. */
- inline const dms& ra() const { return RA; }
+ inline const CachingDms& ra() const { return RA; }
/** @return a pointer to the current Declination. */
- inline const dms& dec() const { return Dec; }
+ inline const CachingDms& dec() const { return Dec; }
/** @return a pointer to the current Azimuth. */
inline const dms& az() const { return Az; }
@@ -559,8 +559,8 @@ protected:
void precess(const KSNumbers *num);
private:
- dms RA0, Dec0; //catalog coordinates
- dms RA, Dec; //current true sky coordinates
+ CachingDms RA0, Dec0; //catalog coordinates
+ CachingDms RA, Dec; //current true sky coordinates
dms Alt, Az;
static KSSun *m_Sun;
protected: