rustfmt
This commit is contained in:
parent
c09c2d9beb
commit
b28a652aef
@ -1,6 +1,5 @@
|
||||
use crate::misc::{add_asterisks, Function};
|
||||
|
||||
|
||||
pub enum UpdateType {
|
||||
FULL,
|
||||
FRONT,
|
||||
@ -34,9 +33,9 @@ impl ChartManager {
|
||||
pub fn draw_back(&mut self) -> Vec<(f64, f64)> {
|
||||
let absrange = (self.max_x - self.min_x).abs();
|
||||
let output: Vec<(f64, f64)> = (1..=self.resolution)
|
||||
.map(|x| ((x as f64 / self.resolution as f64) * absrange) + self.min_x)
|
||||
.map(|x| (x, self.function.run(x)))
|
||||
.collect();
|
||||
.map(|x| ((x as f64 / self.resolution as f64) * absrange) + self.min_x)
|
||||
.map(|x| (x, self.function.run(x)))
|
||||
.collect();
|
||||
output
|
||||
}
|
||||
|
||||
@ -57,7 +56,8 @@ impl ChartManager {
|
||||
let update_func: bool = !self.function.str_compare(func_str.clone());
|
||||
|
||||
let update_back = update_func | (min_x != self.min_x) | (max_x != self.max_x);
|
||||
let update_front = update_back | (self.resolution != resolution) | (num_interval != self.num_interval);
|
||||
let update_front =
|
||||
update_back | (self.resolution != resolution) | (num_interval != self.num_interval);
|
||||
|
||||
if update_func {
|
||||
self.function = Function::from_string(func_str);
|
||||
|
||||
@ -13,7 +13,7 @@ pub struct MathApp {
|
||||
resolution: usize,
|
||||
chart_manager: ChartManager,
|
||||
back_cache: Cache<Vec<Value>>,
|
||||
front_cache: Cache<(Vec<Bar>, f64)>
|
||||
front_cache: Cache<(Vec<Bar>, f64)>,
|
||||
}
|
||||
|
||||
impl Default for MathApp {
|
||||
@ -54,7 +54,7 @@ impl MathApp {
|
||||
} else {
|
||||
let (data, area) = self.chart_manager.draw_front();
|
||||
let bars: Vec<Bar> = data.iter().map(|(x, y)| Bar::new(*x, *y)).collect();
|
||||
|
||||
|
||||
let output = (bars, area);
|
||||
self.front_cache.set(output.clone());
|
||||
output
|
||||
@ -68,7 +68,6 @@ impl MathApp {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl epi::App for MathApp {
|
||||
fn name(&self) -> &str { "Integral Demonstration" }
|
||||
|
||||
@ -138,19 +137,14 @@ impl epi::App for MathApp {
|
||||
);
|
||||
});
|
||||
|
||||
let do_update = chart_manager.update(
|
||||
func_str.clone(),
|
||||
*min_x,
|
||||
*max_x,
|
||||
*num_interval,
|
||||
*resolution,
|
||||
);
|
||||
let do_update =
|
||||
chart_manager.update(func_str.clone(), *min_x, *max_x, *num_interval, *resolution);
|
||||
|
||||
match do_update {
|
||||
UpdateType::FULL => {
|
||||
back_cache.invalidate();
|
||||
front_cache.invalidate();
|
||||
},
|
||||
}
|
||||
UpdateType::BACK => back_cache.invalidate(),
|
||||
UpdateType::FRONT => front_cache.invalidate(),
|
||||
_ => {}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user