More updates to Timespan and Julian

feature/19
Daniel Warner 2011-06-10 19:34:39 +00:00
parent 0f69c839b7
commit 8cba7f685f
5 changed files with 58 additions and 29 deletions

View File

@ -97,7 +97,7 @@ bool Julian::operator==(const Julian &date) const {
bool Julian::operator!=(const Julian &date) const {
return date_ == date.date_ ? false : true;
return !(*this == date);
}
bool Julian::operator>(const Julian &date) const {
@ -140,24 +140,34 @@ Julian& Julian::operator=(const double b) {
/*
* arithmetic
*/
Julian Julian::operator+(const Timespan& b) const {
Julian Julian::operator +(const Timespan& b) const {
Julian result(*this);
result.date_ += b.GetTotalDays();
return result;
return Julian(*this) += b;
}
Julian Julian::operator-(const Timespan& b) const {
Julian result(*this);
result.date_ -= b.GetTotalDays();
return result;
return Julian(*this) -= b;
}
Timespan Julian::operator-(const Julian& b) const {
Timespan result(date_ - b.date_);
return result;
return Timespan(date_ - b.date_);
}
/*
* compound assignment
*/
Julian & Julian::operator +=(const Timespan& b) {
date_ += b;
return (*this);
}
Julian & Julian::operator -=(const Timespan& b) {
date_ -= b;
return (*this);
}
std::ostream & operator<<(std::ostream& stream, const Julian& julian) {
@ -165,13 +175,13 @@ std::ostream & operator<<(std::ostream& stream, const Julian& julian) {
std::stringstream out;
struct Julian::DateTimeComponents datetime;
julian.ToGregorian(&datetime);
out << std::right << std::fixed << std::setprecision(3) << std::setfill('0');
out << std::right << std::fixed << std::setprecision(6) << std::setfill('0');
out << std::setw(4) << datetime.years << "-";
out << std::setw(2) << datetime.months << "-";
out << std::setw(2) << datetime.days << " ";
out << std::setw(2) << datetime.hours << ":";
out << std::setw(2) << datetime.minutes << ":";
out << std::setw(6) << datetime.seconds << " UTC";
out << std::setw(9) << datetime.seconds << " UTC";
stream << out.str();
return stream;
}

View File

@ -18,9 +18,7 @@ public:
~Julian() {
};
/*
* comparison operators
*/
// comparison operators
bool operator==(const Julian &date) const;
bool operator!=(const Julian &date) const;
bool operator>(const Julian &date) const;
@ -28,16 +26,16 @@ public:
bool operator>=(const Julian &date) const;
bool operator<=(const Julian &date) const;
// asign Julian
Julian & operator=(const Julian& b);
// assign double
Julian & operator=(const double b);
// add Timespan
Julian operator+(const Timespan& b) const;
// subtract Timespan
Julian operator-(const Timespan& b) const;
// subtracting two Julians produces a Timespan
Timespan operator-(const Julian& b) const;
// assignment
Julian& operator =(const Julian& b);
Julian& operator =(const double b);
// arithmetic
Julian operator +(const Timespan& b) const;
Julian operator -(const Timespan& b) const;
Timespan operator -(const Julian& b) const;
// compound assignment
Julian & operator +=(const Timespan& b);
Julian & operator -=(const Timespan& b);
friend std::ostream & operator<<(std::ostream& stream, const Julian& julian);

View File

@ -4,6 +4,8 @@
#include <cmath>
#include <iostream>
const int kPASS_TIME_STEP = 180; // time step in seconds, when searching for aos/los
double FindMaxElevation(const CoordGeodetic& user_geo, SGP4& sgp4, const Julian& aos, const Julian& los) {
Observer obs(user_geo);
@ -120,7 +122,7 @@ Julian FindCrossingPoint(const CoordGeodetic& user_geo, SGP4& sgp4, const Julian
/*
* when two times are within a second, stop
*/
if (((time2.GetDate() - time1.GetDate()) * kSECONDS_PER_DAY) < 1.0) {
if (((time2.GetDate() - time1.GetDate()) * kSECONDS_PER_DAY) < 0.5) {
searching = false;
}
@ -136,6 +138,9 @@ void AOSLOS(const CoordGeodetic& user_geo, SGP4& sgp4, const Julian& start_time,
Observer obs(user_geo);
Eci eci;
Timespan time_step;
time_step.AddMinutes(kPASS_TIME_STEP);
bool first_run = true;
Julian previous_time = start_time;
@ -147,6 +152,7 @@ void AOSLOS(const CoordGeodetic& user_geo, SGP4& sgp4, const Julian& start_time,
Julian current_time = start_time;
while (current_time < end_time) {
// find position
sgp4.FindPosition(&eci, current_time);
CoordTopographic topo = obs.GetLookAngle(eci);
@ -189,7 +195,7 @@ void AOSLOS(const CoordGeodetic& user_geo, SGP4& sgp4, const Julian& start_time,
first_run = false;
previous_time = current_time;
current_time.AddMin(1.0);
current_time += time_step;
if (current_time > end_time)
current_time = end_time;
};

View File

@ -6,7 +6,7 @@ Timespan::Timespan()
: time_span_(0.0) {
}
Timespan::Timespan(const double b){
Timespan::Timespan(const double b) {
time_span_ = b;
}
@ -146,3 +146,15 @@ bool Timespan::operator <=(const Timespan & b) const {
else
return false;
}
double& operator +=(double& a, const Timespan& b) {
a += b.time_span_;
return a;
}
double& operator -=(double& a, const Timespan& b) {
a -= b.time_span_;
return a;
}

View File

@ -38,6 +38,9 @@ public:
bool operator>=(const Timespan& b) const;
bool operator<=(const Timespan& b) const;
friend double& operator +=(double& a, const Timespan& b);
friend double& operator -=(double& a, const Timespan& b);
private:
/*
* stores value in minutes