simplify logic
This commit is contained in:
parent
68322f37db
commit
facf603c7a
@ -168,9 +168,8 @@ impl Function {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(&mut self) -> (Line, Option<(BarChart, f64)>) {
|
pub fn run(&mut self) -> (Line, Option<(BarChart, f64)>) {
|
||||||
let back_values: Line = Line::new(Values::from_values(match self.back_cache.is_some() {
|
let back_values: Line = Line::new(Values::from_values({
|
||||||
true => self.back_cache.as_ref().unwrap().clone(),
|
if self.back_cache.is_none() {
|
||||||
false => {
|
|
||||||
let absrange = (self.max_x - self.min_x).abs();
|
let absrange = (self.max_x - self.min_x).abs();
|
||||||
let resolution: f64 = (self.pixel_width as f64 / absrange) as f64;
|
let resolution: f64 = (self.pixel_width as f64 / absrange) as f64;
|
||||||
self.back_cache = Some(
|
self.back_cache = Some(
|
||||||
@ -180,25 +179,22 @@ impl Function {
|
|||||||
.map(|(x, y)| Value::new(x, y))
|
.map(|(x, y)| Value::new(x, y))
|
||||||
.collect(),
|
.collect(),
|
||||||
);
|
);
|
||||||
self.back_cache.as_ref().unwrap().clone()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.back_cache.as_ref().unwrap().clone()
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if self.integral {
|
if self.integral {
|
||||||
let front_bars: (BarChart, f64) = match self.front_cache.is_some() {
|
let front_bars: (BarChart, f64) = {
|
||||||
true => {
|
if self.front_cache.is_none() {
|
||||||
let cache = self.front_cache.as_ref().unwrap();
|
|
||||||
(BarChart::new(cache.0.clone()), cache.1)
|
|
||||||
}
|
|
||||||
false => {
|
|
||||||
let (data, area) = self.integral_rectangles();
|
let (data, area) = self.integral_rectangles();
|
||||||
let bars: Vec<Bar> = data.iter().map(|(x, y)| Bar::new(*x, *y)).collect();
|
self.front_cache =
|
||||||
|
Some((data.iter().map(|(x, y)| Bar::new(*x, *y)).collect(), area));
|
||||||
let output = (bars, area);
|
|
||||||
self.front_cache = Some(output.clone());
|
|
||||||
(BarChart::new(output.0), output.1)
|
|
||||||
}
|
}
|
||||||
|
let cache = self.front_cache.as_ref().unwrap();
|
||||||
|
(BarChart::new(cache.0.clone()), cache.1)
|
||||||
};
|
};
|
||||||
|
|
||||||
(back_values, Some(front_bars))
|
(back_values, Some(front_bars))
|
||||||
} else {
|
} else {
|
||||||
(back_values, None)
|
(back_values, None)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user