improvements
This commit is contained in:
parent
274d072bfe
commit
14fcfc8e54
@ -105,7 +105,7 @@ impl epi::App for MathApp {
|
|||||||
ui.label("- signum, min, max");
|
ui.label("- signum, min, max");
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut new_func_data: Vec<(String, bool)> = Vec::new();
|
let mut new_func_data: Vec<(String, bool, bool)> = Vec::new();
|
||||||
let mut parse_error: String = "".to_string();
|
let mut parse_error: String = "".to_string();
|
||||||
egui::SidePanel::left("side_panel")
|
egui::SidePanel::left("side_panel")
|
||||||
.resizable(false)
|
.resizable(false)
|
||||||
@ -132,11 +132,13 @@ impl epi::App for MathApp {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let func_test_output = test_func(func_str.clone());
|
let func_test_output = test_func(func_str.clone());
|
||||||
|
let mut got_error: bool = false;
|
||||||
if !func_test_output.is_empty() {
|
if !func_test_output.is_empty() {
|
||||||
parse_error += &func_test_output;
|
parse_error += &func_test_output;
|
||||||
|
got_error = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_func_data.push((func_str, integral_toggle));
|
new_func_data.push((func_str, integral_toggle, got_error));
|
||||||
}
|
}
|
||||||
|
|
||||||
let min_x_old = *min_x;
|
let min_x_old = *min_x;
|
||||||
@ -191,7 +193,8 @@ impl epi::App for MathApp {
|
|||||||
|
|
||||||
let mut i: usize = 0;
|
let mut i: usize = 0;
|
||||||
for function in functions.iter_mut() {
|
for function in functions.iter_mut() {
|
||||||
let (func_str, integral_toggle) = (new_func_data[i].0.clone(), new_func_data[i].1);
|
let (func_str, integral_toggle, got_error) = (new_func_data[i].0.clone(), new_func_data[i].1, new_func_data[i].2);
|
||||||
|
|
||||||
let integral: bool = if integral_toggle {
|
let integral: bool = if integral_toggle {
|
||||||
!function.is_integral()
|
!function.is_integral()
|
||||||
} else {
|
} else {
|
||||||
@ -199,7 +202,7 @@ impl epi::App for MathApp {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
function.update(func_str, *min_x, *max_x, integral, Some(*integral_min_x), Some(*integral_max_x), Some(*integral_num));
|
function.update(func_str, *min_x, *max_x, integral, Some(*integral_min_x), Some(*integral_max_x), Some(*integral_num), got_error);
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -218,6 +221,10 @@ impl epi::App for MathApp {
|
|||||||
.include_y(0)
|
.include_y(0)
|
||||||
.show(ui, |plot_ui| {
|
.show(ui, |plot_ui| {
|
||||||
for function in self.functions.iter_mut() {
|
for function in self.functions.iter_mut() {
|
||||||
|
if function.is_broken() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
let output = function.run();
|
let output = function.run();
|
||||||
let back = output.get_back();
|
let back = output.get_back();
|
||||||
plot_ui.line(Line::new(Values::from_values(back)).color(Color32::RED));
|
plot_ui.line(Line::new(Values::from_values(back)).color(Color32::RED));
|
||||||
|
|||||||
@ -51,6 +51,7 @@ pub struct Function {
|
|||||||
integral_min_x: f64,
|
integral_min_x: f64,
|
||||||
integral_max_x: f64,
|
integral_max_x: f64,
|
||||||
integral_num: usize,
|
integral_num: usize,
|
||||||
|
broken_state: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Function {
|
impl Function {
|
||||||
@ -91,6 +92,7 @@ impl Function {
|
|||||||
Some(x) => x,
|
Some(x) => x,
|
||||||
None => 0,
|
None => 0,
|
||||||
},
|
},
|
||||||
|
broken_state: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,7 +104,14 @@ impl Function {
|
|||||||
pub fn update(
|
pub fn update(
|
||||||
&mut self, func_str: String, min_x: f64, max_x: f64, integral: bool,
|
&mut self, func_str: String, min_x: f64, max_x: f64, integral: bool,
|
||||||
integral_min_x: Option<f64>, integral_max_x: Option<f64>, integral_num: Option<usize>,
|
integral_min_x: Option<f64>, integral_max_x: Option<f64>, integral_num: Option<usize>,
|
||||||
|
broken_state: bool,
|
||||||
) {
|
) {
|
||||||
|
if broken_state {
|
||||||
|
self.func_str = func_str.clone();
|
||||||
|
self.broken_state = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// If the function string changes, just wipe and restart from scratch
|
// If the function string changes, just wipe and restart from scratch
|
||||||
if func_str != self.func_str {
|
if func_str != self.func_str {
|
||||||
*self = Self::new(
|
*self = Self::new(
|
||||||
@ -157,6 +166,9 @@ impl Function {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_integral(&self) -> bool { self.integral }
|
pub fn is_integral(&self) -> bool { self.integral }
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn is_broken(&self) -> bool { self.broken_state }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn run(&mut self) -> FunctionOutput {
|
pub fn run(&mut self) -> FunctionOutput {
|
||||||
let front_values: Vec<Value> = match self.back_cache.is_valid() {
|
let front_values: Vec<Value> = match self.back_cache.is_valid() {
|
||||||
@ -208,6 +220,15 @@ impl Function {
|
|||||||
if !self.integral {
|
if !self.integral {
|
||||||
panic!("integral_rectangles called, but self.integral is false!");
|
panic!("integral_rectangles called, but self.integral is false!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.integral_min_x.is_nan() {
|
||||||
|
panic!("integral_min_x is NaN")
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.integral_max_x.is_nan() {
|
||||||
|
panic!("integral_max_x is NaN")
|
||||||
|
}
|
||||||
|
|
||||||
let step = self.get_step();
|
let step = self.get_step();
|
||||||
|
|
||||||
let half_step = step / 2.0;
|
let half_step = step / 2.0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user