changes Norm to use associated type N
This commit is contained in:
parent
0e7116e3bb
commit
2071fdd14f
10
src/lib.rs
10
src/lib.rs
|
@ -329,13 +329,13 @@ pub fn center<N: BaseFloat, P: FloatPnt<N, V>, V: Copy>(a: &P, b: &P) -> P {
|
|||
*/
|
||||
/// Returns the distance between two points.
|
||||
#[inline(always)]
|
||||
pub fn dist<N: BaseFloat, P: FloatPnt<N, V>, V: Norm<N>>(a: &P, b: &P) -> N {
|
||||
pub fn dist<N: BaseFloat, P: FloatPnt<N, V>, V: Norm<N = N>>(a: &P, b: &P) -> N {
|
||||
a.dist(b)
|
||||
}
|
||||
|
||||
/// Returns the squared distance between two points.
|
||||
#[inline(always)]
|
||||
pub fn sqdist<N: BaseFloat, P: FloatPnt<N, V>, V: Norm<N>>(a: &P, b: &P) -> N {
|
||||
pub fn sqdist<N: BaseFloat, P: FloatPnt<N, V>, V: Norm<N = N>>(a: &P, b: &P) -> N {
|
||||
a.sqdist(b)
|
||||
}
|
||||
|
||||
|
@ -678,19 +678,19 @@ pub fn dot<V: Dot<N>, N>(a: &V, b: &V) -> N {
|
|||
|
||||
/// Computes the L2 norm of a vector.
|
||||
#[inline(always)]
|
||||
pub fn norm<V: Norm<N>, N: BaseFloat>(v: &V) -> N {
|
||||
pub fn norm<V: Norm<N = N>, N: BaseFloat>(v: &V) -> N {
|
||||
Norm::norm(v)
|
||||
}
|
||||
|
||||
/// Computes the squared L2 norm of a vector.
|
||||
#[inline(always)]
|
||||
pub fn sqnorm<V: Norm<N>, N: BaseFloat>(v: &V) -> N {
|
||||
pub fn sqnorm<V: Norm<N = N>, N: BaseFloat>(v: &V) -> N {
|
||||
Norm::sqnorm(v)
|
||||
}
|
||||
|
||||
/// Gets the normalized version of a vector.
|
||||
#[inline(always)]
|
||||
pub fn normalize<V: Norm<N>, N: BaseFloat>(v: &V) -> V {
|
||||
pub fn normalize<V: Norm<N = N>, N: BaseFloat>(v: &V) -> V {
|
||||
Norm::normalize(v)
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ pub fn householder_matrix<N, V, M>(dim: usize, start: usize, vec: V) -> M
|
|||
/// * `m` - matrix to decompose
|
||||
pub fn qr<N, V, M>(m: &M) -> (M, M)
|
||||
where N: BaseFloat,
|
||||
V: Indexable<usize, N> + Norm<N>,
|
||||
V: Indexable<usize, N> + Norm<N = N>,
|
||||
M: Copy + Eye + ColSlice<V> + Transpose + Indexable<(usize, usize), N> +
|
||||
Mul<M, Output = M> {
|
||||
let (rows, cols) = m.shape();
|
||||
|
@ -74,7 +74,7 @@ pub fn qr<N, V, M>(m: &M) -> (M, M)
|
|||
/// Eigendecomposition of a square matrix using the qr algorithm.
|
||||
pub fn eigen_qr<N, V, VS, M>(m: &M, eps: &N, niter: usize) -> (M, V)
|
||||
where N: BaseFloat,
|
||||
VS: Indexable<usize, N> + Norm<N>,
|
||||
VS: Indexable<usize, N> + Norm<N = N>,
|
||||
M: Indexable<(usize, usize), N> + SquareMat<N, V> + Add<M, Output = M> +
|
||||
Sub<M, Output = M> + ColSlice<VS> +
|
||||
ApproxEq<N> + Copy {
|
||||
|
|
|
@ -281,7 +281,9 @@ macro_rules! dvec_impl(
|
|||
}
|
||||
}
|
||||
|
||||
impl<N: BaseFloat> Norm<N> for $dvec<N> {
|
||||
impl<N: BaseFloat> Norm for $dvec<N> {
|
||||
type N = N;
|
||||
|
||||
#[inline]
|
||||
fn sqnorm(&self) -> N {
|
||||
Dot::dot(self, self)
|
||||
|
|
|
@ -108,7 +108,9 @@ impl<N: BaseFloat + ApproxEq<N>> Inv for Quat<N> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<N: BaseFloat> Norm<N> for Quat<N> {
|
||||
impl<N: BaseFloat> Norm for Quat<N> {
|
||||
type N = N;
|
||||
|
||||
#[inline]
|
||||
fn sqnorm(&self) -> N {
|
||||
self.w * self.w + self.i * self.i + self.j * self.j + self.k * self.k
|
||||
|
|
|
@ -191,7 +191,9 @@ impl<N: Copy + Add<N, Output = N> + Neg<Output = N>> Translation<vec::Vec0<N>> f
|
|||
}
|
||||
}
|
||||
|
||||
impl<N: BaseFloat> Norm<N> for vec::Vec0<N> {
|
||||
impl<N: BaseFloat> Norm for vec::Vec0<N> {
|
||||
type N = N;
|
||||
|
||||
#[inline]
|
||||
fn sqnorm(&self) -> N {
|
||||
::zero()
|
||||
|
|
|
@ -593,7 +593,9 @@ macro_rules! translation_impl(
|
|||
|
||||
macro_rules! norm_impl(
|
||||
($t: ident, $($compN: ident),+) => (
|
||||
impl<N: Copy + BaseFloat> Norm<N> for $t<N> {
|
||||
impl<N: Copy + BaseFloat> Norm for $t<N> {
|
||||
type N = N;
|
||||
|
||||
#[inline]
|
||||
fn sqnorm(&self) -> N {
|
||||
Dot::dot(self, self)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
//! Traits of operations having a well-known or explicit geometric meaning.
|
||||
|
||||
use std::num::Float;
|
||||
use std::ops::Neg;
|
||||
use traits::structure::{BaseFloat, Mat};
|
||||
|
||||
|
@ -208,23 +209,25 @@ pub trait Dot<N> {
|
|||
}
|
||||
|
||||
/// Traits of objects having an euclidian norm.
|
||||
pub trait Norm<N: BaseFloat> {
|
||||
pub trait Norm {
|
||||
type N: BaseFloat;
|
||||
|
||||
/// Computes the norm of `self`.
|
||||
#[inline]
|
||||
fn norm(&self) -> N {
|
||||
fn norm(&self) -> <Self as Norm>::N {
|
||||
self.sqnorm().sqrt()
|
||||
}
|
||||
|
||||
/// Computes the squared norm of `self`.
|
||||
///
|
||||
/// This is usually faster than computing the norm itself.
|
||||
fn sqnorm(&self) -> N;
|
||||
fn sqnorm(&self) -> <Self as Norm>::N;
|
||||
|
||||
/// Gets the normalized version of a copy of `v`.
|
||||
fn normalize(&self) -> Self;
|
||||
|
||||
/// Normalizes `self`.
|
||||
fn normalize_mut(&mut self) -> N;
|
||||
fn normalize_mut(&mut self) -> <Self as Norm>::N;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -244,7 +244,7 @@ pub trait NumVec<N>: Dim +
|
|||
}
|
||||
|
||||
/// Trait of vector with components implementing the `BaseFloat` trait.
|
||||
pub trait FloatVec<N: BaseFloat>: NumVec<N> + Norm<N> + Basis {
|
||||
pub trait FloatVec<N: BaseFloat>: NumVec<N> + Norm<N = N> + Basis {
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -282,7 +282,7 @@ pub trait NumPnt<N, V>:
|
|||
}
|
||||
|
||||
/// Trait of points with components implementing the `BaseFloat` trait.
|
||||
pub trait FloatPnt<N: BaseFloat, V: Norm<N>>: NumPnt<N, V> + Sized {
|
||||
pub trait FloatPnt<N: BaseFloat, V: Norm<N = N>>: NumPnt<N, V> + Sized {
|
||||
/// Computes the square distance between two points.
|
||||
#[inline]
|
||||
fn sqdist(&self, other: &Self) -> N {
|
||||
|
|
Loading…
Reference in New Issue