Remove use of num::cast
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
parent
c1cbf7465d
commit
165e095a57
|
@ -1,5 +1,4 @@
|
||||||
use std::num;
|
use traits::structure::{BaseFloat, Cast};
|
||||||
use traits::structure::BaseFloat;
|
|
||||||
use structs::{Pnt3, Vec3, Mat4};
|
use structs::{Pnt3, Vec3, Mat4};
|
||||||
|
|
||||||
#[cfg(feature="arbitrary")]
|
#[cfg(feature="arbitrary")]
|
||||||
|
@ -162,13 +161,13 @@ impl<N: BaseFloat> OrthoMat3<N> {
|
||||||
/// The width of the view cuboid.
|
/// The width of the view cuboid.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn width(&self) -> N {
|
pub fn width(&self) -> N {
|
||||||
num::cast::<f64, N>(2.0).unwrap() / self.mat.m11
|
<N as Cast<f64>>::from(2.0) / self.mat.m11
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The height of the view cuboid.
|
/// The height of the view cuboid.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn height(&self) -> N {
|
pub fn height(&self) -> N {
|
||||||
num::cast::<f64, N>(2.0).unwrap() / self.mat.m22
|
<N as Cast<f64>>::from(2.0) / self.mat.m22
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The near plane offset of the view cuboid.
|
/// The near plane offset of the view cuboid.
|
||||||
|
@ -187,14 +186,14 @@ impl<N: BaseFloat> OrthoMat3<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_width(&mut self, width: N) {
|
pub fn set_width(&mut self, width: N) {
|
||||||
assert!(!::is_zero(&width));
|
assert!(!::is_zero(&width));
|
||||||
self.mat.m11 = num::cast::<f64, N>(2.0).unwrap() / width;
|
self.mat.m11 = <N as Cast<f64>>::from(2.0) / width;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the height of the view cuboid.
|
/// Sets the height of the view cuboid.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_height(&mut self, height: N) {
|
pub fn set_height(&mut self, height: N) {
|
||||||
assert!(!::is_zero(&height));
|
assert!(!::is_zero(&height));
|
||||||
self.mat.m22 = num::cast::<f64, N>(2.0).unwrap() / height;
|
self.mat.m22 = <N as Cast<f64>>::from(2.0) / height;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the near plane offset of the view cuboid.
|
/// Sets the near plane offset of the view cuboid.
|
||||||
|
@ -215,7 +214,7 @@ impl<N: BaseFloat> OrthoMat3<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_znear_and_zfar(&mut self, znear: N, zfar: N) {
|
pub fn set_znear_and_zfar(&mut self, znear: N, zfar: N) {
|
||||||
assert!(!::is_zero(&(zfar - znear)));
|
assert!(!::is_zero(&(zfar - znear)));
|
||||||
self.mat.m33 = -num::cast::<f64, N>(2.0).unwrap() / (zfar - znear);
|
self.mat.m33 = -<N as Cast<f64>>::from(2.0) / (zfar - znear);
|
||||||
self.mat.m34 = -(zfar + znear) / (zfar - znear);
|
self.mat.m34 = -(zfar + znear) / (zfar - znear);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
#![allow(missing_docs)] // we allow missing to avoid having to document the dispatch trait.
|
#![allow(missing_docs)] // we allow missing to avoid having to document the dispatch trait.
|
||||||
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::num;
|
|
||||||
use std::slice::{Iter, IterMut};
|
use std::slice::{Iter, IterMut};
|
||||||
use std::ops::{Add, Sub, Mul, Div, Neg, Index, IndexMut};
|
use std::ops::{Add, Sub, Mul, Div, Neg, Index, IndexMut};
|
||||||
use std::iter::{FromIterator, IntoIterator};
|
use std::iter::{FromIterator, IntoIterator};
|
||||||
|
@ -176,7 +175,7 @@ impl<N: BaseFloat> UnitQuat<N> {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let ang = sqang.sqrt();
|
let ang = sqang.sqrt();
|
||||||
let (s, c) = (ang / num::cast(2.0f64).unwrap()).sin_cos();
|
let (s, c) = (ang / Cast::from(2.0)).sin_cos();
|
||||||
|
|
||||||
let s_ang = s / ang;
|
let s_ang = s / ang;
|
||||||
|
|
||||||
|
@ -205,7 +204,7 @@ impl<N: BaseFloat> UnitQuat<N> {
|
||||||
/// The primitive rotations are applied in order: 1 roll − 2 pitch − 3 yaw.
|
/// The primitive rotations are applied in order: 1 roll − 2 pitch − 3 yaw.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new_with_euler_angles(roll: N, pitch: N, yaw: N) -> UnitQuat<N> {
|
pub fn new_with_euler_angles(roll: N, pitch: N, yaw: N) -> UnitQuat<N> {
|
||||||
let _0_5: N = num::cast(0.5f64).unwrap();
|
let _0_5: N = Cast::from(0.5);
|
||||||
let (sr, cr) = (roll * _0_5).sin_cos();
|
let (sr, cr) = (roll * _0_5).sin_cos();
|
||||||
let (sp, cp) = (pitch * _0_5).sin_cos();
|
let (sp, cp) = (pitch * _0_5).sin_cos();
|
||||||
let (sy, cy) = (yaw * _0_5).sin_cos();
|
let (sy, cy) = (yaw * _0_5).sin_cos();
|
||||||
|
@ -223,7 +222,7 @@ impl<N: BaseFloat> UnitQuat<N> {
|
||||||
|
|
||||||
/// Builds a rotation matrix from this quaternion.
|
/// Builds a rotation matrix from this quaternion.
|
||||||
pub fn to_rot(&self) -> Rot3<N> {
|
pub fn to_rot(&self) -> Rot3<N> {
|
||||||
let _2: N = num::cast(2.0f64).unwrap();
|
let _2: N = Cast::from(2.0);
|
||||||
let ww = self.q.w * self.q.w;
|
let ww = self.q.w * self.q.w;
|
||||||
let ii = self.q.i * self.q.i;
|
let ii = self.q.i * self.q.i;
|
||||||
let jj = self.q.j * self.q.j;
|
let jj = self.q.j * self.q.j;
|
||||||
|
|
|
@ -16,7 +16,7 @@ pub trait BaseNum: Copy + Zero + One +
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Basic floating-point number numeric trait.
|
/// Basic floating-point number numeric trait.
|
||||||
pub trait BaseFloat: Float + BaseNum {
|
pub trait BaseFloat: Float + Cast<f64> + BaseNum {
|
||||||
/// Archimedes' constant.
|
/// Archimedes' constant.
|
||||||
fn pi() -> Self;
|
fn pi() -> Self;
|
||||||
/// 2.0 * pi.
|
/// 2.0 * pi.
|
||||||
|
|
Loading…
Reference in New Issue