From 92bc183dbde05df7f8287af81142667fd2f4df45 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Mon, 28 Feb 2022 12:06:54 -0500 Subject: [PATCH] fixes --- src/egui_app.rs | 12 +++++------- src/function.rs | 10 +++++----- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/egui_app.rs b/src/egui_app.rs index 3a17d0b..e7cdc4e 100644 --- a/src/egui_app.rs +++ b/src/egui_app.rs @@ -184,6 +184,8 @@ impl epi::App for MathApp { } else { function.update(proc_func_str, integral, Some(self.integral_min_x), Some(self.integral_max_x), Some(self.integral_num)); } + } else { + function.func_str = "".to_string(); } } @@ -238,15 +240,13 @@ impl epi::App for MathApp { let maxx_bounds: f64 = bounds.max()[0]; let mut i: usize = 0; - let mut functions_2: Vec = Vec::new(); // Todo: figure out why this is required - for function_1 in self.functions.iter_mut() { - let function = function_1; - function.update_bounds(minx_bounds, maxx_bounds, available_width); - + for function in self.functions.iter_mut() { if self.func_strs[i].is_empty() { continue; } + function.update_bounds(minx_bounds, maxx_bounds, available_width); + let output = function.run(); let back = output.get_back(); plot_ui.line(Line::new(Values::from_values(back)).color(Color32::RED)); @@ -261,9 +261,7 @@ impl epi::App for MathApp { area_list.push(0.0); } i += 1; - functions_2.push(function.clone()); } - self.functions = functions_2; }); let duration = start.elapsed(); diff --git a/src/function.rs b/src/function.rs index d410777..14a5538 100644 --- a/src/function.rs +++ b/src/function.rs @@ -163,7 +163,7 @@ impl Function { self.max_x = max_x; self.pixel_width = pixel_width; } else if ((min_x != self.min_x) | (max_x != self.max_x)) && self.back_cache.is_some() { - // debug_log("back_cache: partial regen"); + debug_log("back_cache: partial regen"); let range_new: f64 = max_x.abs() + min_x.abs(); let resolution: f64 = (self.pixel_width as f64 / range_new) as f64; @@ -209,11 +209,11 @@ impl Function { pub fn run(&mut self) -> FunctionOutput { let back_values: Vec = match self.back_cache.is_some() { true => { - // debug_log("back_cache: using"); + debug_log("back_cache: using"); self.back_cache.as_ref().expect("").clone() } false => { - // debug_log("back_cache: regen"); + debug_log("back_cache: regen"); let absrange = (self.max_x - self.min_x).abs(); let resolution: f64 = (self.pixel_width as f64 / absrange) as f64; let back_data: Vec = (1..=self.pixel_width) @@ -231,13 +231,13 @@ impl Function { if self.integral { let front_bars: (Vec, f64) = match self.front_cache.is_some() { true => { - // debug_log("front_cache: using"); + debug_log("front_cache: using"); let cache = self.front_cache.as_ref().expect(""); let vec_bars: Vec = cache.0.to_vec(); (vec_bars, cache.1) } false => { - // debug_log("front_cache: regen"); + debug_log("front_cache: regen"); let (data, area) = self.integral_rectangles(); let bars: Vec = data.iter().map(|(x, y)| Bar::new(*x, *y)).collect();