fix step/resolution logic and fix accuracy issues

This commit is contained in:
Simon Gardling 2022-05-16 10:53:17 -04:00
parent bee782035e
commit 73cb36cb50
4 changed files with 4 additions and 28 deletions

View File

@ -271,9 +271,9 @@ impl FunctionEntry {
return;
}
let step = (settings.plot_width as f64) / (settings.max_x - settings.min_x);
debug_assert!(step > 0.0);
let resolution_iter = resolution_helper(&settings.plot_width + 1, &settings.min_x, &step);
let resolution = (settings.max_x - settings.min_x) / (settings.plot_width as f64);
debug_assert!(resolution > 0.0);
let resolution_iter = step_helper(&settings.plot_width + 1, &settings.min_x, &resolution);
unsafe { assume(!resolution_iter.is_empty()) }
@ -410,7 +410,7 @@ impl FunctionEntry {
self.invalidate_integral();
}
let threshold: f64 = step / 2.0;
let threshold: f64 = resolution / 2.0;
let x_range = settings.min_x..settings.max_x;
// Calculates extrema

View File

@ -32,7 +32,6 @@ pub use crate::{
hashed_storage_create,
hashed_storage_read,
option_vec_printer,
resolution_helper,
step_helper,
SteppedVector,
},

View File

@ -299,13 +299,6 @@ where
.concat()
}
/// Returns a vector of length `max_i` starting at value `min_x` with resolution of `resolution`
pub fn resolution_helper(max_i: usize, min_x: &f64, resolution: &f64) -> Vec<f64> {
(0..max_i)
.map(|x| (x as f64 / resolution) + min_x)
.collect()
}
/// Returns a vector of length `max_i` starting at value `min_x` with step of `step`
pub fn step_helper(max_i: usize, min_x: &f64, step: &f64) -> Vec<f64> {
(0..max_i).map(|x| (x as f64 * step) + min_x).collect()

View File

@ -48,22 +48,6 @@ fn stepped_vector() {
// }
/// Tests [`resolution_helper`] to make sure it returns expected output
#[test]
fn resolution_helper() {
use ytbn_graphing_software::resolution_helper;
assert_eq!(
resolution_helper(10, &1.0, &1.0),
vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
);
assert_eq!(
resolution_helper(5, &-2.0, &1.0),
vec![-2.0, -1.0, 0.0, 1.0, 2.0]
);
assert_eq!(resolution_helper(3, &-2.0, &1.0), vec![-2.0, -1.0, 0.0]);
}
#[test]
fn step_helper() {