Simplify between_0_360
& between_pm_x
from src/utils.rs
#171
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Simplify some functions from
src/utils.rs
and add more UTs.between_0_360
: in this version, we use the modulo operator (%) to obtain the remainder of the division of the angle by 360.0. This gives us a number that is necessarily less than 360.0. If this number is negative (which can happen if the angle is negative), we add 360.0 to make it positive. This function therefore always returns a number between 0.0 and 360.0, as desired.between_pm_x
: this version also uses the modulo operator to normalize the angle, which is more efficient than using a while loop. The unit tests cover several cases: a positive angle greater than x, a negative angle less than -x, an angle already within the interval [-x, x), an angle of zero degrees and an angle of 360 degrees.is_diagonal
: less cryptic (I reckon lol)PS: I also updated the
settings.json
to runclippy
andrust-fmt
directly from VSCode to enforce their usage and get rid of potential CI issues when pushing to remote.