Skip to content

Commit

Permalink
refactor: change the index returned by pass map to be the last index (#…
Browse files Browse the repository at this point in the history
…323)

refactor: change the index returned by pass map to be the last index
  • Loading branch information
vishwa2710 authored Jan 20, 2024
1 parent 4ec6f95 commit 142c4d0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 2 additions & 4 deletions src/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,6 @@ Map<Index, Pass> Orbit::GeneratePassMap(const Array<State>& aStateArray, const I

Map<Index, Pass> passMap;

Index index = 0;
Integer revolutionNumber = anInitialRevolutionNumber;
Instant previousPassEndInstant = Instant::Undefined();

Expand Down Expand Up @@ -1130,9 +1129,8 @@ Map<Index, Pass> Orbit::GeneratePassMap(const Array<State>& aStateArray, const I
southPointCrossing,
};

passMap.insert({index, pass});
passMap.insert({currentIndex, pass});

index = currentIndex;
revolutionNumber++;

southPointCrossing = Instant::Undefined();
Expand Down Expand Up @@ -1167,7 +1165,7 @@ Map<Index, Pass> Orbit::GeneratePassMap(const Array<State>& aStateArray, const I
southPointCrossing,
};

passMap.insert({index, pass});
passMap.insert({currentIndex, pass});
}

previousStatePtr = &state;
Expand Down
12 changes: 11 additions & 1 deletion test/OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -490,6 +491,7 @@ TEST(OpenSpaceToolkit_Astrodynamics_Trajectory_Orbit, GeneratePassMap)
break;
}

// test computed Pass
const Pass& pass = row.second;

const auto& referenceRow = referenceData[i];
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 142c4d0

Please sign in to comment.