From e201d61045e356fe0d3dad3f67548b94307481d1 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Thu, 3 Mar 2022 21:35:03 -0500 Subject: [PATCH] simplify --- src/function.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/function.rs b/src/function.rs index 6e048fb..6d9df35 100644 --- a/src/function.rs +++ b/src/function.rs @@ -186,14 +186,11 @@ impl Function { let step = (self.integral_min_x - self.integral_max_x).abs() / (self.integral_num as f64); - let half_step = step / 2.0; let data2: Vec<(f64, f64)> = (1..=self.integral_num) .map(|e| { let x: f64 = ((e as f64) * step) + self.integral_min_x; - let x2: f64 = match x.is_sign_positive() { - true => x + step, - false => x - step, - }; + let step_offset = step * x.signum(); + let x2: f64 = x + step_offset; let (left_x, right_x) = match x.is_sign_positive() { true => (x, x2), @@ -201,10 +198,7 @@ impl Function { }; ( - match x.is_sign_positive() { - true => x + half_step, - false => x - half_step, - }, + x + (step_offset / 2.0), match self.sum { RiemannSum::Left => self.run_func(left_x), RiemannSum::Right => self.run_func(right_x),