Johann Woelper 5 years ago
parent
commit
cda8534be8
1 changed files with 4 additions and 3 deletions
  1. 4 3
      src/lib.rs

+ 4 - 3
src/lib.rs

@@ -21,9 +21,10 @@ impl BallisticsData {
     fn velocity_at(&self, d: i32) -> f32{
         for i in 0..self.velocity.len() {
             if self.velocity[i].0 >= d {
-                let mu = normalized_pos_in_range(self.velocity[i-1].0 as f32, self.velocity[i].0 as f32, d as f32);
-                dbg!(self.velocity[i].0, self.velocity[i].1, self.velocity[i+1].1);
-                return lerp(self.velocity[i-1].1 as f32, self.velocity[i].1 as f32, mu);
+                let start = self.velocity.get(i-1).unwrap_or(&self.velocity[i]);
+                let end = self.velocity[i];
+                let mu = normalized_pos_in_range(start.0 as f32, end.0 as f32, d as f32);
+                return lerp(start.1 as f32, end.1 as f32, mu);
             }
         }
         0.0