remove some unused logic
This commit is contained in:
parent
5d4c2838a0
commit
0deff05ab5
@ -13,22 +13,10 @@ use epi::{Frame, Storage};
|
||||
use include_flate::flate;
|
||||
use instant::Duration;
|
||||
use shadow_rs::shadow;
|
||||
use std::fmt::{self, Debug};
|
||||
use std::ops::RangeInclusive;
|
||||
|
||||
shadow!(build);
|
||||
|
||||
// Represents the method in which an integral should be displayed
|
||||
#[derive(PartialEq, Debug, Copy, Clone)]
|
||||
enum IntegralDisplay {
|
||||
Rectangles,
|
||||
Line,
|
||||
}
|
||||
|
||||
impl fmt::Display for IntegralDisplay {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{:?}", self) }
|
||||
}
|
||||
|
||||
// Constant string that has a string containing information about the build.
|
||||
const BUILD_INFO: &str = formatc!(
|
||||
"Commit: {} ({})\nBuild Date: {}\nRust Channel: {}\nRust Version: {}",
|
||||
@ -120,9 +108,6 @@ struct AppSettings {
|
||||
// Number of rectangles used to calculate integral
|
||||
pub integral_num: usize,
|
||||
|
||||
// Stores how integrals should be displayed
|
||||
pub integral_display_type: IntegralDisplay,
|
||||
|
||||
// Stores whether or not dark mode is enabled
|
||||
pub dark_mode: bool,
|
||||
}
|
||||
@ -137,7 +122,6 @@ impl Default for AppSettings {
|
||||
integral_min_x: DEFAULT_MIN_X,
|
||||
integral_max_x: DEFAULT_MAX_X,
|
||||
integral_num: DEFAULT_INTEGRAL_NUM,
|
||||
integral_display_type: IntegralDisplay::Rectangles,
|
||||
dark_mode: true,
|
||||
}
|
||||
}
|
||||
@ -186,23 +170,6 @@ impl MathApp {
|
||||
ui.selectable_value(&mut self.settings.sum, RiemannSum::Right, "Right");
|
||||
});
|
||||
|
||||
/*
|
||||
ComboBox::from_label("Integral Display")
|
||||
.selected_text(self.settings.integral_display_type.to_string())
|
||||
.show_ui(ui, |ui| {
|
||||
ui.selectable_value(
|
||||
&mut self.settings.integral_display_type,
|
||||
IntegralDisplay::Rectangles,
|
||||
"Rectangles",
|
||||
);
|
||||
ui.selectable_value(
|
||||
&mut self.settings.integral_display_type,
|
||||
IntegralDisplay::Line,
|
||||
"Line",
|
||||
);
|
||||
});
|
||||
*/
|
||||
|
||||
let min_x_old = self.settings.integral_min_x;
|
||||
let min_x_changed = ui
|
||||
.add(
|
||||
@ -532,20 +499,16 @@ impl epi::App for MathApp {
|
||||
}
|
||||
|
||||
if let Some(integral_data) = integral {
|
||||
let (integral_bar, integral_line, area) = integral_data;
|
||||
let integral_name = format!("Integral of {}", func_str);
|
||||
match self.settings.integral_display_type {
|
||||
IntegralDisplay::Rectangles => plot_ui.bar_chart(
|
||||
integral_bar
|
||||
plot_ui.bar_chart(
|
||||
integral_data
|
||||
.0
|
||||
.color(Color32::BLUE)
|
||||
.width(step)
|
||||
.name(integral_name),
|
||||
),
|
||||
IntegralDisplay::Line => plot_ui.line(
|
||||
integral_line.color(Color32::BLUE).name(integral_name),
|
||||
),
|
||||
}
|
||||
digits_precision(area, 8)
|
||||
);
|
||||
|
||||
digits_precision(integral_data.1, 8)
|
||||
} else {
|
||||
f64::NAN
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ pub struct FunctionEntry {
|
||||
pixel_width: usize,
|
||||
|
||||
back_cache: Option<Vec<Value>>,
|
||||
front_cache: Option<(Vec<Bar>, Vec<Value>, f64)>,
|
||||
front_cache: Option<(Vec<Bar>, f64)>,
|
||||
derivative_cache: Option<Vec<Value>>,
|
||||
|
||||
pub(crate) integral: bool,
|
||||
@ -153,13 +153,7 @@ impl FunctionEntry {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_back(
|
||||
&mut self,
|
||||
) -> (
|
||||
Vec<Value>,
|
||||
Option<(Vec<Bar>, Vec<Value>, f64)>,
|
||||
Option<Vec<Value>>,
|
||||
) {
|
||||
pub fn run_back(&mut self) -> (Vec<Value>, Option<(Vec<Bar>, f64)>, Option<Vec<Value>>) {
|
||||
let resolution: f64 = (self.pixel_width as f64 / (self.max_x - self.min_x).abs()) as f64;
|
||||
let back_values: Vec<Value> = {
|
||||
if self.back_cache.is_none() {
|
||||
@ -193,14 +187,11 @@ impl FunctionEntry {
|
||||
true => {
|
||||
if self.front_cache.is_none() {
|
||||
let (data, area) = self.integral_rectangles();
|
||||
self.front_cache = Some((
|
||||
data.iter().map(|(x, y, _)| Bar::new(*x, *y)).collect(),
|
||||
data.iter().map(|(x, _, y)| Value::new(*x, *y)).collect(),
|
||||
area,
|
||||
));
|
||||
self.front_cache =
|
||||
Some((data.iter().map(|(x, y)| Bar::new(*x, *y)).collect(), area));
|
||||
}
|
||||
let cache = self.front_cache.as_ref().unwrap();
|
||||
Some((cache.0.clone(), cache.1.clone(), cache.2))
|
||||
Some((cache.0.clone(), cache.1))
|
||||
}
|
||||
false => None,
|
||||
};
|
||||
@ -208,17 +199,13 @@ impl FunctionEntry {
|
||||
(back_values, integral_data, derivative_values)
|
||||
}
|
||||
|
||||
pub fn run(&mut self) -> (Line, Option<(BarChart, Line, f64)>, Option<Line>) {
|
||||
pub fn run(&mut self) -> (Line, Option<(BarChart, f64)>, Option<Line>) {
|
||||
let (back_values, integral_data_option, derivative_option) = self.run_back();
|
||||
|
||||
(
|
||||
Line::new(Values::from_values(back_values)),
|
||||
if let Some(integral_data) = integral_data_option {
|
||||
Some((
|
||||
BarChart::new(integral_data.0),
|
||||
Line::new(Values::from_values(integral_data.1)),
|
||||
integral_data.2,
|
||||
))
|
||||
Some((BarChart::new(integral_data.0), integral_data.1))
|
||||
} else {
|
||||
None
|
||||
},
|
||||
@ -228,7 +215,7 @@ impl FunctionEntry {
|
||||
}
|
||||
|
||||
// Creates and does the math for creating all the rectangles under the graph
|
||||
fn integral_rectangles(&self) -> (Vec<(f64, f64, f64)>, f64) {
|
||||
fn integral_rectangles(&self) -> (Vec<(f64, f64)>, f64) {
|
||||
if self.integral_min_x.is_nan() {
|
||||
panic!("integral_min_x is NaN")
|
||||
} else if self.integral_max_x.is_nan() {
|
||||
@ -239,7 +226,7 @@ impl FunctionEntry {
|
||||
|
||||
let mut last_positive: Option<bool> = None;
|
||||
let mut area: f64 = 0.0;
|
||||
let data2: Vec<(f64, f64, f64)> = (0..self.integral_num)
|
||||
let data2: Vec<(f64, f64)> = (0..self.integral_num)
|
||||
.map(|e| {
|
||||
let x: f64 = ((e as f64) * step) + self.integral_min_x;
|
||||
let step_offset = step * x.signum(); // store the offset here so it doesn't have to be calculated multiple times
|
||||
@ -266,9 +253,9 @@ impl FunctionEntry {
|
||||
area += y * step;
|
||||
}
|
||||
|
||||
(x + (step_offset / 2.0), y, area)
|
||||
(x + (step_offset / 2.0), y)
|
||||
})
|
||||
.filter(|(_, y, _)| !y.is_nan())
|
||||
.filter(|(_, y)| !y.is_nan())
|
||||
.collect();
|
||||
(data2, area)
|
||||
}
|
||||
@ -359,7 +346,7 @@ fn left_function_test() {
|
||||
assert!(bars.is_some());
|
||||
assert_eq!(back_values.len(), pixel_width);
|
||||
|
||||
assert_eq!(bars.clone().unwrap().2, area_target);
|
||||
assert_eq!(bars.clone().unwrap().1, area_target);
|
||||
|
||||
let vec_bars = bars.unwrap().0;
|
||||
assert_eq!(vec_bars.len(), integral_num);
|
||||
@ -376,17 +363,10 @@ fn left_function_test() {
|
||||
|
||||
assert!(bars.is_some());
|
||||
assert_eq!(back_values.len(), pixel_width);
|
||||
assert_eq!(bars.clone().unwrap().2, area_target);
|
||||
assert_eq!(bars.clone().unwrap().1, area_target);
|
||||
let bars_unwrapped = bars.unwrap();
|
||||
|
||||
assert_eq!(bars_unwrapped.0.iter().len(), integral_num);
|
||||
|
||||
let integral_line = bars_unwrapped.1;
|
||||
let vec_integral: Vec<(f64, f64)> =
|
||||
integral_line.iter().map(|ele| (ele.x, ele.y)).collect();
|
||||
assert_eq!(vec_integral.len(), integral_num);
|
||||
|
||||
assert_eq!(vec_integral[vec_integral.len() - 1].1, area_target);
|
||||
}
|
||||
}
|
||||
|
||||
@ -433,7 +413,7 @@ fn middle_function_test() {
|
||||
assert!(bars.is_some());
|
||||
assert_eq!(back_values.len(), pixel_width);
|
||||
|
||||
assert_eq!(bars.clone().unwrap().2, area_target);
|
||||
assert_eq!(bars.clone().unwrap().1, area_target);
|
||||
|
||||
let vec_bars = bars.unwrap().0;
|
||||
assert_eq!(vec_bars.len(), integral_num);
|
||||
@ -450,17 +430,10 @@ fn middle_function_test() {
|
||||
|
||||
assert!(bars.is_some());
|
||||
assert_eq!(back_values.len(), pixel_width);
|
||||
assert_eq!(bars.clone().unwrap().2, area_target);
|
||||
assert_eq!(bars.clone().unwrap().1, area_target);
|
||||
let bars_unwrapped = bars.unwrap();
|
||||
|
||||
assert_eq!(bars_unwrapped.0.iter().len(), integral_num);
|
||||
|
||||
let integral_line = bars_unwrapped.1;
|
||||
let vec_integral: Vec<(f64, f64)> =
|
||||
integral_line.iter().map(|ele| (ele.x, ele.y)).collect();
|
||||
assert_eq!(vec_integral.len(), integral_num);
|
||||
|
||||
assert_eq!(vec_integral[vec_integral.len() - 1].1, area_target);
|
||||
}
|
||||
}
|
||||
|
||||
@ -507,7 +480,7 @@ fn right_function_test() {
|
||||
assert!(bars.is_some());
|
||||
assert_eq!(back_values.len(), pixel_width);
|
||||
|
||||
assert_eq!(bars.clone().unwrap().2, area_target);
|
||||
assert_eq!(bars.clone().unwrap().1, area_target);
|
||||
|
||||
let vec_bars = bars.unwrap().0;
|
||||
assert_eq!(vec_bars.len(), integral_num);
|
||||
@ -524,16 +497,9 @@ fn right_function_test() {
|
||||
|
||||
assert!(bars.is_some());
|
||||
assert_eq!(back_values.len(), pixel_width);
|
||||
assert_eq!(bars.clone().unwrap().2, area_target);
|
||||
assert_eq!(bars.clone().unwrap().1, area_target);
|
||||
let bars_unwrapped = bars.unwrap();
|
||||
|
||||
assert_eq!(bars_unwrapped.0.iter().len(), integral_num);
|
||||
|
||||
let integral_line = bars_unwrapped.1;
|
||||
let vec_integral: Vec<(f64, f64)> =
|
||||
integral_line.iter().map(|ele| (ele.x, ele.y)).collect();
|
||||
assert_eq!(vec_integral.len(), integral_num);
|
||||
|
||||
assert_eq!(vec_integral[vec_integral.len() - 1].1, area_target);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user