FunctionEntry: generate_plot_data helper
This commit is contained in:
parent
2d7c987f11
commit
c7760e2123
@ -276,6 +276,17 @@ impl FunctionEntry {
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Generates plot data for a given derivative level over the resolution iterator
|
||||||
|
fn generate_plot_data(&mut self, derivative: usize, resolution_iter: &[f64]) -> Vec<PlotPoint> {
|
||||||
|
if derivative > 0 {
|
||||||
|
self.function.generate_derivative(derivative);
|
||||||
|
}
|
||||||
|
resolution_iter
|
||||||
|
.iter()
|
||||||
|
.map(|&x| PlotPoint::new(x, self.function.get(derivative, x)))
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
/// Does the calculations and stores results in `self`
|
/// Does the calculations and stores results in `self`
|
||||||
pub fn calculate(
|
pub fn calculate(
|
||||||
&mut self,
|
&mut self,
|
||||||
@ -304,32 +315,17 @@ impl FunctionEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if self.back_data.is_empty() {
|
if self.back_data.is_empty() {
|
||||||
let data: Vec<PlotPoint> = resolution_iter
|
self.back_data = self.generate_plot_data(0, &resolution_iter);
|
||||||
.clone()
|
debug_assert_eq!(self.back_data.len(), settings.plot_width + 1);
|
||||||
.into_iter()
|
|
||||||
.map(|x| PlotPoint::new(x, self.function.get(0, x)))
|
|
||||||
.collect();
|
|
||||||
debug_assert_eq!(data.len(), settings.plot_width + 1);
|
|
||||||
|
|
||||||
self.back_data = data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.derivative_data.is_empty() {
|
if self.derivative_data.is_empty() {
|
||||||
self.function.generate_derivative(1);
|
self.derivative_data = self.generate_plot_data(1, &resolution_iter);
|
||||||
let data: Vec<PlotPoint> = resolution_iter
|
debug_assert_eq!(self.derivative_data.len(), settings.plot_width + 1);
|
||||||
.clone()
|
|
||||||
.into_iter()
|
|
||||||
.map(|x| PlotPoint::new(x, self.function.get(1, x)))
|
|
||||||
.collect();
|
|
||||||
debug_assert_eq!(data.len(), settings.plot_width + 1);
|
|
||||||
self.derivative_data = data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.nth_derviative && self.nth_derivative_data.is_none() {
|
if self.nth_derviative && self.nth_derivative_data.is_none() {
|
||||||
let data: Vec<PlotPoint> = resolution_iter
|
let data = self.generate_plot_data(self.curr_nth, &resolution_iter);
|
||||||
.into_iter()
|
|
||||||
.map(|x| PlotPoint::new(x, self.function.get(self.curr_nth, x)))
|
|
||||||
.collect();
|
|
||||||
debug_assert_eq!(data.len(), settings.plot_width + 1);
|
debug_assert_eq!(data.len(), settings.plot_width + 1);
|
||||||
self.nth_derivative_data = Some(data);
|
self.nth_derivative_data = Some(data);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user