Skip to content

Commit

Permalink
Update docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
KmolYuan committed Aug 12, 2023
1 parent fe89ead commit f01c066
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 17 deletions.
4 changes: 3 additions & 1 deletion src/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ pub trait Curve<A: Clone>: Sized {

/// Close the curve by the first element.
///
/// Panic with empty curve.
/// # Panics
///
/// Panics if the curve is empty.
#[must_use]
fn closed_lin(self) -> Vec<A> {
let mut c = self.to_curve();
Expand Down
46 changes: 30 additions & 16 deletions src/efd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,15 @@ impl<D: EfdDim> Efd<D> {
/// The array size is (harmonic) x (dimension x 2). The dimension is
/// [`CoordHint::Dim`].
///
/// # Safety
///
/// Other operations might panic if the harmonic is zero.
/// Zero harmonic is allowed but meaningless. If the harmonic is zero, some
/// operations will panic.
///
/// ```
/// use efd::{Coeff2, Efd2};
/// let coeff = Coeff2::from_column_slice(&[]);
/// let path = Efd2::from_coeffs_unchecked(coeff).generate(20);
/// assert_eq!(path.len(), 0);
/// ```
pub fn from_coeffs_unchecked(coeffs: Coeff<D>) -> Self {
Self { coeffs, trans: Transform::identity() }
}
Expand All @@ -77,9 +83,9 @@ impl<D: EfdDim> Efd<D> {
/// 1. The initial harmonic number is the same as the curve point.
/// 1. Fourier Power Anaysis (FPA) uses 99.99% threshold.
///
/// # Panic
/// # Panics
///
/// Panic if the curve length is not greater than 1 in debug mode. This
/// Panics if the curve length is not greater than 1 in debug mode. This
/// function check the lengths only. Please use [`valid_curve()`] to
/// verify the curve if there has NaN input.
#[must_use]
Expand Down Expand Up @@ -128,9 +134,9 @@ impl<D: EfdDim> Efd<D> {
/// 1. The initial harmonic is decide by user.
/// 1. No harmonic reduced. Please call [`Efd::fourier_power_anaysis()`].
///
/// # Panic
/// # Panics
///
/// Panic if the specific harmonic is zero or the curve length is not
/// Panics if the specific harmonic is zero or the curve length is not
/// greater than 1 in the **debug mode**. This function check the lengths
/// only. Please use [`valid_curve()`] to verify the curve if there has
/// NaN input.
Expand Down Expand Up @@ -171,6 +177,10 @@ impl<D: EfdDim> Efd<D> {
/// undersampling.
///
/// The default threshold is 99.99%.
///
/// # Panics
///
/// Panics if the threshold is not in 0..1, or the harmonic is zero.
#[must_use]
pub fn fourier_power_anaysis<T>(mut self, threshold: T) -> Self
where
Expand All @@ -194,6 +204,10 @@ impl<D: EfdDim> Efd<D> {
///
/// If the coefficients are constructed by `*_unnorm` or `*_unchecked`
/// methods, this method will normalize them.
///
/// # Panics
///
/// Panics if the harmonic is zero.
pub fn normalized(self) -> Self {
let Self { mut coeffs, trans } = self;
let trans_new = D::coeff_norm(&mut coeffs);
Expand Down Expand Up @@ -308,29 +322,29 @@ impl<D: EfdDim> Efd<D> {

/// Generate the described curve. (`theta=TAU`)
///
/// # Panic
/// # Panics
///
/// The number of the points `n` must larger than 1.
/// Panics if the number of the points `n` is less than 2.
#[must_use]
pub fn generate(&self, n: usize) -> Vec<Coord<D>> {
self.generate_in(n, TAU)
}

/// Generate a half of the described curve. (`theta=PI`)
///
/// # Panic
/// # Panics
///
/// The number of the points `n` must larger than 1.
/// Panics if the number of the points `n` is less than 2.
#[must_use]
pub fn generate_half(&self, n: usize) -> Vec<Coord<D>> {
self.generate_in(n, PI)
}

/// Generate the described curve in a specific angle `theta` (`0..=TAU`).
///
/// # Panic
/// # Panics
///
/// The number of the points `n` must larger than 1.
/// Panics if the number of the points `n` is less than 2.
#[must_use]
pub fn generate_in(&self, n: usize, theta: f64) -> Vec<Coord<D>> {
let mut curve = self.generate_norm_in(n, theta);
Expand All @@ -342,9 +356,9 @@ impl<D: EfdDim> Efd<D> {
///
/// Normalized curve is **without** transformation.
///
/// # Panic
/// # Panics
///
/// The number of the points `n` must larger than 1.
/// Panics if the number of the points `n` is less than 2.
#[must_use]
pub fn generate_norm_in(&self, n: usize, theta: f64) -> Vec<Coord<D>> {
assert!(n > 1, "n ({n}) must larger than 1");
Expand All @@ -358,7 +372,7 @@ impl<D: EfdDim> Efd<D> {
CKernel::<D>::from_slice(c.as_slice()) * t
})
.reduce(|a, b| a + b)
.unwrap()
.unwrap_or_else(|| na::OMatrix::<f64, Dim<D>, na::Dyn>::from_vec(Vec::new()))
.column_iter()
.map(Coord::<D>::to_coord)
.collect()
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
//! This crate supports no-std solution via using "libm", a crate provides
//! pure-rust math functions. Disable the "std" feature will automatically
//! enable it.
//!
//! ```toml
//! default-features = false
//! ```
#![warn(missing_docs)]
#![forbid(unsafe_code)]
#![cfg_attr(not(feature = "std"), no_std)]
Expand Down

0 comments on commit f01c066

Please sign in to comment.