This commit is contained in:
Simon Gardling 2022-03-09 13:23:22 -05:00
parent 9afe6f514e
commit 20d8b1421c
2 changed files with 13 additions and 6 deletions

View File

@ -352,10 +352,12 @@ impl MathApp {
} }
} }
ui.add( let integral_num_changed = ui
.add(
Slider::new(&mut self.settings.integral_num, INTEGRAL_NUM_RANGE) Slider::new(&mut self.settings.integral_num, INTEGRAL_NUM_RANGE)
.text("Interval"), .text("Interval"),
); )
.changed();
let functions_len = self.functions.len(); let functions_len = self.functions.len();
let mut remove_i: Option<usize> = None; let mut remove_i: Option<usize> = None;
@ -407,6 +409,7 @@ impl MathApp {
| derivative_toggle | derivative_toggle
| max_x_changed | max_x_changed
| min_x_changed | min_x_changed
| integral_num_changed
| (proc_func_str != function.get_func_str()) | (proc_func_str != function.get_func_str())
| self.last_error.iter().any(|ele| ele.0 == i) | self.last_error.iter().any(|ele| ele.0 == i)
{ {

View File

@ -117,7 +117,7 @@ impl FunctionEntry {
.into(); .into();
self.back_cache = Some( self.back_cache = Some(
(0..=self.pixel_width) (0..self.pixel_width)
.map(|x| (x as f64 / resolution as f64) + min_x) .map(|x| (x as f64 / resolution as f64) + min_x)
.map(|x| { .map(|x| {
if let Some(i) = x_data.get_index(x) { if let Some(i) = x_data.get_index(x) {
@ -128,13 +128,14 @@ impl FunctionEntry {
}) })
.collect(), .collect(),
); );
// assert_eq!(self.back_cache.as_ref().unwrap().len(), self.pixel_width);
if self.derivative_cache.is_some() { if self.derivative_cache.is_some() {
if self.derivative { if self.derivative {
let derivative_cache = self.derivative_cache.as_ref().unwrap(); let derivative_cache = self.derivative_cache.as_ref().unwrap();
self.derivative_cache = Some( self.derivative_cache = Some(
(0..=self.pixel_width) (0..self.pixel_width)
.map(|x| (x as f64 / resolution as f64) + min_x) .map(|x| (x as f64 / resolution as f64) + min_x)
.map(|x| { .map(|x| {
if let Some(i) = x_data.get_index(x) { if let Some(i) = x_data.get_index(x) {
@ -145,6 +146,7 @@ impl FunctionEntry {
}) })
.collect(), .collect(),
); );
// assert_eq!(self.derivative_cache.as_ref().unwrap().len(), self.pixel_width);
} else { } else {
self.derivative_cache = None; self.derivative_cache = None;
} }
@ -262,6 +264,8 @@ impl FunctionEntry {
}) })
.filter(|(_, y)| !y.is_nan()) .filter(|(_, y)| !y.is_nan())
.collect(); .collect();
// assert_eq!(data2.len(), self.integral_num);
(data2, area) (data2, area)
} }