From 1f39756998799821bbc9431e56fa13e9b877cbaa Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Mon, 16 May 2022 11:25:30 -0400 Subject: [PATCH] add `misc::almost_variable` --- src/misc.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/misc.rs b/src/misc.rs index 9ee63e1..4d6c293 100644 --- a/src/misc.rs +++ b/src/misc.rs @@ -304,6 +304,20 @@ pub fn step_helper(max_i: usize, min_x: &f64, step: &f64) -> Vec { (0..max_i).map(|x| (x as f64 * step) + min_x).collect() } +/// Attempts to see what variable `x` is almost +// TODO: use in hovering over points +#[allow(dead_code)] +pub fn almost_variable(x: f64) -> Option { + const EPSILON: f32 = f32::EPSILON * 2.0; + if emath::almost_equal(x as f32, std::f32::consts::E, EPSILON) { + return Some('e'); + } else if emath::almost_equal(x as f32, std::f32::consts::PI, EPSILON) { + return Some('π'); + } else { + None + } +} + pub const HASH_LENGTH: usize = 8; #[allow(dead_code)]