splines/key.rs
1//! Spline control points.
2//!
3//! A control point associates to a “sampling value” (a.k.a. time) a carriede 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
9#[cfg(feature = "serialization")] use serde_derive::{Deserialize, Serialize};
10
11use crate::interpolation::Interpolation;
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(feature = "serialization", derive(Deserialize, Serialize))]
22#[cfg_attr(feature = "serialization", serde(rename_all = "snake_case"))]
23pub struct Key<T, V> {
24 /// Interpolation parameter at which the [`Key`] should be reached.
25 pub t: T,
26 /// Carried value.
27 pub value: V,
28 /// Interpolation mode.
29 pub interpolation: Interpolation<T, V>
30}
31
32impl<T, V> Key<T, V> {
33 /// Create a new key.
34 pub fn new(t: T, value: V, interpolation: Interpolation<T, V>) -> Self {
35 Key { t, value, interpolation }
36 }
37}