-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
Improve Vector Operations, Normalization and Capitalization #180
Conversation
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); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mindblown! https://docs.rs/nalgebra/latest/nalgebra/base/struct.Matrix.html#method.amax I didn't know this was a thing!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fiercely efficient!
Codecov ReportPatch coverage:
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
☔ View full report in Codecov by Sentry. |
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.
Refactored the
rotv
,perpv
, andprojv
functions to use more idiomatic Rust. This includes using thenormalize
,scale
,cross
,dot
,amax
,sub
, andnorm_squared
methods from theVector3
struct.Refactored the
normalize
,denormalize
, andcapitalize
functions.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.
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.