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::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());
}

View File

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

View File

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