splines/
key.rs

1//! Spline control points.
2//!
3//! A control point associates to a “sampling value” (a.k.a. time) a carried value that can be
4//! interpolated along the curve made by the control points.
5//!
6//! Splines constructed with this crate have the property that it’s possible to change the
7//! interpolation mode on a key-based way, allowing you to implement and encode complex curves.
8
9use crate::interpolation::Interpolation;
10#[cfg(feature = "serde")]
11use serde::{Deserialize, Serialize};
12
13/// A spline control point.
14///
15/// This type associates a value at a given interpolation parameter value. It also contains an
16/// interpolation mode used to determine how to interpolate values on the segment defined by this
17/// key and the next one – if existing. Have a look at [`Interpolation`] for further details.
18///
19/// [`Interpolation`]: crate::interpolation::Interpolation
20#[derive(Copy, Clone, Debug, Eq, PartialEq)]
21#[cfg_attr(
22  feature = "serde",
23  derive(Deserialize, Serialize),
24  serde(rename_all = "snake_case")
25)]
26pub struct Key<T, V> {
27  /// Interpolation parameter at which the [`Key`] should be reached.
28  pub t: T,
29  /// Carried value.
30  pub value: V,
31  /// Interpolation mode.
32  pub interpolation: Interpolation<T, V>,
33}
34
35impl<T, V> Key<T, V> {
36  /// Create a new key.
37  pub fn new(t: T, value: V, interpolation: Interpolation<T, V>) -> Self {
38    Key {
39      t,
40      value,
41      interpolation,
42    }
43  }
44}