From 142c4d0e6c3eec3624c6944802e4de8eb226a7f6 Mon Sep 17 00:00:00 2001 From: Vishwa Shah Date: Fri, 19 Jan 2024 16:15:42 -0800 Subject: [PATCH] refactor: change the index returned by pass map to be the last index (#323) refactor: change the index returned by pass map to be the last index --- .../Astrodynamics/Trajectory/Orbit.cpp | 6 ++---- .../Astrodynamics/Trajectory/Orbit.test.cpp | 12 +++++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit.cpp b/src/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit.cpp index 8cd07df2b..92c8053f6 100644 --- a/src/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit.cpp +++ b/src/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit.cpp @@ -1032,7 +1032,6 @@ Map Orbit::GeneratePassMap(const Array& aStateArray, const I Map passMap; - Index index = 0; Integer revolutionNumber = anInitialRevolutionNumber; Instant previousPassEndInstant = Instant::Undefined(); @@ -1130,9 +1129,8 @@ Map Orbit::GeneratePassMap(const Array& aStateArray, const I southPointCrossing, }; - passMap.insert({index, pass}); + passMap.insert({currentIndex, pass}); - index = currentIndex; revolutionNumber++; southPointCrossing = Instant::Undefined(); @@ -1167,7 +1165,7 @@ Map Orbit::GeneratePassMap(const Array& aStateArray, const I southPointCrossing, }; - passMap.insert({index, pass}); + passMap.insert({currentIndex, pass}); } previousStatePtr = &state; diff --git a/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit.test.cpp b/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit.test.cpp index 74f6bfda6..54e5d7636 100644 --- a/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit.test.cpp +++ b/test/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit.test.cpp @@ -482,6 +482,7 @@ TEST(OpenSpaceToolkit_Astrodynamics_Trajectory_Orbit, GeneratePassMap) EXPECT_EQ(referenceData.getRowCount(), passMap.size() - 1); // We're generating 1 pass over the reference data Index i = 0; + Index stateIndex = 0; for (const auto& row : passMap) { // Ignore the lass pass, as it is not complete @@ -490,6 +491,7 @@ TEST(OpenSpaceToolkit_Astrodynamics_Trajectory_Orbit, GeneratePassMap) break; } + // test computed Pass const Pass& pass = row.second; const auto& referenceRow = referenceData[i]; @@ -536,9 +538,17 @@ TEST(OpenSpaceToolkit_Astrodynamics_Trajectory_Orbit, GeneratePassMap) EXPECT_LT( std::fabs((referencePassDescendingNodeInstant - pass.accessInstantAtDescendingNode()).inSeconds()), 1e-6 ); - EXPECT_LT(std::fabs((referencePassEndInstant - pass.getInterval().getEnd()).inSeconds()), 1e-6); EXPECT_LT(std::fabs((referencePassNorthPointInstant - pass.accessInstantAtNorthPoint()).inSeconds()), 3.0); EXPECT_LT(std::fabs((referencePassSouthPointInstant - pass.accessInstantAtSouthPoint()).inSeconds()), 3.0); + + // test state index + const Index& endStateIndex = row.first; + + EXPECT_TRUE(referencePassStartInstant <= states[stateIndex].accessInstant()); + EXPECT_TRUE(referencePassEndInstant >= states[endStateIndex - 1].accessInstant()); + + stateIndex = endStateIndex; + ++i; } }