cleanup
This commit is contained in:
parent
50ef1d17f9
commit
490e4bffbd
26
src/misc.rs
26
src/misc.rs
@ -201,13 +201,15 @@ impl EguiHelper for Vec<Value> {
|
||||
fn to_tuple(&self) -> Vec<(f64, f64)> { self.iter().map(|ele| (ele.x, ele.y)).collect() }
|
||||
}
|
||||
|
||||
// /// Rounds f64 to `n` decimal places
|
||||
// pub fn decimal_round(x: f64, n: usize) -> f64 {
|
||||
// let large_number: f64 = 10.0_f64.powf(n as f64); // 10^n
|
||||
/*
|
||||
/// Rounds f64 to `n` decimal places
|
||||
pub fn decimal_round(x: f64, n: usize) -> f64 {
|
||||
let large_number: f64 = 10.0_f64.powf(n as f64); // 10^n
|
||||
|
||||
// // round and devide in order to cutoff after the `n`th decimal place
|
||||
// (x * large_number).round() / large_number
|
||||
// }
|
||||
// round and devide in order to cutoff after the `n`th decimal place
|
||||
(x * large_number).round() / large_number
|
||||
}
|
||||
*/
|
||||
|
||||
/// Helper that assists with using newton's method of finding roots, iterating over data `data`
|
||||
/// `threshold` is the target accuracy threshold
|
||||
@ -219,12 +221,6 @@ pub fn newtons_method_helper(
|
||||
threshold: &f64, range: &std::ops::Range<f64>, data: &[Value], f: &dyn Fn(f64) -> f64,
|
||||
f_1: &dyn Fn(f64) -> f64,
|
||||
) -> Vec<f64> {
|
||||
debug_assert!(!data.is_empty());
|
||||
|
||||
unsafe {
|
||||
assume(!data.is_empty());
|
||||
}
|
||||
|
||||
data.iter()
|
||||
.tuple_windows()
|
||||
.filter(|(prev, curr)| prev.y.is_finite() && curr.y.is_finite())
|
||||
@ -268,12 +264,6 @@ pub fn option_vec_printer<T: ToString>(data: &[Option<T>]) -> String
|
||||
where
|
||||
T: ToString,
|
||||
{
|
||||
debug_assert!(!data.is_empty());
|
||||
|
||||
unsafe {
|
||||
assume(!data.is_empty());
|
||||
}
|
||||
|
||||
let max_i: i32 = (data.len() as i32) - 1;
|
||||
[
|
||||
"[",
|
||||
|
||||
@ -26,28 +26,28 @@ fn stepped_vector() {
|
||||
assert_eq!(stepped_vector.get_index((max + 1) as f64), None);
|
||||
}
|
||||
|
||||
// /// Ensures [`decimal_round`] returns correct values
|
||||
// #[test]
|
||||
// fn decimal_round() {
|
||||
// use ytbn_graphing_software::decimal_round;
|
||||
/*
|
||||
/// Ensures [`decimal_round`] returns correct values
|
||||
#[test]
|
||||
fn decimal_round() {
|
||||
use ytbn_graphing_software::decimal_round;
|
||||
|
||||
// assert_eq!(decimal_round(0.00001, 1), 0.0);
|
||||
// assert_eq!(decimal_round(0.00001, 2), 0.0);
|
||||
// assert_eq!(decimal_round(0.00001, 3), 0.0);
|
||||
// assert_eq!(decimal_round(0.00001, 4), 0.0);
|
||||
// assert_eq!(decimal_round(0.00001, 5), 0.00001);
|
||||
assert_eq!(decimal_round(0.00001, 1), 0.0);
|
||||
assert_eq!(decimal_round(0.00001, 2), 0.0);
|
||||
assert_eq!(decimal_round(0.00001, 3), 0.0);
|
||||
assert_eq!(decimal_round(0.00001, 4), 0.0);
|
||||
assert_eq!(decimal_round(0.00001, 5), 0.00001);
|
||||
|
||||
// assert_eq!(decimal_round(0.12345, 1), 0.1);
|
||||
// assert_eq!(decimal_round(0.12345, 2), 0.12);
|
||||
// assert_eq!(decimal_round(0.12345, 3), 0.123);
|
||||
// assert_eq!(decimal_round(0.12345, 4), 0.1235); // rounds up
|
||||
// assert_eq!(decimal_round(0.12345, 5), 0.12345);
|
||||
assert_eq!(decimal_round(0.12345, 1), 0.1);
|
||||
assert_eq!(decimal_round(0.12345, 2), 0.12);
|
||||
assert_eq!(decimal_round(0.12345, 3), 0.123);
|
||||
assert_eq!(decimal_round(0.12345, 4), 0.1235); // rounds up
|
||||
assert_eq!(decimal_round(0.12345, 5), 0.12345);
|
||||
|
||||
// assert_eq!(decimal_round(1.9, 0), 2.0);
|
||||
// assert_eq!(decimal_round(1.9, 1), 1.9);
|
||||
// }
|
||||
|
||||
/// Tests [`resolution_helper`] to make sure it returns expected output
|
||||
assert_eq!(decimal_round(1.9, 0), 2.0);
|
||||
assert_eq!(decimal_round(1.9, 1), 1.9);
|
||||
}
|
||||
*/
|
||||
|
||||
#[test]
|
||||
fn step_helper() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user