diff --git a/src/egui_app.rs b/src/egui_app.rs index e74591e..b8ecfcc 100644 --- a/src/egui_app.rs +++ b/src/egui_app.rs @@ -58,11 +58,13 @@ const HELP_EXPR: &str = "- sqrt(x): square root of x // Used in the "Buttons" section of the Help window const HELP_BUTTONS: &str = "- The 'Panel' button on the top bar toggles if the side bar should be shown or not. -- The ∫ button next to the function input indicates whether estimating an integral for that function is enabled or not. - The 'Add Function' button on the top panel adds a new function to be graphed. You can then configure that function in the side panel. - The 'Help' button on the top bar opens and closes this window! -- The 'Info' button provides information on the build currently running."; +- The 'Info' button provides information on the build currently running. +- The X button before the ∫ symbol allows you to delete the function in question. Deleting a function is prevented if only 1 function exists. +- The ∫ button next to the function input indicates whether estimating an integral for that function is enabled or not."; +// Misc help info const HELP_MISC: &str = "- In some edge cases, math functions may not parse correctly. More specifically with implicit multiplication. If you incounter this issue, please do report it on the project's Github page (linked on the side panel). But a bypass would be explicitly stating a multiplication operation through the use of an asterisk - A (very minor) note in regards to the timing functionality (the 'took' number in the top panel): this value is not accurate when running in the browser in comparison to when running natively. Implementations of this timing functionality vary from browser-to-browser."; @@ -357,7 +359,10 @@ impl epi::App for MathApp { if ui .add(Button::new("Help")) - .on_hover_text("Open Help Window") + .on_hover_text(match self.settings.help_open { + true => "Close Help Window", + false => "Open Help Window", + }) .clicked() { self.settings.help_open = !self.settings.help_open; @@ -365,7 +370,10 @@ impl epi::App for MathApp { if ui .add(Button::new("Info")) - .on_hover_text("Show Info") + .on_hover_text(match self.settings.info_open { + true => "Close Info Window", + false => "Open Info Window", + }) .clicked() { self.settings.info_open = !self.settings.info_open; diff --git a/src/function.rs b/src/function.rs index 711238f..ff1db55 100644 --- a/src/function.rs +++ b/src/function.rs @@ -66,14 +66,8 @@ impl Function { back_cache: None, front_cache: None, integral, - integral_min_x: match integral_min_x { - Some(x) => x, - None => f64::NAN, - }, - integral_max_x: match integral_max_x { - Some(x) => x, - None => f64::NAN, - }, + integral_min_x: integral_min_x.unwrap_or(f64::NAN), + integral_max_x: integral_max_x.unwrap_or(f64::NAN), integral_num: integral_num.unwrap_or(0), sum: sum.unwrap_or(RiemannSum::Left), } @@ -107,9 +101,7 @@ impl Function { return; } - if integral != self.integral { - self.integral = integral; - } + self.integral = integral; // Makes sure proper arguments are passed when integral is enabled if integral @@ -133,9 +125,7 @@ impl Function { self.max_x = max_x; self.pixel_width = pixel_width; } else if ((min_x != self.min_x) | (max_x != self.max_x)) && self.back_cache.is_some() { - let range_new: f64 = max_x.abs() + min_x.abs(); - - let resolution: f64 = (self.pixel_width as f64 / range_new) as f64; + let resolution: f64 = self.pixel_width as f64 / (max_x.abs() + min_x.abs()); let back_cache = self.back_cache.as_ref().unwrap(); let x_data: Vec = back_cache.iter().map(|ele| ele.x).collect(); @@ -152,9 +142,9 @@ impl Function { let i_option = x_data.iter().position(|&r| r == x); // Optimize this later, this could be done much much better, but tbh it doesn't matter that much as the program is already super fast if let Some(i) = i_option { - back_cache[i] + return back_cache[i]; } else { - Value::new(x, self.run_func(x)) + return Value::new(x, self.run_func(x)); } }) .collect(), @@ -170,13 +160,12 @@ impl Function { pub fn run(&mut self) -> (Line, Option<(BarChart, f64)>) { let back_values: Line = Line::new(Values::from_values({ if self.back_cache.is_none() { - let absrange = (self.max_x - self.min_x).abs(); - let resolution: f64 = (self.pixel_width as f64 / absrange) as f64; + let resolution: f64 = + (self.pixel_width as f64 / (self.max_x - self.min_x).abs()) as f64; self.back_cache = Some( (0..=self.pixel_width) .map(|x| (x as f64 / resolution as f64) + self.min_x) - .map(|x| (x, self.run_func(x))) - .map(|(x, y)| Value::new(x, y)) + .map(|x| Value::new(x, self.run_func(x))) .collect(), ); } @@ -225,18 +214,18 @@ impl Function { false => (x2, x), }; - let y: f64 = match self.sum { - RiemannSum::Left => self.run_func(left_x), - RiemannSum::Right => self.run_func(right_x), - RiemannSum::Middle => (self.run_func(left_x) + self.run_func(right_x)) / 2.0, - }; - ( match x.is_sign_positive() { true => x + half_step, false => x - half_step, }, - y, + match self.sum { + RiemannSum::Left => self.run_func(left_x), + RiemannSum::Right => self.run_func(right_x), + RiemannSum::Middle => { + (self.run_func(left_x) + self.run_func(right_x)) / 2.0 + } + }, ) }) .filter(|(_, y)| !y.is_nan())