Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve range reduction algorithm #169

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

vishwa2710
Copy link
Contributor

No description provided.

@codecov
Copy link

codecov bot commented Sep 12, 2023

Codecov Report

Merging #169 (2ebde64) into main (82d4af1) will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #169      +/-   ##
==========================================
+ Coverage   79.86%   79.88%   +0.02%     
==========================================
  Files          93       93              
  Lines        7448     7447       -1     
==========================================
+ Hits         5948     5949       +1     
+ Misses       1500     1498       -2     
Files Coverage Δ
...c/OpenSpaceToolkit/Physics/Units/Derived/Angle.cpp 72.99% <100.00%> (-0.08%) ⬇️

... and 1 file with indirect coverage changes

@@ -1,5 +1,5 @@
/// Apache License 2.0

#include <cmath>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simply for consistency:

Suggested change
#include <cmath>
#include <cmath>


const Real range = aRangeUpperBound - aRangeLowerBound;
const Real excessValue = std::fmod(aValue - aRangeLowerBound, aRangeUpperBound - aRangeLowerBound);
const Real adjestedRangeValue = aRangeLowerBound + excessValue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const Real adjestedRangeValue = aRangeLowerBound + excessValue;
const Real adjustedRangeValue = aRangeLowerBound + excessValue;


while (value < aRangeLowerBound
) // [TBM] This is a STUPID implementation: just used as a logic placeholder... should be improved ASAP
if ((adjestedRangeValue >= aRangeLowerBound) && (adjestedRangeValue < aRangeUpperBound))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ((adjestedRangeValue >= aRangeLowerBound) && (adjestedRangeValue < aRangeUpperBound))
if ((adjustedRangeValue >= aRangeLowerBound) && (adjustedRangeValue < aRangeUpperBound))

{
value += range;
return adjestedRangeValue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return adjestedRangeValue;
return adjustedRangeValue;


while (value >= aRangeUpperBound
) // [TBM] This is a STUPID implementation: just used as a logic placeholder... should be improved ASAP
else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for an else block, since the if block returns.

{
value -= range;
/*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment block style is likely different from the rest of the codebase?

Copy link
Contributor Author

@vishwa2710 vishwa2710 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some nits. yeah I agree this is a bit gross :/ let me think if there's a better way to deal with the rounding issues.

@@ -61,7 +62,7 @@ bool Angle::operator==(const Angle& anAngle) const
{
return false;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@@ -356,7 +357,7 @@ Real Angle::in(const Angle::Unit& aUnit) const
return this->accessValue();
}

return this->accessValue() * Angle::SIRatio(unit_) / Angle::SIRatio(aUnit);
return (this->accessValue() * Angle::SIRatio(unit_) / Angle::SIRatio(aUnit));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return (this->accessValue() * Angle::SIRatio(unit_) / Angle::SIRatio(aUnit));
return this->accessValue() * Angle::SIRatio(unit_) / Angle::SIRatio(aUnit);

@@ -732,24 +733,20 @@ Real Angle::ReduceRange(const Real& aValue, const Real& aRangeLowerBound, const
"Lower bound [{}] greater than or equal to upper bound [{}].", aRangeLowerBound, aRangeUpperBound
);
}
// this line handles some rounding error albeit in a way that doesnt pass the smell test...
Real value = aValue + 10.0 - 10.0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Real value = aValue + 10.0 - 10.0;
const Real value = aValue + 10.0 - 10.0;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants