Skip to content

Commit

Permalink
feat: small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vishwa2710 committed Jun 18, 2024
1 parent 5e4bab4 commit 5f72941
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions bindings/python/test/trajectory/orbit/test_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <OpenSpaceToolkit/Physics/Time/Duration.hpp>
#include <OpenSpaceToolkit/Physics/Time/Instant.hpp>
#include <OpenSpaceToolkit/Physics/Time/Interval.hpp>

namespace ostk
{
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions src/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,12 @@ Array<Pass> 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;
Expand Down Expand Up @@ -1321,7 +1321,7 @@ Array<Pass> 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
{
Expand Down
10 changes: 10 additions & 0 deletions src/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit/Pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
46 changes: 23 additions & 23 deletions test/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
}
}

Expand Down
29 changes: 29 additions & 0 deletions test/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit/Pass.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
{
Expand Down

0 comments on commit 5f72941

Please sign in to comment.