From 6f65be125b1a71895cb48a90db2fa28032f6c017 Mon Sep 17 00:00:00 2001 From: Dimitri Sabadie Date: Tue, 24 Sep 2019 10:42:03 +0200 Subject: [PATCH 1/2] 2.0.0. --- CHANGELOG.md | 15 ++++++++++----- Cargo.toml | 3 +-- README.md | 6 ------ src/cgmath.rs | 4 ---- src/interpolate.rs | 8 -------- src/interpolation.rs | 39 ++------------------------------------- src/key.rs | 28 ---------------------------- src/lib.rs | 6 ------ src/nalgebra.rs | 2 -- src/spline.rs | 6 ++---- 10 files changed, 15 insertions(+), 102 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76305e2..3e986d3 100644 --- a/CHANGELOG.md +++ b/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 diff --git a/Cargo.toml b/Cargo.toml index d989696..413e427 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "splines" -version = "1.1.1" +version = "2.0.0" license = "BSD-3-Clause" authors = ["Dimitri Sabadie "] 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"] diff --git a/README.md b/README.md index 8c713fe..20bec4a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/cgmath.rs b/src/cgmath.rs index d6f2733..f200026 100644 --- a/src/cgmath.rs +++ b/src/cgmath.rs @@ -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, 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) diff --git a/src/interpolate.rs b/src/interpolate.rs index 1a6242f..36042e2 100644 --- a/src/interpolate.rs +++ b/src/interpolate.rs @@ -59,11 +59,9 @@ pub trait Interpolate: 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, /// 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(a: V, u: V, b: V, t: T) -> V where V: Linear, T: Additive + Mul + One { @@ -235,7 +232,6 @@ where V: Linear, /// 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(a: V, u: V, v: V, b: V, t: T) -> V where V: Linear, T: Additive + Mul + 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) } diff --git a/src/interpolation.rs b/src/interpolation.rs index 7974832..52a40cc 100644 --- a/src/interpolation.rs +++ b/src/interpolation.rs @@ -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 { /// 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 { - /// 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 Default for Interpolation { /// [`Interpolation::Linear`] is the default. fn default() -> Self { Interpolation::Linear } } - -#[cfg(not(feature = "bezier"))] -impl Default for Interpolation { - /// [`Interpolation::Linear`] is the default. - fn default() -> Self { - Interpolation::Linear - } -} diff --git a/src/key.rs b/src/key.rs index 983ee76..76f09f6 100644 --- a/src/key.rs +++ b/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 { pub interpolation: Interpolation } -/// 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 { - /// Interpolation parameter at which the [`Key`] should be reached. - pub t: T, - /// Carried value. - pub value: V, - /// Interpolation mode. - pub interpolation: Interpolation -} - impl Key { /// Create a new key. - #[cfg(feature = "bezier")] pub fn new(t: T, value: V, interpolation: Interpolation) -> Self { Key { t, value, interpolation } } - - /// Create a new key. - #[cfg(not(feature = "bezier"))] - pub fn new(t: T, value: V, interpolation: Interpolation) -> Self { - Key { t, value, interpolation } - } } diff --git a/src/lib.rs b/src/lib.rs index 734eac8..065ae71 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 diff --git a/src/nalgebra.rs b/src/nalgebra.rs index ccb261f..67c4580 100644 --- a/src/nalgebra.rs +++ b/src/nalgebra.rs @@ -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) diff --git a/src/spline.rs b/src/spline.rs index ac0ed72..7646104 100644 --- a/src/spline.rs +++ b/src/spline.rs @@ -129,7 +129,6 @@ impl Spline { } } - #[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 Spline { 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, - #[cfg(not(feature = "bezier"))] - pub interpolation: &'a mut Interpolation, } // Normalize a time ([0;1]) given two control points. From 784617747133f12a12af33accc4998a3ba369f14 Mon Sep 17 00:00:00 2001 From: Dimitri Sabadie Date: Tue, 24 Sep 2019 10:44:45 +0200 Subject: [PATCH 2/2] Fix CI. --- .github/workflows/ci.yaml | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index aceaad5..43b7110 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -8,12 +8,11 @@ jobs: - uses: actions/checkout@v1 - name: Build run: | - cargo build --verbose - cargo build --verbose --features bezier + cargo build --verbose --all-features - name: Test run: | - cargo test --verbose - cargo test --verbose --features bezier + cargo test --verbose --all-features + build-windows: runs-on: windows-latest @@ -21,12 +20,10 @@ jobs: - uses: actions/checkout@v1 - name: Build run: | - cargo build --verbose - cargo build --verbose --features bezier + cargo build --verbose --all-features - name: Test run: | - cargo test --verbose - cargo test --verbose --features bezier + cargo test --verbose --all-features build-macosx: runs-on: macosx-latest @@ -34,12 +31,10 @@ jobs: - uses: actions/checkout@v1 - name: Build run: | - cargo build --verbose - cargo build --verbose --features bezier + cargo build --verbose --all-features - name: Test run: | - cargo test --verbose - cargo test --verbose --features bezier + cargo test --verbose --all-features check-readme: runs-on: ubuntu-latest