Skip to content

Commit

Permalink
Refactored interpolation imports in three modules
Browse files Browse the repository at this point in the history
The codebase has been refactored so that the 'find_index_at_left_boundary' function is directly imported in the 'natural_cubic.rs', 'catmull_rom.rs', and 'linear.rs' modules. This change simplifies function calls within these modules, making the code easier to read and understand.
  • Loading branch information
nakashima-hikaru committed Jun 15, 2024
1 parent 0dd13bb commit 7a63090
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
5 changes: 2 additions & 3 deletions crates/qlab-math/src/interpolation/linear.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::interpolation;
use crate::interpolation::{Interpolator, Point2D};
use crate::interpolation::{find_index_at_left_boundary, Interpolator, Point2D};
use crate::value::Value;
use num_traits::real::Real;
use qlab_error::InterpolationError;
Expand Down Expand Up @@ -73,7 +72,7 @@ impl<V: Value> Interpolator<Linear<V>, V> for Linear<V> {
///
/// * `InvalidInput` - Represents an error when the input is invalid or out-of-bounds.
fn try_value(&self, x: V) -> Result<V, InterpolationError<V>> {
let pos = interpolation::find_index_at_left_boundary(&self.points, x)?;
let pos = find_index_at_left_boundary(&self.points, x)?;

Ok(self.points[pos].y
+ (self.points[pos + 1].y - self.points[pos].y)
Expand Down
5 changes: 2 additions & 3 deletions crates/qlab-math/src/interpolation/spline/catmull_rom.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::interpolation;
use crate::interpolation::spline::Value;
use crate::interpolation::{Interpolator, Point2D};
use crate::interpolation::{find_index_at_left_boundary, Interpolator, Point2D};
use nalgebra::{Matrix4, Vector4};
use qlab_error::InterpolationError;
use std::ops::Mul;
Expand Down Expand Up @@ -65,7 +64,7 @@ impl<V: Value> Interpolator<CatmullRom<V>, V> for CatmullRom<V> {
/// * Will panic if `V` cannot cast the constant `6`.
#[allow(clippy::too_many_lines)]
fn try_value(&self, x: V) -> Result<V, InterpolationError<V>> {
let pos = interpolation::find_index_at_left_boundary(&self.points, x)?;
let pos = find_index_at_left_boundary(&self.points, x)?;

let point = &self.points[pos];
let next_point = &self.points[pos + 1];
Expand Down
5 changes: 2 additions & 3 deletions crates/qlab-math/src/interpolation/spline/natural_cubic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::interpolation;
use crate::interpolation::spline::Value;
use crate::interpolation::{Interpolator, Point2DWithSlope};
use crate::interpolation::{find_index_at_left_boundary, Interpolator, Point2DWithSlope};
use crate::linear_algebra::tridiagonal_matrix::TridiagonalMatrix;
use qlab_error::InterpolationError;

Expand Down Expand Up @@ -106,7 +105,7 @@ impl<V: Value> Interpolator<NaturalCubic<V>, V> for NaturalCubic<V> {
/// * Will panic if `V` cannot cast constants.
///
fn try_value(&self, x: V) -> Result<V, InterpolationError<V>> {
let pos = interpolation::find_index_at_left_boundary(&self.points, x)?;
let pos = find_index_at_left_boundary(&self.points, x)?;
let point = &self.points[pos];
let next_point = &self.points[pos + 1];
let h = next_point.coordinate.x - point.coordinate.x;
Expand Down

0 comments on commit 7a63090

Please sign in to comment.