From 22c656d0be6dd5356f8839fae716174a9fe474c7 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Fri, 19 Jan 2024 18:11:56 +0100 Subject: only calculate evey point once --- src/main.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 90fc7ea..34adc14 100644 --- a/src/main.rs +++ b/src/main.rs @@ -227,19 +227,18 @@ impl canvas::Program for Graph { state.map_coords(end_x as f32, 0.0), ); frame.stroke(&line, zeroline.clone()); - + let mut y1 = self + .func + .eval( + FunctionArgument::new(vec![Complex::new(start_x as f64, 0.0)]), + &self.ctx, + ) + .unwrap() + .real as f32; for x in start_x..end_x { for d in 0..10 { let d = d as f32 / 10.0; let x1 = x as f32 + d; - let y1 = self - .func - .eval( - FunctionArgument::new(vec![Complex::new(x1 as f64, 0.0)]), - &self.ctx, - ) - .unwrap() - .real as f32; let x2 = x as f32 + d + 0.1; let y2 = self .func @@ -253,6 +252,7 @@ impl canvas::Program for Graph { let line = Path::line(state.map_coords(x1, y1), state.map_coords(x2, y2)); frame.stroke(&line, graphline.clone()) } + y1 = y2; } } }); -- cgit v1.2.3-70-g09d2