From 5f72941f235cf9182ff8c2cfaf4abda2fcd464c2 Mon Sep 17 00:00:00 2001 From: vishwa shah Date: Tue, 4 Jun 2024 23:09:21 +0000 Subject: [PATCH] feat: small fixes --- .../Trajectory/Orbit/Pass.cpp | 10 ++++ .../python/test/trajectory/orbit/test_pass.py | 3 ++ .../Astrodynamics/Trajectory/Orbit/Pass.hpp | 7 +++ .../Astrodynamics/Trajectory/Orbit.cpp | 6 +-- .../Astrodynamics/Trajectory/Orbit/Pass.cpp | 10 ++++ .../Astrodynamics/Trajectory/Orbit.test.cpp | 46 +++++++++---------- .../Trajectory/Orbit/Pass.test.cpp | 29 ++++++++++++ 7 files changed, 85 insertions(+), 26 deletions(-) diff --git a/bindings/python/src/OpenSpaceToolkitAstrodynamicsPy/Trajectory/Orbit/Pass.cpp b/bindings/python/src/OpenSpaceToolkitAstrodynamicsPy/Trajectory/Orbit/Pass.cpp index e8628d127..afb510dce 100644 --- a/bindings/python/src/OpenSpaceToolkitAstrodynamicsPy/Trajectory/Orbit/Pass.cpp +++ b/bindings/python/src/OpenSpaceToolkitAstrodynamicsPy/Trajectory/Orbit/Pass.cpp @@ -157,6 +157,16 @@ inline void OpenSpaceToolkitAstrodynamicsPy_Trajectory_Orbit_Pass(pybind11::modu )doc" ) + .def( + "get_interval", + &Pass::getInterval, + R"doc( + Get the interval of the pass. Undefined if the pass is not complete. + + Returns: + Interval: The interval of the pass. + )doc" + ) .def( "get_instant_at_ascending_node", &Pass::accessInstantAtAscendingNode, diff --git a/bindings/python/test/trajectory/orbit/test_pass.py b/bindings/python/test/trajectory/orbit/test_pass.py index 99f80b5b7..935b65c42 100644 --- a/bindings/python/test/trajectory/orbit/test_pass.py +++ b/bindings/python/test/trajectory/orbit/test_pass.py @@ -47,6 +47,9 @@ def test_get_start_instant(self, pass_: Pass): def test_get_end_instant(self, pass_: Pass): assert pass_.get_end_instant() is not None + def test_get_interval(self, pass_: Pass): + assert pass_.get_interval() is not None + def test_get_instant_at_ascending_node(self, pass_: Pass): assert pass_.get_instant_at_ascending_node() is not None diff --git a/include/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit/Pass.hpp b/include/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit/Pass.hpp index 81f38d5fd..f74c9caf1 100644 --- a/include/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit/Pass.hpp +++ b/include/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit/Pass.hpp @@ -8,6 +8,7 @@ #include #include +#include namespace ostk { @@ -23,6 +24,7 @@ using ostk::core::type::String; using ostk::physics::time::Duration; using ostk::physics::time::Instant; +using ostk::physics::time::Interval; /// @class Pass /// @brief A revolution of an orbiting object. @@ -123,6 +125,11 @@ class Pass /// @return The end instant of the pass. Instant getEndInstant() const; + /// @brief Gets the interval of the pass. + /// + /// @return The interval of the pass. + Interval getInterval() const; + /// @brief Accesses the instant at the ascending node of the pass. /// /// @return The instant at the ascending node of the pass. diff --git a/src/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit.cpp b/src/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit.cpp index bbc2947e9..b1b485498 100644 --- a/src/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit.cpp +++ b/src/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit.cpp @@ -431,12 +431,12 @@ Array Orbit::getPassesWithinInterval(const Interval& anInterval) const Integer revolutionNumber = Integer::Undefined(); - // Check if the pass is already within pass Map + // Check if the Pass is already within Pass map for (const auto& passIt : this->passMap_) { const Pass& pass = passIt.second; - if (pass.accessInstantAtPassBreak() <= currentInstant) + if (pass.getInterval().contains(currentInstant)) { revolutionNumber = passIt.first; break; @@ -1321,7 +1321,7 @@ Array Orbit::ComputePassesWithModel(const orbit::Model& aModel, const Inte } ); - const Instant& epoch = instants.accessFirst(); + const Instant& epoch = aModel.getEpoch(); const auto getZ = [&aModel, &epoch](const double& aDurationInSeconds) -> double { diff --git a/src/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit/Pass.cpp b/src/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit/Pass.cpp index 51e6e189c..922537620 100644 --- a/src/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit/Pass.cpp +++ b/src/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit/Pass.cpp @@ -247,6 +247,16 @@ Instant Pass::getEndInstant() const return instantAtAscendingNode_; } +const Interval Pass::getInterval() const +{ + if (type_ == Pass::Type::Complete) + { + return Interval::Closed(instantAtAscendingNode_, instantAtPassBreak_); + } + + return Interval::Undefined(); +} + const Instant& Pass::accessInstantAtAscendingNode() const { if (!this->isDefined()) diff --git a/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit.test.cpp b/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit.test.cpp index 0aa02acd7..53b07dc78 100644 --- a/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit.test.cpp +++ b/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit.test.cpp @@ -1155,29 +1155,29 @@ TEST(OpenSpaceToolkit_Astrodynamics_Trajectory_Orbit, GetPassesWithinInterval) Instant::DateTime(DateTime::Parse("2018-01-01 23:00:00"), Scale::UTC) ))); - // for (const auto &referenceRow : referenceData) - // { - // const Integer referenceRevolutionNumber = referenceRow[0].accessInteger(); - // const Instant referencePassStartInstant = - // Instant::DateTime(DateTime::Parse(referenceRow[1].accessString()), Scale::UTC); - // const Instant referencePassEndInstant = - // Instant::DateTime(DateTime::Parse(referenceRow[2].accessString()), Scale::UTC); - - // const Pass pass = orbit.getPassWithRevolutionNumber(referenceRevolutionNumber); - - // EXPECT_TRUE(pass.isDefined()); - - // EXPECT_EQ(Pass::Type::Complete, pass.getType()); - - // EXPECT_GT( - // Duration::Microseconds(1.0), - // Duration::Between(referencePassStartInstant, pass.accessInstantAtAscendingNode()).getAbsolute() - // ); - // EXPECT_GT( - // Duration::Microseconds(1.0), - // Duration::Between(referencePassEndInstant, pass.accessInstantAtPassBreak()).getAbsolute() - // ); - // } + for (const auto &referenceRow : referenceData) + { + const Integer referenceRevolutionNumber = referenceRow[0].accessInteger(); + const Instant referencePassStartInstant = + Instant::DateTime(DateTime::Parse(referenceRow[1].accessString()), Scale::UTC); + const Instant referencePassEndInstant = + Instant::DateTime(DateTime::Parse(referenceRow[2].accessString()), Scale::UTC); + + const Pass pass = orbit.getPassWithRevolutionNumber(referenceRevolutionNumber); + + EXPECT_TRUE(pass.isDefined()); + + EXPECT_EQ(Pass::Type::Complete, pass.getType()); + + EXPECT_GT( + Duration::Microseconds(1.0), + Duration::Between(referencePassStartInstant, pass.accessInstantAtAscendingNode()).getAbsolute() + ); + EXPECT_GT( + Duration::Microseconds(1.0), + Duration::Between(referencePassEndInstant, pass.accessInstantAtPassBreak()).getAbsolute() + ); + } } } diff --git a/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit/Pass.test.cpp b/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit/Pass.test.cpp index 91924da9a..de4580153 100644 --- a/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit/Pass.test.cpp +++ b/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit/Pass.test.cpp @@ -682,6 +682,35 @@ TEST_F(OpenSpaceToolkit_Astrodynamics_Trajectory_Orbit_Pass, GetEndInstant) } } +TEST_F(OpenSpaceToolkit_Astrodynamics_Trajectory_Orbit_Pass, GetInterval) +{ + { + EXPECT_THROW(Pass::Undefined().getInterval(), ostk::core::error::runtime::Undefined); + } + + { + EXPECT_TRUE(defaultPass_.getInterval().isDefined()); + } + + { + const Pass pass = { + defaultRevolutionNumber_, + defaultInstantAtAscendingNode_, + defaultInstantAtNorthPoint_, + defaultInstantAtDescendingNode_, + Instant::Undefined(), + defaultInstantAtPassBreak_, + }; + EXPECT_FALSE(pass.getInterval().isDefined()); + } + + { + EXPECT_EQ( + defaultPass_.getInterval(), Interval::Closed(defaultInstantAtAscendingNode_, defaultInstantAtPassBreak_) + ); + } +} + TEST_F(OpenSpaceToolkit_Astrodynamics_Trajectory_Orbit_Pass, AccessInstantAtAscendingNode) { {