From bc0630b4ae6adc35f5c037c65ad0500f45897e21 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Wed, 3 Sep 2025 14:09:40 -0500 Subject: [PATCH] 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. --- src/birdoids/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/birdoids/mod.rs b/src/birdoids/mod.rs index 5395f993..a530c203 100644 --- a/src/birdoids/mod.rs +++ b/src/birdoids/mod.rs @@ -251,7 +251,7 @@ fn alignment( // Skip to next boid if the current one has no neighbors. let avg = if len > 0 { - sum / (len as f32) + sum / ((len + 1) as f32) } else { continue; };