Trait enterpolation::Curve
source · pub trait Curve<R>: Generator<R>where
R: Real,{
// Required method
fn domain(&self) -> [R; 2];
// Provided methods
fn take(self, samples: usize) -> Take<Self, R>
where Self: Sized,
R: FromPrimitive { ... }
fn slice<B>(self, bounds: B) -> Slice<Self, R>
where Self: Sized,
B: RangeBounds<R> { ... }
fn clamp(self) -> Clamp<Self>
where Self: Sized { ... }
}
Expand description
Specialized Generator
which takes a real number as input.
Required Methods§
Provided Methods§
sourcefn take(self, samples: usize) -> Take<Self, R>where
Self: Sized,
R: FromPrimitive,
fn take(self, samples: usize) -> Take<Self, R>where Self: Sized, R: FromPrimitive,
Takes equidistant samples of the curve.
Examples
let linear = Linear::builder()
.elements([0.0,5.0,3.0])
.knots([0.0,1.0,2.0])
.build()?;
let results = [0.0,1.0,2.0,3.0,4.0,5.0,4.6,4.2,3.8,3.4,3.0]; // take 11 samples
for (value,result) in linear.take(results.len()).zip(results.iter().copied()){
assert_f64_near!(value, result);
}
Panics
Panics if given size of samples is 0 or if samples - 1
can not be converted to the type R
.
sourcefn slice<B>(self, bounds: B) -> Slice<Self, R>where
Self: Sized,
B: RangeBounds<R>,
fn slice<B>(self, bounds: B) -> Slice<Self, R>where Self: Sized, B: RangeBounds<R>,
Take a slice of a curve.
A slice of a curve maps its domain onto the given range.
Examples
let linear = Linear::builder()
.elements([0.0,5.0,3.0])
.knots([0.0,1.0,2.0])
.build()?;
let sliced_linear = linear.slice(0.5..1.5);
let results = [2.5,5.0,4.0];
for (value,result) in sliced_linear.take(results.len()).zip(results.iter().copied()){
assert_f64_near!(value, result);
}
sourcefn clamp(self) -> Clamp<Self>where
Self: Sized,
fn clamp(self) -> Clamp<Self>where Self: Sized,
Clamp the input of a curve to its domain.
Examples
let linear = Linear::builder()
.elements([0.0,3.0])
.knots([0.0,1.0])
.build()?
.clamp();
let expected = [[-1.0,0.0],[0.0,0.0],[0.5,1.5],[1.0,3.0],[2.0,3.0]];
for [input,result] in expected {
assert_f64_near!(linear.gen(input), result);
}