diff --git a/src/egui_app.rs b/src/egui_app.rs index 1cfcf7a..dd261d3 100644 --- a/src/egui_app.rs +++ b/src/egui_app.rs @@ -1,5 +1,5 @@ use crate::function::{FunctionEntry, Riemann, DEFAULT_FUNCTION_ENTRY}; -use crate::misc::{option_vec_printer, JsonFileOutput, SerdeValueHelper}; +use crate::misc::{dyn_mut_iter, option_vec_printer, JsonFileOutput, SerdeValueHelper}; use crate::parsing::{process_func_str, test_func}; use crate::consts::*; @@ -15,6 +15,9 @@ use instant::Duration; use shadow_rs::shadow; use std::{collections::BTreeMap, io::Read, ops::BitXorAssign, str}; +#[cfg(not(target_arch = "wasm32"))] +use rayon::iter::{IndexedParallelIterator, ParallelIterator}; + shadow!(build); // Constant string that has a string containing information about the build. @@ -688,23 +691,25 @@ impl epi::App for MathApp { let minx_bounds: f64 = bounds.min()[0]; let maxx_bounds: f64 = bounds.max()[0]; - area_list = self - .functions - .iter_mut() + dyn_mut_iter(&mut self.functions) + // .iter_mut() .enumerate() - .map(|(i, function)| { - if self.func_strs[i].is_empty() { - return None; - } - - function.display( - plot_ui, + .filter(|(i, _)| !self.func_strs[*i].is_empty()) + .for_each(|(_, function)| { + function.calculate( minx_bounds, maxx_bounds, width_changed, settings_copy, ) - }) + }); + + area_list = self + .functions + .iter() + .enumerate() + .filter(|(i, _)| !self.func_strs[*i].is_empty()) + .map(|(_, function)| function.display(plot_ui, settings_copy)) .collect(); }); }); diff --git a/src/function.rs b/src/function.rs index 1d5ec83..84b2f38 100644 --- a/src/function.rs +++ b/src/function.rs @@ -288,11 +288,8 @@ impl FunctionEntry { } /// Calculates and displays the function on PlotUI `plot_ui` - pub fn display( - &mut self, plot_ui: &mut PlotUi, min_x: f64, max_x: f64, width_changed: bool, - settings: AppSettings, - ) -> Option { - self.calculate(min_x, max_x, width_changed, settings); + pub fn display(&self, plot_ui: &mut PlotUi, settings: AppSettings) -> Option { + // self.calculate(min_x, max_x, width_changed, settings); let func_str = self.get_func_str(); let derivative_str = self.function.get_derivative_str(); diff --git a/src/misc.rs b/src/misc.rs index 4618d06..04c5e93 100644 --- a/src/misc.rs +++ b/src/misc.rs @@ -6,16 +6,37 @@ use serde_json::Value as JsonValue; use rayon::prelude::*; #[cfg(target_arch = "wasm32")] -pub fn dyn_iter<'a, T>(input: &'a Vec) -> impl Iterator { input.iter() } +pub fn dyn_iter<'a, T>(input: &'a Vec) -> impl Iterator +where + &'a [T]: IntoIterator, +{ + input.iter() +} #[cfg(not(target_arch = "wasm32"))] -pub fn dyn_iter<'a, T>(input: &'a Vec) -> <&'a [T] as IntoParallelIterator>::Iter +pub fn dyn_iter<'a, I>(input: &'a I) -> <&'a I as IntoParallelIterator>::Iter where - &'a [T]: IntoParallelIterator, + &'a I: IntoParallelIterator, { input.par_iter() } +#[cfg(target_arch = "wasm32")] +pub fn dyn_mut_iter<'a, T>(input: &'a mut Vec) -> impl Iterator +where + &'a mut [T]: IntoIterator, +{ + input.iter_mut() +} + +#[cfg(not(target_arch = "wasm32"))] +pub fn dyn_mut_iter<'a, I>(input: &'a mut I) -> <&'a mut I as IntoParallelIterator>::Iter +where + &'a mut I: IntoParallelIterator, +{ + input.par_iter_mut() +} + pub trait VecValueToTuple { fn to_tuple(&self) -> Vec<(f64, f64)>; }