diff --git a/src/function.rs b/src/function.rs index 9c95168..dfd4781 100644 --- a/src/function.rs +++ b/src/function.rs @@ -363,7 +363,7 @@ impl FunctionEntry { assert!(self.output.back.is_some()); let back_data = self.output.back.as_ref().unwrap().clone(); assert_eq!(back_data.len(), settings.pixel_width + 1); - let back_vec_tuple = value_vec_to_tuple(back_data); + let back_vec_tuple = back_data.to_tuple(); assert_eq!(back_vec_tuple, back_target); assert_eq!(integral_enabled, self.integral); diff --git a/src/misc.rs b/src/misc.rs index bc52f41..96ef8eb 100644 --- a/src/misc.rs +++ b/src/misc.rs @@ -16,6 +16,17 @@ where input.par_iter() } +pub trait VecValueToTuple { + fn to_tuple(&self) -> Vec<(f64, f64)>; +} + +impl VecValueToTuple for Vec +where + Self: IntoIterator, +{ + fn to_tuple(&self) -> Vec<(f64, f64)> { self.iter().map(|ele| (ele.x, ele.y)).collect() } +} + /// `SteppedVector` is used in order to efficiently sort through an ordered /// `Vec` Used in order to speedup the processing of cached data when /// moving horizontally without zoom in `FunctionEntry`. Before this struct, the @@ -270,13 +281,6 @@ pub fn step_helper(max_i: usize, min_x: f64, step: f64) -> Vec { .collect() } -/// Extracts x and y values from `egui::plot::Value` in `data`. Returns -/// `Vec<(f64, f64)>` -#[allow(dead_code)] -pub fn value_vec_to_tuple(data: Vec) -> Vec<(f64, f64)> { - data.iter().map(|ele| (ele.x, ele.y)).collect() -} - #[cfg(test)] mod tests { use super::*;