Skip to content

Commit 866df65

Browse files
apaletta3Copilotvishwa2710
committed
refactor: apply code suggestions
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Vishwa Shah <vishwa2710@gmail.com>
1 parent 4eb739f commit 866df65

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

bindings/python/test/trajectory/test_state.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ def test_is_near_element_wise(
623623
state=state,
624624
tolerance_array_map=tolerance_array_map,
625625
)
626-
expected_is_near_result: dict[CoordinateSubset, bool] = {
626+
expected_is_near_result: dict[CoordinateSubset, list[bool]] = {
627627
CartesianPosition.default(): [True, True, True],
628628
CartesianVelocity.default(): [True, True, True],
629629
}

src/OpenSpaceToolkit/Astrodynamics/Trajectory/State.cpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,10 @@ std::unordered_map<Shared<const CoordinateSubset>, bool> State::isNear(
503503
{
504504
if (aToleranceMap.size() != coordinatesBrokerSPtr_->accessSubsets().getSize())
505505
{
506-
throw ostk::core::error::runtime::Wrong("Tolerance Map");
506+
throw ostk::core::error::runtime::Wrong(
507+
"Tolerance Map: Expected size [" + std::to_string(coordinatesBrokerSPtr_->accessSubsets().getSize()) +
508+
"], but received size [" + std::to_string(aToleranceMap.size()) + "]."
509+
);
507510
}
508511

509512
const State deltaState = aState - *this;
@@ -513,11 +516,15 @@ std::unordered_map<Shared<const CoordinateSubset>, bool> State::isNear(
513516
{
514517
if (!coordinatesBrokerSPtr_->hasSubset(subsetSPtr))
515518
{
516-
throw ostk::core::error::runtime::Wrong("Tolerance Map Coordinate Subset");
519+
throw ostk::core::error::runtime::Wrong(
520+
"Tolerance map doesn't contain coordinate subset [" + subsetSPtr->getName() + "]."
521+
);
517522
}
518523
if (tolerance <= 0.0)
519524
{
520-
throw ostk::core::error::runtime::Wrong("Tolerance");
525+
throw ostk::core::error::runtime::Wrong(
526+
"Tolerance value for subset [" + subsetSPtr->getName() + "] is less than or equal to zero."
527+
);
521528
}
522529

523530
const VectorXd deltaCoordinates = deltaState.extractCoordinate(subsetSPtr);
@@ -533,7 +540,7 @@ std::unordered_map<Shared<const CoordinateSubset>, Array<bool>> State::isNear(
533540
{
534541
if (aToleranceArrayMap.size() != coordinatesBrokerSPtr_->accessSubsets().getSize())
535542
{
536-
throw ostk::core::error::runtime::Wrong("Tolerance Map");
543+
throw ostk::core::error::runtime::Wrong("Tolerance array map is not of the same size as the state.");
537544
}
538545

539546
const State deltaState = aState - *this;
@@ -543,18 +550,26 @@ std::unordered_map<Shared<const CoordinateSubset>, Array<bool>> State::isNear(
543550
{
544551
if (!coordinatesBrokerSPtr_->hasSubset(subsetSPtr))
545552
{
546-
throw ostk::core::error::runtime::Wrong("Tolerance Map Coordinate Subset");
553+
throw ostk::core::error::runtime::Wrong(
554+
"Tolerance array map doesn't contain coordinate subset [" + subsetSPtr->getName() + "]."
555+
);
547556
}
548557

549558
const VectorXd deltaCoordinates = deltaState.extractCoordinate(subsetSPtr);
550559

551560
if (toleranceArray.size() != deltaCoordinates.size())
552561
{
553-
throw ostk::core::error::runtime::Wrong("Tolerance Array Size");
562+
throw ostk::core::error::runtime::Wrong(
563+
"Tolerance Array Size: Expected [" + std::to_string(deltaCoordinates.size()) + "], but got [" +
564+
std::to_string(toleranceArray.size()) + "]"
565+
);
554566
}
555567
if ((toleranceArray.array() <= 0.0).any())
556568
{
557-
throw ostk::core::error::runtime::Wrong("Tolerance Array");
569+
throw ostk::core::error::runtime::Wrong(
570+
"One or more elements in the tolerance array for subset [" + subsetSPtr->getName() +
571+
"] is less than or equal to zero."
572+
);
558573
}
559574

560575
Array<bool> isNearArray;

0 commit comments

Comments
 (0)