fix toggling extrema/roots

This commit is contained in:
Simon Gardling 2022-03-17 03:06:12 -04:00
parent a4b876111e
commit ab31d19db0
2 changed files with 21 additions and 15 deletions

View File

@ -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,
)
}
}

View File

@ -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