cache empty FunctionEntry

This commit is contained in:
Simon Gardling 2022-03-08 09:10:10 -05:00
parent 07aa93046f
commit 9837f51382
3 changed files with 14 additions and 9 deletions

View File

@ -1,4 +1,4 @@
use crate::function::{FunctionEntry, RiemannSum}; use crate::function::{FunctionEntry, RiemannSum, EMPTY_FUNCTIONENTRY};
use crate::misc::digits_precision; use crate::misc::digits_precision;
use crate::parsing::{add_asterisks, test_func}; 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 // The URL of the project
const PROJECT_URL: &str = "https://github.com/Titaniumtown/integral_site"; const PROJECT_URL: &str = "https://github.com/Titaniumtown/integral_site";
// Stores settings // Stores settings
struct AppSettings { struct AppSettings {
// Stores whether or not the Help window is open // Stores whether or not the Help window is open
@ -164,7 +163,7 @@ pub struct MathApp {
impl Default for MathApp { impl Default for MathApp {
fn default() -> Self { fn default() -> Self {
Self { Self {
functions: vec![FunctionEntry::empty().integral(true)], functions: vec![EMPTY_FUNCTIONENTRY.clone().integral(true)],
func_strs: vec![String::from(DEFAULT_FUNCION)], func_strs: vec![String::from(DEFAULT_FUNCION)],
last_error: Vec::new(), last_error: Vec::new(),
last_info: (vec![0.0], Duration::ZERO), last_info: (vec![0.0], Duration::ZERO),
@ -324,10 +323,7 @@ impl MathApp {
} }
// Open Source and Licensing information // Open Source and Licensing information
ui.hyperlink_to( ui.hyperlink_to("I'm Opensource!", PROJECT_URL);
"I'm Opensource!",
PROJECT_URL,
);
ui.label(RichText::new("(and licensed under AGPLv3)").color(Color32::LIGHT_GRAY)) ui.label(RichText::new("(and licensed under AGPLv3)").color(Color32::LIGHT_GRAY))
.on_hover_text(LICENSE_INFO); .on_hover_text(LICENSE_INFO);
@ -391,8 +387,11 @@ impl epi::App for MathApp {
.on_hover_text("Create and graph new function") .on_hover_text("Create and graph new function")
.clicked() .clicked()
{ {
self.functions self.functions.push(
.push(FunctionEntry::empty().update_riemann(self.settings.sum)); EMPTY_FUNCTIONENTRY
.clone()
.update_riemann(self.settings.sum),
);
self.func_strs.push(String::new()); self.func_strs.push(String::new());
} }

View File

@ -22,6 +22,11 @@ impl fmt::Display for RiemannSum {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{:?}", self) } 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 { pub struct FunctionEntry {
function: BackingFunction, function: BackingFunction,
func_str: String, func_str: String,

View File

@ -1,5 +1,6 @@
use exmex::prelude::*; use exmex::prelude::*;
#[derive(Clone)]
pub struct BackingFunction { pub struct BackingFunction {
function: FlatEx<f64>, function: FlatEx<f64>,
derivative_1: FlatEx<f64>, derivative_1: FlatEx<f64>,