diff --git a/src/egui_app.rs b/src/egui_app.rs index e181c53..1bfd370 100644 --- a/src/egui_app.rs +++ b/src/egui_app.rs @@ -1,4 +1,4 @@ -use crate::function::{FunctionEntry, RiemannSum}; +use crate::function::{FunctionEntry, RiemannSum, EMPTY_FUNCTIONENTRY}; use crate::misc::digits_precision; use crate::parsing::{add_asterisks, test_func}; @@ -99,7 +99,6 @@ const LICENSE_INFO: &str = "The AGPL license ensures that the end user, even if // The URL of the project const PROJECT_URL: &str = "https://github.com/Titaniumtown/integral_site"; - // Stores settings struct AppSettings { // Stores whether or not the Help window is open @@ -164,7 +163,7 @@ pub struct MathApp { impl Default for MathApp { fn default() -> Self { Self { - functions: vec![FunctionEntry::empty().integral(true)], + functions: vec![EMPTY_FUNCTIONENTRY.clone().integral(true)], func_strs: vec![String::from(DEFAULT_FUNCION)], last_error: Vec::new(), last_info: (vec![0.0], Duration::ZERO), @@ -324,10 +323,7 @@ impl MathApp { } // Open Source and Licensing information - ui.hyperlink_to( - "I'm Opensource!", - PROJECT_URL, - ); + ui.hyperlink_to("I'm Opensource!", PROJECT_URL); ui.label(RichText::new("(and licensed under AGPLv3)").color(Color32::LIGHT_GRAY)) .on_hover_text(LICENSE_INFO); @@ -391,8 +387,11 @@ impl epi::App for MathApp { .on_hover_text("Create and graph new function") .clicked() { - self.functions - .push(FunctionEntry::empty().update_riemann(self.settings.sum)); + self.functions.push( + EMPTY_FUNCTIONENTRY + .clone() + .update_riemann(self.settings.sum), + ); self.func_strs.push(String::new()); } diff --git a/src/function.rs b/src/function.rs index 9e11eac..1499945 100644 --- a/src/function.rs +++ b/src/function.rs @@ -22,6 +22,11 @@ impl fmt::Display for RiemannSum { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{:?}", self) } } +lazy_static::lazy_static! { + pub static ref EMPTY_FUNCTIONENTRY: FunctionEntry = FunctionEntry::empty(); +} + +#[derive(Clone)] pub struct FunctionEntry { function: BackingFunction, func_str: String, diff --git a/src/parsing.rs b/src/parsing.rs index 1ce2ce4..2a422a0 100644 --- a/src/parsing.rs +++ b/src/parsing.rs @@ -1,5 +1,6 @@ use exmex::prelude::*; +#[derive(Clone)] pub struct BackingFunction { function: FlatEx, derivative_1: FlatEx,