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

Improve Vector Operations, Normalization and Capitalization #180

Merged
merged 3 commits into from
Jun 11, 2023
Merged

Improve Vector Operations, Normalization and Capitalization #180

merged 3 commits into from
Jun 11, 2023

Conversation

ThibFrgsGmz
Copy link
Contributor

This PR introduces several improvements to the vector operations, normalization and capitalization functions.

The changes are intended to make the code more idiomatic Rust, improve readability, and enhance the robustness of the code.

  1. Refactored the rotv, perpv, and projv functions to use more idiomatic Rust. This includes using the normalize, scale, cross, dot, amax, sub, and norm_squared methods from the Vector3 struct.

  2. Refactored the normalize, denormalize, and capitalize functions.

  3. Improved the documentation for these functions. Each function now has a detailed docstring that describes its purpose, its arguments, and its return value. This will make it easier for other developers to understand and use these functions.

  4. Added comprehensive unit tests for these functions. These tests cover various edge cases and ensure that the functions work as expected.

These changes should not affect the functionality of the code, but they will make it easier to read, understand, and maintain. The unit tests will help us catch any potential issues or regressions in the future.


Please review these changes and let me know if you have any feedback or questions.

src/utils.rs Outdated
if big_a < f64::EPSILON {
Vector3::zeros()
} else if big_b < f64::EPSILON {
*a
} else {
let a_scl = a / big_a;
let b_scl = b / big_b;
let a_scl = a.scale(1.0 / big_a);
Copy link
Member

Choose a reason for hiding this comment

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

I prefer using the operator overload instead of .scale() because it's immediately understandable. (Same for the two other uses below)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

pub fn perpv(a: &Vector3<f64>, b: &Vector3<f64>) -> Vector3<f64> {
let big_a = a[0].abs().max(a[1].abs().max(a[2].abs()));
let big_b = b[0].abs().max(b[1].abs().max(b[2].abs()));
let big_a = a.amax();
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fiercely efficient!

@codecov
Copy link

codecov bot commented Jun 10, 2023

Codecov Report

Patch coverage: 65.60% and project coverage change: +0.25 🎉

Comparison is base (2ee5225) 66.33% compared to head (dbebc95) 66.59%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #180      +/-   ##
==========================================
+ Coverage   66.33%   66.59%   +0.25%     
==========================================
  Files         127      127              
  Lines       32445    32506      +61     
==========================================
+ Hits        21524    21648     +124     
+ Misses      10921    10858      -63     
Impacted Files Coverage Δ
src/utils.rs 64.35% <65.60%> (+12.95%) ⬆️

... and 6 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@ChristopherRabotin ChristopherRabotin merged commit 82da8dd into nyx-space:master Jun 11, 2023
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.

2 participants