From cc0a9580ab4602da7c186cbd6590fb7e45a113f6 Mon Sep 17 00:00:00 2001 From: Dimitri Sabadie Date: Thu, 17 Oct 2019 15:31:05 +0200 Subject: [PATCH] Add Interpolation::StrokeBezier. --- .github/workflows/ci.yaml | 6 +++++- CHANGELOG.md | 12 ++++++++++++ Cargo.toml | 2 +- src/interpolation.rs | 12 ++++++++++++ src/spline.rs | 9 ++++++++- 5 files changed, 38 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 43b7110..e080a33 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -26,14 +26,18 @@ jobs: cargo test --verbose --all-features build-macosx: - runs-on: macosx-latest + runs-on: macOS-latest steps: - uses: actions/checkout@v1 + - name: Rust requirements + run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal - name: Build run: | + . ~/.cargo/env cargo build --verbose --all-features - name: Test run: | + . ~/.cargo/env cargo test --verbose --all-features check-readme: diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ba7647..358802f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +# 2.2.0 + +> Mon Oct 17th 2019 + +- Add `Interpolation::StrokeBezier`. + +# 2.1.1 + +> Mon Oct 17th 2019 + +- Licensing support in the crate. + # 2.1 > Mon Sep 30th 2019 diff --git a/Cargo.toml b/Cargo.toml index c6f4366..471fbea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "splines" -version = "2.1.1" +version = "2.2.0" license = "BSD-3-Clause" authors = ["Dimitri Sabadie "] description = "Spline interpolation made easy" diff --git a/src/interpolation.rs b/src/interpolation.rs index 52a40cc..7d30586 100644 --- a/src/interpolation.rs +++ b/src/interpolation.rs @@ -40,6 +40,18 @@ pub enum Interpolation { /// 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. Bezier(V), + /// A special Bézier interpolation using an _input tangent_ and an _output tangent_. + /// + /// With this kind of interpolation, a control point has an input tangent, which has the same role + /// as the one defined by [`Interpolation::Bezier`], and an output tangent, which has the same + /// role defined by the next key’s [`Interpolation::Bezier`] if present, normally. + /// + /// What it means is that instead of setting the output tangent as the next key’s Bézier tangent, + /// this interpolation mode allows you to manually set the output tangent. That will yield more + /// control on the tangents but might generate discontinuities. Use with care. + /// + /// Stroke Bézier interpolation is always a cubic Bézier interpolation by default. + StrokeBezier(V, V), #[doc(hidden)] __NonExhaustive } diff --git a/src/spline.rs b/src/spline.rs index 819c4da..2051dea 100644 --- a/src/spline.rs +++ b/src/spline.rs @@ -84,7 +84,6 @@ impl Spline { /// sampling impossible. For instance, [`Interpolation::CatmullRom`] requires *four* keys. If /// you’re near the beginning of the spline or its end, ensure you have enough keys around to make /// the sampling. - /// pub fn sample_with_key(&self, t: T) -> Option<(V, &Key, Option<&Key>)> where T: Additive + One + Trigo + Mul + Div + PartialOrd, V: Interpolate { @@ -150,6 +149,14 @@ impl Spline { Some((value, cp0, Some(cp1))) } + Interpolation::StrokeBezier(input, output) => { + let cp1 = &keys[i + 1]; + let nt = normalize_time(t, cp0, cp1); + let value = Interpolate::cubic_bezier(cp0.value, input, output, cp1.value, nt); + + Some((value, cp0, Some(cp1))) + } + Interpolation::__NonExhaustive => unreachable!(), } }