2019-04-23 14:12:08 +02:00
|
|
|
|
//! Spline control points.
|
|
|
|
|
//!
|
|
|
|
|
//! A control point associates to a “sampling value” (a.k.a. time) a carriede value that can be
|
|
|
|
|
//! interpolated along the curve made by the control points.
|
|
|
|
|
//!
|
|
|
|
|
//! Splines constructed with this crate have the property that it’s possible to change the
|
|
|
|
|
//! interpolation mode on a key-based way, allowing you to implement and encode complex curves.
|
|
|
|
|
|
2021-02-27 23:09:50 +01:00
|
|
|
|
use crate::interpolation::Interpolation;
|
2020-03-18 11:59:22 +01:00
|
|
|
|
#[cfg(feature = "serialization")]
|
|
|
|
|
use serde_derive::{Deserialize, Serialize};
|
2019-04-19 13:39:37 +02:00
|
|
|
|
|
|
|
|
|
/// A spline control point.
|
|
|
|
|
///
|
|
|
|
|
/// This type associates a value at a given interpolation parameter value. It also contains an
|
2019-04-23 14:12:08 +02:00
|
|
|
|
/// interpolation mode used to determine how to interpolate values on the segment defined by this
|
|
|
|
|
/// key and the next one – if existing. Have a look at [`Interpolation`] for further details.
|
|
|
|
|
///
|
|
|
|
|
/// [`Interpolation`]: crate::interpolation::Interpolation
|
2019-09-21 14:17:56 +02:00
|
|
|
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
2019-04-19 13:39:37 +02:00
|
|
|
|
#[cfg_attr(feature = "serialization", derive(Deserialize, Serialize))]
|
|
|
|
|
#[cfg_attr(feature = "serialization", serde(rename_all = "snake_case"))]
|
|
|
|
|
pub struct Key<T, V> {
|
2020-03-19 01:22:26 +01:00
|
|
|
|
/// Interpolation parameter at which the [`Key`] should be reached.
|
|
|
|
|
pub t: T,
|
|
|
|
|
/// Carried value.
|
|
|
|
|
pub value: V,
|
|
|
|
|
/// Interpolation mode.
|
|
|
|
|
pub interpolation: Interpolation<T, V>,
|
2019-04-19 13:39:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T, V> Key<T, V> {
|
2020-03-19 01:22:26 +01:00
|
|
|
|
/// Create a new key.
|
|
|
|
|
pub fn new(t: T, value: V, interpolation: Interpolation<T, V>) -> Self {
|
|
|
|
|
Key {
|
|
|
|
|
t,
|
|
|
|
|
value,
|
|
|
|
|
interpolation,
|
2020-03-18 11:59:22 +01:00
|
|
|
|
}
|
2020-03-19 01:22:26 +01:00
|
|
|
|
}
|
2019-04-19 13:39:37 +02:00
|
|
|
|
}
|