diff --git a/src/lib.rs b/src/lib.rs index 564ec7b6..a489d249 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -173,7 +173,7 @@ mod macros; // mod chol; /// Change the input value to ensure it is on the range `[min, max]`. -#[inline(always)] +#[inline] pub fn clamp(val: T, min: T, max: T) -> T { if val > min { if val < max { @@ -189,74 +189,74 @@ pub fn clamp(val: T, min: T, max: T) -> T { } /// Same as `cmp::max`. -#[inline(always)] +#[inline] pub fn max(a: T, b: T) -> T { cmp::max(a, b) } /// Same as `cmp::min`. -#[inline(always)] +#[inline] pub fn min(a: T, b: T) -> T { cmp::min(a, b) } /// Returns the infimum of `a` and `b`. -#[inline(always)] +#[inline] pub fn inf(a: &T, b: &T) -> T { PartialOrder::inf(a, b) } /// Returns the supremum of `a` and `b`. -#[inline(always)] +#[inline] pub fn sup(a: &T, b: &T) -> T { PartialOrder::sup(a, b) } /// Compare `a` and `b` using a partial ordering relation. -#[inline(always)] +#[inline] pub fn partial_cmp(a: &T, b: &T) -> PartialOrdering { PartialOrder::partial_cmp(a, b) } /// Returns `true` iff `a` and `b` are comparable and `a < b`. -#[inline(always)] +#[inline] pub fn partial_lt(a: &T, b: &T) -> bool { PartialOrder::partial_lt(a, b) } /// Returns `true` iff `a` and `b` are comparable and `a <= b`. -#[inline(always)] +#[inline] pub fn partial_le(a: &T, b: &T) -> bool { PartialOrder::partial_le(a, b) } /// Returns `true` iff `a` and `b` are comparable and `a > b`. -#[inline(always)] +#[inline] pub fn partial_gt(a: &T, b: &T) -> bool { PartialOrder::partial_gt(a, b) } /// Returns `true` iff `a` and `b` are comparable and `a >= b`. -#[inline(always)] +#[inline] pub fn partial_ge(a: &T, b: &T) -> bool { PartialOrder::partial_ge(a, b) } /// Return the minimum of `a` and `b` if they are comparable. -#[inline(always)] +#[inline] pub fn partial_min<'a, T: PartialOrder>(a: &'a T, b: &'a T) -> Option<&'a T> { PartialOrder::partial_min(a, b) } /// Return the maximum of `a` and `b` if they are comparable. -#[inline(always)] +#[inline] pub fn partial_max<'a, T: PartialOrder>(a: &'a T, b: &'a T) -> Option<&'a T> { PartialOrder::partial_max(a, b) } /// Clamp `value` between `min` and `max`. Returns `None` if `value` is not comparable to /// `min` or `max`. -#[inline(always)] +#[inline] pub fn partial_clamp<'a, T: PartialOrder>(value: &'a T, min: &'a T, max: &'a T) -> Option<&'a T> { PartialOrder::partial_clamp(value, min, max) } @@ -270,7 +270,7 @@ pub fn partial_clamp<'a, T: PartialOrder>(value: &'a T, min: &'a T, max: &'a T) /// Create a special identity object. /// /// Same as `Identity::new()`. -#[inline(always)] +#[inline] pub fn identity() -> Identity { Identity::new() } @@ -278,13 +278,13 @@ pub fn identity() -> Identity { /// Create a zero-valued value. /// /// This is the same as `std::num::zero()`. -#[inline(always)] +#[inline] pub fn zero() -> T { Zero::zero() } /// Tests is a value is iqual to zero. -#[inline(always)] +#[inline] pub fn is_zero(val: &T) -> bool { val.is_zero() } @@ -292,7 +292,7 @@ pub fn is_zero(val: &T) -> bool { /// Create a one-valued value. /// /// This is the same as `std::num::one()`. -#[inline(always)] +#[inline] pub fn one() -> T { One::one() } @@ -304,7 +304,7 @@ pub fn one() -> T { // /// Returns the trivial origin of an affine space. -#[inline(always)] +#[inline] pub fn origin() -> P { Origin::origin() } @@ -312,26 +312,23 @@ pub fn origin() -> P { /// Returns the center of two points. #[inline] pub fn center>(a: &P, b: &P) -> P - where

::Vector: Norm -{ - let _2 = one::() + one(); - (*a + b.to_vector()) / _2 + where

::Vector: Norm { + (*a + b.to_vector()) / ::cast(2.0) } /* * FloatPoint */ /// Returns the distance between two points. -#[inline(always)] +#[inline] pub fn distance>(a: &P, b: &P) -> N where

::Vector: Norm { a.distance(b) } /// Returns the squared distance between two points. -#[inline(always)] +#[inline] pub fn distance_squared>(a: &P, b: &P) -> N - where

::Vector: Norm -{ + where

::Vector: Norm { a.distance_squared(b) } @@ -352,7 +349,7 @@ pub fn distance_squared>(a: &P, b: &P) -> N /// assert!(trans == Vector3::new(1.0, 1.0, 1.0)); /// } /// ``` -#[inline(always)] +#[inline] pub fn translation>(m: &M) -> V { m.translation() } @@ -370,13 +367,13 @@ pub fn translation>(m: &M) -> V { /// assert!(itrans == Vector3::new(-1.0, -1.0, -1.0)); /// } /// ``` -#[inline(always)] +#[inline] pub fn inverse_translation>(m: &M) -> V { m.inverse_translation() } /// Applies the translation `v` to a copy of `m`. -#[inline(always)] +#[inline] pub fn append_translation>(m: &M, v: &V) -> M { Translation::append_translation(m, v) } @@ -400,7 +397,7 @@ pub fn append_translation>(m: &M, v: &V) -> M { /// assert!(tp == Point3::new(3.0, 3.0, 3.0)) /// } /// ``` -#[inline(always)] +#[inline] pub fn translate>(m: &M, p: &P) -> P { m.translate(p) } @@ -419,7 +416,7 @@ pub fn translate>(m: &M, p: &P) -> P { /// /// assert!(na::approx_eq(&tp, &Point3::new(1.0, 1.0, 1.0))) /// } -#[inline(always)] +#[inline] pub fn inverse_translate>(m: &M, p: &P) -> P { m.inverse_translate(p) } @@ -440,7 +437,7 @@ pub fn inverse_translate>(m: &M, p: &P) -> P { /// assert!(na::approx_eq(&na::rotation(&t), &Vector3::new(1.0, 1.0, 1.0))); /// } /// ``` -#[inline(always)] +#[inline] pub fn rotation>(m: &M) -> V { m.rotation() } @@ -458,7 +455,7 @@ pub fn rotation>(m: &M) -> V { /// assert!(na::approx_eq(&na::inverse_rotation(&t), &Vector3::new(-1.0, -1.0, -1.0))); /// } /// ``` -#[inline(always)] +#[inline] pub fn inverse_rotation>(m: &M) -> V { m.inverse_rotation() } @@ -478,7 +475,7 @@ pub fn inverse_rotation>(m: &M) -> V { /// assert!(na::approx_eq(&na::rotation(&rt), &Vector3::new(1.0, 1.0, 1.0))) /// } /// ``` -#[inline(always)] +#[inline] pub fn append_rotation>(m: &M, v: &V) -> M { Rotation::append_rotation(m, v) } @@ -498,7 +495,7 @@ pub fn append_rotation>(m: &M, v: &V) -> M { /// assert!(na::approx_eq(&na::rotation(&rt), &Vector3::new(1.0, 1.0, 1.0))) /// } /// ``` -#[inline(always)] +#[inline] pub fn prepend_rotation>(m: &M, v: &V) -> M { Rotation::prepend_rotation(m, v) } @@ -522,7 +519,7 @@ pub fn prepend_rotation>(m: &M, v: &V) -> M { /// assert!(na::approx_eq(&tv, &Vector3::new(0.0, 1.0, 0.0))) /// } /// ``` -#[inline(always)] +#[inline] pub fn rotate>(m: &M, v: &V) -> V { m.rotate(v) } @@ -543,7 +540,7 @@ pub fn rotate>(m: &M, v: &V) -> V { /// assert!(na::approx_eq(&tv, &Vector3::new(0.0, -1.0, 0.0))) /// } /// ``` -#[inline(always)] +#[inline] pub fn inverse_rotate>(m: &M, v: &V) -> V { m.inverse_rotate(v) } @@ -553,7 +550,7 @@ pub fn inverse_rotate>(m: &M, v: &V) -> V { */ /// Rotates a copy of `m` by `amount` using `center` as the pivot point. -#[inline(always)] +#[inline] pub fn append_rotation_wrt_point + Copy, AV, M: RotationWithTranslation>( @@ -564,7 +561,7 @@ pub fn append_rotation_wrt_point + Copy, } /// Rotates a copy of `m` by `amount` using `m.translation()` as the pivot point. -#[inline(always)] +#[inline] pub fn append_rotation_wrt_center + Copy, AV, M: RotationWithTranslation>( @@ -577,13 +574,13 @@ pub fn append_rotation_wrt_center + Copy, * RotationTo */ /// Computes the angle of the rotation needed to transfom `a` to `b`. -#[inline(always)] +#[inline] pub fn angle_between(a: &V, b: &V) -> V::AngleType { a.angle_to(b) } /// Computes the rotation needed to transform `a` to `b`. -#[inline(always)] +#[inline] pub fn rotation_between(a: &V, b: &V) -> V::DeltaRotationType { a.rotation_to(b) } @@ -593,7 +590,7 @@ pub fn rotation_between(a: &V, b: &V) -> V::DeltaRotationType { */ /// Builds a rotation matrix from `r`. -#[inline(always)] +#[inline] pub fn to_rotation_matrix(r: &R) -> M where R: RotationMatrix, M: SquareMatrix + Rotation + Copy, @@ -608,7 +605,7 @@ pub fn to_rotation_matrix(r: &R) -> M */ /// Applies a rotation using the absolute values of its components. -#[inline(always)] +#[inline] pub fn absolute_rotate>(m: &M, v: &V) -> V { m.absolute_rotate(v) } @@ -618,19 +615,19 @@ pub fn absolute_rotate>(m: &M, v: &V) -> V { */ /// Gets the transformation applicable by `m`. -#[inline(always)] +#[inline] pub fn transformation>(m: &M) -> T { m.transformation() } /// Gets the inverse transformation applicable by `m`. -#[inline(always)] +#[inline] pub fn inverse_transformation>(m: &M) -> T { m.inverse_transformation() } /// Gets a transformed copy of `m`. -#[inline(always)] +#[inline] pub fn append_transformation>(m: &M, t: &T) -> M { Transformation::append_transformation(m, t) } @@ -640,13 +637,13 @@ pub fn append_transformation>(m: &M, t: &T) -> M { */ /// Applies a transformation to a vector. -#[inline(always)] +#[inline] pub fn transform>(m: &M, v: &V) -> V { m.transform(v) } /// Applies an inverse transformation to a vector. -#[inline(always)] +#[inline] pub fn inverse_transform>(m: &M, v: &V) -> V { m.inverse_transform(v) } @@ -656,7 +653,7 @@ pub fn inverse_transform>(m: &M, v: &V) -> V { */ /// Computes the dot product of two vectors. -#[inline(always)] +#[inline] pub fn dot, N>(a: &V, b: &V) -> N { Dot::dot(a, b) } @@ -666,19 +663,19 @@ pub fn dot, N>(a: &V, b: &V) -> N { */ /// Computes the L2 norm of a vector. -#[inline(always)] +#[inline] pub fn norm, N: BaseFloat>(v: &V) -> N { Norm::norm(v) } /// Computes the squared L2 norm of a vector. -#[inline(always)] +#[inline] pub fn norm_squared, N: BaseFloat>(v: &V) -> N { Norm::norm_squared(v) } /// Gets the normalized version of a vector. -#[inline(always)] +#[inline] pub fn normalize, N: BaseFloat>(v: &V) -> V { Norm::normalize(v) } @@ -687,7 +684,7 @@ pub fn normalize, N: BaseFloat>(v: &V) -> V { * Determinant */ /// Computes the determinant of a square matrix. -#[inline(always)] +#[inline] pub fn determinant, N>(m: &M) -> N { Determinant::determinant(m) } @@ -697,7 +694,7 @@ pub fn determinant, N>(m: &M) -> N { */ /// Computes the cross product of two vectors. -#[inline(always)] +#[inline] pub fn cross(a: &LV, b: &LV) -> LV::CrossProductType { Cross::cross(a, b) } @@ -708,7 +705,7 @@ pub fn cross(a: &LV, b: &LV) -> LV::CrossProductType { /// Given a vector, computes the matrix which, when multiplied by another vector, computes a cross /// product. -#[inline(always)] +#[inline] pub fn cross_matrix, M>(v: &V) -> M { CrossMatrix::cross_matrix(v) } @@ -718,7 +715,7 @@ pub fn cross_matrix, M>(v: &V) -> M { */ /// Converts a matrix or vector to homogeneous coordinates. -#[inline(always)] +#[inline] pub fn to_homogeneous, Res>(m: &M) -> Res { ToHomogeneous::to_homogeneous(m) } @@ -730,7 +727,7 @@ pub fn to_homogeneous, Res>(m: &M) -> Res { /// Converts a matrix or vector from homogeneous coordinates. /// /// w-normalization is appied. -#[inline(always)] +#[inline] pub fn from_homogeneous>(m: &M) -> Res { FromHomogeneous::from(m) } @@ -742,7 +739,7 @@ pub fn from_homogeneous>(m: &M) -> Res { /// Samples the unit sphere living on the dimension as the samples types. /// /// The number of sampling point is implementation-specific. It is always uniform. -#[inline(always)] +#[inline] pub fn sample_sphere(f: F) { UniformSphereSample::sample(f) } @@ -757,13 +754,13 @@ pub fn sample_sphere(f: F) { * AproxEq */ /// Tests approximate equality. -#[inline(always)] +#[inline] pub fn approx_eq, N>(a: &T, b: &T) -> bool { ApproxEq::approx_eq(a, b) } /// Tests approximate equality using a custom epsilon. -#[inline(always)] +#[inline] pub fn approx_eq_eps, N>(a: &T, b: &T, eps: &N) -> bool { ApproxEq::approx_eq_eps(a, b, eps) } @@ -774,7 +771,7 @@ pub fn approx_eq_eps, N>(a: &T, b: &T, eps: &N) -> bool { */ /// Computes a component-wise absolute value. -#[inline(always)] +#[inline] pub fn abs, Res>(m: &M) -> Res { Absolute::abs(m) } @@ -784,7 +781,7 @@ pub fn abs, Res>(m: &M) -> Res { */ /// Gets an inverted copy of a matrix. -#[inline(always)] +#[inline] pub fn inverse(m: &M) -> Option { Inverse::inverse(m) } @@ -794,7 +791,7 @@ pub fn inverse(m: &M) -> Option { */ /// Gets a transposed copy of a matrix. -#[inline(always)] +#[inline] pub fn transpose(m: &M) -> M { Transpose::transpose(m) } @@ -804,7 +801,7 @@ pub fn transpose(m: &M) -> M { */ /// Computes the outer product of two vectors. -#[inline(always)] +#[inline] pub fn outer(a: &V, b: &V) -> V::OuterProductType { Outer::outer(a, b) } @@ -814,7 +811,7 @@ pub fn outer(a: &V, b: &V) -> V::OuterProductType { */ /// Computes the covariance of a set of observations. -#[inline(always)] +#[inline] pub fn covariance, Res>(observations: &M) -> Res { Covariance::covariance(observations) } @@ -824,7 +821,7 @@ pub fn covariance, Res>(observations: &M) -> Res { */ /// Computes the mean of a set of observations. -#[inline(always)] +#[inline] pub fn mean>(observations: &M) -> N { Mean::mean(observations) } @@ -833,7 +830,7 @@ pub fn mean>(observations: &M) -> N { * EigenQR */ /// Computes the eigenvalues and eigenvectors of a square matrix usin the QR algorithm. -#[inline(always)] +#[inline] pub fn eigen_qr(m: &M, eps: &N, niter: usize) -> (M, V) where V: Mul, M: EigenQR { @@ -850,7 +847,7 @@ pub fn eigen_qr(m: &M, eps: &N, niter: usize) -> (M, V) * Eye */ /// Construct the identity matrix for a given dimension -#[inline(always)] +#[inline] pub fn new_identity(dimension: usize) -> M { Eye::new_identity(dimension) } @@ -862,7 +859,7 @@ pub fn new_identity(dimension: usize) -> M { /// Create an object by repeating a value. /// /// Same as `Identity::new()`. -#[inline(always)] +#[inline] pub fn repeat>(val: N) -> T { Repeat::repeat(val) } @@ -872,13 +869,13 @@ pub fn repeat>(val: N) -> T { */ /// Computes the canonical basis for a given dimension. -#[inline(always)] +#[inline] pub fn canonical_basis bool>(f: F) { Basis::canonical_basis(f) } /// Computes the basis of the orthonormal subspace of a given vector. -#[inline(always)] +#[inline] pub fn orthonormal_subspace_basis bool>(v: &V, f: F) { Basis::orthonormal_subspace_basis(v, f) } @@ -901,7 +898,7 @@ pub fn canonical_basis_element(i: usize) -> Option { * Diagonal */ /// Gets the diagonal of a square matrix. -#[inline(always)] +#[inline] pub fn diagonal, V>(m: &M) -> V { m.diagonal() } @@ -912,13 +909,13 @@ pub fn diagonal, V>(m: &M) -> V { /// Gets the dimension an object lives in. /// /// Same as `Dimension::dimension::(None::)`. -#[inline(always)] +#[inline] pub fn dimension() -> usize { Dimension::dimension(None::) } /// Gets the indexable range of an object. -#[inline(always)] +#[inline] pub fn shape, I>(v: &V) -> I { v.shape() } @@ -940,7 +937,7 @@ pub fn shape, I>(v: &V) -> I { /// range of an i32 when a cast from i64 to i32 is done). /// * A cast does not affect the dimension of an algebraic object. Note that this prevents an /// isometric transform to be cast to a raw matrix. Use `to_homogeneous` for that special purpose. -#[inline(always)] +#[inline] pub fn cast>(t: T) -> U { Cast::from(t) } diff --git a/src/linalg/decompositions.rs b/src/linalg/decompositions.rs index 112923b9..ed7aea7c 100644 --- a/src/linalg/decompositions.rs +++ b/src/linalg/decompositions.rs @@ -269,7 +269,7 @@ pub fn cholesky(m: &M) -> Result Sub + ColumnSlice + ApproxEq + Copy { - let mut out = m.clone().transpose(); + let mut out = m.transpose(); if !ApproxEq::approx_eq(&out, &m) { return Err("Cholesky: Input matrix is not symmetric"); @@ -302,7 +302,7 @@ pub fn cholesky(m: &M) -> Result } } - return Ok(out); + Ok(out) } /// Hessenberg @@ -320,7 +320,7 @@ pub fn hessenberg(m: &M) -> (M, M) M: Copy + Eye + ColumnSlice + Transpose + Indexable<(usize, usize), N> + Mul { - let mut h = m.clone(); + let mut h = *m; let (rows, cols) = h.shape(); let mut q : M = Eye::new_identity(cols); @@ -347,5 +347,5 @@ pub fn hessenberg(m: &M) -> (M, M) } } - return (q, h); + (q, h) } diff --git a/src/structs/dmatrix.rs b/src/structs/dmatrix.rs index b0e47f6d..3d6a33d6 100644 --- a/src/structs/dmatrix.rs +++ b/src/structs/dmatrix.rs @@ -109,7 +109,7 @@ impl DMatrix { impl DMatrix { /// Builds a matrix filled with the results of a function applied to each of its component coordinates. - #[inline(always)] + #[inline] pub fn from_fn N>(nrows: usize, ncols: usize, mut f: F) -> DMatrix { DMatrix { nrows: nrows, @@ -133,7 +133,7 @@ dmat_impl!(DMatrix, DVector); pub struct DMatrix1 { nrows: usize, ncols: usize, - mij: [N; 1 * 1], + mij: [N; 1], } small_dmat_impl!(DMatrix1, DVector1, 1, 0); diff --git a/src/structs/dmatrix_macros.rs b/src/structs/dmatrix_macros.rs index 96868f7c..ff3e9699 100644 --- a/src/structs/dmatrix_macros.rs +++ b/src/structs/dmatrix_macros.rs @@ -84,9 +84,8 @@ macro_rules! dmat_impl( fn new_identity(dimension: usize) -> $dmatrix { let mut res = $dmatrix::new_zeros(dimension, dimension); - for i in 0..dimension { - let _1: N = ::one(); - res[(i, i)] = _1; + for i in 0 .. dimension { + res[(i, i)] = ::one::(); } res @@ -94,7 +93,7 @@ macro_rules! dmat_impl( } impl $dmatrix { - #[inline(always)] + #[inline] fn offset(&self, i: usize, j: usize) -> usize { i + j * self.nrows } @@ -774,9 +773,8 @@ macro_rules! dmat_impl( // We can init from slice thanks to the matrix being column-major. let start = self.offset(row_start, column_id); let stop = self.offset(row_end, column_id); - let slice = $dvector::from_slice(row_end - row_start, &self.mij[start .. stop]); - slice + $dvector::from_slice(row_end - row_start, &self.mij[start .. stop]) } } @@ -824,12 +822,12 @@ macro_rules! dmat_impl( let mut slice : $dvector = unsafe { $dvector::new_uninitialized(column_end - column_start) }; - let mut slice_idx = 0; + for column_id in column_start .. column_end { unsafe { + let slice_idx = column_id - column_start; slice.unsafe_set(slice_idx, self.unsafe_at((row_id, column_id))); } - slice_idx += 1; } slice @@ -1140,7 +1138,7 @@ macro_rules! small_dmat_from_impl( } /// Builds a matrix using an initialization function. - #[inline(always)] + #[inline] pub fn from_fn N>(nrows: usize, ncols: usize, mut f: F) -> $dmatrix { assert!(nrows <= $dimension); assert!(ncols <= $dimension); diff --git a/src/structs/dvector.rs b/src/structs/dvector.rs index d90370bd..62761272 100644 --- a/src/structs/dvector.rs +++ b/src/structs/dvector.rs @@ -56,9 +56,9 @@ impl DVector { impl DVector { /// Builds a vector filled with the results of a function applied to each of its component coordinates. - #[inline(always)] - pub fn from_fn N>(dimension: usize, mut f: F) -> DVector { - DVector { at: (0 .. dimension).map(|i| f(i)).collect() } + #[inline] + pub fn from_fn N>(dimension: usize, f: F) -> DVector { + DVector { at: (0 .. dimension).map(f).collect() } } /// The vector length. diff --git a/src/structs/dvector_macros.rs b/src/structs/dvector_macros.rs index eee85cd6..12c685b6 100644 --- a/src/structs/dvector_macros.rs +++ b/src/structs/dvector_macros.rs @@ -191,7 +191,7 @@ macro_rules! small_dvec_from_impl ( impl $dvector { /// Builds a vector filled with the result of a function. - #[inline(always)] + #[inline] pub fn from_fn N>(dimension: usize, mut f: F) -> $dvector { assert!(dimension <= $dimension); diff --git a/src/structs/isometry.rs b/src/structs/isometry.rs index 9d43961d..0bd8d1c9 100644 --- a/src/structs/isometry.rs +++ b/src/structs/isometry.rs @@ -44,7 +44,7 @@ pub struct Isometry3 { pub translation: Vector3 } -impl Isometry3 { +impl Isometry3 { /// Creates an isometry that corresponds to the local frame of an observer standing at the /// point `eye` and looking toward `target`. /// @@ -59,7 +59,7 @@ impl Isometry3 { #[inline] pub fn new_observer_frame(eye: &Point3, target: &Point3, up: &Vector3) -> Isometry3 { let new_rotation_matrix = Rotation3::new_observer_frame(&(*target - *eye), up); - Isometry3::new_with_rotation_matrix(eye.as_vector().clone(), new_rotation_matrix) + Isometry3::new_with_rotation_matrix(eye.to_vector(), new_rotation_matrix) } /// Builds a right-handed look-at view matrix. diff --git a/src/structs/matrix_macros.rs b/src/structs/matrix_macros.rs index 3c401c6b..d5de9ea0 100644 --- a/src/structs/matrix_macros.rs +++ b/src/structs/matrix_macros.rs @@ -306,9 +306,9 @@ macro_rules! iterable_impl( ($t: ident, $dimension: expr) => ( impl Iterable for $t { #[inline] - fn iter<'l>(&'l self) -> Iter<'l, N> { + fn iter(&self) -> Iter { unsafe { - mem::transmute::<&'l $t, &'l [N; $dimension * $dimension]>(self).iter() + mem::transmute::<&$t, &[N; $dimension * $dimension]>(self).iter() } } } @@ -319,9 +319,9 @@ macro_rules! iterable_mut_impl( ($t: ident, $dimension: expr) => ( impl IterableMut for $t { #[inline] - fn iter_mut<'l>(&'l mut self) -> IterMut<'l, N> { + fn iter_mut(& mut self) -> IterMut { unsafe { - mem::transmute::<&'l mut $t, &'l mut [N; $dimension * $dimension]>(self).iter_mut() + mem::transmute::<&mut $t, &mut [N; $dimension * $dimension]>(self).iter_mut() } } } @@ -740,8 +740,8 @@ macro_rules! transpose_impl( #[inline] fn transpose_mut(&mut self) { - for i in 1..$dimension { - for j in 0..i { + for i in 1 .. $dimension { + for j in 0 .. i { self.swap((i, j), (j, i)) } } @@ -827,8 +827,9 @@ macro_rules! outer_impl( #[inline] fn outer(&self, other: &$t) -> $m { let mut res: $m = ::zero(); - for i in 0..Dimension::dimension(None::<$t>) { - for j in 0..Dimension::dimension(None::<$t>) { + + for i in 0 .. ::dimension::<$t>() { + for j in 0 .. ::dimension::<$t>() { res[(i, j)] = self[i] * other[j] } } diff --git a/src/structs/orthographic.rs b/src/structs/orthographic.rs index 12b27cc8..3ec39bbd 100644 --- a/src/structs/orthographic.rs +++ b/src/structs/orthographic.rs @@ -71,41 +71,41 @@ impl Arbitrary for Orthographic3 { } } -impl Orthographic3 { +impl Orthographic3 { /// The smallest x-coordinate of the view cuboid. #[inline] pub fn left(&self) -> N { - self.left.clone() + self.left } /// The largest x-coordinate of the view cuboid. #[inline] pub fn right(&self) -> N { - self.right.clone() + self.right } /// The smallest y-coordinate of the view cuboid. #[inline] pub fn bottom(&self) -> N { - self.bottom.clone() + self.bottom } /// The largest y-coordinate of the view cuboid. #[inline] pub fn top(&self) -> N { - self.top.clone() + self.top } /// The near plane offset of the view cuboid. #[inline] pub fn znear(&self) -> N { - self.znear.clone() + self.znear } /// The far plane offset of the view cuboid. #[inline] pub fn zfar(&self) -> N { - self.zfar.clone() + self.zfar } /// Sets the smallest x-coordinate of the view cuboid. @@ -187,12 +187,11 @@ impl OrthographicMatrix3 { assert!(znear < zfar, "The far plane must be farther than the near plane."); assert!(!::is_zero(&aspect)); - let _1: N = ::one(); - let _2 = _1 + _1; - let width = zfar * (vfov / _2).tan(); + let half: N = ::cast(0.5); + let width = zfar * (vfov * half).tan(); let height = width / aspect; - OrthographicMatrix3::new(-width / _2, width / _2, -height / _2, height / _2, znear, zfar) + OrthographicMatrix3::new(-width * half, width * half, -height * half, height * half, znear, zfar) } /// Creates a new orthographic matrix from a 4D matrix. @@ -207,7 +206,7 @@ impl OrthographicMatrix3 { /// Returns a reference to the 4D matrix (using homogeneous coordinates) of this projection. #[inline] - pub fn as_matrix<'a>(&'a self) -> &'a Matrix4 { + pub fn as_matrix(&self) -> &Matrix4 { &self.matrix } @@ -334,11 +333,11 @@ impl OrthographicMatrix3 { } } -impl OrthographicMatrix3 { +impl OrthographicMatrix3 { /// Returns the 4D matrix (using homogeneous coordinates) of this projection. #[inline] - pub fn to_matrix<'a>(&'a self) -> Matrix4 { - self.matrix.clone() + pub fn to_matrix(&self) -> Matrix4 { + self.matrix } } @@ -351,7 +350,7 @@ impl Arbitrary for OrthographicMatrix3 { } -/// Similarityple helper function for rejection sampling +/// Simple helper function for rejection sampling #[cfg(feature="arbitrary")] #[inline] pub fn reject bool, T: Arbitrary>(g: &mut G, f: F) -> T { diff --git a/src/structs/perspective.rs b/src/structs/perspective.rs index f3a7f213..10c6216e 100644 --- a/src/structs/perspective.rs +++ b/src/structs/perspective.rs @@ -63,29 +63,29 @@ impl Arbitrary for Perspective3 { } } -impl Perspective3 { +impl Perspective3 { /// Gets the `width / height` aspect ratio. #[inline] pub fn aspect(&self) -> N { - self.aspect.clone() + self.aspect } /// Gets the y field of view of the view frustrum. #[inline] pub fn fovy(&self) -> N { - self.fovy.clone() + self.fovy } /// Gets the near plane offset of the view frustrum. #[inline] pub fn znear(&self) -> N { - self.znear.clone() + self.znear } /// Gets the far plane offset of the view frustrum. #[inline] pub fn zfar(&self) -> N { - self.zfar.clone() + self.zfar } /// Sets the `width / height` aspect ratio of the view frustrum. @@ -165,7 +165,7 @@ impl PerspectiveMatrix3 { /// Returns a reference to the 4D matrix (using homogeneous coordinates) of this projection. #[inline] - pub fn as_matrix<'a>(&'a self) -> &'a Matrix4 { + pub fn as_matrix(&self) -> &Matrix4 { &self.matrix } @@ -178,30 +178,23 @@ impl PerspectiveMatrix3 { /// Gets the y field of view of the view frustrum. #[inline] pub fn fovy(&self) -> N { - let _1: N = ::one(); - let _2 = _1 + _1; - - (_1 / self.matrix.m22).atan() * _2 + (::one::() / self.matrix.m22).atan() * ::cast(2.0) } /// Gets the near plane offset of the view frustrum. #[inline] pub fn znear(&self) -> N { - let _1: N = ::one(); - let _2 = _1 + _1; - let ratio = (-self.matrix.m33 + _1) / (-self.matrix.m33 - _1); + let ratio = (-self.matrix.m33 + ::one::()) / (-self.matrix.m33 - ::one::()); - self.matrix.m34 / (_2 * ratio) - self.matrix.m34 / _2 + self.matrix.m34 / (ratio * ::cast(2.0)) - self.matrix.m34 / ::cast(2.0) } /// Gets the far plane offset of the view frustrum. #[inline] pub fn zfar(&self) -> N { - let _1: N = ::one(); - let _2 = _1 + _1; - let ratio = (-self.matrix.m33 + _1) / (-self.matrix.m33 - _1); + let ratio = (-self.matrix.m33 + ::one()) / (-self.matrix.m33 - ::one()); - (self.matrix.m34 - ratio * self.matrix.m34) / _2 + (self.matrix.m34 - ratio * self.matrix.m34) / ::cast(2.0) } // FIXME: add a method to retrieve znear and zfar simultaneously? @@ -217,11 +210,8 @@ impl PerspectiveMatrix3 { /// Updates this projection with a new y field of view of the view frustrum. #[inline] pub fn set_fovy(&mut self, fovy: N) { - let _1: N = ::one(); - let _2 = _1 + _1; - - let old_m22 = self.matrix.m22.clone(); - self.matrix.m22 = _1 / (fovy / _2).tan(); + let old_m22 = self.matrix.m22; + self.matrix.m22 = ::one::() / (fovy / ::cast(2.0)).tan(); self.matrix.m11 = self.matrix.m11 * (self.matrix.m22 / old_m22); } @@ -242,18 +232,15 @@ impl PerspectiveMatrix3 { /// Updates this projection matrix with new near and far plane offsets of the view frustrum. #[inline] pub fn set_znear_and_zfar(&mut self, znear: N, zfar: N) { - let _1: N = ::one(); - let _2 = _1 + _1; - self.matrix.m33 = (zfar + znear) / (znear - zfar); - self.matrix.m34 = zfar * znear * _2 / (znear - zfar); + self.matrix.m34 = zfar * znear * ::cast(2.0) / (znear - zfar); } /// Projects a point. #[inline] pub fn project_point(&self, p: &Point3) -> Point3 { - let _1: N = ::one(); - let inverse_denom = -_1 / p.z; + let inverse_denom = -::one::() / p.z; + Point3::new( self.matrix.m11 * p.x * inverse_denom, self.matrix.m22 * p.y * inverse_denom, @@ -264,8 +251,8 @@ impl PerspectiveMatrix3 { /// Projects a vector. #[inline] pub fn project_vector(&self, p: &Vector3) -> Vector3 { - let _1: N = ::one(); - let inverse_denom = -_1 / p.z; + let inverse_denom = -::one::() / p.z; + Vector3::new( self.matrix.m11 * p.x * inverse_denom, self.matrix.m22 * p.y * inverse_denom, @@ -274,11 +261,11 @@ impl PerspectiveMatrix3 { } } -impl PerspectiveMatrix3 { +impl PerspectiveMatrix3 { /// Returns the 4D matrix (using homogeneous coordinates) of this projection. #[inline] - pub fn to_matrix<'a>(&'a self) -> Matrix4 { - self.matrix.clone() + pub fn to_matrix(&self) -> Matrix4 { + self.matrix } } diff --git a/src/structs/point_macros.rs b/src/structs/point_macros.rs index 6e549111..d55cde10 100644 --- a/src/structs/point_macros.rs +++ b/src/structs/point_macros.rs @@ -84,7 +84,7 @@ macro_rules! point_as_vec_impl( /// Converts a reference to this point to a reference to its associated vector. #[inline] - pub fn as_vector<'a>(&'a self) -> &'a $tv { + pub fn as_vector(&self) -> &$tv { unsafe { mem::transmute(self) } @@ -105,7 +105,7 @@ macro_rules! point_as_vec_impl( } #[inline] - fn as_vector<'a>(&'a self) -> &'a $tv { + fn as_vector(&self) -> &$tv { self.as_vector() } diff --git a/src/structs/quaternion.rs b/src/structs/quaternion.rs index aa127402..5cdbd7d1 100644 --- a/src/structs/quaternion.rs +++ b/src/structs/quaternion.rs @@ -45,7 +45,7 @@ impl Quaternion { /// The vector part `(i, j, k)` of this quaternion. #[inline] - pub fn vector<'a>(&'a self) -> &'a Vector3 { + pub fn vector(&self) -> &Vector3 { // FIXME: do this require a `repr(C)` ? unsafe { mem::transmute(&self.i) @@ -54,7 +54,7 @@ impl Quaternion { /// The scalar part `w` of this quaternion. #[inline] - pub fn scalar<'a>(&'a self) -> &'a N { + pub fn scalar(&self) -> &N { &self.w } } @@ -226,10 +226,9 @@ impl UnitQuaternion { /// The primitive rotations are applied in order: 1 roll − 2 pitch − 3 yaw. #[inline] pub fn new_with_euler_angles(roll: N, pitch: N, yaw: N) -> UnitQuaternion { - let _0_5: N = Cast::from(0.5); - let (sr, cr) = (roll * _0_5).sin_cos(); - let (sp, cp) = (pitch * _0_5).sin_cos(); - let (sy, cy) = (yaw * _0_5).sin_cos(); + let (sr, cr) = (roll * ::cast(0.5)).sin_cos(); + let (sp, cp) = (pitch * ::cast(0.5)).sin_cos(); + let (sy, cy) = (yaw * ::cast(0.5)).sin_cos(); unsafe { UnitQuaternion::new_with_unit_quaternion( @@ -244,17 +243,16 @@ impl UnitQuaternion { /// Builds a rotation matrix from this quaternion. pub fn to_rotation_matrix(&self) -> Rotation3 { - let _2: N = Cast::from(2.0); let ww = self.q.w * self.q.w; let ii = self.q.i * self.q.i; let jj = self.q.j * self.q.j; let kk = self.q.k * self.q.k; - let ij = _2 * self.q.i * self.q.j; - let wk = _2 * self.q.w * self.q.k; - let wj = _2 * self.q.w * self.q.j; - let ik = _2 * self.q.i * self.q.k; - let jk = _2 * self.q.j * self.q.k; - let wi = _2 * self.q.w * self.q.i; + let ij = self.q.i * self.q.j * ::cast(2.0); + let wk = self.q.w * self.q.k * ::cast(2.0); + let wj = self.q.w * self.q.j * ::cast(2.0); + let ik = self.q.i * self.q.k * ::cast(2.0); + let jk = self.q.j * self.q.k * ::cast(2.0); + let wi = self.q.w * self.q.i * ::cast(2.0); unsafe { Rotation3::new_with_matrix( @@ -282,7 +280,7 @@ impl UnitQuaternion { /// The `Quaternion` representation of this unit quaternion. #[inline] - pub fn quaternion<'a>(&'a self) -> &'a Quaternion { + pub fn quaternion(&self) -> &Quaternion { &self.q } } @@ -379,11 +377,11 @@ impl Mul> for UnitQuaternion { #[inline] fn mul(self, right: Vector3) -> Vector3 { - let _2: N = ::one::() + ::one(); + let two: N = ::one::() + ::one(); let mut t = ::cross(self.q.vector(), &right); - t.x = t.x * _2; - t.y = t.y * _2; - t.z = t.z * _2; + t.x = t.x * two; + t.y = t.y * two; + t.z = t.z * two; Vector3::new(t.x * self.q.w, t.y * self.q.w, t.z * self.q.w) + ::cross(self.q.vector(), &t) + right } @@ -437,9 +435,8 @@ impl> MulAssign> for Point3 { impl Rotation> for UnitQuaternion { #[inline] fn rotation(&self) -> Vector3 { - let _2 = ::one::() + ::one(); let mut v = *self.q.vector(); - let ang = _2 * v.normalize_mut().atan2(self.q.w); + let ang = v.normalize_mut().atan2(self.q.w) * ::cast(2.0); if ::is_zero(&ang) { ::zero() @@ -520,9 +517,8 @@ impl> RotationTo for UnitQuaternion { #[inline] fn angle_to(&self, other: &Self) -> N { let delta = self.rotation_to(other); - let _2 = ::one::() + ::one(); - _2 * delta.q.vector().norm().atan2(delta.q.w) + delta.q.vector().norm().atan2(delta.q.w) * ::cast(2.0) } #[inline] diff --git a/src/structs/rotation.rs b/src/structs/rotation.rs index d1520fab..94276c7a 100644 --- a/src/structs/rotation.rs +++ b/src/structs/rotation.rs @@ -1,7 +1,7 @@ //! Rotations matrices. use std::fmt; -use std::ops::{Mul, Neg, MulAssign, Index}; +use std::ops::{Mul, MulAssign, Index}; use rand::{Rand, Rng}; use num::{Zero, One}; use traits::geometry::{Rotate, Rotation, AbsoluteRotate, RotationMatrix, RotationTo, Transform, @@ -22,21 +22,21 @@ pub struct Rotation2 { submatrix: Matrix2 } -impl> Rotation2 { +impl Rotation2 { /// Builds a 2 dimensional rotation matrix from an angle in radian. pub fn new(angle: Vector1) -> Rotation2 { let (sia, coa) = angle.x.sin_cos(); Rotation2 { - submatrix: Matrix2::new(coa.clone(), -sia, sia, coa) + submatrix: Matrix2::new(coa, -sia, sia, coa) } } } -impl Rotation> for Rotation2 { +impl Rotation> for Rotation2 { #[inline] fn rotation(&self) -> Vector1 { - Vector1::new((-self.submatrix.m12).atan2(self.submatrix.m11.clone())) + Vector1::new((-self.submatrix.m12).atan2(self.submatrix.m11)) } #[inline] @@ -51,7 +51,7 @@ impl Rotation> for Rotation2 { #[inline] fn append_rotation(&self, rotation: &Vector1) -> Rotation2 { - Rotation2::new(rotation.clone()) * *self + Rotation2::new(*rotation) * *self } #[inline] @@ -61,7 +61,7 @@ impl Rotation> for Rotation2 { #[inline] fn prepend_rotation(&self, rotation: &Vector1) -> Rotation2 { - *self * Rotation2::new(rotation.clone()) + *self * Rotation2::new(*rotation) } #[inline] @@ -106,7 +106,7 @@ impl AbsoluteRotate> for Rotation2 { } #[cfg(feature="arbitrary")] -impl> Arbitrary for Rotation2 { +impl Arbitrary for Rotation2 { fn arbitrary(g: &mut G) -> Rotation2 { Rotation2::new(Arbitrary::arbitrary(g)) } @@ -124,7 +124,7 @@ pub struct Rotation3 { } -impl Rotation3 { +impl Rotation3 { /// Builds a 3 dimensional rotation matrix from an axis and an angle. /// /// # Arguments @@ -137,29 +137,28 @@ impl Rotation3 { else { let mut axis = axisangle; let angle = axis.normalize_mut(); - let _1: N = ::one(); - let ux = axis.x.clone(); - let uy = axis.y.clone(); - let uz = axis.z.clone(); + let ux = axis.x; + let uy = axis.y; + let uz = axis.z; let sqx = ux * ux; let sqy = uy * uy; let sqz = uz * uz; let (sin, cos) = angle.sin_cos(); - let one_m_cos = _1 - cos; + let one_m_cos = ::one::() - cos; Rotation3 { submatrix: Matrix3::new( - (sqx + (_1 - sqx) * cos), + (sqx + (::one::() - sqx) * cos), (ux * uy * one_m_cos - uz * sin), (ux * uz * one_m_cos + uy * sin), (ux * uy * one_m_cos + uz * sin), - (sqy + (_1 - sqy) * cos), + (sqy + (::one::() - sqy) * cos), (uy * uz * one_m_cos - ux * sin), (ux * uz * one_m_cos - uy * sin), (uy * uz * one_m_cos + ux * sin), - (sqz + (_1 - sqz) * cos)) + (sqz + (::one::() - sqz) * cos)) } } } @@ -193,7 +192,7 @@ impl Rotation3 { } } -impl Rotation3 { +impl Rotation3 { /// Creates a rotation that corresponds to the local frame of an observer standing at the /// origin and looking toward `dir`. /// @@ -212,9 +211,9 @@ impl Rotation3 { unsafe { Rotation3::new_with_matrix(Matrix3::new( - xaxis.x.clone(), yaxis.x.clone(), zaxis.x.clone(), - xaxis.y.clone(), yaxis.y.clone(), zaxis.y.clone(), - xaxis.z , yaxis.z , zaxis.z)) + xaxis.x, yaxis.x, zaxis.x, + xaxis.y, yaxis.y, zaxis.y, + xaxis.z, yaxis.z, zaxis.z)) } } @@ -250,17 +249,13 @@ impl Rotation3 { } } -impl> -Rotation> for Rotation3 { +impl Rotation> for Rotation3 { #[inline] fn rotation(&self) -> Vector3 { let angle = ((self.submatrix.m11 + self.submatrix.m22 + self.submatrix.m33 - ::one()) / Cast::from(2.0)).acos(); - if angle != angle { - // FIXME: handle that correctly - ::zero() - } - else if ::is_zero(&angle) { + if !angle.is_finite() || ::is_zero(&angle) { + // FIXME: handle the non-finite case robustly. ::zero() } else { @@ -296,7 +291,7 @@ Rotation> for Rotation3 { #[inline] fn append_rotation(&self, axisangle: &Vector3) -> Rotation3 { - Rotation3::new(axisangle.clone()) * *self + Rotation3::new(*axisangle) * *self } #[inline] @@ -306,7 +301,7 @@ Rotation> for Rotation3 { #[inline] fn prepend_rotation(&self, axisangle: &Vector3) -> Rotation3 { - *self * Rotation3::new(axisangle.clone()) + *self * Rotation3::new(*axisangle) } #[inline] @@ -331,7 +326,7 @@ impl RotationTo for Rotation3 { } } -impl Rand for Rotation3 { +impl Rand for Rotation3 { #[inline] fn rand(rng: &mut R) -> Rotation3 { Rotation3::new(rng.gen()) @@ -349,7 +344,7 @@ impl AbsoluteRotate> for Rotation3 { } #[cfg(feature="arbitrary")] -impl Arbitrary for Rotation3 { +impl Arbitrary for Rotation3 { fn arbitrary(g: &mut G) -> Rotation3 { Rotation3::new(Arbitrary::arbitrary(g)) } diff --git a/src/structs/rotation_macros.rs b/src/structs/rotation_macros.rs index a0074393..22cb90de 100644 --- a/src/structs/rotation_macros.rs +++ b/src/structs/rotation_macros.rs @@ -5,7 +5,7 @@ macro_rules! submat_impl( impl $t { /// This rotation's underlying matrix. #[inline] - pub fn submatrix<'r>(&'r self) -> &'r $submatrix { + pub fn submatrix(&self) -> &$submatrix { &self.submatrix } } diff --git a/src/structs/specializations/matrix.rs b/src/structs/specializations/matrix.rs index d390f912..c1a1d964 100644 --- a/src/structs/specializations/matrix.rs +++ b/src/structs/specializations/matrix.rs @@ -24,9 +24,8 @@ impl> Inverse for Matrix1 { false } else { - let _1: N = ::one(); + self.m11 = ::one::() / Determinant::determinant(self); - self.m11 = _1 / Determinant::determinant(self); true } } @@ -234,7 +233,7 @@ impl + Add> Mul> for Matr impl + Add> Mul> for Matrix2 { type Output = Matrix2; - #[inline(always)] + #[inline] fn mul(self, right: Matrix2) -> Matrix2 { Matrix2::new( self.m11 * right.m11 + self.m12 * right.m21, @@ -249,7 +248,7 @@ impl + Add> Mul> for Matr impl + Add> Mul> for Matrix3 { type Output = Vector3; - #[inline(always)] + #[inline] fn mul(self, right: Vector3) -> Vector3 { Vector3::new( self.m11 * right.x + self.m12 * right.y + self.m13 * right.z, @@ -262,7 +261,7 @@ impl + Add> Mul> for Matr impl + Add> Mul> for Vector3 { type Output = Vector3; - #[inline(always)] + #[inline] fn mul(self, right: Matrix3) -> Vector3 { Vector3::new( self.x * right.m11 + self.y * right.m21 + self.z * right.m31, @@ -275,7 +274,7 @@ impl + Add> Mul> for Vect impl + Add> Mul> for Vector2 { type Output = Vector2; - #[inline(always)] + #[inline] fn mul(self, right: Matrix2) -> Vector2 { Vector2::new( self.x * right.m11 + self.y * right.m21, @@ -287,7 +286,7 @@ impl + Add> Mul> for Vect impl + Add> Mul> for Matrix2 { type Output = Vector2; - #[inline(always)] + #[inline] fn mul(self, right: Vector2) -> Vector2 { Vector2::new( self.m11 * right.x + self.m12 * right.y, @@ -299,7 +298,7 @@ impl + Add> Mul> for Matr impl + Add> Mul> for Matrix3 { type Output = Point3; - #[inline(always)] + #[inline] fn mul(self, right: Point3) -> Point3 { Point3::new( self.m11 * right.x + self.m12 * right.y + self.m13 * right.z, @@ -312,7 +311,7 @@ impl + Add> Mul> for Matri impl + Add> Mul> for Point3 { type Output = Point3; - #[inline(always)] + #[inline] fn mul(self, right: Matrix3) -> Point3 { Point3::new( self.x * right.m11 + self.y * right.m21 + self.z * right.m31, @@ -325,7 +324,7 @@ impl + Add> Mul> for Poin impl + Add> Mul> for Point2 { type Output = Point2; - #[inline(always)] + #[inline] fn mul(self, right: Matrix2) -> Point2 { Point2::new( self.x * right.m11 + self.y * right.m21, @@ -337,7 +336,7 @@ impl + Add> Mul> for Poin impl + Add> Mul> for Matrix2 { type Output = Point2; - #[inline(always)] + #[inline] fn mul(self, right: Point2) -> Point2 { Point2::new( self.m11 * right.x + self.m12 * right.y, @@ -350,7 +349,7 @@ impl + Add> Mul> for Matri macro_rules! impl_mul_assign_from_mul( ($tleft: ident, $tright: ident) => ( impl + Add> MulAssign<$tright> for $tleft { - #[inline(always)] + #[inline] fn mul_assign(&mut self, right: $tright) { // NOTE: there is probably no interesting optimization compared to the not-inplace // operation. diff --git a/src/structs/specializations/primitives.rs b/src/structs/specializations/primitives.rs index 636bdf6b..0605df53 100644 --- a/src/structs/specializations/primitives.rs +++ b/src/structs/specializations/primitives.rs @@ -5,7 +5,7 @@ use traits::structure::Cast; macro_rules! primitive_cast_impl( ($from: ty, $to: ty) => ( impl Cast<$from> for $to { - #[inline(always)] + #[inline] fn from(t: $from) -> $to { t as $to } diff --git a/src/structs/specializations/vector.rs b/src/structs/specializations/vector.rs index c5367e94..4910d420 100644 --- a/src/structs/specializations/vector.rs +++ b/src/structs/specializations/vector.rs @@ -115,12 +115,12 @@ impl Row> for Vector2 { } impl Basis for Vector1 { - #[inline(always)] + #[inline] fn canonical_basis) -> bool>(mut f: F) { f(Vector1::new(::one())); } - #[inline(always)] + #[inline] fn orthonormal_subspace_basis) -> bool>(_: &Vector1, _: F) { } #[inline] @@ -135,7 +135,7 @@ impl Basis for Vector1 { } impl> Basis for Vector2 { - #[inline(always)] + #[inline] fn canonical_basis) -> bool>(mut f: F) { if !f(Vector2::new(::one(), ::zero())) { return }; f(Vector2::new(::zero(), ::one())); @@ -161,14 +161,14 @@ impl> Basis for Vector2 { } impl Basis for Vector3 { - #[inline(always)] + #[inline] fn canonical_basis) -> bool>(mut f: F) { if !f(Vector3::new(::one(), ::zero(), ::zero())) { return }; if !f(Vector3::new(::zero(), ::one(), ::zero())) { return }; f(Vector3::new(::zero(), ::zero(), ::one())); } - #[inline(always)] + #[inline] fn orthonormal_subspace_basis) -> bool>(n: &Vector3, mut f: F) { let a = if n.x.abs() > n.y.abs() { @@ -272,14 +272,14 @@ static SAMPLES_3_F64: [Vector3; 42] = [ impl UniformSphereSample for Vector1 where Vector1: One { - #[inline(always)] + #[inline] fn sample)>(mut f: F) { f(::one()) } } impl + Copy> UniformSphereSample for Vector2 { - #[inline(always)] + #[inline] fn sample)>(mut f: F) { for sample in SAMPLES_2_F64.iter() { f(Cast::from(*sample)) @@ -288,7 +288,7 @@ impl + Copy> UniformSphereSample for Vector2 { } impl + Copy> UniformSphereSample for Vector3 { - #[inline(always)] + #[inline] fn sample)>(mut f: F) { for sample in SAMPLES_3_F64.iter() { f(Cast::from(*sample)) @@ -297,7 +297,7 @@ impl + Copy> UniformSphereSample for Vector3 { } impl + Copy> UniformSphereSample for Vector4 { - #[inline(always)] + #[inline] fn sample)>(_: F) { panic!("UniformSphereSample::>::sample : Not yet implemented.") // for sample in SAMPLES_3_F32.iter() { diff --git a/src/structs/vector_macros.rs b/src/structs/vector_macros.rs index 6f52b342..8deb71c9 100644 --- a/src/structs/vector_macros.rs +++ b/src/structs/vector_macros.rs @@ -250,9 +250,9 @@ macro_rules! iterable_impl( ($t: ident, $dimension: expr) => ( impl Iterable for $t { #[inline] - fn iter<'l>(&'l self) -> Iter<'l, N> { + fn iter(&self) -> Iter { unsafe { - mem::transmute::<&'l $t, &'l [N; $dimension]>(self).iter() + mem::transmute::<&$t, &[N; $dimension]>(self).iter() } } } @@ -263,9 +263,9 @@ macro_rules! iterable_mut_impl( ($t: ident, $dimension: expr) => ( impl IterableMut for $t { #[inline] - fn iter_mut<'l>(&'l mut self) -> IterMut<'l, N> { + fn iter_mut(&mut self) -> IterMut { unsafe { - mem::transmute::<&'l mut $t, &'l mut [N; $dimension]>(self).iter_mut() + mem::transmute::<&mut $t, &mut [N; $dimension]>(self).iter_mut() } } } diff --git a/src/structs/vectorn_macros.rs b/src/structs/vectorn_macros.rs index 04b2b79a..7e7f2d54 100644 --- a/src/structs/vectorn_macros.rs +++ b/src/structs/vectorn_macros.rs @@ -93,14 +93,14 @@ macro_rules! vecn_dvec_common_impl( */ impl)*> Iterable for $vecn { #[inline] - fn iter<'l>(&'l self) -> Iter<'l, N> { + fn iter(&self) -> Iter { self.as_ref().iter() } } impl)*> IterableMut for $vecn { #[inline] - fn iter_mut<'l>(&'l mut self) -> IterMut<'l, N> { + fn iter_mut(&mut self) -> IterMut { self.as_mut().iter_mut() } } diff --git a/src/traits/operations.rs b/src/traits/operations.rs index 10ae7947..07bba122 100644 --- a/src/traits/operations.rs +++ b/src/traits/operations.rs @@ -1,5 +1,6 @@ //! Low level operations on vectors and matrices. +use std::mem; use num::{Float, Signed}; use std::ops::Mul; use std::cmp::Ordering; @@ -136,16 +137,14 @@ pub trait PartialOrder { if v_min.is_not_comparable() || v_max.is_not_comparable() { None } + else if v_min.is_lt() { + Some(min) + } + else if v_max.is_gt() { + Some(max) + } else { - if v_min.is_lt() { - Some(min) - } - else if v_max.is_gt() { - Some(max) - } - else { - Some(self) - } + Some(self) } } } @@ -195,8 +194,8 @@ impl ApproxEq for f32 { // IEEE754 floats are in the same order as 2s complement isizes // so this trick (subtracting the isizes) works. - let iself: i32 = unsafe { ::std::mem::transmute(*self) }; - let iother: i32 = unsafe { ::std::mem::transmute(*other) }; + let iself: i32 = unsafe { mem::transmute(*self) }; + let iother: i32 = unsafe { mem::transmute(*other) }; (iself - iother).abs() < ulps as i32 } @@ -224,8 +223,8 @@ impl ApproxEq for f64 { // Otherwise, differing signs should be not-equal, even if within ulps if self.signum() != other.signum() { return false; } - let iself: i64 = unsafe { ::std::mem::transmute(*self) }; - let iother: i64 = unsafe { ::std::mem::transmute(*other) }; + let iself: i64 = unsafe { mem::transmute(*self) }; + let iother: i64 = unsafe { mem::transmute(*other) }; (iself - iother).abs() < ulps as i64 } diff --git a/src/traits/structure.rs b/src/traits/structure.rs index cc3ddea9..cf1a8295 100644 --- a/src/traits/structure.rs +++ b/src/traits/structure.rs @@ -211,7 +211,7 @@ pub trait Indexable: Shape + IndexMut { /// Traits of objects which can be iterated through like a vector. pub trait Iterable { /// Gets a vector-like read-only iterator. - fn iter<'l>(&'l self) -> Iter<'l, N>; + fn iter(&self) -> Iter; } /// This is a workaround of current Rust limitations. @@ -219,7 +219,7 @@ pub trait Iterable { /// Traits of mutable objects which can be iterated through like a vector. pub trait IterableMut { /// Gets a vector-like read-write iterator. - fn iter_mut<'l>(&'l mut self) -> IterMut<'l, N>; + fn iter_mut(&mut self) -> IterMut; } /* @@ -258,7 +258,7 @@ pub trait PointAsVector { fn to_vector(self) -> Self::Vector; /// Converts a reference to this point to a reference to its associated vector. - fn as_vector<'a>(&'a self) -> &'a Self::Vector; + fn as_vector(&self) -> &Self::Vector; // NOTE: this is used in some places to overcome some limitations untill the trait reform is // done on rustc.