From ab31d19db06db8319134f288ba99825899758d83 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Thu, 17 Mar 2022 03:06:12 -0400 Subject: [PATCH] fix toggling extrema/roots --- src/function.rs | 2 ++ src/function_output.rs | 34 +++++++++++++++++++--------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/function.rs b/src/function.rs index a5a0cb6..4a45b18 100644 --- a/src/function.rs +++ b/src/function.rs @@ -362,6 +362,8 @@ impl FunctionEntry { &self.function.get_derivative_str(), (self.integral_min_x - self.integral_max_x).abs() / (self.integral_num as f64), self.derivative, + extrema, + roots, ) } } diff --git a/src/function_output.rs b/src/function_output.rs index 2e43067..39630ef 100644 --- a/src/function_output.rs +++ b/src/function_output.rs @@ -51,7 +51,7 @@ impl FunctionOutput { /// disabled, it returns `f64::NAN`) pub fn display( &self, plot_ui: &mut PlotUi, func_str: &str, derivative_str: &str, step: f64, - derivative_enabled: bool, + derivative_enabled: bool, extrema: bool, roots: bool, ) -> f64 { // Plot back data plot_ui.line( @@ -72,23 +72,27 @@ impl FunctionOutput { } // Plot extrema points - if let Some(extrema_data) = self.extrema.clone() { - plot_ui.points( - Points::new(Values::from_values(extrema_data)) - .color(Color32::YELLOW) - .name("Extrema") - .radius(5.0), - ); + if extrema { + if let Some(extrema_data) = self.extrema.clone() { + plot_ui.points( + Points::new(Values::from_values(extrema_data)) + .color(Color32::YELLOW) + .name("Extrema") + .radius(5.0), + ); + } } // Plot roots points - if let Some(roots_data) = self.roots.clone() { - plot_ui.points( - Points::new(Values::from_values(roots_data)) - .color(Color32::LIGHT_BLUE) - .name("Root") - .radius(5.0), - ); + if roots { + if let Some(roots_data) = self.roots.clone() { + plot_ui.points( + Points::new(Values::from_values(roots_data)) + .color(Color32::LIGHT_BLUE) + .name("Root") + .radius(5.0), + ); + } } // Plot integral data