diff --git a/src/egui_app.rs b/src/egui_app.rs index ae0e017..6fa402d 100644 --- a/src/egui_app.rs +++ b/src/egui_app.rs @@ -229,7 +229,7 @@ cfg_if::cfg_if! { } } -/// Stores current settings/state of `MathApp` +/// Stores current settings/state of [`MathApp`] // TODO: find a better name for this #[derive(Copy, Clone)] pub struct AppSettings { @@ -251,6 +251,7 @@ pub struct AppSettings { /// Max value for calculating an pub integral_max_x: f64, + /// Stores whether or not integral settings have changed pub integral_changed: bool, /// Number of rectangles used to calculate integral @@ -325,7 +326,7 @@ impl Default for MathApp { impl MathApp { #[allow(dead_code)] // This is used lol - /// Create new instance of `MathApp` and return it + /// Create new instance of [`MathApp`] and return it pub fn new(cc: &eframe::CreationContext<'_>) -> Self { // Remove loading indicator on wasm #[cfg(target_arch = "wasm32")] diff --git a/src/function.rs b/src/function.rs index efe52a9..a8f9e33 100644 --- a/src/function.rs +++ b/src/function.rs @@ -128,21 +128,23 @@ impl FunctionEntry { (data2, area) } - /// Returns `func_str` + /// Returns `self.func_str` pub fn get_func_str(&self) -> &str { &self.func_str } + /// Helps with processing newton's method depending on level of derivative fn newtons_method_helper(&self, threshold: f64, derivative_level: usize) -> Option> { + let range = self.min_x..self.max_x; let newtons_method_output: Vec = match derivative_level { 0 => newtons_method_helper( threshold, - self.min_x..self.max_x, + range, self.output.back.to_owned().unwrap(), &|x: f64| self.function.get(x), &|x: f64| self.function.get_derivative_1(x), ), 1 => newtons_method_helper( threshold, - self.min_x..self.max_x, + range, self.output.derivative.to_owned().unwrap(), &|x: f64| self.function.get_derivative_1(x), &|x: f64| self.function.get_derivative_2(x), @@ -287,10 +289,9 @@ impl FunctionEntry { } } - /// Calculates and displays the function on PlotUI `plot_ui` + /// Displays the function's output on PlotUI `plot_ui` with settings + /// `settings`. Returns an `Option` of the calculated integral pub fn display(&self, plot_ui: &mut PlotUi, settings: AppSettings) -> Option { - // self.calculate(min_x, max_x, width_changed, settings); - let func_str = self.get_func_str(); let derivative_str = self.function.get_derivative_str(); let step = (settings.integral_min_x - settings.integral_max_x).abs() @@ -352,6 +353,7 @@ impl FunctionEntry { } } + /// Runs asserts to make sure everything is the expected value #[cfg(test)] pub fn tests( &mut self, settings: AppSettings, back_target: Vec<(f64, f64)>, diff --git a/src/function_output.rs b/src/function_output.rs index e1a375e..b250390 100644 --- a/src/function_output.rs +++ b/src/function_output.rs @@ -10,7 +10,7 @@ pub struct FunctionOutput { } impl FunctionOutput { - /// Creates empty instance of `FunctionOutput` + /// Creates empty instance of [`FunctionOutput`] pub fn new_empty() -> Self { Self { back: None, @@ -40,6 +40,8 @@ impl FunctionOutput { pub fn invalidate_derivative(&mut self) { self.derivative = None; } } +/// Tests to make sure invalidation and the default empty state works as +/// expected #[test] fn function_output_test() { let mut function_output = FunctionOutput::new_empty(); diff --git a/src/misc.rs b/src/misc.rs index 09d1519..2b5ab36 100644 --- a/src/misc.rs +++ b/src/misc.rs @@ -48,7 +48,7 @@ where fn to_tuple(&self) -> Vec<(f64, f64)> { self.iter().map(|ele| (ele.x, ele.y)).collect() } } -/// `SteppedVector` is used in order to efficiently sort through an ordered +/// [`SteppedVector`] is used in order to efficiently sort through an ordered /// `Vec` Used in order to speedup the processing of cached data when /// moving horizontally without zoom in `FunctionEntry`. Before this struct, the /// index was calculated with `.iter().position(....` which was horribly @@ -110,7 +110,7 @@ impl SteppedVector { pub fn get_data(&self) -> Vec { self.data.clone() } } -// Convert `Vec` into `SteppedVector` +// Convert `Vec` into [`SteppedVector`] impl From> for SteppedVector { fn from(input_data: Vec) -> SteppedVector { let mut data = input_data; @@ -318,8 +318,8 @@ mod tests { use super::*; use std::collections::HashMap; - /// Tests SteppedVector to ensure everything works properly (helped me find - /// a bunch of issues) + /// Tests [`SteppedVector`] to ensure everything works properly (helped me + /// find a bunch of issues) #[test] fn stepped_vector_test() { let min: i32 = -10; @@ -345,7 +345,7 @@ mod tests { assert_eq!(stepped_vector.get_index((max + 1) as f64), None); } - /// Ensures decimal_round returns correct values + /// Ensures [`decimal_round`] returns correct values #[test] fn decimal_round_test() { assert_eq!(decimal_round(0.00001, 1), 0.0); @@ -364,7 +364,7 @@ mod tests { assert_eq!(decimal_round(1.9, 1), 1.9); } - /// Tests `resolution_helper` to make sure it returns expected output + /// Tests [`resolution_helper`] to make sure it returns expected output #[test] fn resolution_helper_test() { assert_eq!( diff --git a/src/parsing.rs b/src/parsing.rs index 5064396..27312b0 100644 --- a/src/parsing.rs +++ b/src/parsing.rs @@ -18,7 +18,7 @@ pub struct BackingFunction { } impl BackingFunction { - /// Create new BackingFunction instance + /// Create new [`BackingFunction`] instance pub fn new(func_str: &str) -> Self { let function = match func_str { "" => EMPTY_FUNCTION.clone(), @@ -213,11 +213,11 @@ mod tests { use std::collections::HashMap; /// returns if function with string `func_str` is valid after processing - /// through `process_func_str` + /// through [`process_func_str`] fn func_is_valid(func_str: &str) -> bool { test_func(&process_func_str(func_str)).is_none() } - /// Used for testing: passes function to `add_asterisks` before running - /// `test_func`. if `expect_valid` == `true`, it expects no errors to be + /// Used for testing: passes function to [`process_func_str`] before running + /// [`test_func`]. if `expect_valid` == `true`, it expects no errors to be /// created. fn test_func_helper(func_str: &str, expect_valid: bool) { let is_valid = func_is_valid(func_str); @@ -273,7 +273,7 @@ mod tests { test_func_helper(func_str, false); } } - /// Helps with tests of `process_func_str` + /// Helps with tests of [`process_func_str`] #[cfg(test)] fn test_process_helper(input: &str, expected: &str) { assert_eq!(&process_func_str(input), expected);