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

Simplify between_0_360 & between_pm_x from src/utils.rs #171

Merged
merged 4 commits into from
Jun 8, 2023
Merged

Simplify between_0_360 & between_pm_x from src/utils.rs #171

merged 4 commits into from
Jun 8, 2023

Conversation

ThibFrgsGmz
Copy link
Contributor

@ThibFrgsGmz ThibFrgsGmz commented Jun 8, 2023

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 run clippy and rust-fmt directly from VSCode to enforce their usage and get rid of potential CI issues when pushing to remote.

@ThibFrgsGmz ThibFrgsGmz changed the title Simplify between_0_360 Simplify between_0_360 & between_pm_x from src/utils.rs Jun 8, 2023
@ChristopherRabotin
Copy link
Member

I never thought of using modulo on floating points, but since it works, it makes sense to use it.

@ChristopherRabotin ChristopherRabotin merged commit 2ee5225 into nyx-space:master Jun 8, 2023
19 checks passed
@ThibFrgsGmz ThibFrgsGmz deleted the feat/simplify_between_0_360 branch June 8, 2023 18:13
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.

None yet

2 participants