Merge pull request #33 from phaazon/feature/stroke-bezier
Add Interpolation::StrokeBezier.
This commit is contained in:
commit
425433cd5b
6
.github/workflows/ci.yaml
vendored
6
.github/workflows/ci.yaml
vendored
@ -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:
|
||||
|
12
CHANGELOG.md
12
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
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "splines"
|
||||
version = "2.1.1"
|
||||
version = "2.2.0"
|
||||
license = "BSD-3-Clause"
|
||||
authors = ["Dimitri Sabadie <dimitri.sabadie@gmail.com>"]
|
||||
description = "Spline interpolation made easy"
|
||||
|
@ -40,6 +40,18 @@ pub enum Interpolation<T, V> {
|
||||
/// 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
|
||||
}
|
||||
|
@ -84,7 +84,6 @@ impl<T, V> Spline<T, V> {
|
||||
/// 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<T, V>, Option<&Key<T, V>>)>
|
||||
where T: Additive + One + Trigo + Mul<T, Output = T> + Div<T, Output = T> + PartialOrd,
|
||||
V: Interpolate<T> {
|
||||
@ -150,6 +149,14 @@ impl<T, V> Spline<T, V> {
|
||||
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!(),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user