瀏覽代碼

linear interpolation

Johann Woelper 5 年之前
父節點
當前提交
a74364729d
共有 2 個文件被更改,包括 21 次插入8 次删除
  1. 1 1
      loading_data.json
  2. 20 7
      src/lib.rs

+ 1 - 1
loading_data.json

@@ -1,5 +1,5 @@
 {
-    "Hammerhead 14.3": {
+    "Hammerhead 14.3g": {
         "velocity": [
             [0, 720],
             [100, 653],

+ 20 - 7
src/lib.rs

@@ -18,11 +18,13 @@ struct BallisticsData {
 }
 
 impl BallisticsData {
-    fn velocity_at(&self, d: i32) -> f32{
-        for i in 0..self.velocity.len() {
-            if self.velocity[i].0 >= d {
-                let start = self.velocity.get(i-1).unwrap_or(&self.velocity[i]);
-                let end = self.velocity[i];
+    fn attr_at(&self, d: i32, attribute: &Vec<(i32, f32)>) -> f32{
+        
+        
+        for i in 0..attribute.len() {
+            if attribute[i].0 >= d {
+                let start = attribute.get(i-1).unwrap_or(&attribute[i]);
+                let end = attribute[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);
             }
@@ -30,6 +32,13 @@ impl BallisticsData {
         0.0
     }
 
+    fn data_at(&self, d: i32) {
+        let vel = self.attr_at(d, &self.velocity);
+        let energy = self.attr_at(d, &self.energy);
+        let trajectory = self.attr_at(d, &self.trajectory);
+        println!("D{} V{} E{} T{}", d, vel, energy, trajectory);
+    }
+
 
 }
 
@@ -70,11 +79,15 @@ fn w() {
     let c = load_cartridges();
     // dbg!(&c);
     
-    let d = 130;
+    // let d = 130;
 
     for (name, cartridge) in c {
         println!("Cartridge {}", name);
-        println!("Cartridge {}", cartridge.velocity_at(d));
+        // println!("Cartridge {}", cartridge.data_at(d));
+        for d in 70..300 {
+            cartridge.data_at(d);
+
+        }
     }