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 include_flate::flate;
|
||||||
use instant::Duration;
|
use instant::Duration;
|
||||||
use shadow_rs::shadow;
|
use shadow_rs::shadow;
|
||||||
use std::fmt::{self, Debug};
|
|
||||||
use std::ops::RangeInclusive;
|
use std::ops::RangeInclusive;
|
||||||
|
|
||||||
shadow!(build);
|
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.
|
// Constant string that has a string containing information about the build.
|
||||||
const BUILD_INFO: &str = formatc!(
|
const BUILD_INFO: &str = formatc!(
|
||||||
"Commit: {} ({})\nBuild Date: {}\nRust Channel: {}\nRust Version: {}",
|
"Commit: {} ({})\nBuild Date: {}\nRust Channel: {}\nRust Version: {}",
|
||||||
@ -120,9 +108,6 @@ struct AppSettings {
|
|||||||
// Number of rectangles used to calculate integral
|
// Number of rectangles used to calculate integral
|
||||||
pub integral_num: usize,
|
pub integral_num: usize,
|
||||||
|
|
||||||
// Stores how integrals should be displayed
|
|
||||||
pub integral_display_type: IntegralDisplay,
|
|
||||||
|
|
||||||
// Stores whether or not dark mode is enabled
|
// Stores whether or not dark mode is enabled
|
||||||
pub dark_mode: bool,
|
pub dark_mode: bool,
|
||||||
}
|
}
|
||||||
@ -137,7 +122,6 @@ impl Default for AppSettings {
|
|||||||
integral_min_x: DEFAULT_MIN_X,
|
integral_min_x: DEFAULT_MIN_X,
|
||||||
integral_max_x: DEFAULT_MAX_X,
|
integral_max_x: DEFAULT_MAX_X,
|
||||||
integral_num: DEFAULT_INTEGRAL_NUM,
|
integral_num: DEFAULT_INTEGRAL_NUM,
|
||||||
integral_display_type: IntegralDisplay::Rectangles,
|
|
||||||
dark_mode: true,
|
dark_mode: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -186,23 +170,6 @@ impl MathApp {
|
|||||||
ui.selectable_value(&mut self.settings.sum, RiemannSum::Right, "Right");
|
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_old = self.settings.integral_min_x;
|
||||||
let min_x_changed = ui
|
let min_x_changed = ui
|
||||||
.add(
|
.add(
|
||||||
@ -532,20 +499,16 @@ impl epi::App for MathApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Some(integral_data) = integral {
|
if let Some(integral_data) = integral {
|
||||||
let (integral_bar, integral_line, area) = integral_data;
|
|
||||||
let integral_name = format!("Integral of {}", func_str);
|
let integral_name = format!("Integral of {}", func_str);
|
||||||
match self.settings.integral_display_type {
|
plot_ui.bar_chart(
|
||||||
IntegralDisplay::Rectangles => plot_ui.bar_chart(
|
integral_data
|
||||||
integral_bar
|
.0
|
||||||
.color(Color32::BLUE)
|
.color(Color32::BLUE)
|
||||||
.width(step)
|
.width(step)
|
||||||
.name(integral_name),
|
.name(integral_name),
|
||||||
),
|
);
|
||||||
IntegralDisplay::Line => plot_ui.line(
|
|
||||||
integral_line.color(Color32::BLUE).name(integral_name),
|
digits_precision(integral_data.1, 8)
|
||||||
),
|
|
||||||
}
|
|
||||||
digits_precision(area, 8)
|
|
||||||
} else {
|
} else {
|
||||||
f64::NAN
|
f64::NAN
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,7 +35,7 @@ pub struct FunctionEntry {
|
|||||||
pixel_width: usize,
|
pixel_width: usize,
|
||||||
|
|
||||||
back_cache: Option<Vec<Value>>,
|
back_cache: Option<Vec<Value>>,
|
||||||
front_cache: Option<(Vec<Bar>, Vec<Value>, f64)>,
|
front_cache: Option<(Vec<Bar>, f64)>,
|
||||||
derivative_cache: Option<Vec<Value>>,
|
derivative_cache: Option<Vec<Value>>,
|
||||||
|
|
||||||
pub(crate) integral: bool,
|
pub(crate) integral: bool,
|
||||||
@ -153,13 +153,7 @@ impl FunctionEntry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_back(
|
pub fn run_back(&mut self) -> (Vec<Value>, Option<(Vec<Bar>, f64)>, Option<Vec<Value>>) {
|
||||||
&mut self,
|
|
||||||
) -> (
|
|
||||||
Vec<Value>,
|
|
||||||
Option<(Vec<Bar>, Vec<Value>, f64)>,
|
|
||||||
Option<Vec<Value>>,
|
|
||||||
) {
|
|
||||||
let resolution: f64 = (self.pixel_width as f64 / (self.max_x - self.min_x).abs()) as f64;
|
let resolution: f64 = (self.pixel_width as f64 / (self.max_x - self.min_x).abs()) as f64;
|
||||||
let back_values: Vec<Value> = {
|
let back_values: Vec<Value> = {
|
||||||
if self.back_cache.is_none() {
|
if self.back_cache.is_none() {
|
||||||
@ -193,14 +187,11 @@ impl FunctionEntry {
|
|||||||
true => {
|
true => {
|
||||||
if self.front_cache.is_none() {
|
if self.front_cache.is_none() {
|
||||||
let (data, area) = self.integral_rectangles();
|
let (data, area) = self.integral_rectangles();
|
||||||
self.front_cache = Some((
|
self.front_cache =
|
||||||
data.iter().map(|(x, y, _)| Bar::new(*x, *y)).collect(),
|
Some((data.iter().map(|(x, y)| Bar::new(*x, *y)).collect(), area));
|
||||||
data.iter().map(|(x, _, y)| Value::new(*x, *y)).collect(),
|
|
||||||
area,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
let cache = self.front_cache.as_ref().unwrap();
|
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,
|
false => None,
|
||||||
};
|
};
|
||||||
@ -208,17 +199,13 @@ impl FunctionEntry {
|
|||||||
(back_values, integral_data, derivative_values)
|
(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();
|
let (back_values, integral_data_option, derivative_option) = self.run_back();
|
||||||
|
|
||||||
(
|
(
|
||||||
Line::new(Values::from_values(back_values)),
|
Line::new(Values::from_values(back_values)),
|
||||||
if let Some(integral_data) = integral_data_option {
|
if let Some(integral_data) = integral_data_option {
|
||||||
Some((
|
Some((BarChart::new(integral_data.0), integral_data.1))
|
||||||
BarChart::new(integral_data.0),
|
|
||||||
Line::new(Values::from_values(integral_data.1)),
|
|
||||||
integral_data.2,
|
|
||||||
))
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
@ -228,7 +215,7 @@ impl FunctionEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Creates and does the math for creating all the rectangles under the graph
|
// 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() {
|
if self.integral_min_x.is_nan() {
|
||||||
panic!("integral_min_x is NaN")
|
panic!("integral_min_x is NaN")
|
||||||
} else if self.integral_max_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 last_positive: Option<bool> = None;
|
||||||
let mut area: f64 = 0.0;
|
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| {
|
.map(|e| {
|
||||||
let x: f64 = ((e as f64) * step) + self.integral_min_x;
|
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
|
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;
|
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();
|
.collect();
|
||||||
(data2, area)
|
(data2, area)
|
||||||
}
|
}
|
||||||
@ -359,7 +346,7 @@ fn left_function_test() {
|
|||||||
assert!(bars.is_some());
|
assert!(bars.is_some());
|
||||||
assert_eq!(back_values.len(), pixel_width);
|
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;
|
let vec_bars = bars.unwrap().0;
|
||||||
assert_eq!(vec_bars.len(), integral_num);
|
assert_eq!(vec_bars.len(), integral_num);
|
||||||
@ -376,17 +363,10 @@ fn left_function_test() {
|
|||||||
|
|
||||||
assert!(bars.is_some());
|
assert!(bars.is_some());
|
||||||
assert_eq!(back_values.len(), pixel_width);
|
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();
|
let bars_unwrapped = bars.unwrap();
|
||||||
|
|
||||||
assert_eq!(bars_unwrapped.0.iter().len(), integral_num);
|
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!(bars.is_some());
|
||||||
assert_eq!(back_values.len(), pixel_width);
|
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;
|
let vec_bars = bars.unwrap().0;
|
||||||
assert_eq!(vec_bars.len(), integral_num);
|
assert_eq!(vec_bars.len(), integral_num);
|
||||||
@ -450,17 +430,10 @@ fn middle_function_test() {
|
|||||||
|
|
||||||
assert!(bars.is_some());
|
assert!(bars.is_some());
|
||||||
assert_eq!(back_values.len(), pixel_width);
|
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();
|
let bars_unwrapped = bars.unwrap();
|
||||||
|
|
||||||
assert_eq!(bars_unwrapped.0.iter().len(), integral_num);
|
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!(bars.is_some());
|
||||||
assert_eq!(back_values.len(), pixel_width);
|
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;
|
let vec_bars = bars.unwrap().0;
|
||||||
assert_eq!(vec_bars.len(), integral_num);
|
assert_eq!(vec_bars.len(), integral_num);
|
||||||
@ -524,16 +497,9 @@ fn right_function_test() {
|
|||||||
|
|
||||||
assert!(bars.is_some());
|
assert!(bars.is_some());
|
||||||
assert_eq!(back_values.len(), pixel_width);
|
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();
|
let bars_unwrapped = bars.unwrap();
|
||||||
|
|
||||||
assert_eq!(bars_unwrapped.0.iter().len(), integral_num);
|
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