Struct efd::Efd

source ·
pub struct Efd<D: EfdDim> { /* private fields */ }
Expand description

Elliptical Fourier Descriptor coefficients. Provide transformation between discrete points and coefficients.

Transformation

The transformation of normalized coefficients.

Implements Kuhl and Giardina method of normalizing the coefficients An, Bn, Cn, Dn. Performs 3 separate normalizations. First, it makes the data location invariant by re-scaling the data to a common origin. Secondly, the data is rotated with respect to the major axis. Thirdly, the coefficients are normalized with regard to the absolute value of A₁.

Please see Transform for more information.

Implementations§

source§

impl<D: EfdDim> Efd<D>

source

pub fn try_from_coeffs(coeffs: Array2<f64>) -> Result<Self, EfdError<D>>

Create object from a nx4 array with boundary check.

source

pub fn gate<C, T>(curve: C, threshold: T) -> Option<usize>where C: Curve<Coord<D>>, Option<f64>: From<T>,

Apply Nyquist Frequency on Fourier power analysis with a custom threshold value (default to 99.99%).

This method returns the minimum harmonic number to keep the shape features.

The threshold must in [0, 1). This function returns None if the curve length is less than 1.

let harmonic = efd::Efd2::gate(curve, None).unwrap();
source

pub fn from_curve<C>(curve: C) -> Option<Self>where C: Curve<Coord<D>>,

Calculate EFD coefficients from an existing discrete points.

The curve must be closed. (first == last)

Return none if the curve length is less than 1.

source

pub fn from_curve_gate<C, T>(curve: C, threshold: T) -> Option<Self>where C: Curve<Coord<D>>, Option<f64>: From<T>,

Calculate EFD coefficients from an existing discrete points and Fourier power gate.

The curve must be closed. (first == last)

Return none if the curve length is less than 1.

source

pub fn from_curve_harmonic<C, H>(curve: C, harmonic: H) -> Option<Self>where C: Curve<Coord<D>>, Option<usize>: From<H>,

Calculate EFD coefficients from a series of existing discrete points.

The curve must be closed. (first == last)

Return none if harmonic number is zero or the curve is less than two points.

If the harmonic number is not given, it will be calculated with Self::gate() function.

See also [closed_curve].

source

pub fn with_trans(self, trans: Transform<D::Trans>) -> Self

A builder method for changing transform type.

source

pub fn into_inner(self) -> Array2<f64>

Consume self and return a raw array of the coefficients.

source

pub fn coeffs(&self) -> ArrayView2<'_, f64>

Get the array view of the coefficients.

source

pub fn as_trans(&self) -> &Transform<D::Trans>

Get the reference of transform type.

source

pub fn as_trans_mut(&mut self) -> &mut Transform<D::Trans>

Get the mutable reference of transform type.

source

pub fn harmonic(&self) -> usize

Get the harmonic number of the coefficients.

source

pub fn square_err(&self, rhs: &Self) -> f64

Square error.

Panics

When the harmonic number is different.

source

pub fn l1_norm(&self, rhs: &Self) -> f64

L1 norm error, aka Manhattan distance.

Panics

When the harmonic number is different.

source

pub fn l2_norm(&self, rhs: &Self) -> f64

L2 norm error, aka Euclidean distance.

Panics

When the harmonic number is different.

source

pub fn lp_norm(&self, rhs: &Self, p: i32) -> f64

Lp norm error, slower than Self::l1_norm() and Self::l2_norm().

Panics

When the harmonic number is different.

source

pub fn reverse(&mut self) -> &mut Self

Reverse the order of described curve then return a mutable reference.

source

pub fn reversed(self) -> Self

Consume and return a reversed version of the coefficients. This method can avoid mutable require.

Please clone the object if you want to do self-comparison.

source

pub fn generate_norm(&self, n: usize) -> Vec<Coord<D>>

Generate the normalized curve without transformation.

The number of the points n must larger than 3.

source

pub fn generate(&self, n: usize) -> Vec<Coord<D>>

Generate the described curve from the coefficients.

The number of the points n must given.

Trait Implementations§

source§

impl<D: Clone + EfdDim> Clone for Efd<D>where D::Trans: Clone,

source§

fn clone(&self) -> Efd<D>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<D> RefUnwindSafe for Efd<D>where D: RefUnwindSafe, <D as EfdDim>::Trans: RefUnwindSafe,

§

impl<D> Send for Efd<D>where D: Send, <D as EfdDim>::Trans: Send,

§

impl<D> Sync for Efd<D>where D: Sync, <D as EfdDim>::Trans: Sync,

§

impl<D> Unpin for Efd<D>where D: Unpin, <D as EfdDim>::Trans: Unpin,

§

impl<D> UnwindSafe for Efd<D>where D: UnwindSafe, <D as EfdDim>::Trans: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.