Documentation, step 4.
This commit is contained in:
parent
e88da58a87
commit
e7ecc9819a
@ -3,13 +3,22 @@
|
|||||||
//! The [`Interpolate`] trait is the central concept of the crate. It enables a spline to be
|
//! The [`Interpolate`] trait is the central concept of the crate. It enables a spline to be
|
||||||
//! sampled at by interpolating in between control points.
|
//! sampled at by interpolating in between control points.
|
||||||
//!
|
//!
|
||||||
//! In order for a type to be used in [`Spline<K, V>`], some properties must be met:
|
//! In order for a type to be used in [`Spline<K, V>`], some properties must be met about the `K`
|
||||||
|
//! type must implementing several traits:
|
||||||
//!
|
//!
|
||||||
//! - The `K` type must implement several traits:
|
//! - [`One`], giving a neutral element for the multiplication monoid.
|
||||||
//! - [`One`], giving a neutral element for the multiplication monoid.
|
//! - [`Additive`], making the type additive (i.e. one can add or subtract with it).
|
||||||
//! - [`Additive`], making the type additive (i.e. one can add or subtract with it).
|
//! - [`Linear`], unlocking linear combinations, required for interpolating.
|
||||||
//! - [`Linear`], unlocking linear combinations, required for interpolating.
|
//! - [`Trigo`], a trait giving *π* and *cosine*, required for e.g. cosine interpolation.
|
||||||
//! - [`Trigo`], a trait giving *π* and *cosine*, required for e.g. cosine interpolation.
|
//!
|
||||||
|
//! Feel free to have a look at current implementors for further help.
|
||||||
|
//!
|
||||||
|
//! > *Why doesn’t this crate use [num-traits] instead of
|
||||||
|
//! > defining its own traits?*
|
||||||
|
//!
|
||||||
|
//! The reason for this is quite simple: this crate provides a `no_std` support, which is not
|
||||||
|
//! currently available easily with [num-traits]. Also, if something changes in [num-traits] with
|
||||||
|
//! those traits, it would make this whole crate unstable.
|
||||||
//!
|
//!
|
||||||
//! [`Interpolate`]: crate::interpolate::Interpolate
|
//! [`Interpolate`]: crate::interpolate::Interpolate
|
||||||
//! [`Spline<K, V>`]: crate::spline::Spline
|
//! [`Spline<K, V>`]: crate::spline::Spline
|
||||||
@ -17,6 +26,7 @@
|
|||||||
//! [`Additive`]: crate::interpolate::Additive
|
//! [`Additive`]: crate::interpolate::Additive
|
||||||
//! [`Linear`]: crate::interpolate::Linear
|
//! [`Linear`]: crate::interpolate::Linear
|
||||||
//! [`Trigo`]: crate::interpolate::Trigo
|
//! [`Trigo`]: crate::interpolate::Trigo
|
||||||
|
//! [num-traits]: https://crates.io/crates/num-traits
|
||||||
|
|
||||||
#[cfg(feature = "std")] use std::f32;
|
#[cfg(feature = "std")] use std::f32;
|
||||||
#[cfg(not(feature = "std"))] use core::f32;
|
#[cfg(not(feature = "std"))] use core::f32;
|
||||||
@ -178,10 +188,10 @@ impl Trigo for f64 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default implementation of Interpolate::cubic_hermite`.
|
/// Default implementation of [`Interpolate::cubic_hermite`].
|
||||||
//
|
///
|
||||||
// `V` is the value being interpolated. `T` is the sampling value (also sometimes called time).
|
/// `V` is the value being interpolated. `T` is the sampling value (also sometimes called time).
|
||||||
pub(crate) fn cubic_hermite_def<V, T>(x: (V, T), a: (V, T), b: (V, T), y: (V, T), t: T) -> V
|
pub fn cubic_hermite_def<V, T>(x: (V, T), a: (V, T), b: (V, T), y: (V, T), t: T) -> V
|
||||||
where V: Linear<T>,
|
where V: Linear<T>,
|
||||||
T: Additive + Mul<T, Output = T> + One {
|
T: Additive + Mul<T, Output = T> + One {
|
||||||
// some stupid generic constants, because Rust doesn’t have polymorphic literals…
|
// some stupid generic constants, because Rust doesn’t have polymorphic literals…
|
||||||
|
11
src/lib.rs
11
src/lib.rs
@ -33,11 +33,11 @@
|
|||||||
//! # Interpolate values
|
//! # Interpolate values
|
||||||
//!
|
//!
|
||||||
//! The whole purpose of splines is to interpolate discrete values to yield continuous ones. This is
|
//! The whole purpose of splines is to interpolate discrete values to yield continuous ones. This is
|
||||||
//! usually done with the `Spline::sample` method. This method expects the interpolation parameter
|
//! usually done with the [`Spline::sample`] method. This method expects the sampling parameter
|
||||||
//! (often, this will be the time of your simulation) as argument and will yield an interpolated
|
//! (often, this will be the time of your simulation) as argument and will yield an interpolated
|
||||||
//! value.
|
//! value.
|
||||||
//!
|
//!
|
||||||
//! If you try to sample in out-of-bounds interpolation parameter, you’ll get no value.
|
//! If you try to sample in out-of-bounds sampling parameter, you’ll get no value.
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
//! # use splines::{Interpolation, Key, Spline};
|
//! # use splines::{Interpolation, Key, Spline};
|
||||||
@ -62,6 +62,13 @@
|
|||||||
//! assert_eq!(spline.clamped_sample(1.1), Some(10.)); // clamped to the last key
|
//! assert_eq!(spline.clamped_sample(1.1), Some(10.)); // clamped to the last key
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
|
//! # Polymorphic sampling types
|
||||||
|
//!
|
||||||
|
//! [`Spline`] curves are parametered both by the carried value (being interpolated) but also the
|
||||||
|
//! sampling type. It’s very typical to use `f32` or `f64` but really, you can in theory use any
|
||||||
|
//! kind of type; that type must, however, implement a contract defined by a set of traits to
|
||||||
|
//! implement. See [the documentation of this module](crate::interpolate) for further details.
|
||||||
|
//!
|
||||||
//! # Features and customization
|
//! # Features and customization
|
||||||
//!
|
//!
|
||||||
//! This crate was written with features baked in and hidden behind feature-gates. The idea is that
|
//! This crate was written with features baked in and hidden behind feature-gates. The idea is that
|
||||||
|
Loading…
Reference in New Issue
Block a user