Struct enterpolation::ConstEquidistant
source · pub struct ConstEquidistant<R, const N: usize>(_);
Expand description
Struct used as a generator for equidistant elements in constant context. Acts like an array of knots.
This struct is necessary as to date neither generic bounds nor floating point opterations are allowed in constant functions. Such to be able to use Equidistant in a constant context, we use this structure instead.
In comparison to Equidistant
, this struct is slower (as it has to do more calculations) and
only represents knots in [0.0,1.0]. However as knot base for interpolations, it is more performant,
as we have the knowledge of the domain.
Implementations§
Trait Implementations§
source§impl<R: Clone, const N: usize> Clone for ConstEquidistant<R, N>
impl<R: Clone, const N: usize> Clone for ConstEquidistant<R, N>
source§fn clone(&self) -> ConstEquidistant<R, N>
fn clone(&self) -> ConstEquidistant<R, N>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<R, const N: usize> DiscreteGenerator for ConstEquidistant<R, N>where
R: Real + FromPrimitive,
impl<R, const N: usize> DiscreteGenerator for ConstEquidistant<R, N>where R: Real + FromPrimitive,
source§fn len(&self) -> usize
fn len(&self) -> usize
source§fn first(&self) -> Option<Self::Output>
fn first(&self) -> Option<Self::Output>
None
if it is empty.source§fn last(&self) -> Option<Self::Output>
fn last(&self) -> Option<Self::Output>
None
if it is empty.source§impl<R, const N: usize> Generator<usize> for ConstEquidistant<R, N>where
R: Real + FromPrimitive,
impl<R, const N: usize> Generator<usize> for ConstEquidistant<R, N>where R: Real + FromPrimitive,
source§fn extract<I, J>(self, iterator: I) -> Extract<Self, J> ⓘwhere
Self: Sized,
I: IntoIterator<IntoIter = J>,
J: Iterator<Item = Input>,
fn extract<I, J>(self, iterator: I) -> Extract<Self, J> ⓘwhere Self: Sized, I: IntoIterator<IntoIter = J>, J: Iterator<Item = Input>,
source§fn stack<G>(self, gen: G) -> Stack<Self, G>where
Self: Sized,
fn stack<G>(self, gen: G) -> Stack<Self, G>where Self: Sized,
source§impl<R: PartialEq, const N: usize> PartialEq<ConstEquidistant<R, N>> for ConstEquidistant<R, N>
impl<R: PartialEq, const N: usize> PartialEq<ConstEquidistant<R, N>> for ConstEquidistant<R, N>
source§fn eq(&self, other: &ConstEquidistant<R, N>) -> bool
fn eq(&self, other: &ConstEquidistant<R, N>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<R, const N: usize> SortedGenerator for ConstEquidistant<R, N>where
R: Real + FromPrimitive,
impl<R, const N: usize> SortedGenerator for ConstEquidistant<R, N>where R: Real + FromPrimitive,
source§fn strict_upper_bound(&self, element: Self::Output) -> usizewhere
Self::Output: PartialOrd + Copy,
fn strict_upper_bound(&self, element: Self::Output) -> usizewhere Self::Output: PartialOrd + Copy,
Returns the smallest index for which the corresponding element is bigger then the input. If all elements are bigger, this function will return self.len().
Panics
Panics if N
is 0.
May panic if N-1
can not be converted to type R
.
Examples
let equi = ConstEquidistant::<f64,11>::new();
assert_eq!(equi.strict_upper_bound(-1.0),0);
assert_eq!(equi.strict_upper_bound(0.15),2);
assert_eq!(equi.strict_upper_bound(20.0),11);
source§fn strict_upper_bound_clamped(
&self,
element: Self::Output,
min: usize,
max: usize
) -> usizewhere
Self::Output: PartialOrd + Copy,
fn strict_upper_bound_clamped( &self, element: Self::Output, min: usize, max: usize ) -> usizewhere Self::Output: PartialOrd + Copy,
Returns the smallest index between min
and max
for which the corresponding element is bigger then the input.
If all elements are bigger, this function will return the given maximum.
#Panic
Panics if min
or max
are not within [0,self.len()].
Examples
let equi = ConstEquidistant::<f64,11>::new();
assert_eq!(equi.strict_upper_bound_clamped(-1.0,1,3),1);
assert_eq!(equi.strict_upper_bound_clamped(0.15,1,3),2);
assert_eq!(equi.strict_upper_bound_clamped(20.0,1,3),3);
source§fn upper_border(&self, element: R) -> (usize, usize, R)where
R: PartialOrd + Sub<Output = R> + Div<Output = R> + Copy + Debug,
fn upper_border(&self, element: R) -> (usize, usize, R)where R: PartialOrd + Sub<Output = R> + Div<Output = R> + Copy + Debug,
Find the values inside the collection for which the given element is inbetween and a linear factor at how close it is to which value.
This function in general returns indices with values (first
and second
)
such that first <= value <= second
is true.
If the given element is smaller/bigger than every element in the collection, then the indices given will be the smallest/biggest possible.
Remark
There are collections for which the returned values of this function are not uniquely defined.
You may not assume any other invariant except
first * factor + second * (1.0 - factor) == value
,
where value
is the value inserted into this function,
and the function returned (first, second, factor)
.
Panics
Panics if self
is has less than two elements.
Also panics if length-1 as usize can not be converted to R
.
Examples
let equdist = ConstEquidistant::<f64,6>::new();
let values = vec![-1.0,0.0,0.15,0.6,1.0,20.0];
for value in values {
let (min_index, max_index, factor) = equdist.upper_border(value);
let min = equdist.gen(min_index);
let max = equdist.gen(max_index);
assert_f64_near!(utils::lerp(min,max,factor),value);
}