diff --git a/Julian.cpp b/Julian.cpp index be3917c..4b1e4cd 100755 --- a/Julian.cpp +++ b/Julian.cpp @@ -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; } diff --git a/Julian.h b/Julian.h index aa7b6e7..c936358 100755 --- a/Julian.h +++ b/Julian.h @@ -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); diff --git a/PassPredict.cpp b/PassPredict.cpp index e332cd3..e4abe4d 100755 --- a/PassPredict.cpp +++ b/PassPredict.cpp @@ -4,6 +4,8 @@ #include #include +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); @@ -61,7 +63,7 @@ double FindMaxElevation(const CoordGeodetic& user_geo, SGP4& sgp4, const Julian& * reset elevation */ max_elevation = -99.9; - + } else { /* * found max elevation @@ -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; }; diff --git a/Timespan.cpp b/Timespan.cpp index 55ebc17..261b46e 100755 --- a/Timespan.cpp +++ b/Timespan.cpp @@ -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; +} \ No newline at end of file diff --git a/Timespan.h b/Timespan.h index e8ccff6..b1e68dc 100755 --- a/Timespan.h +++ b/Timespan.h @@ -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