splines/
interpolation.rs

1//! Available interpolation modes.
2
3#[cfg(feature = "serialization")] use serde_derive::{Deserialize, Serialize};
4
5/// Available kind of interpolations.
6///
7/// Feel free to visit each variant for more documentation.
8#[derive(Copy, Clone, Debug, Eq, PartialEq)]
9#[cfg_attr(feature = "serialization", derive(Deserialize, Serialize))]
10#[cfg_attr(feature = "serialization", serde(rename_all = "snake_case"))]
11pub enum Interpolation<T, V> {
12  /// Hold a [`Key`] until the sampling value passes the normalized step threshold, in which
13  /// case the next key is used.
14  ///
15  /// > Note: if you set the threshold to `0.5`, the first key will be used until half the time
16  /// > between the two keys; the second key will be in used afterwards. If you set it to `1.0`, the
17  /// > first key will be kept until the next key. Set it to `0.` and the first key will never be
18  /// > used.
19  ///
20  /// [`Key`]: crate::key::Key
21  Step(T),
22  /// Linear interpolation between a key and the next one.
23  Linear,
24  /// Cosine interpolation between a key and the next one.
25  Cosine,
26  /// Catmull-Rom interpolation, performing a cubic Hermite interpolation using four keys.
27  CatmullRom,
28  /// Bézier interpolation.
29  ///
30  /// A control point that uses such an interpolation is associated with an extra point. The segmant
31  /// connecting both is called the _tangent_ of this point. The part of the spline defined between
32  /// this control point and the next one will be interpolated across with Bézier interpolation. Two
33  /// cases are possible:
34  ///
35  /// - The next control point also has a Bézier interpolation mode. In this case, its tangent is
36  ///   used for the interpolation process. This is called _cubic Bézier interpolation_ and it
37  ///   kicks ass.
38  /// - The next control point doesn’t have a Bézier interpolation mode set. In this case, the
39  ///   tangent used for the next control point is defined as the segment connecting that control
40  ///   point and the current control point’s associated point. This is called _quadratic Bézer
41  ///   interpolation_ and it kicks ass too, but a bit less than cubic.
42  Bezier(V),
43  /// A special Bézier interpolation using an _input tangent_ and an _output tangent_.
44  ///
45  /// With this kind of interpolation, a control point has an input tangent, which has the same role
46  /// as the one defined by [`Interpolation::Bezier`], and an output tangent, which has the same
47  /// role defined by the next key’s [`Interpolation::Bezier`] if present, normally.
48  ///
49  /// What it means is that instead of setting the output tangent as the next key’s Bézier tangent,
50  /// this interpolation mode allows you to manually set the output tangent. That will yield more
51  /// control on the tangents but might generate discontinuities. Use with care.
52  ///
53  /// Stroke Bézier interpolation is always a cubic Bézier interpolation by default.
54  StrokeBezier(V, V),
55  #[doc(hidden)]
56  __NonExhaustive
57}
58
59impl<T, V> Default for Interpolation<T, V> {
60  /// [`Interpolation::Linear`] is the default.
61  fn default() -> Self {
62    Interpolation::Linear
63  }
64}