Commit 13ac9e9e authored by Akarsh Simha's avatar Akarsh Simha
Browse files

Change LST and latitude to CachingDms -- this saves a lot of trig calls!

Test case:
==========

Simulation clock running at 1s per step, centered around USNO NOMAD
milky way artifact patch at the center of milky way, specifically on
Globular Cluster NGC 6569 at Zoom Factor of 32000. Using Horizontal
Coordinates. Projection = 3.

Results:
========

Before:
-------
For the USNO NOMAD catalog under these conditions,
DeepStarComponent::draw spent ~ 0.25s doing ~2233550 trigonometric
function calls per draw ( presumably without updateCoords() being
called -- we call updateCoords only if there's a time slew of more
than 1 solar minute; see StarObject::JITUpdate() )

After:
------

After the change, DSC::draw() spent only ~ 0.18s doing only ~1489260
trigonometric function calls.

Note: A call to sincos() is considered to be 2 trigonometric calls.
parent 5a9c6a42
......@@ -1462,7 +1462,7 @@ double Scheduler::findAltitude(const SkyPoint & target, const QDateTime when)
KStarsDateTime myUT = ut.addSecs(when.time().msecsSinceStartOfDay()/1000);
dms LST = KStarsData::Instance()->geo()->GSTtoLST( myUT.gst() );
CachingDms LST = KStarsData::Instance()->geo()->GSTtoLST( myUT.gst() );
p.EquatorialToHorizontal( &LST, KStarsData::Instance()->geo()->lat() );
return p.alt().Degrees();
......@@ -1490,7 +1490,7 @@ bool Scheduler::calculateAltitudeTime(SchedulerJob *job, double minAltitude, dou
if (rawFrac < Dawn || rawFrac > Dusk)
{
dms LST = geo->GSTtoLST( myUT.gst() );
CachingDms LST = geo->GSTtoLST( myUT.gst() );
target.EquatorialToHorizontal( &LST, geo->lat() );
altitude = target.alt().Degrees();
......@@ -1761,7 +1761,7 @@ double Scheduler::getCurrentMoonSeparation(SchedulerJob *job)
QDateTime midnight( KStarsData::Instance()->lt().date(), QTime() );
KStarsDateTime ut = geo->LTtoUT( midnight );
KStarsDateTime myUT = ut.addSecs(KStarsData::Instance()->lt().time().msecsSinceStartOfDay()/1000);
dms LST = geo->GSTtoLST( myUT.gst() );
CachingDms LST = geo->GSTtoLST( myUT.gst() );
p.EquatorialToHorizontal( &LST, geo->lat() );
// Update moon
......@@ -1783,7 +1783,7 @@ int16_t Scheduler::getMoonSeparationScore(SchedulerJob *job, QDateTime when)
QDateTime midnight( when.date(), QTime() );
KStarsDateTime ut = geo->LTtoUT( midnight );
KStarsDateTime myUT = ut.addSecs(when.time().msecsSinceStartOfDay()/1000);
dms LST = geo->GSTtoLST( myUT.gst() );
CachingDms LST = geo->GSTtoLST( myUT.gst() );
p.EquatorialToHorizontal( &LST, geo->lat() );
double currentAlt = p.alt().Degrees();
......
......@@ -73,7 +73,7 @@ void KSAlmanac::RiseSetTime( SkyObject *o, double *riseTime, double *setTime, QT
// them back.
KSNumbers num( dt.djd() );
dms LST = geo->GSTtoLST( dt.gst() );
CachingDms LST = geo->GSTtoLST( dt.gst() );
o->updateCoords( &num, true, geo->lat(), &LST, true );
if ( o->checkCircumpolar( geo->lat() ) ) {
if ( o->alt().Degrees() > 0.0 ) {
......@@ -96,7 +96,7 @@ void KSAlmanac::findDawnDusk() {
KStarsDateTime today = dt;
KSNumbers num( today.djd() );
dms LST = geo->GSTtoLST( today.gst() );
CachingDms LST = geo->GSTtoLST( today.gst() );
m_Sun.updateCoords( &num, true, geo->lat(), &LST, true ); // We can abuse our own copy of the sun
double dawn, da, dusk, du, max_alt, min_alt;
......@@ -140,7 +140,7 @@ void KSAlmanac::findDawnDusk() {
void KSAlmanac::findMoonPhase() {
const KStarsDateTime today = dt;
KSNumbers num( today.djd() );
dms LST = geo->GSTtoLST( today.gst() );
CachingDms LST = geo->GSTtoLST( today.gst() );
m_Sun.updateCoords( &num, true, geo->lat(), &LST, true ); // We can abuse our own copy of the sun and/or moon
m_Moon.updateCoords( &num, true, geo->lat(), &LST, true );
......
......@@ -103,7 +103,7 @@ void KSPlanetBase::EclipticToEquatorial( const dms *Obliquity ) {
setFromEcliptic( Obliquity, ep.longitude, ep.latitude );
}
void KSPlanetBase::updateCoords( const KSNumbers *num, bool includePlanets, const dms *lat, const dms *LST, bool )
void KSPlanetBase::updateCoords( const KSNumbers *num, bool includePlanets, const CachingDms *lat, const CachingDms *LST, bool )
{
KStarsData *kd = KStarsData::Instance();
if ( includePlanets ) {
......@@ -120,7 +120,7 @@ void KSPlanetBase::updateCoords( const KSNumbers *num, bool includePlanets, cons
}
}
void KSPlanetBase::findPosition( const KSNumbers *num, const dms *lat, const dms *LST, const KSPlanetBase *Earth ) {
void KSPlanetBase::findPosition( const KSNumbers *num, const CachingDms *lat, const CachingDms *LST, const KSPlanetBase *Earth ) {
// DEBUG edit
findGeocentricPosition( num, Earth ); //private function, reimplemented in each subclass
findPhase();
......@@ -157,7 +157,7 @@ bool KSPlanetBase::isMajorPlanet() const {
return false;
}
void KSPlanetBase::localizeCoords( const KSNumbers *num, const dms *lat, const dms *LST ) {
void KSPlanetBase::localizeCoords( const KSNumbers *num, const CachingDms *lat, const CachingDms *LST ) {
//convert geocentric coordinates to local apparent coordinates (topocentric coordinates)
dms HA, HA2; //Hour Angle, before and after correction
double rsinp, rcosp, u, sinHA, cosHA, sinDec, cosDec, D;
......
......@@ -148,7 +148,7 @@ public:
* @param lat pointer to the geographic latitude; if NULL, we skip localizeCoords()
* @param LST pointer to the local sidereal time; if NULL, we skip localizeCoords()
*/
virtual void updateCoords( const KSNumbers *num, bool includePlanets=true, const dms *lat=0, const dms *LST=0, bool forceRecompute = false );
virtual void updateCoords( const KSNumbers *num, bool includePlanets=true, const CachingDms *lat=0, const CachingDms *LST=0, bool forceRecompute = false );
/** @short Find position, including correction for Figure-of-the-Earth.
* @param num KSNumbers pointer for the target date/time
......@@ -156,7 +156,7 @@ public:
* @param LST pointer to the local sidereal time; if NULL, we skip localizeCoords()
* @param Earth pointer to the Earth (not used for the Moon)
*/
void findPosition( const KSNumbers *num, const dms *lat=0, const dms *LST=0, const KSPlanetBase *Earth = 0 );
void findPosition( const KSNumbers *num, const CachingDms *lat=0, const CachingDms *LST=0, const KSPlanetBase *Earth = 0 );
/** @return the Planet's position angle. */
virtual double pa() const { return PositionAngle; }
......@@ -253,7 +253,7 @@ private:
* @param lat pointer to the geographic latitude of the location.
* @param LST pointer to the local sidereal time.
*/
void localizeCoords( const KSNumbers *num, const dms *lat, const dms *LST );
void localizeCoords( const KSNumbers *num, const CachingDms *lat, const CachingDms *LST );
double PositionAngle, AngularSize, PhysicalSize;
QColor m_Color;
......
......@@ -323,7 +323,7 @@ SkyPoint SkyObject::recomputeCoords( const KStarsDateTime &dt, const GeoLocation
// the passing of lat and LST
if ( isSolarSystem() && geo ) {
dms LST = geo->GSTtoLST( dt.gst() );
CachingDms LST = geo->GSTtoLST( dt.gst() );
c->updateCoords( &num, true, geo->lat(), &LST );
} else {
c->updateCoords( &num );
......
......@@ -60,6 +60,12 @@ SkyPoint::~SkyPoint(){
}
void SkyPoint::EquatorialToHorizontal( const dms *LST, const dms *lat ) {
qDebug() << "NOTE: This EquatorialToHorizontal overload (using dms pointers instead of CachingDms pointers) is deprecated and should be replaced with CachingDms prototype wherever speed is desirable!";
CachingDms _LST( *LST ), _lat( *lat );
EquatorialToHorizontal( &_LST, &_lat );
}
void SkyPoint::EquatorialToHorizontal( const CachingDms *LST, const CachingDms *lat ) {
#ifdef PROFILE_COORDINATE_CONVERSION
std::clock_t start = std::clock();
#endif
......@@ -356,7 +362,7 @@ void SkyPoint::aberrate(const KSNumbers *num) {
}
// Note: This method is one of the major rate determining factors in how fast the map pans / zooms in or out
void SkyPoint::updateCoords( const KSNumbers *num, bool /*includePlanets*/, const dms *lat, const dms *LST, bool forceRecompute ) {
void SkyPoint::updateCoords( const KSNumbers *num, bool /*includePlanets*/, const CachingDms *lat, const CachingDms *LST, bool forceRecompute ) {
//Correct the catalog coordinates for the time-dependent effects
//of precession, nutation and aberration
bool recompute, lens;
......
......@@ -23,7 +23,7 @@
#include <QList>
#include "dms.h"
#include "cachingdms.h"
#include "kstarsdatetime.h"
#define PROFILE_COORDINATE_CONVERSION true
......@@ -215,6 +215,9 @@ public:
*@param LST pointer to the local sidereal time
*@param lat pointer to the geographic latitude
*/
void EquatorialToHorizontal( const CachingDms* LST, const CachingDms* lat );
// Deprecated method provided for compatibility
void EquatorialToHorizontal( const dms* LST, const dms* lat );
/** Determine the (RA, Dec) coordinates of the
......@@ -261,7 +264,7 @@ public:
*@param LST does nothing in this implementation (see KSPlanetBase::updateCoords()).
*@param forceRecompute reapplies precession, nutation and aberration even if the time passed since the last computation is not significant.
*/
virtual void updateCoords( const KSNumbers *num, bool includePlanets=true, const dms *lat=0, const dms *LST=0, bool forceRecompute = false );
virtual void updateCoords( const KSNumbers *num, bool includePlanets=true, const CachingDms *lat=0, const CachingDms *LST=0, bool forceRecompute = false );
/**
* @brief updateCoordsNow Shortcut for updateCoords( const KSNumbers *num, false, NULL, NULL, true)
......
......@@ -254,7 +254,7 @@ void StarObject::initPopupMenu( KSPopupMenu *pmenu ) {
#endif
}
void StarObject::updateCoords( const KSNumbers *num, bool , const dms*, const dms*, bool ) {
void StarObject::updateCoords( const KSNumbers *num, bool , const CachingDms*, const CachingDms*, bool ) {
//Correct for proper motion of stars. Determine RA and Dec offsets.
//Proper motion is given im milliarcsec per year by the pmRA() and pmDec() functions.
//That is numerically identical to the number of arcsec per millenium, so multiply by
......
......@@ -162,7 +162,7 @@ public:
* @param lat does nothing in this implementation (see KSPlanetBase::updateCoords()).
* @param LST does nothing in this implementation (see KSPlanetBase::updateCoords()).
*/
virtual void updateCoords( const KSNumbers *num, bool includePlanets=true, const dms *lat=0, const dms *LST=0, bool forceRecompute = false );
virtual void updateCoords( const KSNumbers *num, bool includePlanets=true, const CachingDms *lat=0, const CachingDms *LST=0, bool forceRecompute = false );
/** @short fills ra and dec with the coordinates of the star with the proper
* motion correction but without precesion and its friends. It is used
......
......@@ -446,7 +446,7 @@ double AltVsTime::findAltitude( SkyPoint *p, double hour ) {
//getDate converts the user-entered local time to UT
KStarsDateTime ut = getDate().addSecs( hour*3600.0 );
dms LST = geo->GSTtoLST( ut.gst() );
CachingDms LST = geo->GSTtoLST( ut.gst() );
p->EquatorialToHorizontal( &LST, geo->lat() );
return p->alt().Degrees();
}
......@@ -972,7 +972,7 @@ void AltVsTime::slotUpdateDateLoc() {
KStarsDateTime today = getDate();
KSNumbers *num = new KSNumbers( today.djd() );
KSNumbers *oldNum = 0;
dms LST = geo->GSTtoLST( today.gst() );
CachingDms LST = geo->GSTtoLST( today.gst() );
//First determine time of sunset and sunrise
computeSunRiseSetTimes();
......@@ -1278,7 +1278,7 @@ void AltVsTime::setDawnDusk()
{
KStarsDateTime today = getDate();
KSNumbers num( today.djd() );
dms LST = geo->GSTtoLST( today.gst() );
CachingDms LST = geo->GSTtoLST( today.gst() );
KSSun sun;
sun.updateCoords( &num, true, geo->lat(), &LST, true );
......
......@@ -139,7 +139,7 @@ dms KSConjunct::findDistance(long double jd, SkyObject *Object1, KSPlanetBase *O
KSPlanet *m_Earth = new KSPlanet( I18N_NOOP( "Earth" ), QString(), QColor( "white" ), 12756.28 /*diameter in km*/ );
m_Earth -> findPosition( &num );
dms LST(geoPlace->GSTtoLST(t.gst()));
CachingDms LST(geoPlace->GSTtoLST(t.gst()));
KSPlanetBase* p = dynamic_cast<KSPlanetBase*>(Object1);
if( p )
......
......@@ -84,7 +84,7 @@ void modCalcPlanets::slotComputePosition (void)
KStarsDateTime dt = DateTimeBox->dateTime();
long double julianDay = dt.djd();
KSNumbers num( julianDay );
dms LST( geoPlace->GSTtoLST( dt.gst() ) );
CachingDms LST( geoPlace->GSTtoLST( dt.gst() ) );
// Earth
KSPlanet Earth( I18N_NOOP( "Earth" ));
......@@ -250,7 +250,7 @@ void modCalcPlanets::processLines( QTextStream &istream )
unsigned int i = 0, nline = 0;
QTime utB;
QDate dtB;
dms longB, latB, hlongB, hlatB, glongB, glatB, raB, decB, azmB, altB;
CachingDms longB, latB, hlongB, hlatB, glongB, glatB, raB, decB, azmB, altB;
double rSunB(0.0), rEarthB(0.0);
//Initialize planet names
......@@ -341,7 +341,7 @@ void modCalcPlanets::processLines( QTextStream &istream )
// Read Longitude and write in ostream if corresponds
if (LongCheckBatch->isChecked() ) {
longB = dms::fromString( fields[i],true);
longB = CachingDms::fromString( fields[i],true);
i++;
} else {
longB = LongBoxBatch->createDms(true);
......@@ -351,7 +351,7 @@ void modCalcPlanets::processLines( QTextStream &istream )
// Read Latitude
if (LatCheckBatch->isChecked() ) {
latB = dms::fromString( fields[i], true);
latB = CachingDms::fromString( fields[i], true);
i++;
} else {
latB = LatBoxBatch->createDms(true);
......@@ -361,7 +361,7 @@ void modCalcPlanets::processLines( QTextStream &istream )
KStarsDateTime edt( dtB, utB );
dms LST = edt.gst() + longB;
CachingDms LST = edt.gst() + longB;
KSNumbers num( edt.djd() );
KSPlanet Earth( I18N_NOOP( "Earth" ));
......
......@@ -282,7 +282,7 @@ void ObservingList::slotAddObject( SkyObject *obj, bool session, bool update ) {
obj->type() == SkyObject::PLANET) && obj->mag() == 0)
{
KSNumbers num( dt.djd() );
dms LST = geo->GSTtoLST( dt.gst() );
CachingDms LST = geo->GSTtoLST( dt.gst() );
obj->updateCoords(&num, true, geo->lat(), &LST, true);
}
......
......@@ -153,7 +153,7 @@ void WUTDialog::init() {
//check to see if Sun is circumpolar
KSNumbers *num = new KSNumbers( UT0.djd() );
KSNumbers *oldNum = new KSNumbers( data->ut().djd() );
dms LST = geo->GSTtoLST( T0.gst() );
CachingDms LST = geo->GSTtoLST( T0.gst() );
oSun->updateCoords( num, true, geo->lat(), &LST, true );
if ( oSun->checkCircumpolar( geo->lat() ) ) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment