summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkarsh Simha <akarsh@kde.org>2016-09-28 21:52:30 (GMT)
committerAkarsh Simha <akarsh@kde.org>2016-09-29 02:20:27 (GMT)
commitfdf1cac2eb57430b86b8c63ffe842574467f6a77 (patch)
treedb7ae2be9bf12119be05bbb1933bb3c69dcfe703
parent4fd4a0067604c52b7a52da90fbbf2646daf53304 (diff)
Experiment: Make Azimuth CachingDms
-rw-r--r--kstars/auxiliary/cachingdms.h14
-rw-r--r--kstars/projections/projector.cpp31
-rw-r--r--kstars/skyobjects/skypoint.cpp12
-rw-r--r--kstars/skyobjects/skypoint.h6
4 files changed, 38 insertions, 25 deletions
diff --git a/kstars/auxiliary/cachingdms.h b/kstars/auxiliary/cachingdms.h
index 4cc4c55..490ede2 100644
--- a/kstars/auxiliary/cachingdms.h
+++ b/kstars/auxiliary/cachingdms.h
@@ -152,6 +152,20 @@ public:
void setUsing_acos( const double & cosine );
/**
+ * @short Sets angle and trigonometric values
+ */
+ inline void setTrigonometric( double angleDegrees, double sine, double cosine ) {
+ D = angleDegrees;
+ m_sin = sine;
+ m_cos = cosine;
+#ifdef COUNT_DMS_SINCOS_CALLS
+ if(!m_cacheUsed)
+ ++cachingdms_bad_uses;
+ m_cacheUsed = false;
+#endif
+ }
+
+ /**
* @short Get the sine and cosine together
* @note Re-implements dms::SinCos()
* @note This just uses the cached values assuming that they are good
diff --git a/kstars/projections/projector.cpp b/kstars/projections/projector.cpp
index f8e053d..68d29e1 100644
--- a/kstars/projections/projector.cpp
+++ b/kstars/projections/projector.cpp
@@ -24,6 +24,7 @@
#include "ksutils.h"
#include "kstarsdata.h"
#include "skycomponents/skylabeler.h"
+#include "auxiliary/cachingdms.h"
namespace {
void toXYZ(const SkyPoint* p, double *x, double *y, double *z) {
@@ -448,22 +449,22 @@ SkyPoint Projector::fromScreen(const QPointF& p, dms* LST, const dms* lat) const
Vector2f Projector::toScreenVec(const SkyPoint* o, bool oRefract, bool* onVisibleHemisphere) const
{
- double Y, dX;
+ CachingDms Y, dX;
double sindX, cosdX, sinY, cosY;
oRefract &= m_vp.useRefraction;
if ( m_vp.useAltAz ) {
if ( oRefract )
- Y = SkyPoint::refract( o->alt() ).radians(); //account for atmospheric refraction
+ Y = SkyPoint::refract( o->alt() ); //account for atmospheric refraction
else
- Y = o->alt().radians();
- dX = m_vp.focus->az().radians() - o->az().radians();
+ Y = o->alt();
+ dX = m_vp.focus->az() - o->az(); // CachingDms - operator
} else {
- dX = o->ra().radians() - m_vp.focus->ra().radians();
- Y = o->dec().radians();
+ dX = o->ra() - m_vp.focus->ra(); // CachingDms - operator
+ Y = o->dec();
}
- if( !( std::isfinite( Y ) && std::isfinite( dX ) ) ) {
+ if( !( std::isfinite( Y.Degrees() ) && std::isfinite( dX.Degrees() ) ) ) {
qDebug() << "Assert in Projector::toScreenVec failed!";
qDebug() << "using AltAz?" << m_vp.useAltAz << " Refract? " << oRefract;
const SkyObject *obj;
@@ -471,22 +472,18 @@ Vector2f Projector::toScreenVec(const SkyPoint* o, bool oRefract, bool* onVisibl
if ( (obj = dynamic_cast<const SkyObject *>(o) ) ) {
qDebug() << "Point is object with name = " << obj->name() << " longname = " << obj->longname();
}
- qDebug() << "dX = " << dX << " and isfinite(dX) is" << std::isfinite(dX);
- qDebug() << "Y = " << Y << " and isfinite(Y) is" << std::isfinite(Y);
+ qDebug() << "dX = " << dX.Degrees() << " and isfinite(dX) is" << std::isfinite(dX.Degrees());
+ qDebug() << "Y = " << Y.Degrees() << " and isfinite(Y) is" << std::isfinite(Y.Degrees());
return Vector2f(0,0);
//Q_ASSERT( false );
}
- dX = KSUtils::reduceAngle(dX, -dms::PI, dms::PI);
+// dX = KSUtils::reduceAngle(dX, -dms::PI, dms::PI);
+ dX.reduceToRange( dms::MINUSPI_TO_PI );
//Convert dX, Y coords to screen pixel coords, using GNU extension if available
- #if ( __GLIBC__ >= 2 && __GLIBC_MINOR__ >=1 )
- sincos( dX, &sindX, &cosdX );
- sincos( Y, &sinY, &cosY );
- #else
- sindX = sin(dX); cosdX = cos(dX);
- sinY = sin(Y); cosY = cos(Y);
- #endif
+ dX.SinCos( sindX, cosdX );
+ Y.SinCos( sinY, cosY );
//c is the cosine of the angular distance from the center
double c = m_sinY0*sinY + m_cosY0*cosY*cosdX;
diff --git a/kstars/skyobjects/skypoint.cpp b/kstars/skyobjects/skypoint.cpp
index 6f9ae9a..4f75cde 100644
--- a/kstars/skyobjects/skypoint.cpp
+++ b/kstars/skyobjects/skypoint.cpp
@@ -72,7 +72,7 @@ void SkyPoint::EquatorialToHorizontal( const CachingDms *LST, const CachingDms *
std::clock_t start = std::clock();
#endif
//Uncomment for spherical trig version
- double AltRad, AzRad;
+ double AltRad;
double sindec, cosdec, sinlat, coslat, sinHA, cosHA;
double sinAlt, cosAlt;
@@ -89,14 +89,14 @@ void SkyPoint::EquatorialToHorizontal( const CachingDms *LST, const CachingDms *
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;
- else if ( arg >= 1.0 ) AzRad = 0.0;
- else AzRad = acos( arg );
+ if ( arg <= -1.0 ) Az.setTrigonometric( 180., 0., -1. );
+ else if ( arg >= 1.0 ) Az.setTrigonometric( 0., 0., 1. );
+ else Az.setUsing_acos( arg );
- if ( sinHA > 0.0 ) AzRad = 2.0*dms::PI - AzRad; // resolve acos() ambiguity
+ if ( sinHA > 0.0 ) Az.setTrigonometric( 360. - Az.Degrees(), -Az.sin(), Az.cos() ); // resolve acos() ambiguity
Alt.setRadians( AltRad );
- Az.setRadians( AzRad );
+
#ifdef PROFILE_COORDINATE_CONVERSION
std::clock_t stop = std::clock();
cpuTime_EqToHz += double( stop - start )/double( CLOCKS_PER_SEC ); // Accumulate time in seconds
diff --git a/kstars/skyobjects/skypoint.h b/kstars/skyobjects/skypoint.h
index ca517c3..077216b 100644
--- a/kstars/skyobjects/skypoint.h
+++ b/kstars/skyobjects/skypoint.h
@@ -171,6 +171,8 @@ public:
*/
inline void setAz( dms az ) { Az = az; }
+ inline void setAz( const CachingDms &az ) { Az = az; }
+
/** Overloaded member function, provided for convenience.
*It behaves essentially like the above function.
*@param az Azimuth, expressed as a double.
@@ -194,7 +196,7 @@ public:
inline const CachingDms& dec() const { return Dec; }
/** @return a pointer to the current Azimuth. */
- inline const dms& az() const { return Az; }
+ inline const CachingDms& az() const { return Az; }
/** @return a pointer to the current Altitude. */
inline const dms& alt() const { return Alt; }
@@ -575,7 +577,7 @@ protected:
private:
CachingDms RA0, Dec0; //catalog coordinates
CachingDms RA, Dec; //current true sky coordinates
- dms Alt, Az;
+ CachingDms Az; dms Alt; // Altitude is dms because it undergoes refraction
static KSSun *m_Sun;
protected:
double lastPrecessJD; // JD at which the last coordinate update (see updateCoords) for this SkyPoint was done