Fix: off-by-one error in alignment averaging
The "length" is actually the `enumerate()` index, which is one less than the item count. The previous version was not using the average, and may have been deviding by 0 for boids with exactly one neighbor.
This commit is contained in:
@@ -251,7 +251,7 @@ fn alignment(
|
|||||||
|
|
||||||
// Skip to next boid if the current one has no neighbors.
|
// Skip to next boid if the current one has no neighbors.
|
||||||
let avg = if len > 0 {
|
let avg = if len > 0 {
|
||||||
sum / (len as f32)
|
sum / ((len + 1) as f32)
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user