1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-02-22 00:13:10 +02:00

Change hardcoded vector update to a for loop (#1833)

iterating over the vector instead of hardcoding each item

---------

Co-authored-by: Martin Geisler <mgeisler@google.com>
This commit is contained in:
Jean Carlo Vicelli 2024-02-20 17:29:49 +01:00 committed by GitHub
parent 8344cbc273
commit 9d63f23f1d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -25,9 +25,9 @@ fn magnitude(vector: &[f64; 3]) -> f64 {
/// Change the magnitude of the vector to 1.0 without changing its direction.
fn normalize(vector: &mut [f64; 3]) {
let mag = magnitude(vector);
vector[0] /= mag;
vector[1] /= mag;
vector[2] /= mag;
for item in vector {
*item /= mag;
}
}
// ANCHOR: main