refactor: simplify Newton's method helper by extracting data source selection

This commit is contained in:
Simon Gardling 2025-12-05 20:17:09 -05:00
parent df05601e26
commit 3305227ffe
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D

View File

@ -252,25 +252,20 @@ impl FunctionEntry {
) -> Vec<PlotPoint> {
self.function.generate_derivative(derivative_level);
self.function.generate_derivative(derivative_level + 1);
let newtons_method_output: Vec<f64> = match derivative_level {
0 => newtons_method_helper(
threshold,
range,
self.back_data.as_slice(),
self.function.get_function_derivative(0),
self.function.get_function_derivative(1),
),
1 => newtons_method_helper(
threshold,
range,
self.derivative_data.as_slice(),
self.function.get_function_derivative(1),
self.function.get_function_derivative(2),
),
let data_source = match derivative_level {
0 => self.back_data.as_slice(),
1 => self.derivative_data.as_slice(),
_ => unreachable!(),
};
newtons_method_output
newtons_method_helper(
threshold,
range,
data_source,
self.function.get_function_derivative(derivative_level),
self.function.get_function_derivative(derivative_level + 1),
)
.into_iter()
.map(|x| PlotPoint::new(x, self.function.get(0, x)))
.collect()