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:
parent
8344cbc273
commit
9d63f23f1d
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user