forked from M-Labs/nalgebra
update to the latest rust: FloatMath for math functions (sin/exp/...)
Also removed a bunch of duplicate trait usages
This commit is contained in:
parent
b3bc4c66f1
commit
987b91767a
@ -1,6 +1,6 @@
|
|||||||
//! **nalgebra** prelude.
|
//! **nalgebra** prelude.
|
||||||
|
|
||||||
use std::num::{Zero, One};
|
use std::num::{Zero, One, FloatMath};
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
pub use traits::{PartialLess, PartialEqual, PartialGreater, NotComparable};
|
pub use traits::{PartialLess, PartialEqual, PartialGreater, NotComparable};
|
||||||
pub use traits::{
|
pub use traits::{
|
||||||
@ -217,7 +217,7 @@ pub fn one<T: One>() -> T {
|
|||||||
*/
|
*/
|
||||||
/// Computes a projection matrix given the frustrum near plane width, height, the field of
|
/// Computes a projection matrix given the frustrum near plane width, height, the field of
|
||||||
/// view, and the distance to the clipping planes (`znear` and `zfar`).
|
/// view, and the distance to the clipping planes (`znear` and `zfar`).
|
||||||
pub fn perspective3d<N: Float + Cast<f32> + Zero + One>(width: N, height: N, fov: N, znear: N, zfar: N) -> Mat4<N> {
|
pub fn perspective3d<N: FloatMath + Cast<f32> + Zero + One>(width: N, height: N, fov: N, znear: N, zfar: N) -> Mat4<N> {
|
||||||
let aspect = width / height;
|
let aspect = width / height;
|
||||||
|
|
||||||
let _1: N = one();
|
let _1: N = one();
|
||||||
|
@ -576,11 +576,11 @@ impl<N: Show + Clone> Show for DMat<N> {
|
|||||||
fn fmt(&self, form:&mut Formatter) -> Result {
|
fn fmt(&self, form:&mut Formatter) -> Result {
|
||||||
for i in range(0u, self.nrows()) {
|
for i in range(0u, self.nrows()) {
|
||||||
for j in range(0u, self.ncols()) {
|
for j in range(0u, self.ncols()) {
|
||||||
let _ = write!(form.buf, "{} ", self.at((i, j)));
|
let _ = write!(form, "{} ", self.at((i, j)));
|
||||||
}
|
}
|
||||||
let _ = write!(form.buf, "\n");
|
let _ = write!(form, "\n");
|
||||||
}
|
}
|
||||||
write!(form.buf, "\n")
|
write!(form, "\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,7 +198,7 @@ impl<N> FromIterator<N> for DVec<N> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Clone + Num + Float + ApproxEq<N> + DVecMulRhs<N, DVec<N>>> DVec<N> {
|
impl<N: Clone + Float + ApproxEq<N> + DVecMulRhs<N, DVec<N>>> DVec<N> {
|
||||||
/// Computes the canonical basis for the given dimension. A canonical basis is a set of
|
/// Computes the canonical basis for the given dimension. A canonical basis is a set of
|
||||||
/// vectors, mutually orthogonal, with all its component equal to 0.0 except one which is equal
|
/// vectors, mutually orthogonal, with all its component equal to 0.0 except one which is equal
|
||||||
/// to 1.0.
|
/// to 1.0.
|
||||||
@ -305,7 +305,7 @@ impl<N: Num + Clone> Dot<N> for DVec<N> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Num + Float + Clone> Norm<N> for DVec<N> {
|
impl<N: Float + Clone> Norm<N> for DVec<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sqnorm(v: &DVec<N>) -> N {
|
fn sqnorm(v: &DVec<N>) -> N {
|
||||||
Dot::dot(v, v)
|
Dot::dot(v, v)
|
||||||
|
@ -51,7 +51,7 @@ pub struct Iso4<N> {
|
|||||||
pub translation: Vec4<N>
|
pub translation: Vec4<N>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Clone + Num + Float> Iso3<N> {
|
impl<N: Clone + Float> Iso3<N> {
|
||||||
/// Reorient and translate this transformation such that its local `x` axis points to a given
|
/// Reorient and translate this transformation such that its local `x` axis points to a given
|
||||||
/// direction. Note that the usually known `look_at` function does the same thing but with the
|
/// direction. Note that the usually known `look_at` function does the same thing but with the
|
||||||
/// `z` axis. See `look_at_z` for that.
|
/// `z` axis. See `look_at_z` for that.
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
macro_rules! iso_impl(
|
macro_rules! iso_impl(
|
||||||
($t: ident, $submat: ident, $subvec: ident, $subrotvec: ident) => (
|
($t: ident, $submat: ident, $subvec: ident, $subrotvec: ident) => (
|
||||||
impl<N: Clone + Float + Float + Num> $t<N> {
|
impl<N: Clone + FloatMath + Num> $t<N> {
|
||||||
/// Creates a new isometry from a rotation matrix and a vector.
|
/// Creates a new isometry from a rotation matrix and a vector.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(translation: $subvec<N>, rotation: $subrotvec<N>) -> $t<N> {
|
pub fn new(translation: $subvec<N>, rotation: $subrotvec<N>) -> $t<N> {
|
||||||
@ -26,7 +26,7 @@ macro_rules! iso_impl(
|
|||||||
|
|
||||||
macro_rules! rotation_matrix_impl(
|
macro_rules! rotation_matrix_impl(
|
||||||
($t: ident, $trot: ident, $tlv: ident, $tav: ident) => (
|
($t: ident, $trot: ident, $tlv: ident, $tav: ident) => (
|
||||||
impl<N: Cast<f32> + Float + Float + Num + Clone>
|
impl<N: Cast<f32> + FloatMath + Num + Clone>
|
||||||
RotationMatrix<$tlv<N>, $tav<N>, $trot<N>> for $t<N> {
|
RotationMatrix<$tlv<N>, $tav<N>, $trot<N>> for $t<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_rot_mat(&self) -> $trot<N> {
|
fn to_rot_mat(&self) -> $trot<N> {
|
||||||
@ -50,7 +50,7 @@ macro_rules! dim_impl(
|
|||||||
|
|
||||||
macro_rules! one_impl(
|
macro_rules! one_impl(
|
||||||
($t: ident) => (
|
($t: ident) => (
|
||||||
impl<N: Float + Float + Num + Clone> One for $t<N> {
|
impl<N: FloatMath + Clone> One for $t<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn one() -> $t<N> {
|
fn one() -> $t<N> {
|
||||||
$t::new_with_rotmat(Zero::zero(), One::one())
|
$t::new_with_rotmat(Zero::zero(), One::one())
|
||||||
@ -61,7 +61,7 @@ macro_rules! one_impl(
|
|||||||
|
|
||||||
macro_rules! iso_mul_iso_impl(
|
macro_rules! iso_mul_iso_impl(
|
||||||
($t: ident, $tmul: ident) => (
|
($t: ident, $tmul: ident) => (
|
||||||
impl<N: Num + Float + Float + Clone> $tmul<N, $t<N>> for $t<N> {
|
impl<N: FloatMath + Clone> $tmul<N, $t<N>> for $t<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn binop(left: &$t<N>, right: &$t<N>) -> $t<N> {
|
fn binop(left: &$t<N>, right: &$t<N>) -> $t<N> {
|
||||||
$t::new_with_rotmat(
|
$t::new_with_rotmat(
|
||||||
@ -96,7 +96,7 @@ macro_rules! vec_mul_iso_impl(
|
|||||||
|
|
||||||
macro_rules! translation_impl(
|
macro_rules! translation_impl(
|
||||||
($t: ident, $tv: ident) => (
|
($t: ident, $tv: ident) => (
|
||||||
impl<N: Float + Num + Float + Clone> Translation<$tv<N>> for $t<N> {
|
impl<N: FloatMath + Clone> Translation<$tv<N>> for $t<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn translation(&self) -> $tv<N> {
|
fn translation(&self) -> $tv<N> {
|
||||||
self.translation.clone()
|
self.translation.clone()
|
||||||
@ -153,7 +153,7 @@ macro_rules! translate_impl(
|
|||||||
|
|
||||||
macro_rules! rotation_impl(
|
macro_rules! rotation_impl(
|
||||||
($t: ident, $trot: ident, $tav: ident) => (
|
($t: ident, $trot: ident, $tav: ident) => (
|
||||||
impl<N: Cast<f32> + Num + Float + Float + Clone> Rotation<$tav<N>> for $t<N> {
|
impl<N: Cast<f32> + FloatMath + Clone> Rotation<$tav<N>> for $t<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rotation(&self) -> $tav<N> {
|
fn rotation(&self) -> $tav<N> {
|
||||||
self.rotation.rotation()
|
self.rotation.rotation()
|
||||||
@ -220,7 +220,7 @@ macro_rules! rotate_impl(
|
|||||||
|
|
||||||
macro_rules! transformation_impl(
|
macro_rules! transformation_impl(
|
||||||
($t: ident) => (
|
($t: ident) => (
|
||||||
impl<N: Num + Float + Float + Clone> Transformation<$t<N>> for $t<N> {
|
impl<N: FloatMath + Clone> Transformation<$t<N>> for $t<N> {
|
||||||
fn transformation(&self) -> $t<N> {
|
fn transformation(&self) -> $t<N> {
|
||||||
self.clone()
|
self.clone()
|
||||||
}
|
}
|
||||||
@ -336,7 +336,7 @@ macro_rules! approx_eq_impl(
|
|||||||
|
|
||||||
macro_rules! rand_impl(
|
macro_rules! rand_impl(
|
||||||
($t: ident) => (
|
($t: ident) => (
|
||||||
impl<N: Rand + Clone + Float + Float + Num> Rand for $t<N> {
|
impl<N: Rand + Clone + FloatMath> Rand for $t<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rand<R: Rng>(rng: &mut R) -> $t<N> {
|
fn rand<R: Rng>(rng: &mut R) -> $t<N> {
|
||||||
$t::new(rng.gen(), rng.gen())
|
$t::new(rng.gen(), rng.gen())
|
||||||
|
@ -20,7 +20,7 @@ pub struct Rot2<N> {
|
|||||||
submat: Mat2<N>
|
submat: Mat2<N>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Clone + Float + Neg<N>> Rot2<N> {
|
impl<N: Clone + FloatMath + Neg<N>> Rot2<N> {
|
||||||
/// Builds a 2 dimensional rotation matrix from an angle in radian.
|
/// Builds a 2 dimensional rotation matrix from an angle in radian.
|
||||||
pub fn new(angle: Vec1<N>) -> Rot2<N> {
|
pub fn new(angle: Vec1<N>) -> Rot2<N> {
|
||||||
let (sia, coa) = angle.x.sin_cos();
|
let (sia, coa) = angle.x.sin_cos();
|
||||||
@ -31,7 +31,7 @@ impl<N: Clone + Float + Neg<N>> Rot2<N> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Float + Num + Clone>
|
impl<N: FloatMath + Clone>
|
||||||
Rotation<Vec1<N>> for Rot2<N> {
|
Rotation<Vec1<N>> for Rot2<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rotation(&self) -> Vec1<N> {
|
fn rotation(&self) -> Vec1<N> {
|
||||||
@ -69,7 +69,7 @@ Rotation<Vec1<N>> for Rot2<N> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Clone + Rand + Float + Neg<N>> Rand for Rot2<N> {
|
impl<N: Clone + Rand + FloatMath + Neg<N>> Rand for Rot2<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rand<R: Rng>(rng: &mut R) -> Rot2<N> {
|
fn rand<R: Rng>(rng: &mut R) -> Rot2<N> {
|
||||||
Rot2::new(rng.gen())
|
Rot2::new(rng.gen())
|
||||||
@ -99,7 +99,7 @@ pub struct Rot3<N> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl<N: Clone + Float + Num + Float> Rot3<N> {
|
impl<N: Clone + FloatMath> Rot3<N> {
|
||||||
/// Builds a 3 dimensional rotation matrix from an axis and an angle.
|
/// Builds a 3 dimensional rotation matrix from an axis and an angle.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
@ -140,7 +140,7 @@ impl<N: Clone + Float + Num + Float> Rot3<N> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Clone + Num + Float> Rot3<N> {
|
impl<N: Clone + Float> Rot3<N> {
|
||||||
/// Reorient this matrix such that its local `x` axis points to a given point. Note that the
|
/// Reorient this matrix such that its local `x` axis points to a given point. Note that the
|
||||||
/// usually known `look_at` function does the same thing but with the `z` axis. See `look_at_z`
|
/// usually known `look_at` function does the same thing but with the `z` axis. See `look_at_z`
|
||||||
/// for that.
|
/// for that.
|
||||||
@ -180,7 +180,7 @@ impl<N: Clone + Num + Float> Rot3<N> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Clone + Float + Num + Float + Cast<f32>>
|
impl<N: Clone + FloatMath + Cast<f32>>
|
||||||
Rotation<Vec3<N>> for Rot3<N> {
|
Rotation<Vec3<N>> for Rot3<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rotation(&self) -> Vec3<N> {
|
fn rotation(&self) -> Vec3<N> {
|
||||||
@ -245,7 +245,7 @@ Rotation<Vec3<N>> for Rot3<N> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Clone + Rand + Float + Num + Float>
|
impl<N: Clone + Rand + FloatMath>
|
||||||
Rand for Rot3<N> {
|
Rand for Rot3<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rand<R: Rng>(rng: &mut R) -> Rot3<N> {
|
fn rand<R: Rng>(rng: &mut R) -> Rot3<N> {
|
||||||
@ -309,7 +309,7 @@ impl<N: Signed> AbsoluteRotate<Vec4<N>> for Rot4<N> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Float + Num + Clone>
|
impl<N: Float + Clone>
|
||||||
Rotation<Vec4<N>> for Rot4<N> {
|
Rotation<Vec4<N>> for Rot4<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rotation(&self) -> Vec4<N> {
|
fn rotation(&self) -> Vec4<N> {
|
||||||
|
@ -56,7 +56,7 @@ macro_rules! dim_impl(
|
|||||||
|
|
||||||
macro_rules! rotation_matrix_impl(
|
macro_rules! rotation_matrix_impl(
|
||||||
($t: ident, $tlv: ident, $tav: ident) => (
|
($t: ident, $tlv: ident, $tav: ident) => (
|
||||||
impl<N: Cast<f32> + Float + Float + Num + Clone>
|
impl<N: Cast<f32> + FloatMath + Clone>
|
||||||
RotationMatrix<$tlv<N>, $tav<N>, $t<N>> for $t<N> {
|
RotationMatrix<$tlv<N>, $tav<N>, $t<N>> for $t<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_rot_mat(&self) -> $t<N> {
|
fn to_rot_mat(&self) -> $t<N> {
|
||||||
|
@ -164,7 +164,7 @@ impl<N: Clone + Add<N, N> + Neg<N>> Translation<vec::Vec0<N>> for vec::Vec0<N> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Num + Float> Norm<N> for vec::Vec0<N> {
|
impl<N: Float> Norm<N> for vec::Vec0<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sqnorm(_: &vec::Vec0<N>) -> N {
|
fn sqnorm(_: &vec::Vec0<N>) -> N {
|
||||||
Zero::zero()
|
Zero::zero()
|
||||||
|
@ -38,7 +38,7 @@ macro_rules! at_fast_impl(
|
|||||||
// However, f32/f64 does not implement TotalOrd…
|
// However, f32/f64 does not implement TotalOrd…
|
||||||
macro_rules! ord_impl(
|
macro_rules! ord_impl(
|
||||||
($t: ident, $comp0: ident $(,$compN: ident)*) => (
|
($t: ident, $comp0: ident $(,$compN: ident)*) => (
|
||||||
impl<N: Float + Eq + Clone> PartialOrd for $t<N> {
|
impl<N: FloatMath + Eq + Clone> PartialOrd for $t<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn inf(a: &$t<N>, b: &$t<N>) -> $t<N> {
|
fn inf(a: &$t<N>, b: &$t<N>) -> $t<N> {
|
||||||
$t::new(a.$comp0.min(b.$comp0.clone())
|
$t::new(a.$comp0.min(b.$comp0.clone())
|
||||||
@ -255,7 +255,7 @@ macro_rules! container_impl(
|
|||||||
|
|
||||||
macro_rules! basis_impl(
|
macro_rules! basis_impl(
|
||||||
($t: ident, $trhs: ident, $dim: expr) => (
|
($t: ident, $trhs: ident, $dim: expr) => (
|
||||||
impl<N: Clone + Num + Float + ApproxEq<N> + $trhs<N, $t<N>>> Basis for $t<N> {
|
impl<N: Clone + Float + ApproxEq<N> + $trhs<N, $t<N>>> Basis for $t<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn canonical_basis(f: |$t<N>| -> bool) {
|
fn canonical_basis(f: |$t<N>| -> bool) {
|
||||||
for i in range(0u, $dim) {
|
for i in range(0u, $dim) {
|
||||||
@ -465,7 +465,7 @@ macro_rules! translation_impl(
|
|||||||
|
|
||||||
macro_rules! norm_impl(
|
macro_rules! norm_impl(
|
||||||
($t: ident, $comp0: ident $(,$compN: ident)*) => (
|
($t: ident, $comp0: ident $(,$compN: ident)*) => (
|
||||||
impl<N: Clone + Num + Float> Norm<N> for $t<N> {
|
impl<N: Clone + Float> Norm<N> for $t<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sqnorm(v: &$t<N>) -> N {
|
fn sqnorm(v: &$t<N>) -> N {
|
||||||
Dot::dot(v, v)
|
Dot::dot(v, v)
|
||||||
|
Loading…
Reference in New Issue
Block a user