diff --git a/src/egui_app.rs b/src/egui_app.rs index 9a15045..22648b6 100644 --- a/src/egui_app.rs +++ b/src/egui_app.rs @@ -1,5 +1,5 @@ use crate::function::{FunctionEntry, RiemannSum, DEFAULT_FUNCTION_ENTRY}; -use crate::misc::{JsonFileOutput, SerdeValueHelper}; +use crate::misc::{option_vec_printer, JsonFileOutput, SerdeValueHelper}; use crate::parsing::{process_func_str, test_func}; use const_format::formatc; @@ -329,7 +329,7 @@ pub struct MathApp { /// Contains the list of Areas calculated (the vector of f64) and time it /// took for the last frame (the Duration). Stored in a Tuple. - last_info: (Vec, Duration), + last_info: (Vec>, Duration), /// Stores settings (pretty self-explanatory) settings: AppSettings, @@ -341,7 +341,7 @@ impl Default for MathApp { functions: vec![DEFAULT_FUNCTION_ENTRY.clone()], func_strs: vec![String::new()], last_error: Vec::new(), - last_info: (vec![0.0], Duration::ZERO), + last_info: (vec![None], Duration::ZERO), settings: AppSettings::default(), } } @@ -617,8 +617,9 @@ impl epi::App for MathApp { // Display Area and time of last frame ui.label(format!( - "Area: {:?} Took: {:?}", - self.last_info.0, self.last_info.1 + "Area: {} Took: {:?}", + option_vec_printer(self.last_info.0.clone()), + self.last_info.1 )); }); }); @@ -668,8 +669,9 @@ impl epi::App for MathApp { self.side_panel(ctx); } - let mut area_list: Vec = Vec::new(); // Referenced in plotting code, but needs to be here so it can be later - // referenced when storing `last_info` + // Referenced in plotting code, but needs to be here so it can be later + // referenced when storing `last_info` + let mut area_list: Vec> = Vec::new(); // Central panel which contains the central plot (or an error created when // parsing) @@ -708,7 +710,7 @@ impl epi::App for MathApp { .enumerate() .map(|(i, function)| { if self.func_strs[i].is_empty() { - return f64::NAN; + return None; } function.display( diff --git a/src/function.rs b/src/function.rs index 0f6d417..5bcc944 100644 --- a/src/function.rs +++ b/src/function.rs @@ -166,7 +166,7 @@ impl FunctionEntry { pub fn display( &mut self, plot_ui: &mut PlotUi, min_x: f64, max_x: f64, pixel_width: usize, width_changed: bool, settings: AppSettings, - ) -> f64 { + ) -> Option { let resolution: f64 = pixel_width as f64 / (max_x.abs() + min_x.abs()); let resolution_iter = resolution_helper(pixel_width + 1, min_x, resolution); @@ -342,9 +342,9 @@ impl FunctionEntry { ); // return value rounded to 8 decimal places - crate::misc::decimal_round(integral_data.1, 8) + Some(crate::misc::decimal_round(integral_data.1, 8)) } else { - f64::NAN // return NaN if integrals are disabled + None } } } diff --git a/src/misc.rs b/src/misc.rs index 403d430..27bd364 100644 --- a/src/misc.rs +++ b/src/misc.rs @@ -229,6 +229,35 @@ fn newtons_method( } } +/// Inputs `Vec>` and outputs a `String` containing a pretty +/// representation of the Vector +pub fn option_vec_printer(data: Vec>) -> String { + let none_representation = "None"; + let unwrapped: Vec = data + .iter() + .map(|x| { + if let Some(inner) = x { + inner.to_string() + } else { + none_representation.to_owned() + } + }) + .collect(); + + let mut output: String = String::from("["); + let mut curr_len: usize = 0; + let total_len: usize = unwrapped.len(); + for ele in unwrapped.iter() { + curr_len += 1; + output += ele; + if total_len > curr_len { + output += ", "; + } + } + output += "]"; + output +} + // Returns a vector of length `max_i` starting at value `min_x` with resolution // of `resolution` pub fn resolution_helper(max_i: usize, min_x: f64, resolution: f64) -> Vec {