This commit is contained in:
Simon Gardling 2022-02-23 01:52:10 -05:00
parent 7a00ed62f6
commit 1dc42105f2
2 changed files with 8 additions and 18 deletions

View File

@ -233,9 +233,7 @@ impl ChartManager {
// 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
#[inline] #[inline]
fn integral_rectangles( fn integral_rectangles(&self, step: f32) -> (Vec<(f32, f32, f32)>, f32) {
&self, step: f32
) -> (Vec<(f32, f32, f32)>, f32) {
let data2: Vec<(f32, f32, f32)> = (0..self.num_interval) let data2: Vec<(f32, f32, f32)> = (0..self.num_interval)
.map(|e| { .map(|e| {
let x: f32 = ((e as f32) * step) + self.min_x; let x: f32 = ((e as f32) * step) + self.min_x;

View File

@ -1,5 +1,5 @@
use wasm_bindgen::prelude::*;
use meval::Expr; use meval::Expr;
use wasm_bindgen::prelude::*;
pub type DrawResult<T> = Result<T, Box<dyn std::error::Error>>; pub type DrawResult<T> = Result<T, Box<dyn std::error::Error>>;
@ -90,7 +90,7 @@ pub fn add_asterisks(function_in: String) -> String {
pub struct Function { pub struct Function {
function: Box<dyn Fn(f64) -> f64>, function: Box<dyn Fn(f64) -> f64>,
func_str: String func_str: String,
} }
impl Function { impl Function {
@ -99,25 +99,18 @@ impl Function {
let func = expr.bind("x").unwrap(); let func = expr.bind("x").unwrap();
Self { Self {
function: Box::new(func), function: Box::new(func),
func_str func_str,
} }
} }
#[inline] #[inline]
pub fn run(&self, x: f32) -> f32 { pub fn run(&self, x: f32) -> f32 { (self.function)(x as f64) as f32 }
(self.function)(x as f64) as f32
}
pub fn str_compare(&self, other_string: String) -> bool { pub fn str_compare(&self, other_string: String) -> bool { self.func_str == other_string }
self.func_str == other_string
}
pub fn get_string(&self) -> String { pub fn get_string(&self) -> String { self.func_str.clone() }
self.func_str.clone()
}
} }
/// Result of screen to chart coordinates conversion. /// Result of screen to chart coordinates conversion.
#[wasm_bindgen] #[wasm_bindgen]
pub struct Point { pub struct Point {
@ -211,7 +204,6 @@ fn asterisk_test() {
assert_eq!(&add_asterisks("x!".to_string()), "x!"); assert_eq!(&add_asterisks("x!".to_string()), "x!");
} }
// Tests cache when initialized with value // Tests cache when initialized with value
#[test] #[test]
fn cache_test_full() { fn cache_test_full() {
@ -232,4 +224,4 @@ fn cache_test_empty() {
assert_eq!(cache.is_valid(), false); assert_eq!(cache.is_valid(), false);
cache.set("data"); cache.set("data");
assert_eq!(cache.is_valid(), true); assert_eq!(cache.is_valid(), true);
} }