diff --git a/src/fd.rs b/src/fd.rs index 2544537..aac4fa4 100644 --- a/src/fd.rs +++ b/src/fd.rs @@ -1,6 +1,8 @@ #![feature(generic_const_exprs)] +#![feature(let_chains)] mod system; +mod cli; use std::fs::File; use std::os::unix::fs::symlink; @@ -8,6 +10,7 @@ use bevy::tasks::ParallelSlice; use crate::system::spaces::square_grid::{Grid2D, Grid3D}; use itertools::{Itertools, MinMaxResult}; use clap::Parser; +use crate::cli::cli::OutputFormat; use crate::system::{GriddedPosition, Position}; use crate::system::model::HistoryLine; @@ -90,9 +93,9 @@ fn box_count_3d(data: &Vec, size: u32) -> usize { let grid_points = data.iter() .map(|Grid3D { x, y, z }| [ - ((x - x_min) as f64 / w) as u32, - ((y - y_min) as f64 / w) as u32, - ((z - z_min) as f64 / w) as u32, + ((x - x_min) as f64 / w) as i32, + ((y - y_min) as f64 / w) as i32, + ((z - z_min) as f64 / w) as i32, ]) .collect::>(); @@ -120,19 +123,31 @@ fn box_count_nd(data: &Vec<[f32; N]>, size: u32) -> usize { #[derive(Parser)] struct FDArgs { + format: OutputFormat, path: std::path::PathBuf, } fn main() { let args = FDArgs::parse(); - let lines: Vec> = serde_json::from_reader(File::open(args.path).unwrap()) - .expect("Failed to read json"); - let a = lines.iter() - .map(|l| l.position.to_cartesian()) - .collect::>(); + let qa = match args.format { + OutputFormat::FullDataJson => { + serde_json::from_reader::<_, Vec>>(File::open(args.path).unwrap()) + .expect("Failed to read json") + .iter() + .map(|l| l.position.clone()) + .collect::>() + } + OutputFormat::Positions => { + csv::Reader::from_path(args.path).unwrap().deserialize::() + .collect::, _>>() + .unwrap() + } + }; + + assert_eq!(qa.iter().unique().collect::>().len(), qa.len()); for size in 1..250 { - println!("[{}, {:?}],", size, box_count_nd(&a, size)); + println!("[{}, {:?}],", size, box_count_3d(&qa, size)); } }