refactor progress
This commit is contained in:
@@ -31,7 +31,7 @@ impl fmt::Display for Riemann {
|
||||
#[derive(Clone)]
|
||||
pub struct FunctionEntry {
|
||||
/// The `BackingFunction` instance that is used to generate `f(x)`, `f'(x)`, and `f''(x)`
|
||||
function: BackingFunction,
|
||||
function: BackingFunction<'static>,
|
||||
|
||||
/// Stores a function string (that hasn't been processed via `process_func_str`) to display to the user
|
||||
pub raw_func_str: String,
|
||||
@@ -121,28 +121,10 @@ impl<'de> Deserialize<'de> for FunctionEntry {
|
||||
|
||||
impl const Default for FunctionEntry {
|
||||
/// Creates default FunctionEntry instance (which is empty)
|
||||
fn default() -> FunctionEntry { FunctionEntry::EMPTY }
|
||||
fn default() -> FunctionEntry {}
|
||||
}
|
||||
|
||||
impl FunctionEntry {
|
||||
pub const EMPTY: FunctionEntry = FunctionEntry {
|
||||
function: BackingFunction::EMPTY,
|
||||
raw_func_str: String::new(),
|
||||
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::EMPTY,
|
||||
test_result: None,
|
||||
curr_nth: 3,
|
||||
settings_opened: false,
|
||||
};
|
||||
|
||||
pub const fn is_some(&self) -> bool { !self.function.is_none() }
|
||||
|
||||
pub fn settings_window(&mut self, ctx: &Context) {
|
||||
@@ -216,10 +198,10 @@ impl FunctionEntry {
|
||||
};
|
||||
|
||||
let y = match sum {
|
||||
Riemann::Left => self.function.get(left_x),
|
||||
Riemann::Right => self.function.get(right_x),
|
||||
Riemann::Left => self.function.get(0, left_x),
|
||||
Riemann::Right => self.function.get(0, right_x),
|
||||
Riemann::Middle => {
|
||||
(self.function.get(left_x) + self.function.get(right_x)) / 2.0
|
||||
(self.function.get(0, left_x) + self.function.get(0, right_x)) / 2.0
|
||||
}
|
||||
};
|
||||
|
||||
@@ -242,22 +224,22 @@ impl FunctionEntry {
|
||||
threshold,
|
||||
range,
|
||||
self.back_data.as_slice(),
|
||||
&|x: f64| self.function.get(x),
|
||||
&|x: f64| self.function.get_derivative_1(x),
|
||||
&|x: f64| self.function.get(0, x),
|
||||
&|x: f64| self.function.get(1, x),
|
||||
),
|
||||
1 => newtons_method_helper(
|
||||
threshold,
|
||||
range,
|
||||
self.derivative_data.as_slice(),
|
||||
&|x: f64| self.function.get_derivative_1(x),
|
||||
&|x: f64| self.function.get_derivative_2(x),
|
||||
&|x: f64| self.function.get(1, x),
|
||||
&|x: f64| self.function.get(2, x),
|
||||
),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
newtons_method_output
|
||||
.into_iter()
|
||||
.map(|x| PlotPoint::new(x, self.function.get(x)))
|
||||
.map(|x| PlotPoint::new(x, self.function.get(0, x)))
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -291,7 +273,7 @@ impl FunctionEntry {
|
||||
let data: Vec<PlotPoint> = resolution_iter
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|x| PlotPoint::new(x, self.function.get(x)))
|
||||
.map(|x| PlotPoint::new(x, self.function.get(0, x)))
|
||||
.collect();
|
||||
debug_assert_eq!(data.len(), settings.plot_width + 1);
|
||||
|
||||
@@ -302,7 +284,7 @@ impl FunctionEntry {
|
||||
let data: Vec<PlotPoint> = resolution_iter
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|x| PlotPoint::new(x, self.function.get_derivative_1(x)))
|
||||
.map(|x| PlotPoint::new(x, self.function.get(1, x)))
|
||||
.collect();
|
||||
debug_assert_eq!(data.len(), settings.plot_width + 1);
|
||||
self.derivative_data = data;
|
||||
@@ -311,7 +293,7 @@ impl FunctionEntry {
|
||||
if self.nth_derviative && self.nth_derivative_data.is_none() {
|
||||
let data: Vec<PlotPoint> = resolution_iter
|
||||
.into_iter()
|
||||
.map(|x| PlotPoint::new(x, self.function.get_nth_derivative(self.curr_nth, x)))
|
||||
.map(|x| PlotPoint::new(x, self.function.get(self.curr_nth, x)))
|
||||
.collect();
|
||||
debug_assert_eq!(data.len(), settings.plot_width + 1);
|
||||
self.nth_derivative_data = Some(data);
|
||||
|
||||
Reference in New Issue
Block a user