|
@@ -37,81 +37,26 @@ pub struct BallisticsData {
|
|
|
pub energy: Vec<(u32, f32)>,
|
|
|
pub trajectory: Vec<(u32, f32)>,
|
|
|
#[serde(default)]
|
|
|
+ pub diameter: f64,
|
|
|
+ #[serde(default)]
|
|
|
pub trajectory_filled: Vec<(u32, f32)>,
|
|
|
}
|
|
|
|
|
|
impl BallisticsData {
|
|
|
- fn attr_at(&self, d: u32, attribute: &Vec<(u32, 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);
|
|
|
- // }
|
|
|
- // }
|
|
|
- 0.0
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
pub fn monospline(&self) -> MonotonicCubicSpline {
|
|
|
- // let x = vec![50.0, 100.0, 150.0, 200.0, 300.0];
|
|
|
- // let y = vec![1.0, 4.0, -8.0, -10.5, -40.0];
|
|
|
-
|
|
|
let x: Vec<f64> = self.trajectory.iter().map(|x| x.0 as f64).collect();
|
|
|
let y: Vec<f64> = self.trajectory.iter().map(|x| x.1 as f64).collect();
|
|
|
-
|
|
|
- // let smooth = MonotonicCubicSpline::partial(x.clone(), y.clone());
|
|
|
-
|
|
|
MonotonicCubicSpline::new(&x, &y)
|
|
|
-
|
|
|
- // let mut a = vec![];
|
|
|
-
|
|
|
- // for i in self.trajectory[0].0..self.trajectory[self.trajectory.len() - 1].0 {
|
|
|
- // let p = i as f32;
|
|
|
- // a.push(Key::new(
|
|
|
- // p as f32,
|
|
|
- // smooth.interpolate(p as f64) as f32,
|
|
|
- // Interpolation::Linear,
|
|
|
- // ));
|
|
|
- // // a.push(Key::new(p as f32, spline.smooth(p as f64) as f32, Interpolation::Linear));
|
|
|
- // }
|
|
|
-
|
|
|
- //Spline::from_vec(a)
|
|
|
- // smooth
|
|
|
}
|
|
|
|
|
|
fn data_at(&self, d: u32) {
|
|
|
- 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);
|
|
|
+ // 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);
|
|
|
}
|
|
|
|
|
|
- // pub fn spline(&self) -> Spline<f32, f32> {
|
|
|
- // // let mut a: Vec<Key<f32, f32>> = self.trajectory
|
|
|
- // // .iter()
|
|
|
- // // .map(|x| Key::new(x.0 as f32, x.1, Interpolation::CatmullRom))
|
|
|
- // // .collect();
|
|
|
-
|
|
|
- // let mut a = vec![];
|
|
|
-
|
|
|
- // let mut i = 0;
|
|
|
- // for pt in &self.trajectory {
|
|
|
- // // let mut interp : Interpolation<f32, f32> = Interpolation::Cosine;
|
|
|
- // let mut interp: Interpolation<f32, f32> = Interpolation::CatmullRom;
|
|
|
- // if i == 0 || i >= self.trajectory.len() - 2 {
|
|
|
- // interp = Interpolation::Linear;
|
|
|
- // }
|
|
|
- // a.push(Key::new(pt.0 as f32, pt.1, interp));
|
|
|
- // i += 1;
|
|
|
- // }
|
|
|
-
|
|
|
- // a[0] = Key::new(self.trajectory[0].0 as f32, self.trajectory[0].1, Interpolation::Linear);
|
|
|
- // a[self.trajectory.len()-1] = Key::new(self.trajectory[self.trajectory.len()-1].0 as f32, self.trajectory[self.trajectory.len()-1].1, Interpolation::Linear);
|
|
|
-
|
|
|
- // Spline::from_vec(a)
|
|
|
- // }
|
|
|
|
|
|
fn interpolate_drop_at(&self, dist: u32) -> f64 {
|
|
|
self.monospline()
|
|
@@ -136,13 +81,8 @@ fn moa_at_distance(d: u32) -> f64 {
|
|
|
moa
|
|
|
}
|
|
|
|
|
|
-fn clicks_at_distance(d: u32, moa_divisor: Adjustment) -> u32 {
|
|
|
- let radius:f64 = d as f64;
|
|
|
- let diameter = 2. * radius * std::f64::consts::PI;
|
|
|
- let deg = diameter/360.;
|
|
|
- let moa = deg/60.*100.;
|
|
|
- dbg!(moa);
|
|
|
- 1
|
|
|
+fn clicks_at_distance(distance: u32, drop: f64, moa_divisor: Adjustment) -> i32 {
|
|
|
+ (drop / ( moa_at_distance(distance) / (moa_divisor as i32) as f64 )) as i32
|
|
|
}
|
|
|
|
|
|
|
|
@@ -184,8 +124,7 @@ fn test_drop() {
|
|
|
|
|
|
dbg!(cartridge.drop_zeroed(d, 100));
|
|
|
dbg!(&drop);
|
|
|
- let moa = moa_at_distance(d);
|
|
|
- let clicks = (drop / (moa/4.)) as i32;
|
|
|
+ let clicks = clicks_at_distance(d, drop, Adjustment::MOAQuarter);
|
|
|
dbg!(&clicks);
|
|
|
|
|
|
}
|
|
@@ -229,7 +168,7 @@ fn plot_graphs(){
|
|
|
.x_range(0., 300.)
|
|
|
.y_range(-100., 20.)
|
|
|
.x_label("Distance")
|
|
|
- .y_label("Drop");
|
|
|
+ .y_label(format!("Drop for {}", name));
|
|
|
|
|
|
// A page with a single view is then saved to an SVG file
|
|
|
Page::single(&v).save(format!("plot-{}.svg", name)).unwrap();
|