Rename similar in-place and copy methods
Fixes #52. This renames pairs of methods like `normalize_cpy`, `normalize` to `normalize` and `normalize_mut`. Note that the previous in-place operations had the same name that now belongs to the copy operations. Therefore this is a breaking change. On a similar note, the `Quat::conjugate` method was also renamed to `conjugate_mut` and a new copying method has taken its place. This appears to be a similar issue (apart from the lack of the copy operation) and thus was dealt with here, too.
This commit is contained in:
parent
39fd7c1ae7
commit
3107dd607b
20
src/lib.rs
20
src/lib.rs
|
@ -31,7 +31,7 @@ fn main() {
|
||||||
let a = Vec3::new(1.0f64, 1.0, 1.0);
|
let a = Vec3::new(1.0f64, 1.0, 1.0);
|
||||||
let mut b = Rot3::new(na::zero());
|
let mut b = Rot3::new(na::zero());
|
||||||
|
|
||||||
b.append_rotation(&a);
|
b.append_rotation_mut(&a);
|
||||||
|
|
||||||
assert!(na::approx_eq(&na::rotation(&b), &a));
|
assert!(na::approx_eq(&na::rotation(&b), &a));
|
||||||
}
|
}
|
||||||
|
@ -407,7 +407,7 @@ pub fn inv_translation<V, M: Translation<V>>(m: &M) -> V {
|
||||||
/// Applies the translation `v` to a copy of `m`.
|
/// Applies the translation `v` to a copy of `m`.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn append_translation<V, M: Translation<V>>(m: &M, v: &V) -> M {
|
pub fn append_translation<V, M: Translation<V>>(m: &M, v: &V) -> M {
|
||||||
Translation::append_translation_cpy(m, v)
|
Translation::append_translation(m, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -509,7 +509,7 @@ pub fn inv_rotation<V, M: Rotation<V>>(m: &M) -> V {
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn append_rotation<V, M: Rotation<V>>(m: &M, v: &V) -> M {
|
pub fn append_rotation<V, M: Rotation<V>>(m: &M, v: &V) -> M {
|
||||||
Rotation::append_rotation_cpy(m, v)
|
Rotation::append_rotation(m, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: this example is a bit shity
|
// FIXME: this example is a bit shity
|
||||||
|
@ -529,7 +529,7 @@ pub fn append_rotation<V, M: Rotation<V>>(m: &M, v: &V) -> M {
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn prepend_rotation<V, M: Rotation<V>>(m: &M, v: &V) -> M {
|
pub fn prepend_rotation<V, M: Rotation<V>>(m: &M, v: &V) -> M {
|
||||||
Rotation::prepend_rotation_cpy(m, v)
|
Rotation::prepend_rotation(m, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -589,7 +589,7 @@ pub fn append_rotation_wrt_point<LV: Neg<Output = LV> + Copy,
|
||||||
m: &M,
|
m: &M,
|
||||||
amount: &AV,
|
amount: &AV,
|
||||||
center: &LV) -> M {
|
center: &LV) -> M {
|
||||||
RotationWithTranslation::append_rotation_wrt_point_cpy(m, amount, center)
|
RotationWithTranslation::append_rotation_wrt_point(m, amount, center)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Rotates a copy of `m` by `amount` using `m.translation()` as the pivot point.
|
/// Rotates a copy of `m` by `amount` using `m.translation()` as the pivot point.
|
||||||
|
@ -599,7 +599,7 @@ pub fn append_rotation_wrt_center<LV: Neg<Output = LV> + Copy,
|
||||||
M: RotationWithTranslation<LV, AV>>(
|
M: RotationWithTranslation<LV, AV>>(
|
||||||
m: &M,
|
m: &M,
|
||||||
amount: &AV) -> M {
|
amount: &AV) -> M {
|
||||||
RotationWithTranslation::append_rotation_wrt_center_cpy(m, amount)
|
RotationWithTranslation::append_rotation_wrt_center(m, amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -641,7 +641,7 @@ pub fn inv_transformation<T, M: Transformation<T>>(m: &M) -> T {
|
||||||
/// Gets a transformed copy of `m`.
|
/// Gets a transformed copy of `m`.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn append_transformation<T, M: Transformation<T>>(m: &M, t: &T) -> M {
|
pub fn append_transformation<T, M: Transformation<T>>(m: &M, t: &T) -> M {
|
||||||
Transformation::append_transformation_cpy(m, t)
|
Transformation::append_transformation(m, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -689,7 +689,7 @@ pub fn sqnorm<V: Norm<N>, N: BaseFloat>(v: &V) -> N {
|
||||||
/// Gets the normalized version of a vector.
|
/// Gets the normalized version of a vector.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn normalize<V: Norm<N>, N: BaseFloat>(v: &V) -> V {
|
pub fn normalize<V: Norm<N>, N: BaseFloat>(v: &V) -> V {
|
||||||
Norm::normalize_cpy(v)
|
Norm::normalize(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -795,7 +795,7 @@ pub fn abs<M: Absolute<Res>, Res>(m: &M) -> Res {
|
||||||
/// Gets an inverted copy of a matrix.
|
/// Gets an inverted copy of a matrix.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn inv<M: Inv>(m: &M) -> Option<M> {
|
pub fn inv<M: Inv>(m: &M) -> Option<M> {
|
||||||
Inv::inv_cpy(m)
|
Inv::inv(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -805,7 +805,7 @@ pub fn inv<M: Inv>(m: &M) -> Option<M> {
|
||||||
/// Gets a transposed copy of a matrix.
|
/// Gets a transposed copy of a matrix.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn transpose<M: Transpose>(m: &M) -> M {
|
pub fn transpose<M: Transpose>(m: &M) -> M {
|
||||||
Transpose::transpose_cpy(m)
|
Transpose::transpose(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -63,10 +63,10 @@ pub fn qr<N, V, M>(m: &M) -> (M, M)
|
||||||
let x = v.unsafe_at(0);
|
let x = v.unsafe_at(0);
|
||||||
v.unsafe_set(0, x - alpha);
|
v.unsafe_set(0, x - alpha);
|
||||||
}
|
}
|
||||||
if !::is_zero(&v.normalize()) {
|
if !::is_zero(&v.normalize_mut()) {
|
||||||
let qk: M = householder_matrix(rows, ite, v);
|
let qk: M = householder_matrix(rows, ite, v);
|
||||||
r = qk * r;
|
r = qk * r;
|
||||||
q = q * Transpose::transpose_cpy(&qk);
|
q = q * Transpose::transpose(&qk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ impl<N: Clone + Copy> DMat<N> {
|
||||||
let mut res = DMat::from_col_vec(ncols, nrows, vec);
|
let mut res = DMat::from_col_vec(ncols, nrows, vec);
|
||||||
|
|
||||||
// we transpose because the buffer is row_major
|
// we transpose because the buffer is row_major
|
||||||
res.transpose();
|
res.transpose_mut();
|
||||||
|
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
@ -370,9 +370,9 @@ impl<N: Copy + Add<N, Output = N> + Mul<N, Output = N> + Zero> Mul<DMat<N>> for
|
||||||
|
|
||||||
impl<N: BaseNum + Clone> Inv for DMat<N> {
|
impl<N: BaseNum + Clone> Inv for DMat<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn inv_cpy(&self) -> Option<DMat<N>> {
|
fn inv(&self) -> Option<DMat<N>> {
|
||||||
let mut res: DMat<N> = self.clone();
|
let mut res: DMat<N> = self.clone();
|
||||||
if res.inv() {
|
if res.inv_mut() {
|
||||||
Some(res)
|
Some(res)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -380,7 +380,7 @@ impl<N: BaseNum + Clone> Inv for DMat<N> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inv(&mut self) -> bool {
|
fn inv_mut(&mut self) -> bool {
|
||||||
assert!(self.nrows == self.ncols);
|
assert!(self.nrows == self.ncols);
|
||||||
|
|
||||||
let dim = self.nrows;
|
let dim = self.nrows;
|
||||||
|
@ -456,11 +456,11 @@ impl<N: BaseNum + Clone> Inv for DMat<N> {
|
||||||
|
|
||||||
impl<N: Clone + Copy> Transpose for DMat<N> {
|
impl<N: Clone + Copy> Transpose for DMat<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn transpose_cpy(&self) -> DMat<N> {
|
fn transpose(&self) -> DMat<N> {
|
||||||
if self.nrows == self.ncols {
|
if self.nrows == self.ncols {
|
||||||
let mut res = self.clone();
|
let mut res = self.clone();
|
||||||
|
|
||||||
res.transpose();
|
res.transpose_mut();
|
||||||
|
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
@ -480,7 +480,7 @@ impl<N: Clone + Copy> Transpose for DMat<N> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn transpose(&mut self) {
|
fn transpose_mut(&mut self) {
|
||||||
if self.nrows == self.ncols {
|
if self.nrows == self.ncols {
|
||||||
for i in (1us .. self.nrows) {
|
for i in (1us .. self.nrows) {
|
||||||
for j in (0us .. self.ncols - 1) {
|
for j in (0us .. self.ncols - 1) {
|
||||||
|
@ -495,7 +495,7 @@ impl<N: Clone + Copy> Transpose for DMat<N> {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// FIXME: implement a better algorithm which does that in-place.
|
// FIXME: implement a better algorithm which does that in-place.
|
||||||
*self = Transpose::transpose_cpy(self);
|
*self = Transpose::transpose(self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -539,7 +539,7 @@ impl<N: BaseNum + Cast<f64> + Clone> Cov<DMat<N>> for DMat<N> {
|
||||||
let fnormalizer: f64 = Cast::from(self.nrows() - 1);
|
let fnormalizer: f64 = Cast::from(self.nrows() - 1);
|
||||||
let normalizer: N = Cast::from(fnormalizer);
|
let normalizer: N = Cast::from(fnormalizer);
|
||||||
// FIXME: this will do 2 allocations for temporaries!
|
// FIXME: this will do 2 allocations for temporaries!
|
||||||
(Transpose::transpose_cpy(¢ered) * centered) / normalizer
|
(Transpose::transpose(¢ered) * centered) / normalizer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -184,7 +184,7 @@ macro_rules! dvec_impl(
|
||||||
};
|
};
|
||||||
|
|
||||||
if !ApproxEq::approx_eq(&Norm::sqnorm(&elt), &::zero()) {
|
if !ApproxEq::approx_eq(&Norm::sqnorm(&elt), &::zero()) {
|
||||||
res.push(Norm::normalize_cpy(&elt));
|
res.push(Norm::normalize(&elt));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,14 +290,14 @@ macro_rules! dvec_impl(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn normalize_cpy(&self) -> $dvec<N> {
|
fn normalize(&self) -> $dvec<N> {
|
||||||
let mut res : $dvec<N> = self.clone();
|
let mut res : $dvec<N> = self.clone();
|
||||||
let _ = res.normalize();
|
let _ = res.normalize_mut();
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn normalize(&mut self) -> N {
|
fn normalize_mut(&mut self) -> N {
|
||||||
let l = Norm::norm(self);
|
let l = Norm::norm(self);
|
||||||
|
|
||||||
for n in self.as_mut_slice().iter_mut() {
|
for n in self.as_mut_slice().iter_mut() {
|
||||||
|
|
|
@ -115,22 +115,22 @@ macro_rules! translation_impl(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn append_translation(&mut self, t: &$tv<N>) {
|
fn append_translation_mut(&mut self, t: &$tv<N>) {
|
||||||
self.translation = *t + self.translation
|
self.translation = *t + self.translation
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn append_translation_cpy(&self, t: &$tv<N>) -> $t<N> {
|
fn append_translation(&self, t: &$tv<N>) -> $t<N> {
|
||||||
$t::new_with_rotmat(*t + self.translation, self.rotation)
|
$t::new_with_rotmat(*t + self.translation, self.rotation)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn prepend_translation(&mut self, t: &$tv<N>) {
|
fn prepend_translation_mut(&mut self, t: &$tv<N>) {
|
||||||
self.translation = self.translation + self.rotation * *t
|
self.translation = self.translation + self.rotation * *t
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn prepend_translation_cpy(&self, t: &$tv<N>) -> $t<N> {
|
fn prepend_translation(&self, t: &$tv<N>) -> $t<N> {
|
||||||
$t::new_with_rotmat(self.translation + self.rotation * *t, self.rotation)
|
$t::new_with_rotmat(self.translation + self.rotation * *t, self.rotation)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ macro_rules! rotation_impl(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn append_rotation(&mut self, rot: &$tav<N>) {
|
fn append_rotation_mut(&mut self, rot: &$tav<N>) {
|
||||||
let delta = $trot::new(*rot);
|
let delta = $trot::new(*rot);
|
||||||
|
|
||||||
self.rotation = delta * self.rotation;
|
self.rotation = delta * self.rotation;
|
||||||
|
@ -180,21 +180,21 @@ macro_rules! rotation_impl(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn append_rotation_cpy(&self, rot: &$tav<N>) -> $t<N> {
|
fn append_rotation(&self, rot: &$tav<N>) -> $t<N> {
|
||||||
let delta = $trot::new(*rot);
|
let delta = $trot::new(*rot);
|
||||||
|
|
||||||
$t::new_with_rotmat(delta * self.translation, delta * self.rotation)
|
$t::new_with_rotmat(delta * self.translation, delta * self.rotation)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn prepend_rotation(&mut self, rot: &$tav<N>) {
|
fn prepend_rotation_mut(&mut self, rot: &$tav<N>) {
|
||||||
let delta = $trot::new(*rot);
|
let delta = $trot::new(*rot);
|
||||||
|
|
||||||
self.rotation = self.rotation * delta;
|
self.rotation = self.rotation * delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn prepend_rotation_cpy(&self, rot: &$tav<N>) -> $t<N> {
|
fn prepend_rotation(&self, rot: &$tav<N>) -> $t<N> {
|
||||||
let delta = $trot::new(*rot);
|
let delta = $trot::new(*rot);
|
||||||
|
|
||||||
$t::new_with_rotmat(self.translation, self.rotation * delta)
|
$t::new_with_rotmat(self.translation, self.rotation * delta)
|
||||||
|
@ -234,22 +234,22 @@ macro_rules! transformation_impl(
|
||||||
|
|
||||||
fn inv_transformation(&self) -> $t<N> {
|
fn inv_transformation(&self) -> $t<N> {
|
||||||
// inversion will never fails
|
// inversion will never fails
|
||||||
Inv::inv_cpy(self).unwrap()
|
Inv::inv(self).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn append_transformation(&mut self, t: &$t<N>) {
|
fn append_transformation_mut(&mut self, t: &$t<N>) {
|
||||||
*self = *t * *self
|
*self = *t * *self
|
||||||
}
|
}
|
||||||
|
|
||||||
fn append_transformation_cpy(&self, t: &$t<N>) -> $t<N> {
|
fn append_transformation(&self, t: &$t<N>) -> $t<N> {
|
||||||
*t * *self
|
*t * *self
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prepend_transformation(&mut self, t: &$t<N>) {
|
fn prepend_transformation_mut(&mut self, t: &$t<N>) {
|
||||||
*self = *self * *t
|
*self = *self * *t
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prepend_transformation_cpy(&self, t: &$t<N>) -> $t<N> {
|
fn prepend_transformation(&self, t: &$t<N>) -> $t<N> {
|
||||||
*self * *t
|
*self * *t
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,17 +280,17 @@ macro_rules! inv_impl(
|
||||||
($t: ident) => (
|
($t: ident) => (
|
||||||
impl<N: BaseNum> Inv for $t<N> {
|
impl<N: BaseNum> Inv for $t<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn inv(&mut self) -> bool {
|
fn inv_mut(&mut self) -> bool {
|
||||||
self.rotation.inv();
|
self.rotation.inv_mut();
|
||||||
self.translation = self.rotation * -self.translation;
|
self.translation = self.rotation * -self.translation;
|
||||||
// always succeed
|
// always succeed
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn inv_cpy(&self) -> Option<$t<N>> {
|
fn inv(&self) -> Option<$t<N>> {
|
||||||
let mut res = *self;
|
let mut res = *self;
|
||||||
res.inv();
|
res.inv_mut();
|
||||||
// always succeed
|
// always succeed
|
||||||
Some(res)
|
Some(res)
|
||||||
}
|
}
|
||||||
|
|
|
@ -532,9 +532,9 @@ macro_rules! inv_impl(
|
||||||
impl<N: Copy + BaseNum>
|
impl<N: Copy + BaseNum>
|
||||||
Inv for $t<N> {
|
Inv for $t<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn inv_cpy(&self) -> Option<$t<N>> {
|
fn inv(&self) -> Option<$t<N>> {
|
||||||
let mut res : $t<N> = *self;
|
let mut res : $t<N> = *self;
|
||||||
if res.inv() {
|
if res.inv_mut() {
|
||||||
Some(res)
|
Some(res)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -542,7 +542,7 @@ macro_rules! inv_impl(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inv(&mut self) -> bool {
|
fn inv_mut(&mut self) -> bool {
|
||||||
let mut res: $t<N> = ::one();
|
let mut res: $t<N> = ::one();
|
||||||
|
|
||||||
// inversion using Gauss-Jordan elimination
|
// inversion using Gauss-Jordan elimination
|
||||||
|
@ -614,15 +614,15 @@ macro_rules! transpose_impl(
|
||||||
($t: ident, $dim: expr) => (
|
($t: ident, $dim: expr) => (
|
||||||
impl<N: Copy> Transpose for $t<N> {
|
impl<N: Copy> Transpose for $t<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn transpose_cpy(&self) -> $t<N> {
|
fn transpose(&self) -> $t<N> {
|
||||||
let mut res = *self;
|
let mut res = *self;
|
||||||
|
|
||||||
res.transpose();
|
res.transpose_mut();
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn transpose(&mut self) {
|
fn transpose_mut(&mut self) {
|
||||||
for i in (1us .. $dim) {
|
for i in (1us .. $dim) {
|
||||||
for j in (0us .. i) {
|
for j in (0us .. i) {
|
||||||
self.swap((i, j), (j, i))
|
self.swap((i, j), (j, i))
|
||||||
|
|
|
@ -61,9 +61,15 @@ impl<N> Quat<N> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Neg<Output = N> + Copy> Quat<N> {
|
impl<N: Neg<Output = N> + Copy> Quat<N> {
|
||||||
|
/// Compute the conjugate of this quaternion.
|
||||||
|
#[inline]
|
||||||
|
pub fn conjugate(&self) -> Quat<N> {
|
||||||
|
Quat { w: self.w, i: -self.i, j: -self.j, k: -self.k }
|
||||||
|
}
|
||||||
|
|
||||||
/// Replaces this quaternion by its conjugate.
|
/// Replaces this quaternion by its conjugate.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn conjugate(&mut self) {
|
pub fn conjugate_mut(&mut self) {
|
||||||
self.i = -self.i;
|
self.i = -self.i;
|
||||||
self.j = -self.j;
|
self.j = -self.j;
|
||||||
self.k = -self.k;
|
self.k = -self.k;
|
||||||
|
@ -72,10 +78,10 @@ impl<N: Neg<Output = N> + Copy> Quat<N> {
|
||||||
|
|
||||||
impl<N: BaseFloat + ApproxEq<N>> Inv for Quat<N> {
|
impl<N: BaseFloat + ApproxEq<N>> Inv for Quat<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn inv_cpy(&self) -> Option<Quat<N>> {
|
fn inv(&self) -> Option<Quat<N>> {
|
||||||
let mut res = *self;
|
let mut res = *self;
|
||||||
|
|
||||||
if res.inv() {
|
if res.inv_mut() {
|
||||||
Some(res)
|
Some(res)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -84,14 +90,14 @@ impl<N: BaseFloat + ApproxEq<N>> Inv for Quat<N> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn inv(&mut self) -> bool {
|
fn inv_mut(&mut self) -> bool {
|
||||||
let sqnorm = Norm::sqnorm(self);
|
let sqnorm = Norm::sqnorm(self);
|
||||||
|
|
||||||
if ApproxEq::approx_eq(&sqnorm, &::zero()) {
|
if ApproxEq::approx_eq(&sqnorm, &::zero()) {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
self.conjugate();
|
self.conjugate_mut();
|
||||||
self.w = self.w / sqnorm;
|
self.w = self.w / sqnorm;
|
||||||
self.i = self.i / sqnorm;
|
self.i = self.i / sqnorm;
|
||||||
self.j = self.j / sqnorm;
|
self.j = self.j / sqnorm;
|
||||||
|
@ -109,13 +115,13 @@ impl<N: BaseFloat> Norm<N> for Quat<N> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn normalize_cpy(&self) -> Quat<N> {
|
fn normalize(&self) -> Quat<N> {
|
||||||
let n = self.norm();
|
let n = self.norm();
|
||||||
Quat::new(self.w / n, self.i / n, self.j / n, self.k / n)
|
Quat::new(self.w / n, self.i / n, self.j / n, self.k / n)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn normalize(&mut self) -> N {
|
fn normalize_mut(&mut self) -> N {
|
||||||
let n = Norm::norm(self);
|
let n = Norm::norm(self);
|
||||||
|
|
||||||
self.w = self.w / n;
|
self.w = self.w / n;
|
||||||
|
@ -146,7 +152,7 @@ impl<N: ApproxEq<N> + BaseFloat> Div<Quat<N>> for Quat<N> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn div(self, right: Quat<N>) -> Quat<N> {
|
fn div(self, right: Quat<N>) -> Quat<N> {
|
||||||
self * right.inv_cpy().expect("Unable to invert the denominator.")
|
self * right.inv().expect("Unable to invert the denominator.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,16 +279,16 @@ impl<N: BaseNum> One for UnitQuat<N> {
|
||||||
|
|
||||||
impl<N: Copy + Neg<Output = N>> Inv for UnitQuat<N> {
|
impl<N: Copy + Neg<Output = N>> Inv for UnitQuat<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn inv_cpy(&self) -> Option<UnitQuat<N>> {
|
fn inv(&self) -> Option<UnitQuat<N>> {
|
||||||
let mut cpy = *self;
|
let mut cpy = *self;
|
||||||
|
|
||||||
cpy.inv();
|
cpy.inv_mut();
|
||||||
Some(cpy)
|
Some(cpy)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn inv(&mut self) -> bool {
|
fn inv_mut(&mut self) -> bool {
|
||||||
self.q.conjugate();
|
self.q.conjugate_mut();
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -366,7 +372,7 @@ impl<N: BaseNum> Mul<UnitQuat<N>> for Vec3<N> {
|
||||||
fn mul(self, right: UnitQuat<N>) -> Vec3<N> {
|
fn mul(self, right: UnitQuat<N>) -> Vec3<N> {
|
||||||
let mut inv_quat = right;
|
let mut inv_quat = right;
|
||||||
|
|
||||||
inv_quat.inv();
|
inv_quat.inv_mut();
|
||||||
|
|
||||||
inv_quat * self
|
inv_quat * self
|
||||||
}
|
}
|
||||||
|
@ -386,7 +392,7 @@ impl<N: BaseFloat> Rotation<Vec3<N>> for UnitQuat<N> {
|
||||||
fn rotation(&self) -> Vec3<N> {
|
fn rotation(&self) -> Vec3<N> {
|
||||||
let _2 = ::one::<N>() + ::one();
|
let _2 = ::one::<N>() + ::one();
|
||||||
let mut v = *self.q.vector();
|
let mut v = *self.q.vector();
|
||||||
let ang = _2 * v.normalize().atan2(self.q.w);
|
let ang = _2 * v.normalize_mut().atan2(self.q.w);
|
||||||
|
|
||||||
if ::is_zero(&ang) {
|
if ::is_zero(&ang) {
|
||||||
::zero()
|
::zero()
|
||||||
|
@ -402,22 +408,22 @@ impl<N: BaseFloat> Rotation<Vec3<N>> for UnitQuat<N> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn append_rotation(&mut self, amount: &Vec3<N>) {
|
fn append_rotation_mut(&mut self, amount: &Vec3<N>) {
|
||||||
*self = Rotation::append_rotation_cpy(self, amount)
|
*self = Rotation::append_rotation(self, amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn append_rotation_cpy(&self, amount: &Vec3<N>) -> UnitQuat<N> {
|
fn append_rotation(&self, amount: &Vec3<N>) -> UnitQuat<N> {
|
||||||
*self * UnitQuat::new(*amount)
|
*self * UnitQuat::new(*amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn prepend_rotation(&mut self, amount: &Vec3<N>) {
|
fn prepend_rotation_mut(&mut self, amount: &Vec3<N>) {
|
||||||
*self = Rotation::prepend_rotation_cpy(self, amount)
|
*self = Rotation::prepend_rotation(self, amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn prepend_rotation_cpy(&self, amount: &Vec3<N>) -> UnitQuat<N> {
|
fn prepend_rotation(&self, amount: &Vec3<N>) -> UnitQuat<N> {
|
||||||
UnitQuat::new(*amount) * *self
|
UnitQuat::new(*amount) * *self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,22 +44,22 @@ impl<N: BaseFloat + Clone> Rotation<Vec1<N>> for Rot2<N> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn append_rotation(&mut self, rot: &Vec1<N>) {
|
fn append_rotation_mut(&mut self, rot: &Vec1<N>) {
|
||||||
*self = Rotation::append_rotation_cpy(self, rot)
|
*self = Rotation::append_rotation(self, rot)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn append_rotation_cpy(&self, rot: &Vec1<N>) -> Rot2<N> {
|
fn append_rotation(&self, rot: &Vec1<N>) -> Rot2<N> {
|
||||||
Rot2::new(rot.clone()) * *self
|
Rot2::new(rot.clone()) * *self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn prepend_rotation(&mut self, rot: &Vec1<N>) {
|
fn prepend_rotation_mut(&mut self, rot: &Vec1<N>) {
|
||||||
*self = Rotation::prepend_rotation_cpy(self, rot)
|
*self = Rotation::prepend_rotation(self, rot)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn prepend_rotation_cpy(&self, rot: &Vec1<N>) -> Rot2<N> {
|
fn prepend_rotation(&self, rot: &Vec1<N>) -> Rot2<N> {
|
||||||
*self * Rot2::new(rot.clone())
|
*self * Rot2::new(rot.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ impl<N: Clone + BaseFloat> Rot3<N> {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let mut axis = axisangle;
|
let mut axis = axisangle;
|
||||||
let angle = axis.normalize();
|
let angle = axis.normalize_mut();
|
||||||
let _1: N = ::one();
|
let _1: N = ::one();
|
||||||
let ux = axis.x.clone();
|
let ux = axis.x.clone();
|
||||||
let uy = axis.y.clone();
|
let uy = axis.y.clone();
|
||||||
|
@ -187,8 +187,8 @@ impl<N: Clone + BaseFloat> Rot3<N> {
|
||||||
/// * up - Vector pointing `up`. The only requirement of this parameter is to not be colinear
|
/// * up - Vector pointing `up`. The only requirement of this parameter is to not be colinear
|
||||||
/// with `at`. Non-colinearity is not checked.
|
/// with `at`. Non-colinearity is not checked.
|
||||||
pub fn look_at(&mut self, at: &Vec3<N>, up: &Vec3<N>) {
|
pub fn look_at(&mut self, at: &Vec3<N>, up: &Vec3<N>) {
|
||||||
let xaxis = Norm::normalize_cpy(at);
|
let xaxis = Norm::normalize(at);
|
||||||
let zaxis = Norm::normalize_cpy(&Cross::cross(up, &xaxis));
|
let zaxis = Norm::normalize(&Cross::cross(up, &xaxis));
|
||||||
let yaxis = Cross::cross(&zaxis, &xaxis);
|
let yaxis = Cross::cross(&zaxis, &xaxis);
|
||||||
|
|
||||||
self.submat = Mat3::new(
|
self.submat = Mat3::new(
|
||||||
|
@ -204,8 +204,8 @@ impl<N: Clone + BaseFloat> Rot3<N> {
|
||||||
/// * up - Vector pointing `up`. The only requirement of this parameter is to not be colinear
|
/// * up - Vector pointing `up`. The only requirement of this parameter is to not be colinear
|
||||||
/// with `at`. Non-colinearity is not checked.
|
/// with `at`. Non-colinearity is not checked.
|
||||||
pub fn look_at_z(&mut self, at: &Vec3<N>, up: &Vec3<N>) {
|
pub fn look_at_z(&mut self, at: &Vec3<N>, up: &Vec3<N>) {
|
||||||
let zaxis = Norm::normalize_cpy(at);
|
let zaxis = Norm::normalize(at);
|
||||||
let xaxis = Norm::normalize_cpy(&Cross::cross(up, &zaxis));
|
let xaxis = Norm::normalize(&Cross::cross(up, &zaxis));
|
||||||
let yaxis = Cross::cross(&zaxis, &xaxis);
|
let yaxis = Cross::cross(&zaxis, &xaxis);
|
||||||
|
|
||||||
self.submat = Mat3::new(
|
self.submat = Mat3::new(
|
||||||
|
@ -255,22 +255,22 @@ Rotation<Vec3<N>> for Rot3<N> {
|
||||||
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn append_rotation(&mut self, rot: &Vec3<N>) {
|
fn append_rotation_mut(&mut self, rot: &Vec3<N>) {
|
||||||
*self = Rotation::append_rotation_cpy(self, rot)
|
*self = Rotation::append_rotation(self, rot)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn append_rotation_cpy(&self, axisangle: &Vec3<N>) -> Rot3<N> {
|
fn append_rotation(&self, axisangle: &Vec3<N>) -> Rot3<N> {
|
||||||
Rot3::new(axisangle.clone()) * *self
|
Rot3::new(axisangle.clone()) * *self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn prepend_rotation(&mut self, rot: &Vec3<N>) {
|
fn prepend_rotation_mut(&mut self, rot: &Vec3<N>) {
|
||||||
*self = Rotation::prepend_rotation_cpy(self, rot)
|
*self = Rotation::prepend_rotation(self, rot)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn prepend_rotation_cpy(&self, axisangle: &Vec3<N>) -> Rot3<N> {
|
fn prepend_rotation(&self, axisangle: &Vec3<N>) -> Rot3<N> {
|
||||||
*self * Rot3::new(axisangle.clone())
|
*self * Rot3::new(axisangle.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,22 +364,22 @@ Rotation<Vec4<N>> for Rot4<N> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn append_rotation(&mut self, _: &Vec4<N>) {
|
fn append_rotation_mut(&mut self, _: &Vec4<N>) {
|
||||||
panic!("Not yet implemented")
|
panic!("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn append_rotation_cpy(&self, _: &Vec4<N>) -> Rot4<N> {
|
fn append_rotation(&self, _: &Vec4<N>) -> Rot4<N> {
|
||||||
panic!("Not yet implemented")
|
panic!("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn prepend_rotation(&mut self, _: &Vec4<N>) {
|
fn prepend_rotation_mut(&mut self, _: &Vec4<N>) {
|
||||||
panic!("Not yet implemented")
|
panic!("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn prepend_rotation_cpy(&self, _: &Vec4<N>) -> Rot4<N> {
|
fn prepend_rotation(&self, _: &Vec4<N>) -> Rot4<N> {
|
||||||
panic!("Not yet implemented")
|
panic!("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -157,17 +157,17 @@ macro_rules! inv_impl(
|
||||||
($t: ident) => (
|
($t: ident) => (
|
||||||
impl<N: Copy> Inv for $t<N> {
|
impl<N: Copy> Inv for $t<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn inv(&mut self) -> bool {
|
fn inv_mut(&mut self) -> bool {
|
||||||
self.transpose();
|
self.transpose_mut();
|
||||||
|
|
||||||
// always succeed
|
// always succeed
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn inv_cpy(&self) -> Option<$t<N>> {
|
fn inv(&self) -> Option<$t<N>> {
|
||||||
// always succeed
|
// always succeed
|
||||||
Some(self.transpose_cpy())
|
Some(self.transpose())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -177,13 +177,13 @@ macro_rules! transpose_impl(
|
||||||
($t: ident) => (
|
($t: ident) => (
|
||||||
impl<N: Copy> Transpose for $t<N> {
|
impl<N: Copy> Transpose for $t<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn transpose_cpy(&self) -> $t<N> {
|
fn transpose(&self) -> $t<N> {
|
||||||
$t { submat: Transpose::transpose_cpy(&self.submat) }
|
$t { submat: Transpose::transpose(&self.submat) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn transpose(&mut self) {
|
fn transpose_mut(&mut self) {
|
||||||
self.submat.transpose()
|
self.submat.transpose_mut()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -45,7 +45,7 @@ impl<N: Clone + BaseNum + BaseNumCast + Zero> Inv for Cmplx<N> {
|
||||||
|
|
||||||
impl<N> Dim for Cmplx<N> {
|
impl<N> Dim for Cmplx<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn dim(unsused_self: Option<Cmplx<N>>) -> usize {
|
fn dim(unsused_mut: Option<Cmplx<N>>) -> usize {
|
||||||
2
|
2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,11 +13,11 @@ impl One for mat::Identity {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Inv for mat::Identity {
|
impl Inv for mat::Identity {
|
||||||
fn inv_cpy(&self) -> Option<mat::Identity> {
|
fn inv(&self) -> Option<mat::Identity> {
|
||||||
Some(mat::Identity::new())
|
Some(mat::Identity::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inv(&mut self) -> bool {
|
fn inv_mut(&mut self) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,12 +33,12 @@ impl<T: Clone> Mul<T> for mat::Identity {
|
||||||
|
|
||||||
impl Transpose for mat::Identity {
|
impl Transpose for mat::Identity {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn transpose_cpy(&self) -> mat::Identity {
|
fn transpose(&self) -> mat::Identity {
|
||||||
mat::Identity::new()
|
mat::Identity::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn transpose(&mut self) {
|
fn transpose_mut(&mut self) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,22 +54,22 @@ impl<V: Zero> Translation<V> for mat::Identity {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn append_translation(&mut self, _: &V) {
|
fn append_translation_mut(&mut self, _: &V) {
|
||||||
panic!("Attempted to translate the identity matrix.")
|
panic!("Attempted to translate the identity matrix.")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn append_translation_cpy(&self, _: &V) -> mat::Identity {
|
fn append_translation(&self, _: &V) -> mat::Identity {
|
||||||
panic!("Attempted to translate the identity matrix.")
|
panic!("Attempted to translate the identity matrix.")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn prepend_translation(&mut self, _: &V) {
|
fn prepend_translation_mut(&mut self, _: &V) {
|
||||||
panic!("Attempted to translate the identity matrix.")
|
panic!("Attempted to translate the identity matrix.")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn prepend_translation_cpy(&self, _: &V) -> mat::Identity {
|
fn prepend_translation(&self, _: &V) -> mat::Identity {
|
||||||
panic!("Attempted to translate the identity matrix.")
|
panic!("Attempted to translate the identity matrix.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,22 +103,22 @@ impl<V: Zero> Rotation<V> for mat::Identity {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn append_rotation(&mut self, _: &V) {
|
fn append_rotation_mut(&mut self, _: &V) {
|
||||||
panic!("Attempted to rotate the identity matrix.")
|
panic!("Attempted to rotate the identity matrix.")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn append_rotation_cpy(&self, _: &V) -> mat::Identity {
|
fn append_rotation(&self, _: &V) -> mat::Identity {
|
||||||
panic!("Attempted to rotate the identity matrix.")
|
panic!("Attempted to rotate the identity matrix.")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn prepend_rotation(&mut self, _: &V) {
|
fn prepend_rotation_mut(&mut self, _: &V) {
|
||||||
panic!("Attempted to rotate the identity matrix.")
|
panic!("Attempted to rotate the identity matrix.")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn prepend_rotation_cpy(&self, _: &V) -> mat::Identity {
|
fn prepend_rotation(&self, _: &V) -> mat::Identity {
|
||||||
panic!("Attempted to rotate the identity matrix.")
|
panic!("Attempted to rotate the identity matrix.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,22 +159,22 @@ impl<M: One> Transformation<M> for mat::Identity {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn append_transformation(&mut self, _: &M) {
|
fn append_transformation_mut(&mut self, _: &M) {
|
||||||
panic!("Attempted to transform the identity matrix.")
|
panic!("Attempted to transform the identity matrix.")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn append_transformation_cpy(&self, _: &M) -> mat::Identity {
|
fn append_transformation(&self, _: &M) -> mat::Identity {
|
||||||
panic!("Attempted to transform the identity matrix.")
|
panic!("Attempted to transform the identity matrix.")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn prepend_transformation(&mut self, _: &M) {
|
fn prepend_transformation_mut(&mut self, _: &M) {
|
||||||
panic!("Attempted to transform the identity matrix.")
|
panic!("Attempted to transform the identity matrix.")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn prepend_transformation_cpy(&self, _: &M) -> mat::Identity {
|
fn prepend_transformation(&self, _: &M) -> mat::Identity {
|
||||||
panic!("Attempted to transform the identity matrix.")
|
panic!("Attempted to transform the identity matrix.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,9 @@ use traits::structure::{Row, Col, BaseNum};
|
||||||
// some specializations:
|
// some specializations:
|
||||||
impl<N: BaseNum + ApproxEq<N>> Inv for Mat1<N> {
|
impl<N: BaseNum + ApproxEq<N>> Inv for Mat1<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn inv_cpy(&self) -> Option<Mat1<N>> {
|
fn inv(&self) -> Option<Mat1<N>> {
|
||||||
let mut res = *self;
|
let mut res = *self;
|
||||||
if res.inv() {
|
if res.inv_mut() {
|
||||||
Some(res)
|
Some(res)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -19,7 +19,7 @@ impl<N: BaseNum + ApproxEq<N>> Inv for Mat1<N> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn inv(&mut self) -> bool {
|
fn inv_mut(&mut self) -> bool {
|
||||||
if ApproxEq::approx_eq(&self.m11, &::zero()) {
|
if ApproxEq::approx_eq(&self.m11, &::zero()) {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
@ -34,9 +34,9 @@ impl<N: BaseNum + ApproxEq<N>> Inv for Mat1<N> {
|
||||||
|
|
||||||
impl<N: BaseNum + ApproxEq<N>> Inv for Mat2<N> {
|
impl<N: BaseNum + ApproxEq<N>> Inv for Mat2<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn inv_cpy(&self) -> Option<Mat2<N>> {
|
fn inv(&self) -> Option<Mat2<N>> {
|
||||||
let mut res = *self;
|
let mut res = *self;
|
||||||
if res.inv() {
|
if res.inv_mut() {
|
||||||
Some(res)
|
Some(res)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -45,7 +45,7 @@ impl<N: BaseNum + ApproxEq<N>> Inv for Mat2<N> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn inv(&mut self) -> bool {
|
fn inv_mut(&mut self) -> bool {
|
||||||
let det = Det::det(self);
|
let det = Det::det(self);
|
||||||
|
|
||||||
if ApproxEq::approx_eq(&det, &::zero()) {
|
if ApproxEq::approx_eq(&det, &::zero()) {
|
||||||
|
@ -63,10 +63,10 @@ impl<N: BaseNum + ApproxEq<N>> Inv for Mat2<N> {
|
||||||
|
|
||||||
impl<N: BaseNum + ApproxEq<N>> Inv for Mat3<N> {
|
impl<N: BaseNum + ApproxEq<N>> Inv for Mat3<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn inv_cpy(&self) -> Option<Mat3<N>> {
|
fn inv(&self) -> Option<Mat3<N>> {
|
||||||
let mut res = *self;
|
let mut res = *self;
|
||||||
|
|
||||||
if res.inv() {
|
if res.inv_mut() {
|
||||||
Some(res)
|
Some(res)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -75,7 +75,7 @@ impl<N: BaseNum + ApproxEq<N>> Inv for Mat3<N> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn inv(&mut self) -> bool {
|
fn inv_mut(&mut self) -> bool {
|
||||||
let minor_m12_m23 = self.m22 * self.m33 - self.m32 * self.m23;
|
let minor_m12_m23 = self.m22 * self.m33 - self.m32 * self.m23;
|
||||||
let minor_m11_m23 = self.m21 * self.m33 - self.m31 * self.m23;
|
let minor_m11_m23 = self.m21 * self.m33 - self.m31 * self.m23;
|
||||||
let minor_m11_m22 = self.m21 * self.m32 - self.m31 * self.m22;
|
let minor_m11_m22 = self.m21 * self.m32 - self.m31 * self.m22;
|
||||||
|
|
|
@ -130,10 +130,10 @@ impl<N: BaseFloat> Basis for Vec3<N> {
|
||||||
fn orthonormal_subspace_basis<F: FnMut(Vec3<N>) -> bool>(n: &Vec3<N>, mut f: F) {
|
fn orthonormal_subspace_basis<F: FnMut(Vec3<N>) -> bool>(n: &Vec3<N>, mut f: F) {
|
||||||
let a =
|
let a =
|
||||||
if n.x.abs() > n.y.abs() {
|
if n.x.abs() > n.y.abs() {
|
||||||
Norm::normalize_cpy(&Vec3::new(n.z, ::zero(), -n.x))
|
Norm::normalize(&Vec3::new(n.z, ::zero(), -n.x))
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Norm::normalize_cpy(&Vec3::new(::zero(), -n.z, n.y))
|
Norm::normalize(&Vec3::new(::zero(), -n.z, n.y))
|
||||||
};
|
};
|
||||||
|
|
||||||
if !f(Cross::cross(&a, n)) { return };
|
if !f(Cross::cross(&a, n)) { return };
|
||||||
|
|
|
@ -167,22 +167,22 @@ impl<N: Copy + Add<N, Output = N> + Neg<Output = N>> Translation<vec::Vec0<N>> f
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn append_translation(&mut self, t: &vec::Vec0<N>) {
|
fn append_translation_mut(&mut self, t: &vec::Vec0<N>) {
|
||||||
*self = *t + *self;
|
*self = *t + *self;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn append_translation_cpy(&self, t: &vec::Vec0<N>) -> vec::Vec0<N> {
|
fn append_translation(&self, t: &vec::Vec0<N>) -> vec::Vec0<N> {
|
||||||
*t + self
|
*t + self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn prepend_translation(&mut self, t: &vec::Vec0<N>) {
|
fn prepend_translation_mut(&mut self, t: &vec::Vec0<N>) {
|
||||||
*self = *self + *t;
|
*self = *self + *t;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn prepend_translation_cpy(&self, t: &vec::Vec0<N>) -> vec::Vec0<N> {
|
fn prepend_translation(&self, t: &vec::Vec0<N>) -> vec::Vec0<N> {
|
||||||
*self + *t
|
*self + *t
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,12 +203,12 @@ impl<N: BaseFloat> Norm<N> for vec::Vec0<N> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn normalize_cpy(&self) -> vec::Vec0<N> {
|
fn normalize(&self) -> vec::Vec0<N> {
|
||||||
::zero()
|
::zero()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn normalize(&mut self) -> N {
|
fn normalize_mut(&mut self) -> N {
|
||||||
::zero()
|
::zero()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -341,7 +341,7 @@ macro_rules! basis_impl(
|
||||||
};
|
};
|
||||||
|
|
||||||
if !ApproxEq::approx_eq(&Norm::sqnorm(&elt), &::zero()) {
|
if !ApproxEq::approx_eq(&Norm::sqnorm(&elt), &::zero()) {
|
||||||
let new_element = Norm::normalize_cpy(&elt);
|
let new_element = Norm::normalize(&elt);
|
||||||
|
|
||||||
if !f(new_element) { return };
|
if !f(new_element) { return };
|
||||||
|
|
||||||
|
@ -566,22 +566,22 @@ macro_rules! translation_impl(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn append_translation(&mut self, t: &$t<N>) {
|
fn append_translation_mut(&mut self, t: &$t<N>) {
|
||||||
*self = *t + *self;
|
*self = *t + *self;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn append_translation_cpy(&self, t: &$t<N>) -> $t<N> {
|
fn append_translation(&self, t: &$t<N>) -> $t<N> {
|
||||||
*t + *self
|
*t + *self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn prepend_translation(&mut self, t: &$t<N>) {
|
fn prepend_translation_mut(&mut self, t: &$t<N>) {
|
||||||
*self = *self + *t;
|
*self = *self + *t;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn prepend_translation_cpy(&self, t: &$t<N>) -> $t<N> {
|
fn prepend_translation(&self, t: &$t<N>) -> $t<N> {
|
||||||
*self + *t
|
*self + *t
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -602,14 +602,14 @@ macro_rules! norm_impl(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn normalize_cpy(&self) -> $t<N> {
|
fn normalize(&self) -> $t<N> {
|
||||||
let mut res : $t<N> = *self;
|
let mut res : $t<N> = *self;
|
||||||
let _ = res.normalize();
|
let _ = res.normalize_mut();
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn normalize(&mut self) -> N {
|
fn normalize_mut(&mut self) -> N {
|
||||||
let l = Norm::norm(self);
|
let l = Norm::norm(self);
|
||||||
|
|
||||||
$(self.$compN = self.$compN / l;)*
|
$(self.$compN = self.$compN / l;)*
|
||||||
|
|
|
@ -14,16 +14,16 @@ pub trait Translation<V> {
|
||||||
fn inv_translation(&self) -> V;
|
fn inv_translation(&self) -> V;
|
||||||
|
|
||||||
/// Appends a translation to this object.
|
/// Appends a translation to this object.
|
||||||
fn append_translation(&mut self, &V);
|
fn append_translation_mut(&mut self, &V);
|
||||||
|
|
||||||
/// Appends the translation `amount` to a copy of `t`.
|
/// Appends the translation `amount` to a copy of `t`.
|
||||||
fn append_translation_cpy(&self, amount: &V) -> Self;
|
fn append_translation(&self, amount: &V) -> Self;
|
||||||
|
|
||||||
/// Prepends a translation to this object.
|
/// Prepends a translation to this object.
|
||||||
fn prepend_translation(&mut self, &V);
|
fn prepend_translation_mut(&mut self, &V);
|
||||||
|
|
||||||
/// Prepends the translation `amount` to a copy of `t`.
|
/// Prepends the translation `amount` to a copy of `t`.
|
||||||
fn prepend_translation_cpy(&self, amount: &V) -> Self;
|
fn prepend_translation(&self, amount: &V) -> Self;
|
||||||
|
|
||||||
/// Sets the translation.
|
/// Sets the translation.
|
||||||
fn set_translation(&mut self, V);
|
fn set_translation(&mut self, V);
|
||||||
|
@ -49,16 +49,16 @@ pub trait Rotation<V> {
|
||||||
fn inv_rotation(&self) -> V;
|
fn inv_rotation(&self) -> V;
|
||||||
|
|
||||||
/// Appends a rotation to this object.
|
/// Appends a rotation to this object.
|
||||||
fn append_rotation(&mut self, &V);
|
fn append_rotation_mut(&mut self, &V);
|
||||||
|
|
||||||
/// Appends the rotation `amount` to a copy of `t`.
|
/// Appends the rotation `amount` to a copy of `t`.
|
||||||
fn append_rotation_cpy(&self, amount: &V) -> Self;
|
fn append_rotation(&self, amount: &V) -> Self;
|
||||||
|
|
||||||
/// Prepends a rotation to this object.
|
/// Prepends a rotation to this object.
|
||||||
fn prepend_rotation(&mut self, &V);
|
fn prepend_rotation_mut(&mut self, &V);
|
||||||
|
|
||||||
/// Prepends the rotation `amount` to a copy of `t`.
|
/// Prepends the rotation `amount` to a copy of `t`.
|
||||||
fn prepend_rotation_cpy(&self, amount: &V) -> Self;
|
fn prepend_rotation(&self, amount: &V) -> Self;
|
||||||
|
|
||||||
/// Sets the rotation of `self`.
|
/// Sets the rotation of `self`.
|
||||||
fn set_rotation(&mut self, V);
|
fn set_rotation(&mut self, V);
|
||||||
|
@ -90,11 +90,11 @@ pub trait RotationWithTranslation<LV: Neg<Output = LV> + Copy, AV>: Rotation<AV>
|
||||||
/// * `amount` - the rotation to apply.
|
/// * `amount` - the rotation to apply.
|
||||||
/// * `point` - the center of rotation.
|
/// * `point` - the center of rotation.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn append_rotation_wrt_point_cpy(&self, amount: &AV, center: &LV) -> Self {
|
fn append_rotation_wrt_point(&self, amount: &AV, center: &LV) -> Self {
|
||||||
let mut res = Translation::append_translation_cpy(self, &-*center);
|
let mut res = Translation::append_translation(self, &-*center);
|
||||||
|
|
||||||
res.append_rotation(amount);
|
res.append_rotation_mut(amount);
|
||||||
res.append_translation(center);
|
res.append_translation_mut(center);
|
||||||
|
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
@ -107,10 +107,10 @@ pub trait RotationWithTranslation<LV: Neg<Output = LV> + Copy, AV>: Rotation<AV>
|
||||||
/// * `amount` - the rotation to be applied
|
/// * `amount` - the rotation to be applied
|
||||||
/// * `center` - the new center of rotation
|
/// * `center` - the new center of rotation
|
||||||
#[inline]
|
#[inline]
|
||||||
fn append_rotation_wrt_point(&mut self, amount: &AV, center: &LV) {
|
fn append_rotation_wrt_point_mut(&mut self, amount: &AV, center: &LV) {
|
||||||
self.append_translation(&-*center);
|
self.append_translation_mut(&-*center);
|
||||||
self.append_rotation(amount);
|
self.append_rotation_mut(amount);
|
||||||
self.append_translation(center);
|
self.append_translation_mut(center);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Applies a rotation centered on the translation of `m`.
|
/// Applies a rotation centered on the translation of `m`.
|
||||||
|
@ -119,8 +119,8 @@ pub trait RotationWithTranslation<LV: Neg<Output = LV> + Copy, AV>: Rotation<AV>
|
||||||
/// * `t` - the object to be rotated.
|
/// * `t` - the object to be rotated.
|
||||||
/// * `amount` - the rotation to apply.
|
/// * `amount` - the rotation to apply.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn append_rotation_wrt_center_cpy(&self, amount: &AV) -> Self {
|
fn append_rotation_wrt_center(&self, amount: &AV) -> Self {
|
||||||
RotationWithTranslation::append_rotation_wrt_point_cpy(self, amount, &self.translation())
|
RotationWithTranslation::append_rotation_wrt_point(self, amount, &self.translation())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Applies a rotation centered on the translation of `m`.
|
/// Applies a rotation centered on the translation of `m`.
|
||||||
|
@ -130,9 +130,9 @@ pub trait RotationWithTranslation<LV: Neg<Output = LV> + Copy, AV>: Rotation<AV>
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
/// * `amount` - the rotation to apply.
|
/// * `amount` - the rotation to apply.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn append_rotation_wrt_center(&mut self, amount: &AV) {
|
fn append_rotation_wrt_center_mut(&mut self, amount: &AV) {
|
||||||
let center = self.translation();
|
let center = self.translation();
|
||||||
self.append_rotation_wrt_point(amount, ¢er)
|
self.append_rotation_wrt_point_mut(amount, ¢er)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,16 +173,16 @@ pub trait Transformation<M> {
|
||||||
fn inv_transformation(&self) -> M;
|
fn inv_transformation(&self) -> M;
|
||||||
|
|
||||||
/// Appends a transformation to this object.
|
/// Appends a transformation to this object.
|
||||||
fn append_transformation(&mut self, &M);
|
fn append_transformation_mut(&mut self, &M);
|
||||||
|
|
||||||
/// Appends the transformation `amount` to a copy of `t`.
|
/// Appends the transformation `amount` to a copy of `t`.
|
||||||
fn append_transformation_cpy(&self, amount: &M) -> Self;
|
fn append_transformation(&self, amount: &M) -> Self;
|
||||||
|
|
||||||
/// Prepends a transformation to this object.
|
/// Prepends a transformation to this object.
|
||||||
fn prepend_transformation(&mut self, &M);
|
fn prepend_transformation_mut(&mut self, &M);
|
||||||
|
|
||||||
/// Prepends the transformation `amount` to a copy of `t`.
|
/// Prepends the transformation `amount` to a copy of `t`.
|
||||||
fn prepend_transformation_cpy(&self, amount: &M) -> Self;
|
fn prepend_transformation(&self, amount: &M) -> Self;
|
||||||
|
|
||||||
/// Sets the transformation of `self`.
|
/// Sets the transformation of `self`.
|
||||||
fn set_transformation(&mut self, M);
|
fn set_transformation(&mut self, M);
|
||||||
|
@ -220,10 +220,10 @@ pub trait Norm<N: BaseFloat> {
|
||||||
fn sqnorm(&self) -> N;
|
fn sqnorm(&self) -> N;
|
||||||
|
|
||||||
/// Gets the normalized version of a copy of `v`.
|
/// Gets the normalized version of a copy of `v`.
|
||||||
fn normalize_cpy(&self) -> Self;
|
fn normalize(&self) -> Self;
|
||||||
|
|
||||||
/// Normalizes `self`.
|
/// Normalizes `self`.
|
||||||
fn normalize(&mut self) -> N;
|
fn normalize_mut(&mut self) -> N;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -153,13 +153,13 @@ pub trait POrd {
|
||||||
/// Trait for testing approximate equality
|
/// Trait for testing approximate equality
|
||||||
pub trait ApproxEq<Eps>: Sized {
|
pub trait ApproxEq<Eps>: Sized {
|
||||||
/// Default epsilon for approximation.
|
/// Default epsilon for approximation.
|
||||||
fn approx_epsilon(unused_self: Option<Self>) -> Eps;
|
fn approx_epsilon(unused_mut: Option<Self>) -> Eps;
|
||||||
|
|
||||||
/// Tests approximate equality using a custom epsilon.
|
/// Tests approximate equality using a custom epsilon.
|
||||||
fn approx_eq_eps(&self, other: &Self, epsilon: &Eps) -> bool;
|
fn approx_eq_eps(&self, other: &Self, epsilon: &Eps) -> bool;
|
||||||
|
|
||||||
/// Default ULPs for approximation.
|
/// Default ULPs for approximation.
|
||||||
fn approx_ulps(unused_self: Option<Self>) -> u32;
|
fn approx_ulps(unused_mut: Option<Self>) -> u32;
|
||||||
|
|
||||||
/// Tests approximate equality using units in the last place (ULPs)
|
/// Tests approximate equality using units in the last place (ULPs)
|
||||||
fn approx_eq_ulps(&self, other: &Self, ulps: u32) -> bool;
|
fn approx_eq_ulps(&self, other: &Self, ulps: u32) -> bool;
|
||||||
|
@ -278,10 +278,10 @@ pub trait Absolute<A> {
|
||||||
/// Trait of objects having an inverse. Typically used to implement matrix inverse.
|
/// Trait of objects having an inverse. Typically used to implement matrix inverse.
|
||||||
pub trait Inv {
|
pub trait Inv {
|
||||||
/// Returns the inverse of `m`.
|
/// Returns the inverse of `m`.
|
||||||
fn inv_cpy(&self) -> Option<Self>;
|
fn inv(&self) -> Option<Self>;
|
||||||
|
|
||||||
/// In-place version of `inverse`.
|
/// In-place version of `inverse`.
|
||||||
fn inv(&mut self) -> bool;
|
fn inv_mut(&mut self) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Trait of objects having a determinant. Typically used by square matrices.
|
/// Trait of objects having a determinant. Typically used by square matrices.
|
||||||
|
@ -293,10 +293,10 @@ pub trait Det<N> {
|
||||||
/// Trait of objects which can be transposed.
|
/// Trait of objects which can be transposed.
|
||||||
pub trait Transpose {
|
pub trait Transpose {
|
||||||
/// Computes the transpose of a matrix.
|
/// Computes the transpose of a matrix.
|
||||||
fn transpose_cpy(&self) -> Self;
|
fn transpose(&self) -> Self;
|
||||||
|
|
||||||
/// In-place version of `transposed`.
|
/// In-place version of `transposed`.
|
||||||
fn transpose(&mut self);
|
fn transpose_mut(&mut self);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Traits of objects having an outer product.
|
/// Traits of objects having an outer product.
|
||||||
|
|
|
@ -161,7 +161,7 @@ pub trait RowSlice<R> {
|
||||||
/// Trait of objects having a spacial dimension known at compile time.
|
/// Trait of objects having a spacial dimension known at compile time.
|
||||||
pub trait Dim {
|
pub trait Dim {
|
||||||
/// The dimension of the object.
|
/// The dimension of the object.
|
||||||
fn dim(unused_self: Option<Self>) -> usize;
|
fn dim(unused_mut: Option<Self>) -> usize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Trait to get the diagonal of square matrices.
|
/// Trait to get the diagonal of square matrices.
|
||||||
|
|
Loading…
Reference in New Issue