Consistently use associated functions throughout codebase

This commit is contained in:
Brendan Zabarauskas 2015-09-29 21:36:57 +10:00
parent 046ff64b72
commit 5023b6c01e
12 changed files with 248 additions and 240 deletions

View file

@ -22,7 +22,7 @@
use std::fmt;
use rust_num::{Float, zero, one};
use rust_num::{Float, Zero, One};
use bound::*;
use point::{Point, Point2, Point3};
@ -54,7 +54,7 @@ pub trait Aabb<S: BaseNum, V: Vector<S>, P: Point<S, V>>: Sized {
/// Return the center point of this AABB.
#[inline]
fn center(&self) -> P {
let two = one::<S>() + one::<S>();
let two = S::one() + S::one();
self.min().add_v(&self.dim().div_s(two))
}
@ -131,8 +131,8 @@ impl<S: BaseNum> Aabb<S, Vector2<S>, Point2<S>> for Aabb2<S> {
fn contains(&self, p: &Point2<S>) -> bool {
let v_min = p.sub_p(self.min());
let v_max = self.max().sub_p(p);
v_min.x >= zero() && v_min.y >= zero() &&
v_max.x > zero() && v_max.y > zero()
v_min.x >= S::zero() && v_min.y >= S::zero() &&
v_max.x > S::zero() && v_max.y > S::zero()
}
}
@ -191,8 +191,8 @@ impl<S: BaseNum> Aabb<S, Vector3<S>, Point3<S>> for Aabb3<S> {
fn contains(&self, p: &Point3<S>) -> bool {
let v_min = p.sub_p(self.min());
let v_max = self.max().sub_p(p);
v_min.x >= zero() && v_min.y >= zero() && v_min.z >= zero() &&
v_max.x > zero() && v_max.y > zero() && v_max.z > zero()
v_min.x >= S::zero() && v_min.y >= S::zero() && v_min.z >= S::zero() &&
v_max.x > S::zero() && v_max.y > S::zero() && v_max.z > S::zero()
}
}
@ -206,28 +206,28 @@ impl<S: BaseFloat> Intersect<Option<Point2<S>>> for (Ray2<S>, Aabb2<S>) {
fn intersection(&self) -> Option<Point2<S>> {
let (ref ray, ref aabb) = *self;
let mut tmin: S = Float::neg_infinity();
let mut tmax: S = Float::infinity();
let mut tmin = S::neg_infinity();
let mut tmax = S::infinity();
if ray.direction.x != zero() {
if ray.direction.x != S::zero() {
let tx1 = (aabb.min.x - ray.origin.x) / ray.direction.x;
let tx2 = (aabb.max.x - ray.origin.x) / ray.direction.x;
tmin = tmin.max(tx1.min(tx2));
tmax = tmax.min(tx1.max(tx2));
}
if ray.direction.y != zero() {
if ray.direction.y != S::zero() {
let ty1 = (aabb.min.y - ray.origin.y) / ray.direction.y;
let ty2 = (aabb.max.y - ray.origin.y) / ray.direction.y;
tmin = tmin.max(ty1.min(ty2));
tmax = tmax.min(ty1.max(ty2));
}
if tmin < zero() && tmax < zero() {
if tmin < S::zero() && tmax < S::zero() {
None
}
else if tmax >= tmin {
if tmin >= zero() {
if tmin >= S::zero() {
Some(Point2::new(ray.origin.x + ray.direction.x * tmin,
ray.origin.y + ray.direction.y * tmin))
}

View file

@ -22,7 +22,7 @@ use std::ops::*;
use rand::{Rand, Rng};
use rand::distributions::range::SampleRange;
use rust_num::{Float, One, Zero, one, zero};
use rust_num::{Float, One, Zero};
use rust_num::traits::cast;
use approx::ApproxEq;
@ -132,15 +132,15 @@ pub trait Angle
/// Normalize the angle to the range `[0, full_turn)`.
#[inline]
fn normalize_self(&mut self) {
let full_turn: Self = Angle::full_turn();
let full_turn = Self::full_turn();
self.rem_self_s(full_turn.s().clone());
if *self < zero() { self.add_self_a(full_turn) };
if *self < Self::zero() { self.add_self_a(full_turn) };
}
/// Return the angle rotated by half a turn
#[inline]
fn opposite(&self) -> Self {
self.add_a(Angle::turn_div_2()).normalize()
self.add_a(Self::turn_div_2()).normalize()
}
/// Returns the interior bisector of the two angles
@ -151,37 +151,16 @@ pub trait Angle
fn full_turn() -> Self;
#[inline] fn turn_div_2() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(2i8).unwrap()) }
#[inline] fn turn_div_3() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(3i8).unwrap()) }
#[inline] fn turn_div_4() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(4i8).unwrap()) }
#[inline] fn turn_div_6() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(6i8).unwrap()) }
#[inline] fn turn_div_2() -> Self { Self::full_turn().div_s(cast(2i8).unwrap()) }
#[inline] fn turn_div_3() -> Self { Self::full_turn().div_s(cast(3i8).unwrap()) }
#[inline] fn turn_div_4() -> Self { Self::full_turn().div_s(cast(4i8).unwrap()) }
#[inline] fn turn_div_6() -> Self { Self::full_turn().div_s(cast(6i8).unwrap()) }
#[inline] fn equiv(&self, other: &Self) -> bool { self.normalize() == other.normalize() }
}
#[inline] pub fn bisect<S: BaseFloat, A: Angle<S>>(a: A, b: A) -> A { a.bisect(b) }
impl<S: BaseFloat>
Rad<S> {
#[inline] pub fn zero() -> Rad<S> { zero() }
#[inline] pub fn full_turn() -> Rad<S> { Angle::full_turn() }
#[inline] pub fn turn_div_2() -> Rad<S> { Angle::turn_div_2() }
#[inline] pub fn turn_div_3() -> Rad<S> { Angle::turn_div_3() }
#[inline] pub fn turn_div_4() -> Rad<S> { Angle::turn_div_4() }
#[inline] pub fn turn_div_6() -> Rad<S> { Angle::turn_div_6() }
}
impl<S: BaseFloat>
Deg<S> {
#[inline] pub fn zero() -> Deg<S> { zero() }
#[inline] pub fn full_turn() -> Deg<S> { Angle::full_turn() }
#[inline] pub fn turn_div_2() -> Deg<S> { Angle::turn_div_2() }
#[inline] pub fn turn_div_3() -> Deg<S> { Angle::turn_div_3() }
#[inline] pub fn turn_div_4() -> Deg<S> { Angle::turn_div_4() }
#[inline] pub fn turn_div_6() -> Deg<S> { Angle::turn_div_6() }
}
impl<R: Into<Rad<S>>, S: BaseFloat> Add<R> for Rad<S> {
type Output = Rad<S>;
@ -225,15 +204,15 @@ impl<S: BaseFloat> Neg for Deg<S> {
impl<S: BaseFloat> Zero for Rad<S> {
#[inline]
fn zero() -> Rad<S> { rad(zero()) }
fn zero() -> Rad<S> { rad(S::zero()) }
#[inline]
fn is_zero(&self) -> bool { *self == zero() }
fn is_zero(&self) -> bool { *self == Self::zero() }
}
impl<S: BaseFloat> Zero for Deg<S> {
#[inline]
fn zero() -> Deg<S> { deg(zero()) }
fn zero() -> Deg<S> { deg(S::zero()) }
#[inline]
fn is_zero(&self) -> bool { *self == zero() }
fn is_zero(&self) -> bool { *self == Self::zero() }
}
impl<R: Into<Rad<S>>, S: BaseFloat> Mul<R> for Rad<S> {
@ -252,11 +231,11 @@ impl<R: Into<Rad<S>>, S: BaseFloat> Mul<R> for Deg<S> {
impl<S: BaseFloat> One for Rad<S> {
#[inline]
fn one() -> Rad<S> { rad(one()) }
fn one() -> Rad<S> { rad(S::one()) }
}
impl<S: BaseFloat> One for Deg<S> {
#[inline]
fn one() -> Deg<S> { deg(one()) }
fn one() -> Deg<S> { deg(S::one()) }
}
const PI_2: f64 = f64::consts::PI * 2f64;

View file

@ -17,7 +17,7 @@
use std::marker::PhantomData;
use rust_num::{Zero, zero, One, one};
use rust_num::{Zero, One};
use num::{BaseNum, BaseFloat};
use point::{Point, Point2, Point3};
@ -57,14 +57,13 @@ impl<S: BaseFloat> Intersect<Option<Point2<S>>> for (Ray2<S>, Line2<S>) {
let q = line.origin;
let r = ray.direction;
let s = Vector2::new(line.dest.x - line.origin.x, line.dest.y - line.origin.y);
let zero: S = Zero::zero();
let cross_1 = r.perp_dot(&s);
let qmp = Vector2::new(q.x - p.x, q.y - p.y);
let cross_2 = qmp.perp_dot(&r);
if cross_1 == zero {
if cross_2 != zero {
if cross_1 == S::zero() {
if cross_2 != S::zero() {
// parallel
return None;
}
@ -73,10 +72,10 @@ impl<S: BaseFloat> Intersect<Option<Point2<S>>> for (Ray2<S>, Line2<S>) {
let q2mp = Vector2::new(line.dest.x - p.x, line.dest.y - p.y);
let dot_1 = qmp.dot(&r);
let dot_2 = q2mp.dot(&r);
if (dot_1 <= zero && dot_2 >= zero) || (dot_1 >= zero && dot_2 <= zero) {
if (dot_1 <= S::zero() && dot_2 >= S::zero()) || (dot_1 >= S::zero() && dot_2 <= S::zero()) {
return Some(p);
}
else if dot_1 >= zero && dot_2 >= zero {
else if dot_1 >= S::zero() && dot_2 >= S::zero() {
if dot_1 <= dot_2 {
return Some(q);
}
@ -92,7 +91,7 @@ impl<S: BaseFloat> Intersect<Option<Point2<S>>> for (Ray2<S>, Line2<S>) {
let t = qmp.perp_dot(&s) / cross_1;
let u = cross_2 / cross_1;
if zero <= t && u >= zero && u <= One::one() {
if S::zero() <= t && u >= S::zero() && u <= S::one() {
return Some(Point2::new(p.x + t*r.x, p.y + t*r.y));
}

View file

@ -21,7 +21,7 @@ use std::ops::*;
use rand::{Rand, Rng};
use rust_num::{zero, one};
use rust_num::{Zero, One};
use rust_num::traits::cast;
use angle::{Rad, sin, cos, sin_cos};
@ -122,27 +122,27 @@ impl<S: BaseFloat> Matrix3<S> {
pub fn from_angle_x(theta: Rad<S>) -> Matrix3<S> {
// http://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations
let (s, c) = sin_cos(theta);
Matrix3::new( one(), zero(), zero(),
zero(), c.clone(), s.clone(),
zero(), -s.clone(), c.clone())
Matrix3::new(S::one(), S::zero(), S::zero(),
S::zero(), c.clone(), s.clone(),
S::zero(), -s.clone(), c.clone())
}
/// Create a matrix from a rotation around the `y` axis (yaw).
pub fn from_angle_y(theta: Rad<S>) -> Matrix3<S> {
// http://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations
let (s, c) = sin_cos(theta);
Matrix3::new(c.clone(), zero(), -s.clone(),
zero(), one(), zero(),
s.clone(), zero(), c.clone())
Matrix3::new(c.clone(), S::zero(), -s.clone(),
S::zero(), S::one(), S::zero(),
s.clone(), S::zero(), c.clone())
}
/// Create a matrix from a rotation around the `z` axis (roll).
pub fn from_angle_z(theta: Rad<S>) -> Matrix3<S> {
// http://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations
let (s, c) = sin_cos(theta);
Matrix3::new( c.clone(), s.clone(), zero(),
-s.clone(), c.clone(), zero(),
zero(), zero(), one())
Matrix3::new( c.clone(), s.clone(), S::zero(),
-s.clone(), c.clone(), S::zero(),
S::zero(), S::zero(), S::one())
}
/// Create a matrix from a set of euler angles.
@ -166,7 +166,7 @@ impl<S: BaseFloat> Matrix3<S> {
/// Create a matrix from a rotation around an arbitrary axis
pub fn from_axis_angle(axis: &Vector3<S>, angle: Rad<S>) -> Matrix3<S> {
let (s, c) = sin_cos(angle);
let _1subc = one::<S>() - c;
let _1subc = S::one() - c;
Matrix3::new(_1subc * axis.x * axis.x + c,
_1subc * axis.x * axis.y + s * axis.z,
@ -216,10 +216,10 @@ impl<S: BaseNum> Matrix4<S> {
/// Create a translation matrix from a Vector3
#[inline]
pub fn from_translation(v: &Vector3<S>) -> Matrix4<S> {
Matrix4::new(one(), zero(), zero(), zero(),
zero(), one(), zero(), zero(),
zero(), zero(), one(), zero(),
v.x, v.y, v.z, one())
Matrix4::new(S::one(), S::zero(), S::zero(), S::zero(),
S::zero(), S::one(), S::zero(), S::zero(),
S::zero(), S::zero(), S::one(), S::zero(),
v.x, v.y, v.z, S::one())
}
}
@ -231,10 +231,10 @@ impl<S: BaseFloat> Matrix4<S> {
let s = f.cross(up).normalize();
let u = s.cross(&f);
Matrix4::new( s.x.clone(), u.x.clone(), -f.x.clone(), zero(),
s.y.clone(), u.y.clone(), -f.y.clone(), zero(),
s.z.clone(), u.z.clone(), -f.z.clone(), zero(),
-eye.dot(&s), -eye.dot(&u), eye.dot(&f), one())
Matrix4::new(s.x.clone(), u.x.clone(), -f.x.clone(), S::zero(),
s.y.clone(), u.y.clone(), -f.y.clone(), S::zero(),
s.z.clone(), u.z.clone(), -f.z.clone(), S::zero(),
-eye.dot(&s), -eye.dot(&u), eye.dot(&f), S::one())
}
}
@ -259,10 +259,10 @@ pub trait Matrix<S: BaseFloat, V: Clone + Vector<S> + 'static>: Array2<V, V, S>
/// Create a matrix with all elements equal to zero.
#[inline]
fn zero() -> Self { Self::from_value(zero()) }
fn zero() -> Self { Self::from_value(S::zero()) }
/// Create a matrix where the each element of the diagonal is equal to one.
#[inline]
fn identity() -> Self { Self::from_value(one()) }
fn identity() -> Self { Self::from_value(S::one()) }
/// Multiply this matrix by a scalar, returning the new matrix.
#[must_use]
@ -334,7 +334,7 @@ pub trait Matrix<S: BaseFloat, V: Clone + Vector<S> + 'static>: Array2<V, V, S>
/// Test if this matrix is invertible.
#[inline]
fn is_invertible(&self) -> bool { !self.determinant().approx_eq(&zero()) }
fn is_invertible(&self) -> bool { !self.determinant().approx_eq(&S::zero()) }
/// Test if this matrix is the identity matrix. That is, it is diagonal
/// and every element in the diagonal is one.
@ -512,14 +512,14 @@ impl<S: Copy + 'static> Array2<Vector4<S>, Vector4<S>, S> for Matrix4<S> {
impl<S: BaseFloat> Matrix<S, Vector2<S>> for Matrix2<S> {
#[inline]
fn from_value(value: S) -> Matrix2<S> {
Matrix2::new(value, zero(),
zero(), value)
Matrix2::new(value, S::zero(),
S::zero(), value)
}
#[inline]
fn from_diagonal(value: &Vector2<S>) -> Matrix2<S> {
Matrix2::new(value.x, zero(),
zero(), value.y)
Matrix2::new(value.x, S::zero(),
S::zero(), value.y)
}
#[inline]
@ -617,7 +617,7 @@ impl<S: BaseFloat> Matrix<S, Vector2<S>> for Matrix2<S> {
#[inline]
fn invert(&self) -> Option<Matrix2<S>> {
let det = self.determinant();
if det.approx_eq(&zero()) {
if det.approx_eq(&S::zero()) {
None
} else {
Some(Matrix2::new( self[1][1] / det, -self[0][1] / det,
@ -627,8 +627,8 @@ impl<S: BaseFloat> Matrix<S, Vector2<S>> for Matrix2<S> {
#[inline]
fn is_diagonal(&self) -> bool {
(&self[0][1]).approx_eq(&zero()) &&
(&self[1][0]).approx_eq(&zero())
(&self[0][1]).approx_eq(&S::zero()) &&
(&self[1][0]).approx_eq(&S::zero())
}
@ -642,16 +642,16 @@ impl<S: BaseFloat> Matrix<S, Vector2<S>> for Matrix2<S> {
impl<S: BaseFloat> Matrix<S, Vector3<S>> for Matrix3<S> {
#[inline]
fn from_value(value: S) -> Matrix3<S> {
Matrix3::new(value, zero(), zero(),
zero(), value, zero(),
zero(), zero(), value)
Matrix3::new(value, S::zero(), S::zero(),
S::zero(), value, S::zero(),
S::zero(), S::zero(), value)
}
#[inline]
fn from_diagonal(value: &Vector3<S>) -> Matrix3<S> {
Matrix3::new(value.x, zero(), zero(),
zero(), value.y, zero(),
zero(), zero(), value.z)
Matrix3::new(value.x, S::zero(), S::zero(),
S::zero(), value.y, S::zero(),
S::zero(), S::zero(), value.z)
}
#[inline]
@ -765,7 +765,7 @@ impl<S: BaseFloat> Matrix<S, Vector3<S>> for Matrix3<S> {
fn invert(&self) -> Option<Matrix3<S>> {
let det = self.determinant();
if det.approx_eq(&zero()) { None } else {
if det.approx_eq(&S::zero()) { None } else {
Some(Matrix3::from_cols(self[1].cross(&self[2]).div_s(det),
self[2].cross(&self[0]).div_s(det),
self[0].cross(&self[1]).div_s(det)).transpose())
@ -773,14 +773,14 @@ impl<S: BaseFloat> Matrix<S, Vector3<S>> for Matrix3<S> {
}
fn is_diagonal(&self) -> bool {
(&self[0][1]).approx_eq(&zero()) &&
(&self[0][2]).approx_eq(&zero()) &&
(&self[0][1]).approx_eq(&S::zero()) &&
(&self[0][2]).approx_eq(&S::zero()) &&
(&self[1][0]).approx_eq(&zero()) &&
(&self[1][2]).approx_eq(&zero()) &&
(&self[1][0]).approx_eq(&S::zero()) &&
(&self[1][2]).approx_eq(&S::zero()) &&
(&self[2][0]).approx_eq(&zero()) &&
(&self[2][1]).approx_eq(&zero())
(&self[2][0]).approx_eq(&S::zero()) &&
(&self[2][1]).approx_eq(&S::zero())
}
fn is_symmetric(&self) -> bool {
@ -810,18 +810,18 @@ macro_rules! dot_matrix4(
impl<S: BaseFloat> Matrix<S, Vector4<S>> for Matrix4<S> {
#[inline]
fn from_value(value: S) -> Matrix4<S> {
Matrix4::new(value, zero(), zero(), zero(),
zero(), value, zero(), zero(),
zero(), zero(), value, zero(),
zero(), zero(), zero(), value)
Matrix4::new(value, S::zero(), S::zero(), S::zero(),
S::zero(), value, S::zero(), S::zero(),
S::zero(), S::zero(), value, S::zero(),
S::zero(), S::zero(), S::zero(), value)
}
#[inline]
fn from_diagonal(value: &Vector4<S>) -> Matrix4<S> {
Matrix4::new(value.x, zero(), zero(), zero(),
zero(), value.y, zero(), zero(),
zero(), zero(), value.z, zero(),
zero(), zero(), zero(), value.w)
Matrix4::new(value.x, S::zero(), S::zero(), S::zero(),
S::zero(), value.y, S::zero(), S::zero(),
S::zero(), S::zero(), value.z, S::zero(),
S::zero(), S::zero(), S::zero(), value.w)
}
#[inline]
@ -965,9 +965,8 @@ impl<S: BaseFloat> Matrix<S, Vector4<S>> for Matrix4<S> {
fn invert(&self) -> Option<Matrix4<S>> {
let det = self.determinant();
if !det.approx_eq(&zero()) {
let one: S = one();
let inv_det = one / det;
if !det.approx_eq(&S::zero()) {
let inv_det = S::one() / det;
let t = self.transpose();
let cf = |i, j| {
let mat = match i {
@ -985,7 +984,7 @@ impl<S: BaseFloat> Matrix<S, Vector4<S>> for Matrix4<S> {
t.z.truncate_n(j)),
_ => panic!("out of range")
};
let sign = if (i+j) & 1 == 1 {-one} else {one};
let sign = if (i + j) & 1 == 1 { -S::one() } else { S::one() };
mat.determinant() * sign * inv_det
};
@ -1000,21 +999,21 @@ impl<S: BaseFloat> Matrix<S, Vector4<S>> for Matrix4<S> {
}
fn is_diagonal(&self) -> bool {
(&self[0][1]).approx_eq(&zero()) &&
(&self[0][2]).approx_eq(&zero()) &&
(&self[0][3]).approx_eq(&zero()) &&
(&self[0][1]).approx_eq(&S::zero()) &&
(&self[0][2]).approx_eq(&S::zero()) &&
(&self[0][3]).approx_eq(&S::zero()) &&
(&self[1][0]).approx_eq(&zero()) &&
(&self[1][2]).approx_eq(&zero()) &&
(&self[1][3]).approx_eq(&zero()) &&
(&self[1][0]).approx_eq(&S::zero()) &&
(&self[1][2]).approx_eq(&S::zero()) &&
(&self[1][3]).approx_eq(&S::zero()) &&
(&self[2][0]).approx_eq(&zero()) &&
(&self[2][1]).approx_eq(&zero()) &&
(&self[2][3]).approx_eq(&zero()) &&
(&self[2][0]).approx_eq(&S::zero()) &&
(&self[2][1]).approx_eq(&S::zero()) &&
(&self[2][3]).approx_eq(&S::zero()) &&
(&self[3][0]).approx_eq(&zero()) &&
(&self[3][1]).approx_eq(&zero()) &&
(&self[3][2]).approx_eq(&zero())
(&self[3][0]).approx_eq(&S::zero()) &&
(&self[3][1]).approx_eq(&S::zero()) &&
(&self[3][2]).approx_eq(&S::zero())
}
fn is_symmetric(&self) -> bool {
@ -1200,9 +1199,9 @@ impl<S: BaseFloat> From<Matrix2<S>> for Matrix3<S> {
/// Clone the elements of a 2-dimensional matrix into the top-left corner
/// of a 3-dimensional identity matrix.
fn from(m: Matrix2<S>) -> Matrix3<S> {
Matrix3::new(m[0][0], m[0][1], zero(),
m[1][0], m[1][1], zero(),
zero(), zero(), one())
Matrix3::new(m[0][0], m[0][1], S::zero(),
m[1][0], m[1][1], S::zero(),
S::zero(), S::zero(), S::one())
}
}
@ -1210,10 +1209,10 @@ impl<S: BaseFloat> From<Matrix2<S>> for Matrix4<S> {
/// Clone the elements of a 2-dimensional matrix into the top-left corner
/// of a 4-dimensional identity matrix.
fn from(m: Matrix2<S>) -> Matrix4<S> {
Matrix4::new(m[0][0], m[0][1], zero(), zero(),
m[1][0], m[1][1], zero(), zero(),
zero(), zero(), one(), zero(),
zero(), zero(), zero(), one())
Matrix4::new(m[0][0], m[0][1], S::zero(), S::zero(),
m[1][0], m[1][1], S::zero(), S::zero(),
S::zero(), S::zero(), S::one(), S::zero(),
S::zero(), S::zero(), S::zero(), S::one())
}
}
@ -1221,10 +1220,10 @@ impl<S: BaseFloat> From<Matrix3<S>> for Matrix4<S> {
/// Clone the elements of a 3-dimensional matrix into the top-left corner
/// of a 4-dimensional identity matrix.
fn from(m: Matrix3<S>) -> Matrix4<S> {
Matrix4::new(m[0][0], m[0][1], m[0][2], zero(),
m[1][0], m[1][1], m[1][2], zero(),
m[2][0], m[2][1], m[2][2], zero(),
zero(), zero(), zero(), one())
Matrix4::new(m[0][0], m[0][1], m[0][2], S::zero(),
m[1][0], m[1][1], m[1][2], S::zero(),
m[2][0], m[2][1], m[2][2], S::zero(),
S::zero(), S::zero(), S::zero(), S::one())
}
}
@ -1235,8 +1234,8 @@ impl<S: BaseFloat> From<Matrix3<S>> for Quaternion<S> {
let trace = mat.trace();
let half: S = cast(0.5f64).unwrap();
if trace >= zero::<S>() {
let s = (one::<S>() + trace).sqrt();
if trace >= S::zero() {
let s = (S::one() + trace).sqrt();
let w = half * s;
let s = half / s;
let x = (mat[1][2] - mat[2][1]) * s;

View file

@ -15,7 +15,7 @@
use std::fmt;
use rust_num::{one, Zero, zero};
use rust_num::{One, Zero};
use approx::ApproxEq;
use intersect::Intersect;
@ -85,7 +85,7 @@ impl<S: BaseFloat> Plane<S> {
// find the normal vector that is perpendicular to v1 and v2
let mut n = v0.cross(&v1);
if n.approx_eq(&zero()) { None }
if n.approx_eq(&Vector3::zero()) { None }
else {
// compute the normal and the distance to the plane
n.normalize_self();
@ -103,9 +103,9 @@ impl<S: BaseFloat> Plane<S> {
/// Normalize a plane.
pub fn normalize(&self) -> Option<Plane<S>> {
if self.n.approx_eq(&zero()) { None }
if self.n.approx_eq(&Vector3::zero()) { None }
else {
let denom = one::<S>() / self.n.length();
let denom = S::one() / self.n.length();
Some(Plane::new(self.n.mul_s(denom), self.d*denom))
}
}

View file

@ -21,7 +21,7 @@ use std::fmt;
use std::mem;
use std::ops::*;
use rust_num::{one, zero};
use rust_num::{One, Zero};
use approx::ApproxEq;
use array::Array1;
@ -57,13 +57,13 @@ impl<S: BaseNum> Point3<S> {
impl<S: BaseNum> Point3<S> {
#[inline]
pub fn from_homogeneous(v: &Vector4<S>) -> Point3<S> {
let e = v.truncate().mul_s(one::<S>() / v.w);
let e = v.truncate().mul_s(S::one() / v.w);
Point3::new(e.x, e.y, e.z) //FIXME
}
#[inline]
pub fn to_homogeneous(&self) -> Vector4<S> {
Vector4::new(self.x, self.y, self.z, one())
Vector4::new(self.x, self.y, self.z, S::one())
}
}
@ -118,7 +118,7 @@ impl<S: BaseNum> Array1<S> for Point2<S> {}
impl<S: BaseNum> Point<S, Vector2<S>> for Point2<S> {
#[inline]
fn origin() -> Point2<S> {
Point2::new(zero(), zero())
Point2::new(S::zero(), S::zero())
}
#[inline]
@ -218,7 +218,7 @@ impl<S: BaseNum> Array1<S> for Point3<S> {}
impl<S: BaseNum> Point<S, Vector3<S>> for Point3<S> {
#[inline]
fn origin() -> Point3<S> {
Point3::new(zero(), zero(), zero())
Point3::new(S::zero(), S::zero(), S::zero())
}
#[inline]

View file

@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use rust_num::{zero, one};
use rust_num::{Zero, One};
use rust_num::traits::cast;
use angle::{Angle, Rad, tan, cot};
@ -107,11 +107,11 @@ impl<S: BaseFloat, A: Angle<S>> From<PerspectiveFov<S, A>> for Matrix4<S> {
fn from(persp: PerspectiveFov<S, A>) -> Matrix4<S> {
let half_turn: A = Angle::turn_div_2();
assert!(persp.fovy > zero(), "The vertical field of view cannot be below zero, found: {:?}", persp.fovy);
assert!(persp.fovy > A::zero(), "The vertical field of view cannot be below zero, found: {:?}", persp.fovy);
assert!(persp.fovy < half_turn, "The vertical field of view cannot be greater than a half turn, found: {:?}", persp.fovy);
assert!(persp.aspect > zero(), "The aspect ratio cannot be below zero, found: {:?}", persp.aspect);
assert!(persp.near > zero(), "The near plane distance cannot be below zero, found: {:?}", persp.near);
assert!(persp.far > zero(), "The far plane distance cannot be below zero, found: {:?}", persp.far);
assert!(persp.aspect > S::zero(), "The aspect ratio cannot be below zero, found: {:?}", persp.aspect);
assert!(persp.near > S::zero(), "The near plane distance cannot be below zero, found: {:?}", persp.near);
assert!(persp.far > S::zero(), "The far plane distance cannot be below zero, found: {:?}", persp.far);
assert!(persp.far > persp.near, "The far plane cannot be closer than the near plane, found: far: {:?}, near: {:?}", persp.far, persp.near);
let f: Rad<_> = persp.fovy.div_s(cast(2i8).unwrap()).into();
@ -119,24 +119,24 @@ impl<S: BaseFloat, A: Angle<S>> From<PerspectiveFov<S, A>> for Matrix4<S> {
let two: S = cast(2i8).unwrap();
let c0r0 = f / persp.aspect;
let c0r1 = zero();
let c0r2 = zero();
let c0r3 = zero();
let c0r1 = S::zero();
let c0r2 = S::zero();
let c0r3 = S::zero();
let c1r0 = zero();
let c1r0 = S::zero();
let c1r1 = f;
let c1r2 = zero();
let c1r3 = zero();
let c1r2 = S::zero();
let c1r3 = S::zero();
let c2r0 = zero();
let c2r1 = zero();
let c2r0 = S::zero();
let c2r1 = S::zero();
let c2r2 = (persp.far + persp.near) / (persp.near - persp.far);
let c2r3 = -one::<S>();
let c2r3 = -S::one();
let c3r0 = zero();
let c3r1 = zero();
let c3r0 = S::zero();
let c3r1 = S::zero();
let c3r2 = (two * persp.far * persp.near) / (persp.near - persp.far);
let c3r3 = zero();
let c3r3 = S::zero();
Matrix4::new(c0r0, c0r1, c0r2, c0r3,
c1r0, c1r1, c1r2, c1r3,
@ -172,24 +172,24 @@ impl<S: BaseFloat + 'static> From<Perspective<S>> for Matrix4<S> {
let two: S = cast(2i8).unwrap();
let c0r0 = (two * persp.near) / (persp.right - persp.left);
let c0r1 = zero();
let c0r2 = zero();
let c0r3 = zero();
let c0r1 = S::zero();
let c0r2 = S::zero();
let c0r3 = S::zero();
let c1r0 = zero();
let c1r0 = S::zero();
let c1r1 = (two * persp.near) / (persp.top - persp.bottom);
let c1r2 = zero();
let c1r3 = zero();
let c1r2 = S::zero();
let c1r3 = S::zero();
let c2r0 = (persp.right + persp.left) / (persp.right - persp.left);
let c2r1 = (persp.top + persp.bottom) / (persp.top - persp.bottom);
let c2r2 = -(persp.far + persp.near) / (persp.far - persp.near);
let c2r3 = -one::<S>();
let c2r3 = -S::one();
let c3r0 = zero();
let c3r1 = zero();
let c3r0 = S::zero();
let c3r1 = S::zero();
let c3r2 = -(two * persp.far * persp.near) / (persp.far - persp.near);
let c3r3 = zero();
let c3r3 = S::zero();
Matrix4::new(c0r0, c0r1, c0r2, c0r3,
c1r0, c1r1, c1r2, c1r3,
@ -212,12 +212,12 @@ pub struct Ortho<S> {
impl<S: BaseFloat> Projection<S> for Ortho<S> {
fn to_frustum(&self) -> Frustum<S> {
Frustum {
left: Plane::from_abcd( one::<S>(), zero::<S>(), zero::<S>(), self.left.clone()),
right: Plane::from_abcd(-one::<S>(), zero::<S>(), zero::<S>(), self.right.clone()),
bottom: Plane::from_abcd(zero::<S>(), one::<S>(), zero::<S>(), self.bottom.clone()),
top: Plane::from_abcd(zero::<S>(), -one::<S>(), zero::<S>(), self.top.clone()),
near: Plane::from_abcd(zero::<S>(), zero::<S>(), -one::<S>(), self.near.clone()),
far: Plane::from_abcd(zero::<S>(), zero::<S>(), one::<S>(), self.far.clone()),
left: Plane::from_abcd( S::one(), S::zero(), S::zero(), self.left.clone()),
right: Plane::from_abcd(-S::one(), S::zero(), S::zero(), self.right.clone()),
bottom: Plane::from_abcd(S::zero(), S::one(), S::zero(), self.bottom.clone()),
top: Plane::from_abcd(S::zero(), -S::one(), S::zero(), self.top.clone()),
near: Plane::from_abcd(S::zero(), S::zero(), -S::one(), self.near.clone()),
far: Plane::from_abcd(S::zero(), S::zero(), S::one(), self.far.clone()),
}
}
}
@ -227,24 +227,24 @@ impl<S: BaseFloat> From<Ortho<S>> for Matrix4<S> {
let two: S = cast(2i8).unwrap();
let c0r0 = two / (ortho.right - ortho.left);
let c0r1 = zero();
let c0r2 = zero();
let c0r3 = zero();
let c0r1 = S::zero();
let c0r2 = S::zero();
let c0r3 = S::zero();
let c1r0 = zero();
let c1r0 = S::zero();
let c1r1 = two / (ortho.top - ortho.bottom);
let c1r2 = zero();
let c1r3 = zero();
let c1r2 = S::zero();
let c1r3 = S::zero();
let c2r0 = zero();
let c2r1 = zero();
let c2r0 = S::zero();
let c2r1 = S::zero();
let c2r2 = -two / (ortho.far - ortho.near);
let c2r3 = zero();
let c2r3 = S::zero();
let c3r0 = -(ortho.right + ortho.left) / (ortho.right - ortho.left);
let c3r1 = -(ortho.top + ortho.bottom) / (ortho.top - ortho.bottom);
let c3r2 = -(ortho.far + ortho.near) / (ortho.far - ortho.near);
let c3r3 = one::<S>();
let c3r3 = S::one();
Matrix4::new(c0r0, c0r1, c0r2, c0r3,
c1r0, c1r1, c1r2, c1r3,

View file

@ -19,7 +19,7 @@ use std::mem;
use std::ops::*;
use rand::{Rand, Rng};
use rust_num::{Float, one, zero};
use rust_num::{Float, One, Zero};
use rust_num::traits::cast;
use angle::{Angle, Rad, acos, sin, sin_cos, rad};
@ -59,13 +59,13 @@ impl<S: BaseFloat> Quaternion<S> {
/// The additive identity, ie: `q = 0 + 0i + 0j + 0i`
#[inline]
pub fn zero() -> Quaternion<S> {
Quaternion::new(zero(), zero(), zero(), zero())
Quaternion::new(S::zero(), S::zero(), S::zero(), S::zero())
}
/// The multiplicative identity, ie: `q = 1 + 0i + 0j + 0i`
#[inline]
pub fn identity() -> Quaternion<S> {
Quaternion::from_sv(one::<S>(), zero())
Quaternion::from_sv(S::one(), Vector3::zero())
}
/// The result of multiplying the quaternion a scalar
@ -176,12 +176,12 @@ impl<S: BaseFloat> Quaternion<S> {
/// Normalize this quaternion, returning the new quaternion.
#[inline]
pub fn normalize(&self) -> Quaternion<S> {
self.mul_s(one::<S>() / self.magnitude())
self.mul_s(S::one() / self.magnitude())
}
/// Do a normalized linear interpolation with `other`, by `amount`.
pub fn nlerp(&self, other: &Quaternion<S>, amount: S) -> Quaternion<S> {
self.mul_s(one::<S>() - amount).add_q(&other.mul_s(amount)).normalize()
self.mul_s(S::one() - amount).add_q(&other.mul_s(amount)).normalize()
}
}
@ -220,17 +220,17 @@ impl<S: BaseFloat> Quaternion<S> {
} else {
// stay within the domain of acos()
// TODO REMOVE WHEN https://github.com/mozilla/rust/issues/12068 IS RESOLVED
let robust_dot = if dot > one::<S>() {
one::<S>()
} else if dot < -one::<S>() {
-one::<S>()
let robust_dot = if dot > S::one() {
S::one()
} else if dot < -S::one() {
-S::one()
} else {
dot
};
let theta: Rad<S> = acos(robust_dot.clone());
let scale1 = sin(theta.mul_s(one::<S>() - amount));
let scale1 = sin(theta.mul_s(S::one() - amount));
let scale2 = sin(theta.mul_s(amount));
self.mul_s(scale1)
@ -258,14 +258,14 @@ impl<S: BaseFloat> Quaternion<S> {
if test > sig * unit {
(
rad(zero::<S>()),
rad(S::zero()),
rad(cast(f64::consts::FRAC_PI_2).unwrap()),
rad(two * qx.atan2(qw)),
)
} else if test < -sig * unit {
let y: S = cast(f64::consts::FRAC_PI_2).unwrap();
(
rad(zero::<S>()),
rad(S::zero()),
rad(-y),
rad(two * qx.atan2(qw)),
)
@ -298,9 +298,9 @@ impl<S: BaseFloat> From<Quaternion<S>> for Matrix3<S> {
let sz2 = z2 * quat.s;
let sx2 = x2 * quat.s;
Matrix3::new(one::<S>() - yy2 - zz2, xy2 + sz2, xz2 - sy2,
xy2 - sz2, one::<S>() - xx2 - zz2, yz2 + sx2,
xz2 + sy2, yz2 - sx2, one::<S>() - xx2 - yy2)
Matrix3::new(S::one() - yy2 - zz2, xy2 + sz2, xz2 - sy2,
xy2 - sz2, S::one() - xx2 - zz2, yz2 + sx2,
xz2 + sy2, yz2 - sx2, S::one() - xx2 - yy2)
}
}
@ -323,10 +323,10 @@ impl<S: BaseFloat> From<Quaternion<S>> for Matrix4<S> {
let sz2 = z2 * quat.s;
let sx2 = x2 * quat.s;
Matrix4::new(one::<S>() - yy2 - zz2, xy2 + sz2, xz2 - sy2, zero::<S>(),
xy2 - sz2, one::<S>() - xx2 - zz2, yz2 + sx2, zero::<S>(),
xz2 + sy2, yz2 - sx2, one::<S>() - xx2 - yy2, zero::<S>(),
zero::<S>(), zero::<S>(), zero::<S>(), one::<S>())
Matrix4::new(S::one() - yy2 - zz2, xy2 + sz2, xz2 - sy2, S::zero(),
xy2 - sz2, S::one() - xx2 - zz2, yz2 + sx2, S::zero(),
xz2 + sy2, yz2 - sx2, S::one() - xx2 - yy2, S::zero(),
S::zero(), S::zero(), S::zero(), S::one())
}
}
@ -369,7 +369,7 @@ impl<S: BaseFloat + 'static> Rotation<S, Vector3<S>, Point3<S>> for Quaternion<S
fn between_vectors(a: &Vector3<S>, b: &Vector3<S>) -> Quaternion<S> {
//http://stackoverflow.com/questions/1171849/
//finding-quaternion-representing-the-rotation-from-one-vector-to-another
Quaternion::from_sv(one::<S>() + a.dot(b), a.cross(b)).normalize()
Quaternion::from_sv(S::one() + a.dot(b), a.cross(b)).normalize()
}
#[inline]

View file

@ -44,7 +44,7 @@ pub trait Rotation<S: BaseFloat, V: Vector<S>, P: Point<S, V>>: PartialEq + Appr
/// representation as a vector.
#[inline]
fn rotate_point(&self, point: &P) -> P {
Point::from_vec( &self.rotate_vector( &point.to_vec() ) )
P::from_vec(&self.rotate_vector(&point.to_vec()))
}
/// Rotate a ray using this rotation.
@ -63,7 +63,7 @@ pub trait Rotation<S: BaseFloat, V: Vector<S>, P: Point<S, V>>: PartialEq + Appr
/// Modify this rotation in-place by combining it with another.
#[inline]
fn concat_self(&mut self, other: &Self) {
*self = Rotation::concat(self, other);
*self = Self::concat(self, other);
}
/// Invert this rotation in-place.

View file

@ -15,7 +15,7 @@
//! Bounding sphere
use rust_num::zero;
use rust_num::Zero;
use bound::*;
use intersect::Intersect;
@ -37,7 +37,7 @@ impl<S: BaseFloat> Intersect<Option<Point3<S>>> for (Sphere<S>, Ray3<S>) {
let l = s.center.sub_p(&r.origin);
let tca = l.dot(&r.direction);
if tca < zero() { return None; }
if tca < S::zero() { return None; }
let d2 = l.dot(&l) - tca*tca;
if d2 > s.radius*s.radius { return None; }
let thc = (s.radius*s.radius - d2).sqrt();

View file

@ -15,7 +15,7 @@
use std::fmt;
use rust_num::{zero, one};
use rust_num::{Zero, One};
use approx::ApproxEq;
use matrix::*;
@ -52,7 +52,7 @@ pub trait Transform<S: BaseNum, V: Vector<S>, P: Point<S, V>>: Sized {
/// Transform a vector as a point using this transform.
#[inline]
fn transform_as_point(&self, vec: &V) -> V {
self.transform_point(&Point::from_vec(vec)).to_vec()
self.transform_point(&P::from_vec(vec)).to_vec()
}
/// Combine this transform with another, yielding a new transformation
@ -65,7 +65,7 @@ pub trait Transform<S: BaseNum, V: Vector<S>, P: Point<S, V>>: Sized {
/// Combine this transform with another, in-place.
#[inline]
fn concat_self(&mut self, other: &Self) {
*self = Transform::concat(self, other);
*self = Self::concat(self, other);
}
/// Invert this transform in-place, failing if the transformation is not
@ -94,19 +94,18 @@ impl<
#[inline]
fn identity() -> Decomposed<S, V, R> {
Decomposed {
scale: one(),
rot: Rotation::identity(),
disp: zero(),
scale: S::one(),
rot: R::identity(),
disp: V::zero(),
}
}
#[inline]
fn look_at(eye: &P, center: &P, up: &V) -> Decomposed<S, V, R> {
let origin: P = Point::origin();
let rot: R = Rotation::look_at(&center.sub_p(eye), up);
let disp: V = rot.rotate_vector(&origin.sub_p(eye));
let rot = R::look_at(&center.sub_p(eye), up);
let disp = rot.rotate_vector(&P::origin().sub_p(eye));
Decomposed {
scale: one(),
scale: S::one(),
rot: rot,
disp: disp,
}
@ -131,10 +130,10 @@ impl<
}
fn invert(&self) -> Option<Decomposed<S, V, R>> {
if self.scale.approx_eq(&zero()) {
if self.scale.approx_eq(&S::zero()) {
None
} else {
let s = one::<S>() / self.scale;
let s = S::one() / self.scale;
let r = self.rot.invert();
let d = r.rotate_vector(&self.disp).mul_s(-s);
Some(Decomposed {
@ -156,7 +155,7 @@ impl<
fn from(dec: Decomposed<S, Vector2<S>, R>) -> Matrix3<S> {
let m: Matrix2<_> = dec.rot.into();
let mut m: Matrix3<_> = m.mul_s(dec.scale).into();
m.z = dec.disp.extend(one());
m.z = dec.disp.extend(S::one());
m
}
}
@ -168,7 +167,7 @@ impl<
fn from(dec: Decomposed<S, Vector3<S>, R>) -> Matrix4<S> {
let m: Matrix3<_> = dec.rot.into();
let mut m: Matrix4<_> = m.mul_s(dec.scale).into();
m.w = dec.disp.extend(one());
m.w = dec.disp.extend(S::one());
m
}
}
@ -212,7 +211,7 @@ impl<S: BaseFloat + 'static> Transform<S, Vector3<S>, Point3<S>> for AffineMatri
#[inline]
fn transform_vector(&self, vec: &Vector3<S>) -> Vector3<S> {
self.mat.mul_v(&vec.extend(zero())).truncate()
self.mat.mul_v(&vec.extend(S::zero())).truncate()
}
#[inline]
@ -263,8 +262,7 @@ impl<
R: Rotation<S, V, P> + Clone,
> ToComponents<S, V, P, R> for Decomposed<S, V, R> {
fn decompose(&self) -> (V, R, V) {
let v: V = one();
(v.mul_s(self.scale), self.rot.clone(), self.disp.clone())
(V::one().mul_s(self.scale), self.rot.clone(), self.disp.clone())
}
}

View file

@ -102,7 +102,7 @@ use std::ops::*;
use rand::{Rand, Rng};
use rust_num::{NumCast, Zero, One, zero, one};
use rust_num::{NumCast, Zero, One};
use angle::{Rad, atan2, acos};
use approx::ApproxEq;
@ -217,7 +217,7 @@ macro_rules! vec {
impl<$S: Zero + BaseNum> Zero for $Self_<$S> {
#[inline]
fn zero() -> $Self_<S> { $Self_ { $($field: zero()),+ } }
fn zero() -> $Self_<S> { $Self_ { $($field: $S::zero()),+ } }
#[inline]
fn is_zero(&self) -> bool { $((self.$field.is_zero()) )&&+ }
@ -225,7 +225,7 @@ macro_rules! vec {
impl<$S: One + BaseNum> One for $Self_<$S> {
#[inline]
fn one() -> $Self_<$S> { $Self_ { $($field: one()),+ } }
fn one() -> $Self_<$S> { $Self_ { $($field: S::one()),+ } }
}
impl<$S: NumCast + Copy> $Self_<$S> {
@ -482,9 +482,16 @@ index_operators!(Vector4<S>, 4, [S], RangeFull);
/// Operations specific to numeric two-dimensional vectors.
impl<S: BaseNum> Vector2<S> {
/// A unit vector in the `x` direction.
#[inline] pub fn unit_x() -> Vector2<S> { Vector2::new(one(), zero()) }
#[inline]
pub fn unit_x() -> Vector2<S> {
Vector2::new(S::one(), S::zero())
}
/// A unit vector in the `y` direction.
#[inline] pub fn unit_y() -> Vector2<S> { Vector2::new(zero(), one()) }
#[inline]
pub fn unit_y() -> Vector2<S> {
Vector2::new(S::zero(), S::one())
}
/// The perpendicular dot product of the vector and `other`.
#[inline]
@ -503,11 +510,22 @@ impl<S: BaseNum> Vector2<S> {
/// Operations specific to numeric three-dimensional vectors.
impl<S: BaseNum> Vector3<S> {
/// A unit vector in the `x` direction.
#[inline] pub fn unit_x() -> Vector3<S> { Vector3::new(one(), zero(), zero()) }
#[inline]
pub fn unit_x() -> Vector3<S> {
Vector3::new(S::one(), S::zero(), S::zero())
}
/// A unit vector in the `y` direction.
#[inline] pub fn unit_y() -> Vector3<S> { Vector3::new(zero(), one(), zero()) }
#[inline]
pub fn unit_y() -> Vector3<S> {
Vector3::new(S::zero(), S::one(), S::zero())
}
/// A unit vector in the `w` direction.
#[inline] pub fn unit_z() -> Vector3<S> { Vector3::new(zero(), zero(), one()) }
#[inline]
pub fn unit_z() -> Vector3<S> {
Vector3::new(S::zero(), S::zero(), S::one())
}
/// Returns the cross product of the vector and `other`.
#[inline]
@ -542,13 +560,28 @@ impl<S: BaseNum> Vector3<S> {
/// Operations specific to numeric four-dimensional vectors.
impl<S: BaseNum> Vector4<S> {
/// A unit vector in the `x` direction.
#[inline] pub fn unit_x() -> Vector4<S> { Vector4::new(one(), zero(), zero(), zero()) }
#[inline]
pub fn unit_x() -> Vector4<S> {
Vector4::new(S::one(), S::zero(), S::zero(), S::zero())
}
/// A unit vector in the `y` direction.
#[inline] pub fn unit_y() -> Vector4<S> { Vector4::new(zero(), one(), zero(), zero()) }
#[inline]
pub fn unit_y() -> Vector4<S> {
Vector4::new(S::zero(), S::one(), S::zero(), S::zero())
}
/// A unit vector in the `z` direction.
#[inline] pub fn unit_z() -> Vector4<S> { Vector4::new(zero(), zero(), one(), zero()) }
#[inline]
pub fn unit_z() -> Vector4<S> {
Vector4::new(S::zero(), S::zero(), S::one(), S::zero())
}
/// A unit vector in the `w` direction.
#[inline] pub fn unit_w() -> Vector4<S> { Vector4::new(zero(), zero(), zero(), one()) }
#[inline]
pub fn unit_w() -> Vector4<S> {
Vector4::new(S::zero(), S::zero(), S::zero(), S::one())
}
/// Create a `Vector3`, dropping the `w` value.
#[inline]
@ -577,7 +610,7 @@ pub trait EuclideanVector<S: BaseFloat>: Vector<S>
/// Returns `true` if the vector is perpendicular (at right angles) to the
/// other vector.
fn is_perpendicular(&self, other: &Self) -> bool {
self.dot(other).approx_eq(&zero())
self.dot(other).approx_eq(&S::zero())
}
/// Returns the squared length of the vector. This does not perform an
@ -602,7 +635,7 @@ pub trait EuclideanVector<S: BaseFloat>: Vector<S>
#[inline]
#[must_use]
fn normalize(&self) -> Self {
self.normalize_to(one::<S>())
self.normalize_to(S::one())
}
/// Returns a vector with the same direction and a given `length`.