pub struct PiecewiseLinearCurve<I> { /* private fields */ }
Expand description
Represents a numeric value that changes over the course of the buffer.
We represent values changing over the course of the buffer as a piecewise linear curve, where the curve moving linearly from point to point.
Note that the curve is guaranteed to begin at 0, however it may end before the end of the buffer - in this case, the value remains constant until the end of the buffer.
Some invariants:
- There will always be at least one point
- The first point’s
sample_offset
will be 0 sample_offset
s will be monotonically increasing and only one point will appear for eachsample_offset
- All point’s
value
will be between the parameter’smin
andmax
Implementations§
Source§impl<I: IntoIterator<Item = PiecewiseLinearCurvePoint> + Clone> PiecewiseLinearCurve<I>
impl<I: IntoIterator<Item = PiecewiseLinearCurvePoint> + Clone> PiecewiseLinearCurve<I>
Sourcepub fn new(
points: I,
buffer_size: usize,
valid_range: RangeInclusive<f32>,
) -> Option<Self>
pub fn new( points: I, buffer_size: usize, valid_range: RangeInclusive<f32>, ) -> Option<Self>
Construct a new PiecewiseLinearCurve
from an iterator of points.
This will check the invariants for the curve, and if any are invalid, this will
return None
.
§Examples
assert!(PiecewiseLinearCurve::new(
vec![PiecewiseLinearCurvePoint { sample_offset: 0, value: 0.0 },
PiecewiseLinearCurvePoint { sample_offset: 100, value: 1.0 }],
128,
0.0..=1.0,
).is_some());
// Curves must include at least one point
assert!(PiecewiseLinearCurve::new(vec![], 128, 0.0..=1.0).is_none());
// Curves can't go outside the valid range.
assert!(PiecewiseLinearCurve::new(
vec![PiecewiseLinearCurvePoint { sample_offset: 0, value: 0.0 },
PiecewiseLinearCurvePoint { sample_offset: 100, value: 2.0 }],
128,
0.0..=1.0,
).is_none());
// The curve must not go past the end of the buffer
assert!(PiecewiseLinearCurve::new(
vec![PiecewiseLinearCurvePoint { sample_offset: 0, value: 0.0 },
PiecewiseLinearCurvePoint { sample_offset: 128, value: 1.0 }],
128,
0.0..=1.0,
).is_none());
// The first point must be at 0
assert!(PiecewiseLinearCurve::new(
vec![PiecewiseLinearCurvePoint { sample_offset: 50, value: 0.0 },
PiecewiseLinearCurvePoint { sample_offset: 100, value: 1.0 }],
128,
0.0..=1.0,
).is_none());
// Sample offsets must monotonically increase
assert!(PiecewiseLinearCurve::new(
vec![PiecewiseLinearCurvePoint { sample_offset: 0, value: 0.0 },
PiecewiseLinearCurvePoint { sample_offset: 100, value: 1.0 },
PiecewiseLinearCurvePoint { sample_offset: 50, value: 0.5 }],
128,
0.0..=1.0,
).is_none());
Source§impl<I> PiecewiseLinearCurve<I>
impl<I> PiecewiseLinearCurve<I>
Sourcepub fn buffer_size(&self) -> usize
pub fn buffer_size(&self) -> usize
Get the size of the buffer this curve is defined over.
Note that the last point may occur before the end of the buffer, in which case the value remains constant from that point until the end of the buffer.
Trait Implementations§
Source§impl<I: Clone> Clone for PiecewiseLinearCurve<I>
impl<I: Clone> Clone for PiecewiseLinearCurve<I>
Source§fn clone(&self) -> PiecewiseLinearCurve<I>
fn clone(&self) -> PiecewiseLinearCurve<I>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<I: IntoIterator<Item = PiecewiseLinearCurvePoint>> IntoIterator for PiecewiseLinearCurve<I>
impl<I: IntoIterator<Item = PiecewiseLinearCurvePoint>> IntoIterator for PiecewiseLinearCurve<I>
Auto Trait Implementations§
impl<I> Freeze for PiecewiseLinearCurve<I>where
I: Freeze,
impl<I> RefUnwindSafe for PiecewiseLinearCurve<I>where
I: RefUnwindSafe,
impl<I> Send for PiecewiseLinearCurve<I>where
I: Send,
impl<I> Sync for PiecewiseLinearCurve<I>where
I: Sync,
impl<I> Unpin for PiecewiseLinearCurve<I>where
I: Unpin,
impl<I> UnwindSafe for PiecewiseLinearCurve<I>where
I: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more