rename some variables
This commit is contained in:
parent
e0709ae845
commit
6e281e0569
@ -243,10 +243,12 @@ pub struct AppSettings {
|
||||
pub show_side_panel: bool,
|
||||
|
||||
/// Stores the type of Rienmann sum that should be calculated
|
||||
pub sum: Riemann,
|
||||
pub riemann_sum: Riemann,
|
||||
|
||||
/// Min and Max range for calculating an integral
|
||||
pub integral_min_x: f64,
|
||||
|
||||
/// Max value for calculating an
|
||||
pub integral_max_x: f64,
|
||||
|
||||
pub integral_changed: bool,
|
||||
@ -258,12 +260,13 @@ pub struct AppSettings {
|
||||
pub dark_mode: bool,
|
||||
|
||||
/// Stores whether or not displaying extrema is enabled
|
||||
pub extrema: bool,
|
||||
pub do_extrema: bool,
|
||||
|
||||
/// Stores whether or not displaying roots is enabled
|
||||
pub roots: bool,
|
||||
pub do_roots: bool,
|
||||
|
||||
pub pixel_width: usize,
|
||||
/// Stores current plot pixel width
|
||||
pub plot_width: usize,
|
||||
}
|
||||
|
||||
impl Default for AppSettings {
|
||||
@ -274,15 +277,15 @@ impl Default for AppSettings {
|
||||
help_open: true,
|
||||
info_open: false,
|
||||
show_side_panel: true,
|
||||
sum: DEFAULT_RIEMANN,
|
||||
riemann_sum: DEFAULT_RIEMANN,
|
||||
integral_min_x: DEFAULT_MIN_X,
|
||||
integral_max_x: DEFAULT_MAX_X,
|
||||
integral_changed: true,
|
||||
integral_num: DEFAULT_INTEGRAL_NUM,
|
||||
dark_mode: true,
|
||||
extrema: true,
|
||||
roots: true,
|
||||
pixel_width: 0,
|
||||
do_extrema: true,
|
||||
do_roots: true,
|
||||
plot_width: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -349,16 +352,24 @@ impl MathApp {
|
||||
SidePanel::left("side_panel")
|
||||
.resizable(false)
|
||||
.show(ctx, |ui| {
|
||||
let prev_sum = self.settings.sum;
|
||||
let prev_sum = self.settings.riemann_sum;
|
||||
// ComboBox for selecting what Riemann sum type to use
|
||||
ComboBox::from_label("Riemann Sum Type")
|
||||
.selected_text(self.settings.sum.to_string())
|
||||
.selected_text(self.settings.riemann_sum.to_string())
|
||||
.show_ui(ui, |ui| {
|
||||
ui.selectable_value(&mut self.settings.sum, Riemann::Left, "Left");
|
||||
ui.selectable_value(&mut self.settings.sum, Riemann::Middle, "Middle");
|
||||
ui.selectable_value(&mut self.settings.sum, Riemann::Right, "Right");
|
||||
ui.selectable_value(&mut self.settings.riemann_sum, Riemann::Left, "Left");
|
||||
ui.selectable_value(
|
||||
&mut self.settings.riemann_sum,
|
||||
Riemann::Middle,
|
||||
"Middle",
|
||||
);
|
||||
ui.selectable_value(
|
||||
&mut self.settings.riemann_sum,
|
||||
Riemann::Right,
|
||||
"Right",
|
||||
);
|
||||
});
|
||||
let riemann_changed = prev_sum == self.settings.sum;
|
||||
let riemann_changed = prev_sum == self.settings.riemann_sum;
|
||||
|
||||
// Config options for Extrema and roots
|
||||
let mut extrema_toggled: bool = false;
|
||||
@ -366,7 +377,7 @@ impl MathApp {
|
||||
ui.horizontal(|ui| {
|
||||
extrema_toggled = ui
|
||||
.add(Button::new("Extrema"))
|
||||
.on_hover_text(match self.settings.extrema {
|
||||
.on_hover_text(match self.settings.do_extrema {
|
||||
true => "Disable Displaying Extrema",
|
||||
false => "Display Extrema",
|
||||
})
|
||||
@ -374,7 +385,7 @@ impl MathApp {
|
||||
|
||||
roots_toggled = ui
|
||||
.add(Button::new("Roots"))
|
||||
.on_hover_text(match self.settings.roots {
|
||||
.on_hover_text(match self.settings.do_roots {
|
||||
true => "Disable Displaying Roots",
|
||||
false => "Display Roots",
|
||||
})
|
||||
@ -382,8 +393,8 @@ impl MathApp {
|
||||
});
|
||||
|
||||
// If options toggled, flip the boolean
|
||||
self.settings.extrema.bitxor_assign(extrema_toggled);
|
||||
self.settings.roots.bitxor_assign(roots_toggled);
|
||||
self.settings.do_extrema.bitxor_assign(extrema_toggled);
|
||||
self.settings.do_roots.bitxor_assign(roots_toggled);
|
||||
|
||||
let min_x_old = self.settings.integral_min_x;
|
||||
let min_x_changed = ui
|
||||
@ -669,10 +680,10 @@ impl epi::App for MathApp {
|
||||
}
|
||||
|
||||
let available_width: usize = (ui.available_width() as usize) + 1; // Used in later logic
|
||||
let width_changed = available_width != self.settings.pixel_width;
|
||||
let width_changed = available_width != self.settings.plot_width;
|
||||
|
||||
if width_changed {
|
||||
self.settings.pixel_width = available_width;
|
||||
self.settings.plot_width = available_width;
|
||||
}
|
||||
let settings_copy = self.settings;
|
||||
|
||||
|
||||
@ -166,8 +166,8 @@ impl FunctionEntry {
|
||||
pub fn calculate(
|
||||
&mut self, min_x: f64, max_x: f64, width_changed: bool, settings: AppSettings,
|
||||
) {
|
||||
let resolution: f64 = settings.pixel_width as f64 / (max_x.abs() + min_x.abs());
|
||||
let resolution_iter = resolution_helper(settings.pixel_width + 1, min_x, resolution);
|
||||
let resolution: f64 = settings.plot_width as f64 / (max_x.abs() + min_x.abs());
|
||||
let resolution_iter = resolution_helper(settings.plot_width + 1, min_x, resolution);
|
||||
|
||||
// Makes sure proper arguments are passed when integral is enabled
|
||||
if self.integral && settings.integral_changed {
|
||||
@ -203,7 +203,7 @@ impl FunctionEntry {
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(back_data.len(), settings.pixel_width + 1);
|
||||
assert_eq!(back_data.len(), settings.plot_width + 1);
|
||||
self.output.back = Some(back_data);
|
||||
|
||||
let derivative_cache = self.output.derivative.as_ref().unwrap();
|
||||
@ -217,7 +217,7 @@ impl FunctionEntry {
|
||||
})
|
||||
.collect();
|
||||
|
||||
assert_eq!(new_derivative_data.len(), settings.pixel_width + 1);
|
||||
assert_eq!(new_derivative_data.len(), settings.plot_width + 1);
|
||||
|
||||
self.output.derivative = Some(new_derivative_data);
|
||||
} else {
|
||||
@ -236,7 +236,7 @@ impl FunctionEntry {
|
||||
let data: Vec<Value> = dyn_iter(&resolution_iter)
|
||||
.map(|x| Value::new(*x, self.function.get(*x)))
|
||||
.collect();
|
||||
assert_eq!(data.len(), settings.pixel_width + 1);
|
||||
assert_eq!(data.len(), settings.plot_width + 1);
|
||||
|
||||
self.output.back = Some(data);
|
||||
}
|
||||
@ -249,7 +249,7 @@ impl FunctionEntry {
|
||||
let data: Vec<Value> = dyn_iter(&resolution_iter)
|
||||
.map(|x| Value::new(*x, self.function.get_derivative_1(*x)))
|
||||
.collect();
|
||||
assert_eq!(data.len(), settings.pixel_width + 1);
|
||||
assert_eq!(data.len(), settings.plot_width + 1);
|
||||
self.output.derivative = Some(data);
|
||||
}
|
||||
|
||||
@ -263,7 +263,7 @@ impl FunctionEntry {
|
||||
let (data, area) = self.integral_rectangles(
|
||||
settings.integral_min_x,
|
||||
settings.integral_max_x,
|
||||
settings.sum,
|
||||
settings.riemann_sum,
|
||||
settings.integral_num,
|
||||
);
|
||||
self.output.integral =
|
||||
@ -277,12 +277,12 @@ impl FunctionEntry {
|
||||
};
|
||||
|
||||
// Calculates extrema
|
||||
if settings.extrema && (min_max_changed | self.output.extrema.is_none()) {
|
||||
if settings.do_extrema && (min_max_changed | self.output.extrema.is_none()) {
|
||||
self.output.extrema = self.newtons_method_helper(threshold, 1);
|
||||
}
|
||||
|
||||
// Calculates roots
|
||||
if settings.roots && (min_max_changed | self.output.roots.is_none()) {
|
||||
if settings.do_roots && (min_max_changed | self.output.roots.is_none()) {
|
||||
self.output.roots = self.newtons_method_helper(threshold, 0);
|
||||
}
|
||||
}
|
||||
@ -314,7 +314,7 @@ impl FunctionEntry {
|
||||
}
|
||||
|
||||
// Plot extrema points
|
||||
if settings.extrema {
|
||||
if settings.do_extrema {
|
||||
if let Some(extrema_data) = self.output.extrema.clone() {
|
||||
plot_ui.points(
|
||||
vec_tuple_to_points(extrema_data)
|
||||
@ -326,7 +326,7 @@ impl FunctionEntry {
|
||||
}
|
||||
|
||||
// Plot roots points
|
||||
if settings.roots {
|
||||
if settings.do_roots {
|
||||
if let Some(roots_data) = self.output.roots.clone() {
|
||||
plot_ui.points(
|
||||
vec_tuple_to_points(roots_data)
|
||||
@ -363,15 +363,15 @@ impl FunctionEntry {
|
||||
let back_target = back_target;
|
||||
assert!(self.output.back.is_some());
|
||||
let back_data = self.output.back.as_ref().unwrap().clone();
|
||||
assert_eq!(back_data.len(), settings.pixel_width + 1);
|
||||
assert_eq!(back_data.len(), settings.plot_width + 1);
|
||||
let back_vec_tuple = back_data.to_tuple();
|
||||
assert_eq!(back_vec_tuple, back_target);
|
||||
|
||||
assert!(self.integral);
|
||||
assert!(self.derivative);
|
||||
|
||||
assert_eq!(self.output.roots.is_some(), settings.roots);
|
||||
assert_eq!(self.output.extrema.is_some(), settings.extrema);
|
||||
assert_eq!(self.output.roots.is_some(), settings.do_roots);
|
||||
assert_eq!(self.output.extrema.is_some(), settings.do_extrema);
|
||||
assert!(self.output.derivative.is_some());
|
||||
assert!(self.output.integral.is_some());
|
||||
|
||||
@ -397,15 +397,15 @@ mod tests {
|
||||
help_open: false,
|
||||
info_open: false,
|
||||
show_side_panel: false,
|
||||
sum,
|
||||
riemann_sum: sum,
|
||||
integral_min_x,
|
||||
integral_max_x,
|
||||
integral_changed: true,
|
||||
integral_num,
|
||||
dark_mode: false,
|
||||
extrema: false,
|
||||
roots: false,
|
||||
pixel_width,
|
||||
do_extrema: false,
|
||||
do_roots: false,
|
||||
plot_width: pixel_width,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user