dyn_mut_iter

This commit is contained in:
Simon Gardling 2022-03-24 19:22:28 -04:00
parent e6b87a178e
commit 723d61d1b5
3 changed files with 43 additions and 20 deletions

View File

@ -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();
});
});

View File

@ -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<f64> {
self.calculate(min_x, max_x, width_changed, settings);
pub fn display(&self, plot_ui: &mut PlotUi, settings: AppSettings) -> Option<f64> {
// self.calculate(min_x, max_x, width_changed, settings);
let func_str = self.get_func_str();
let derivative_str = self.function.get_derivative_str();

View File

@ -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<T>) -> impl Iterator<Item = &'a T> { input.iter() }
pub fn dyn_iter<'a, T>(input: &'a Vec<T>) -> impl Iterator<Item = &'a T>
where
&'a [T]: IntoIterator,
{
input.iter()
}
#[cfg(not(target_arch = "wasm32"))]
pub fn dyn_iter<'a, T>(input: &'a Vec<T>) -> <&'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<T>) -> impl Iterator<Item = &'a mut T>
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)>;
}