|
@@ -43,16 +43,28 @@ 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()));
|
|
|
- }
|
|
|
+ let a: Vec<Key<f32, f32>> = self.trajectory
|
|
|
+ .iter()
|
|
|
+ .map(|x| Key::new(x.0 as f32, x.1, Interpolation::Cosine))
|
|
|
+ .collect();
|
|
|
+ Spline::from_vec(a)
|
|
|
+ }
|
|
|
|
|
|
- Spline::from_vec(splinesource)
|
|
|
+
|
|
|
+ fn drop(&self, dist: i32) -> f32 {
|
|
|
+ self.spline()
|
|
|
+ .clamped_sample(dist as f32)
|
|
|
+ .unwrap_or(-999999.0)
|
|
|
}
|
|
|
|
|
|
+ fn drop_zeroed(&self, dist: i32, zero_dist: i32) -> f32 {
|
|
|
+ let z_comp = self.spline().clamped_sample(zero_dist as f32).unwrap_or(0.0);
|
|
|
+ // println!("drop at {} {}", dist, z_comp);
|
|
|
+ self.spline()
|
|
|
+ .clamped_sample(dist as f32)
|
|
|
+ .unwrap_or(-999999.0) - z_comp
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -77,9 +89,11 @@ fn write_sample() {
|
|
|
}
|
|
|
|
|
|
|
|
|
-fn load_cartridges() -> HashMap<String, BallisticsData> {
|
|
|
+fn load_cartridges() -> Result<HashMap<String, BallisticsData>, serde_json::Error> {
|
|
|
let reader = BufReader::new(File::open("loading_data.json").unwrap());
|
|
|
- serde_json::from_reader(reader).unwrap()
|
|
|
+
|
|
|
+ // let s: Result<HashMap<String, BallisticsData>, _> = serde_json::from_reader(reader);
|
|
|
+ serde_json::from_reader(reader)
|
|
|
// println!("{:?}", loaded_car);
|
|
|
}
|
|
|
|
|
@@ -88,33 +102,34 @@ fn load_cartridges() -> HashMap<String, BallisticsData> {
|
|
|
|
|
|
#[test]
|
|
|
fn w() {
|
|
|
- write_sample();
|
|
|
+ //write_sample();
|
|
|
|
|
|
- let c = load_cartridges();
|
|
|
- // dbg!(&c);
|
|
|
-
|
|
|
- // let d = 130;
|
|
|
-
|
|
|
- for (name, cartridge) in c {
|
|
|
- println!("Cartridge {}", name);
|
|
|
- // println!("Cartridge {}", cartridge.data_at(d));
|
|
|
- for d in 70..300 {
|
|
|
- // 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);
|
|
|
+ match load_cartridges() {
|
|
|
+ Ok(c) => {
|
|
|
+ for (name, cartridge) in c {
|
|
|
+ println!("=== Cartridge {} ===", name);
|
|
|
|
|
|
- }
|
|
|
+ dbg!(cartridge.drop_zeroed(200, 100));
|
|
|
+ // dbg!(cartridge.drop_zeroed(300, 150));
|
|
|
+ // dbg!(cartridge.drop(250));
|
|
|
|
|
|
+ let s = cartridge.spline();
|
|
|
+ for d in (50..310).step_by(10) {
|
|
|
+ // cartridge.data_at(d);
|
|
|
+ let z = s.clamped_sample(100.0).unwrap_or(-999999.0);
|
|
|
+ let r = s.clamped_sample(d as f32).unwrap_or(-999999.0) - z;
|
|
|
+ println!("{} {:?}", d, r);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ },
|
|
|
+ Err(e) => println!("{:?}",e)
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
}
|