cleanup + further optimize split_function_chars

This commit is contained in:
Simon Gardling
2022-05-07 02:19:52 -04:00
parent bf58e82c80
commit 79782d84b1
8 changed files with 89 additions and 82 deletions

View File

@@ -68,30 +68,30 @@ pub struct FunctionEntry {
impl const Default for FunctionEntry {
/// Creates default FunctionEntry instance (which is empty)
fn default() -> FunctionEntry {
FunctionEntry {
function: BackingFunction::EMPTY,
raw_func_str: String::new(),
min_x: -1.0,
max_x: 1.0,
integral: false,
derivative: false,
nth_derviative: false,
back_data: Vec::new(),
integral_data: None,
derivative_data: Vec::new(),
extrema_data: Vec::new(),
root_data: Vec::new(),
nth_derivative_data: None,
autocomplete: AutoComplete::default(),
test_result: None,
curr_nth: 3,
settings_opened: false,
}
}
fn default() -> FunctionEntry { FunctionEntry::EMPTY }
}
impl FunctionEntry {
pub const EMPTY: FunctionEntry = FunctionEntry {
function: BackingFunction::EMPTY,
raw_func_str: String::new(),
min_x: -1.0,
max_x: 1.0,
integral: false,
derivative: false,
nth_derviative: false,
back_data: Vec::new(),
integral_data: None,
derivative_data: Vec::new(),
extrema_data: Vec::new(),
root_data: Vec::new(),
nth_derivative_data: None,
autocomplete: AutoComplete::default(),
test_result: None,
curr_nth: 3,
settings_opened: false,
};
pub fn settings_window(&mut self, ctx: &Context) {
let mut invalidate_nth = false;
egui::Window::new(format!("Settings: {}", self.raw_func_str))
@@ -605,7 +605,7 @@ mod tests {
fn do_test(sum: Riemann, area_target: f64) {
let settings = app_settings_constructor(sum, -1.0, 1.0, 10, 10);
let mut function = FunctionEntry::default();
let mut function = FunctionEntry::EMPTY;
function.update_string("x^2");
function.integral = true;
function.derivative = true;

View File

@@ -14,7 +14,10 @@ pub struct FunctionManager {
impl Default for FunctionManager {
fn default() -> Self {
Self {
functions: vec![(Uuid::new_v4(), FunctionEntry::default())],
functions: vec![(
uuid!("684fc8be-4ba0-408d-96ef-480b0642126f"), // Random uuid here to avoid call to `Uuid::new_v4()`
FunctionEntry::EMPTY,
)],
}
}
}
@@ -196,10 +199,7 @@ impl FunctionManager {
}
}
pub fn new_function(&mut self) {
self.functions
.push((Uuid::new_v4(), FunctionEntry::default()));
}
pub fn new_function(&mut self) { self.functions.push((Uuid::new_v4(), FunctionEntry::EMPTY)); }
pub fn any_using_integral(&self) -> bool {
self.functions.iter().any(|(_, func)| func.integral)

View File

@@ -9,6 +9,9 @@
#[macro_use]
extern crate static_assertions;
#[macro_use]
extern crate uuid;
mod consts;
mod function_entry;
mod function_manager;

View File

@@ -7,6 +7,9 @@
#[macro_use]
extern crate static_assertions;
#[macro_use]
extern crate uuid;
mod consts;
mod function_entry;
mod function_manager;

View File

@@ -107,6 +107,7 @@ pub struct MathApp {
/// Contains the list of Areas calculated (the vector of f64) and time it took for the last frame (the Duration). Stored in a Tuple.
last_info: (Vec<Option<f64>>, Option<Duration>),
/// Whether or not dark mode is enabled
dark_mode: bool,
/// Stores opened windows/elements for later reference