99//! * Linear
1010//! * Power
1111//!
12- //! The crate uses generics to allow interpolation of any type for
13- //! which certain traits are defined.
12+ //! The crate uses generics to allow interpolation of any type for which
13+ //! certain traits are defined.
1414//!
15- //! I.e. you can use this crate to interpolate splines in 1D, 2D, 3D,
16- //! etc.
15+ //! I.e. you can use this crate to interpolate splines in 1D, 2D, 3D, etc.
1716//!
1817//! ## Cargo Features
1918//!
2019//! * `monotonic_check` -- The [`spline_inverse()`] code will check if the knot
2120//! vector is monotonic (on by default).
2221//!
23- //! The crate does not depend on the standard library (i.e. is marked
24- //! `no_std`).
22+ //! The crate does not depend on the standard library (i.e. is marked `no_std`).
2523//!
2624//! ## Example
2725//!
28- //! Using a combination of [`spline()`] and [`spline_inverse()`] it is
29- //! possible to compute a full spline-with-non-uniform-abscissæ:
26+ //! Using a combination of [`spline()`] and [`spline_inverse()`] it is possible
27+ //! to compute a full spline-with-non-uniform-abscissæ:
3028//!
3129//! ```
3230//! use uniform_cubic_splines::{basis::CatmullRom, spline, spline_inverse};
5149//! [Open Shading Language](https://github.com/imageworks/OpenShadingLanguage)
5250//! C++ source.
5351//!
54- //! If you come from a background of computer graphics/shading
55- //! languages used in offline rendering this crate should feel like
56- //! home.
52+ //! If you come from a background of computer graphics/shading languages used in
53+ //! offline rendering this crate should feel like home.
5754use core:: ops:: { Add , Mul } ;
5855use lerp:: Lerp ;
5956use num_traits:: {
@@ -67,23 +64,22 @@ mod basis_macros;
6764pub mod basis;
6865use basis:: * ;
6966
70- /// As `x` varies from `0` to `1`, this function returns the value
71- /// of a cubic interpolation of uniformly spaced `knots`.
72- /// The input value `x` will be clamped to the range `[0, 1]`.
67+ /// As `x` varies from `0` to `1`, this function returns the value of a cubic
68+ /// interpolation of uniformly spaced `knots`.
7369///
74- /// Depending on the choosen [`Basis`] the length of the `knots`
75- /// parameter has certain constraints.
70+ /// The input value `x` will be clamped to the range `[0, 1]`.
7671///
77- /// If these constraints are not honored the code produces
78- /// undefined behavior in a release build.
72+ /// Depending on the choosen [`Basis`] the length of the `knots` parameter has
73+ /// certain constraints. If these constraints are not honored the code will
74+ /// produce undefined results in a `release` build.
7975///
8076/// # Panics
8177///
82- /// If the `knots` slice has the wrong length this will panic when
83- /// the code is built with debug assertion enabled.
78+ /// If the `knots` slice has the wrong length this will panic with a resp. error
79+ /// message when the code is built with debug assertion enabled.
8480///
85- /// Use the [`is_len_ok()`] helper to check if a knot slice you want
86- /// to feed to this function has the correct length.
81+ /// Use the [`is_len_ok()`] helper to check if a knot slice you want to feed to
82+ /// this function has the correct length.
8783///
8884/// # Examples
8985///
@@ -99,7 +95,7 @@ pub fn spline<B, T, U>(x: T, knots: &[U]) -> U
9995where
10096 B : Basis < T > ,
10197 T : AsPrimitive < usize > + Float + FromPrimitive + PartialOrd + One + Zero ,
102- U : Add < Output = U > + Copy + Mul < T , Output = U > + Zero ,
98+ U : Add < Output = U > + Clone + Mul < T , Output = U > + Zero ,
10399{
104100 // UX
105101 #[ cfg( debug_assertions) ]
@@ -145,12 +141,15 @@ where
145141 . map ( |row| {
146142 cv. iter ( )
147143 . zip ( row. iter ( ) )
148- . fold ( U :: zero ( ) , |total, ( cv, basis) | total + * cv * * basis)
144+ . fold ( U :: zero ( ) , |total, ( cv, basis) | {
145+ total + cv. clone ( ) * * basis
146+ } )
149147 } )
150148 . fold ( Zero :: zero ( ) , |acc, elem| acc * x + elem)
151149}
152150
153151/// Computes the inverse of the [`spline()`] function.
152+ ///
154153/// This returns the value `x` for which `spline(x)` would return `y`.
155154///
156155/// Results are undefined if the `knots` do not specifiy a monotonic (only
@@ -286,7 +285,7 @@ where
286285{
287286 // Use the Regula Falsi method, falling back to bisection if it
288287 // hasn't converged after 3/4 of the maximum number of iterations.
289- // See, e.g., Numerical Recipes for the basic ideas behind both
288+ // See, e.g., " Numerical Recipes" for the basic ideas behind both
290289 // methods.
291290 let mut v0 = function ( x_min) ;
292291 let mut v1 = function ( x_max) ;
0 commit comments