Johann Woelper 5 years ago
parent
commit
b2619002a0
2 changed files with 27 additions and 2 deletions
  1. 2 1
      Cargo.toml
  2. 25 1
      src/lib.rs

+ 2 - 1
Cargo.toml

@@ -9,4 +9,5 @@ edition = "2018"
 [dependencies]
 serde = "1.0"
 serde_derive = "1.0"
-serde_json = "1.0"
+serde_json = "1.0"
+splines = "3.0.0"

+ 25 - 1
src/lib.rs

@@ -1,3 +1,4 @@
+// #![no_std]
 #[macro_use]
 extern crate serde_derive;
 extern crate serde;
@@ -6,6 +7,7 @@ use std::io::BufWriter;
 use std::io::BufReader;
 use std::fs::File;
 use std::collections::HashMap;
+use splines::{Interpolation, Key, Spline};
 
 #[derive(Serialize, Deserialize, Debug, Default)]
 struct BallisticsData {
@@ -40,6 +42,18 @@ impl BallisticsData {
     }
 
 
+    fn spline(&self) -> Spline<f32, f32>{
+        let mut splinesource = vec![]; 
+
+        for t in &self.trajectory {
+            println!("{:?}", t);
+            splinesource.push(Key::new(t.0 as f32, t.1, Interpolation::default()));
+        }
+
+        Spline::from_vec(splinesource)
+    }
+
+
 }
 
 fn normalized_pos_in_range(min: f32, max: f32, d: f32) -> f32 {
@@ -85,9 +99,19 @@ fn w() {
         println!("Cartridge {}", name);
         // println!("Cartridge {}", cartridge.data_at(d));
         for d in 70..300 {
-            cartridge.data_at(d);
+            // cartridge.data_at(d);
+            
+        }
+        
+        let s = cartridge.spline();
+
+        for d in (0..310).step_by(10) {
+            // cartridge.data_at(d);
+            let r = s.clamped_sample(d as f32);
+            println!("{} {:?}", d, r);
 
         }
+
     }