2.0.0.
This commit is contained in:
		
							
								
								
									
										15
									
								
								CHANGELOG.md
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								CHANGELOG.md
									
									
									
									
									
								
							| @@ -1,10 +1,15 @@ | ||||
| # 1.1.1 | ||||
| # 2.0.0 | ||||
|  | ||||
| > Mon Sep 22rd 2019 | ||||
| > Mon Sep 24th 2019 | ||||
|  | ||||
| ## Major changes | ||||
|  | ||||
| - Add support for [Bézier curves](https://en.wikipedia.org/wiki/B%C3%A9zier_curve). | ||||
| - Because of Bézier curves, the `Interpolation` type now has one more type variable to know how we | ||||
|   should interpolate with Bézier. | ||||
|  | ||||
| ## Minor changes | ||||
|  | ||||
| - Add support for [Bézier curves](https://en.wikipedia.org/wiki/B%C3%A9zier_curve). This is | ||||
|   normally a breaking change so it’s currently disabled by default and available via the | ||||
|   `"bezier"` feature-gate. | ||||
| - Add `Spline::get`, `Spline::get_mut` and `Spline::replace`. | ||||
|  | ||||
| # 1.0 | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| [package] | ||||
| name = "splines" | ||||
| version = "1.1.1" | ||||
| version = "2.0.0" | ||||
| license = "BSD-3-Clause" | ||||
| authors = ["Dimitri Sabadie <dimitri.sabadie@gmail.com>"] | ||||
| description = "Spline interpolation made easy" | ||||
| @@ -21,7 +21,6 @@ maintenance = { status = "actively-developed" } | ||||
|  | ||||
| [features] | ||||
| default = ["std"] | ||||
| bezier = [] | ||||
| impl-cgmath = ["cgmath"] | ||||
| impl-nalgebra = ["alga", "nalgebra", "num-traits"] | ||||
| serialization = ["serde", "serde_derive"] | ||||
|   | ||||
| @@ -98,12 +98,6 @@ So here’s a list of currently supported features and how to enable them: | ||||
|     - Compiling with the standard library is enabled by default. | ||||
|     - Use `default-features = []` in your `Cargo.toml` to disable. | ||||
|     - Enable explicitly with the `"std"` feature. | ||||
|   - **Extra interpolation modes.** | ||||
|     - In order not to introduce breaking changes, some feature-gates are added to augment the | ||||
|       [`Interpolation`] enum. | ||||
|     - Those feature-gates will disappear on the next major release of the crate. | ||||
|     - The following lists all currently available: | ||||
|       - `"bezier"`: [Bézier curves](https://en.wikipedia.org/wiki/B%C3%A9zier_curve). | ||||
|  | ||||
| [`Interpolation`]: crate::interpolation::Interpolation | ||||
|  | ||||
|   | ||||
| @@ -32,13 +32,11 @@ macro_rules! impl_interpolate_vec { | ||||
|         cubic_hermite_def(x, a, b, y, t) | ||||
|       } | ||||
|  | ||||
|       #[cfg(feature = "bezier")] | ||||
|       #[inline(always)] | ||||
|       fn quadratic_bezier(a: Self, u: Self, b: Self, t: T) -> Self { | ||||
|         quadratic_bezier_def(a, u, b, t) | ||||
|       } | ||||
|  | ||||
|       #[cfg(feature = "bezier")] | ||||
|       #[inline(always)] | ||||
|       fn cubic_bezier(a: Self, u: Self, v: Self, b: Self, t: T) -> Self { | ||||
|         cubic_bezier_def(a, u, v, b, t) | ||||
| @@ -76,13 +74,11 @@ where Self: InnerSpace<Scalar = T>, T: Additive + BaseFloat + One { | ||||
|     cubic_hermite_def(x, a, b, y, t) | ||||
|   } | ||||
|  | ||||
|   #[cfg(feature = "bezier")] | ||||
|   #[inline(always)] | ||||
|   fn quadratic_bezier(a: Self, u: Self, b: Self, t: T) -> Self { | ||||
|     quadratic_bezier_def(a, u, b, t) | ||||
|   } | ||||
|  | ||||
|   #[cfg(feature = "bezier")] | ||||
|   #[inline(always)] | ||||
|   fn cubic_bezier(a: Self, u: Self, v: Self, b: Self, t: T) -> Self { | ||||
|     cubic_bezier_def(a, u, v, b, t) | ||||
|   | ||||
| @@ -59,11 +59,9 @@ pub trait Interpolate<T>: Sized + Copy { | ||||
|   } | ||||
|  | ||||
|   /// Quadratic Bézier interpolation. | ||||
|   #[cfg(feature = "bezier")] | ||||
|   fn quadratic_bezier(a: Self, u: Self, b: Self, t: T) -> Self; | ||||
|  | ||||
|   /// Cubic Bézier interpolation. | ||||
|   #[cfg(feature = "bezier")] | ||||
|   fn cubic_bezier(a: Self, u: Self, v: Self, b: Self, t: T) -> Self; | ||||
| } | ||||
|  | ||||
| @@ -223,7 +221,6 @@ where V: Linear<T>, | ||||
| /// Default implementation of [`Interpolate::quadratic_bezier`]. | ||||
| /// | ||||
| /// `V` is the value being interpolated. `T` is the sampling value (also sometimes called time). | ||||
| #[cfg(feature = "bezier")] | ||||
| pub fn quadratic_bezier_def<V, T>(a: V, u: V, b: V, t: T) -> V | ||||
| where V: Linear<T>, | ||||
|       T: Additive + Mul<T, Output = T> + One { | ||||
| @@ -235,7 +232,6 @@ where V: Linear<T>, | ||||
| /// Default implementation of [`Interpolate::cubic_bezier`]. | ||||
| /// | ||||
| /// `V` is the value being interpolated. `T` is the sampling value (also sometimes called time). | ||||
| #[cfg(feature = "bezier")] | ||||
| pub fn cubic_bezier_def<V, T>(a: V, u: V, v: V, b: V, t: T) -> V | ||||
| where V: Linear<T>, | ||||
|       T: Additive + Mul<T, Output = T> + One { | ||||
| @@ -258,12 +254,10 @@ macro_rules! impl_interpolate_simple { | ||||
|         cubic_hermite_def(x, a, b, y, t) | ||||
|       } | ||||
|  | ||||
|       #[cfg(feature = "bezier")] | ||||
|       fn quadratic_bezier(a: Self, u: Self, b: Self, t: $t) -> Self { | ||||
|         quadratic_bezier_def(a, u, b, t) | ||||
|       } | ||||
|  | ||||
|       #[cfg(feature = "bezier")] | ||||
|       fn cubic_bezier(a: Self, u: Self, v: Self, b: Self, t: $t) -> Self { | ||||
|         cubic_bezier_def(a, u, v, b, t) | ||||
|       } | ||||
| @@ -285,12 +279,10 @@ macro_rules! impl_interpolate_via { | ||||
|         cubic_hermite_def((x, xt as $v), (a, at as $v), (b, bt as $v), (y, yt as $v), t as $v) | ||||
|       } | ||||
|  | ||||
|       #[cfg(feature = "bezier")] | ||||
|       fn quadratic_bezier(a: Self, u: Self, b: Self, t: $t) -> Self { | ||||
|         quadratic_bezier_def(a, u, b, t as $v) | ||||
|       } | ||||
|  | ||||
|       #[cfg(feature = "bezier")] | ||||
|       fn cubic_bezier(a: Self, u: Self, v: Self, b: Self, t: $t) -> Self { | ||||
|         cubic_bezier_def(a, u, v, b, t as $v) | ||||
|       } | ||||
|   | ||||
| @@ -5,7 +5,6 @@ | ||||
| /// Available kind of interpolations. | ||||
| /// | ||||
| /// Feel free to visit each variant for more documentation. | ||||
| #[cfg(feature = "bezier")] | ||||
| #[derive(Copy, Clone, Debug, Eq, PartialEq)] | ||||
| #[cfg_attr(feature = "serialization", derive(Deserialize, Serialize))] | ||||
| #[cfg_attr(feature = "serialization", serde(rename_all = "snake_case"))] | ||||
| @@ -40,48 +39,14 @@ pub enum Interpolation<T, V> { | ||||
|   ///   tangent used for the next control point is defined as the segment connecting that control | ||||
|   ///   point and the current control point’s associated point. This is called _quadratic Bézer | ||||
|   ///   interpolation_ and it kicks ass too, but a bit less than cubic. | ||||
|   #[cfg(feature = "bezier")] | ||||
|   Bezier(V), | ||||
|   #[doc(hidden)] | ||||
|   __NonExhaustive | ||||
| } | ||||
|  | ||||
| /// Available kind of interpolations. | ||||
| /// | ||||
| /// Feel free to visit each variant for more documentation. | ||||
| #[cfg(not(feature = "bezier"))] | ||||
| #[derive(Copy, Clone, Debug, Eq, PartialEq)] | ||||
| #[cfg_attr(feature = "serialization", derive(Deserialize, Serialize))] | ||||
| #[cfg_attr(feature = "serialization", serde(rename_all = "snake_case"))] | ||||
| pub enum Interpolation<T> { | ||||
|   /// Hold a [`Key`] until the sampling value passes the normalized step threshold, in which | ||||
|   /// case the next key is used. | ||||
|   /// | ||||
|   /// > Note: if you set the threshold to `0.5`, the first key will be used until half the time | ||||
|   /// > between the two keys; the second key will be in used afterwards. If you set it to `1.0`, the | ||||
|   /// > first key will be kept until the next key. Set it to `0.` and the first key will never be | ||||
|   /// > used. | ||||
|   /// | ||||
|   /// [`Key`]: crate::key::Key | ||||
|   Step(T), | ||||
|   /// Linear interpolation between a key and the next one. | ||||
|   Linear, | ||||
|   /// Cosine interpolation between a key and the next one. | ||||
|   Cosine, | ||||
|   /// Catmull-Rom interpolation, performing a cubic Hermite interpolation using four keys. | ||||
|   CatmullRom, | ||||
| } | ||||
|  | ||||
| #[cfg(feature = "bezier")] | ||||
| impl<T, V> Default for Interpolation<T, V> { | ||||
|   /// [`Interpolation::Linear`] is the default. | ||||
|   fn default() -> Self { | ||||
|     Interpolation::Linear | ||||
|   } | ||||
| } | ||||
|  | ||||
| #[cfg(not(feature = "bezier"))] | ||||
| impl<T> Default for Interpolation<T> { | ||||
|   /// [`Interpolation::Linear`] is the default. | ||||
|   fn default() -> Self { | ||||
|     Interpolation::Linear | ||||
|   } | ||||
| } | ||||
|   | ||||
							
								
								
									
										28
									
								
								src/key.rs
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								src/key.rs
									
									
									
									
									
								
							| @@ -17,7 +17,6 @@ use crate::interpolation::Interpolation; | ||||
| /// key and the next one – if existing. Have a look at [`Interpolation`] for further details. | ||||
| /// | ||||
| /// [`Interpolation`]: crate::interpolation::Interpolation | ||||
| #[cfg(feature = "bezier")] | ||||
| #[derive(Copy, Clone, Debug, Eq, PartialEq)] | ||||
| #[cfg_attr(feature = "serialization", derive(Deserialize, Serialize))] | ||||
| #[cfg_attr(feature = "serialization", serde(rename_all = "snake_case"))] | ||||
| @@ -30,36 +29,9 @@ pub struct Key<T, V> { | ||||
|   pub interpolation: Interpolation<T, V> | ||||
| } | ||||
|  | ||||
| /// A spline control point. | ||||
| /// | ||||
| /// This type associates a value at a given interpolation parameter value. It also contains an | ||||
| /// interpolation mode used to determine how to interpolate values on the segment defined by this | ||||
| /// key and the next one – if existing. Have a look at [`Interpolation`] for further details. | ||||
| /// | ||||
| /// [`Interpolation`]: crate::interpolation::Interpolation | ||||
| #[cfg(not(feature = "bezier"))] | ||||
| #[derive(Copy, Clone, Debug, Eq, PartialEq)] | ||||
| #[cfg_attr(feature = "serialization", derive(Deserialize, Serialize))] | ||||
| #[cfg_attr(feature = "serialization", serde(rename_all = "snake_case"))] | ||||
| pub struct Key<T, V> { | ||||
|   /// Interpolation parameter at which the [`Key`] should be reached. | ||||
|   pub t: T, | ||||
|   /// Carried value. | ||||
|   pub value: V, | ||||
|   /// Interpolation mode. | ||||
|   pub interpolation: Interpolation<T> | ||||
| } | ||||
|  | ||||
| impl<T, V> Key<T, V> { | ||||
|   /// Create a new key. | ||||
|   #[cfg(feature = "bezier")] | ||||
|   pub fn new(t: T, value: V, interpolation: Interpolation<T, V>) -> Self { | ||||
|     Key { t, value, interpolation } | ||||
|   } | ||||
|  | ||||
|   /// Create a new key. | ||||
|   #[cfg(not(feature = "bezier"))] | ||||
|   pub fn new(t: T, value: V, interpolation: Interpolation<T>) -> Self { | ||||
|     Key { t, value, interpolation } | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -99,12 +99,6 @@ | ||||
| //!     - Compiling with the standard library is enabled by default. | ||||
| //!     - Use `default-features = []` in your `Cargo.toml` to disable. | ||||
| //!     - Enable explicitly with the `"std"` feature. | ||||
| //!   - **Extra interpolation modes.** | ||||
| //!     - In order not to introduce breaking changes, some feature-gates are added to augment the | ||||
| //!       [`Interpolation`] enum. | ||||
| //!     - Those feature-gates will disappear on the next major release of the crate. | ||||
| //!     - The following lists all currently available: | ||||
| //!       - `"bezier"`: [Bézier curves](https://en.wikipedia.org/wiki/B%C3%A9zier_curve). | ||||
| //! | ||||
| //! [`Interpolation`]: crate::interpolation::Interpolation | ||||
|  | ||||
|   | ||||
| @@ -43,13 +43,11 @@ macro_rules! impl_interpolate_vector { | ||||
|         cubic_hermite_def(x, a, b, y, t) | ||||
|       } | ||||
|  | ||||
|       #[cfg(feature = "bezier")] | ||||
|       #[inline(always)] | ||||
|       fn quadratic_bezier(a: Self, u: Self, b: Self, t: T) -> Self { | ||||
|         quadratic_bezier_def(a, u, b, t) | ||||
|       } | ||||
|  | ||||
|       #[cfg(feature = "bezier")] | ||||
|       #[inline(always)] | ||||
|       fn cubic_bezier(a: Self, u: Self, v: Self, b: Self, t: T) -> Self { | ||||
|         cubic_bezier_def(a, u, v, b, t) | ||||
|   | ||||
| @@ -129,7 +129,6 @@ impl<T, V> Spline<T, V> { | ||||
|         } | ||||
|       } | ||||
|  | ||||
|       #[cfg(feature = "bezier")] | ||||
|       Interpolation::Bezier(u) => { | ||||
|         // We need to check the next control point to see whether we want quadratic or cubic Bezier. | ||||
|         let cp1 = &keys[i + 1]; | ||||
| @@ -146,6 +145,8 @@ impl<T, V> Spline<T, V> { | ||||
|           Some(Interpolate::quadratic_bezier(cp0.value, u, cp1.value, nt)) | ||||
|         } | ||||
|       } | ||||
|  | ||||
|       Interpolation::__NonExhaustive => unreachable!(), | ||||
|     } | ||||
|   } | ||||
|  | ||||
| @@ -243,10 +244,7 @@ pub struct KeyMut<'a, T, V> { | ||||
|   /// Carried value. | ||||
|   pub value: &'a mut V, | ||||
|   /// Interpolation mode to use for that key. | ||||
|   #[cfg(feature = "bezier")] | ||||
|   pub interpolation: &'a mut Interpolation<T, V>, | ||||
|   #[cfg(not(feature = "bezier"))] | ||||
|   pub interpolation: &'a mut Interpolation<T>, | ||||
| } | ||||
|  | ||||
| // Normalize a time ([0;1]) given two control points. | ||||
|   | ||||
		Reference in New Issue
	
	Block a user