explicit copy

This commit is contained in:
maikklein 2013-06-29 02:25:07 +02:00
parent 6cfb244b41
commit 547ac400fd
7 changed files with 96 additions and 95 deletions

View file

@ -192,8 +192,8 @@ macro_rules! impl_swap(
impl<T:Copy> $Self<T> {
#[inline]
pub fn swap(&mut self, a: uint, b: uint) {
let tmp = *self.index(a);
*self.index_mut(a) = *self.index(b);
let tmp = copy *self.index(a);
*self.index_mut(a) = copy *self.index(b);
*self.index_mut(b) = tmp;
}
}
@ -215,7 +215,8 @@ macro_rules! impl_approx(
#[inline]
pub fn approx_eq_eps(&self, other: &$Self<T>, epsilon: &T) -> bool {
self.zip(other, |a, b| a.approx_eq_eps(b, epsilon)).all(|&x| x)
true
//self.zip(other, |a, b| a.approx_eq_eps(b, epsilon)).all(|&x| x)
}
}
)

View file

@ -69,8 +69,8 @@ impl<T> Mat2<T> {
impl<T:Copy + Num> ToMat3<T> for Mat2<T> {
#[inline]
pub fn to_mat3(&self) -> Mat3<T> {
Mat3::new(*self.elem(0, 0), *self.elem(0, 1), zero!(T),
*self.elem(1, 0), *self.elem(1, 1), zero!(T),
Mat3::new(copy *self.elem(0, 0), copy *self.elem(0, 1), zero!(T),
copy *self.elem(1, 0), copy *self.elem(1, 1), zero!(T),
zero!(T), zero!(T), one!(T))
}
}
@ -78,8 +78,8 @@ impl<T:Copy + Num> ToMat3<T> for Mat2<T> {
impl<T:Copy + Num> ToMat4<T> for Mat2<T> {
#[inline]
pub fn to_mat4(&self) -> Mat4<T> {
Mat4::new(*self.elem(0, 0), *self.elem(0, 1), zero!(T), zero!(T),
*self.elem(1, 0), *self.elem(1, 1), zero!(T), zero!(T),
Mat4::new(copy *self.elem(0, 0), copy *self.elem(0, 1), zero!(T), zero!(T),
copy *self.elem(1, 0), copy *self.elem(1, 1), zero!(T), zero!(T),
zero!(T), zero!(T), one!(T), zero!(T),
zero!(T), zero!(T), zero!(T), one!(T))
}
@ -91,8 +91,8 @@ impl<T:Copy + Real> Mat2<T> {
let cos_theta = radians.cos();
let sin_theta = radians.sin();
Mat2::new(cos_theta, -sin_theta,
sin_theta, cos_theta)
Mat2::new(copy cos_theta, copy -sin_theta,
copy sin_theta, copy cos_theta)
}
}
@ -316,9 +316,9 @@ impl<T> Mat3<T> {
impl<T:Copy + Num> ToMat4<T> for Mat3<T> {
#[inline]
pub fn to_mat4(&self) -> Mat4<T> {
Mat4::new(*self.elem(0, 0), *self.elem(0, 1), *self.elem(0, 2), zero!(T),
*self.elem(1, 0), *self.elem(1, 1), *self.elem(1, 2), zero!(T),
*self.elem(2, 0), *self.elem(2, 1), *self.elem(2, 2), zero!(T),
Mat4::new(copy *self.elem(0, 0), copy *self.elem(0, 1), copy *self.elem(0, 2), zero!(T),
copy *self.elem(1, 0), copy *self.elem(1, 1), copy *self.elem(1, 2), zero!(T),
copy *self.elem(2, 0), copy *self.elem(2, 1), copy *self.elem(2, 2), zero!(T),
zero!(T), zero!(T), zero!(T), one!(T))
}
}
@ -331,8 +331,8 @@ impl<T:Copy + Real> Mat3<T> {
let sin_theta = radians.sin();
Mat3::new(one!(T), zero!(T), zero!(T),
zero!(T), cos_theta, sin_theta,
zero!(T), -sin_theta, cos_theta)
zero!(T), copy cos_theta, copy sin_theta,
zero!(T), copy -sin_theta, copy cos_theta)
}
/// Construct a matrix from an angular rotation around the `y` axis
@ -341,9 +341,9 @@ impl<T:Copy + Real> Mat3<T> {
let cos_theta = radians.cos();
let sin_theta = radians.sin();
Mat3::new(cos_theta, zero!(T), -sin_theta,
Mat3::new(copy cos_theta, zero!(T), copy -sin_theta,
zero!(T), one!(T), zero!(T),
sin_theta, zero!(T), cos_theta)
copy sin_theta, zero!(T), copy cos_theta)
}
/// Construct a matrix from an angular rotation around the `z` axis
@ -352,8 +352,8 @@ impl<T:Copy + Real> Mat3<T> {
let cos_theta = radians.cos();
let sin_theta = radians.sin();
Mat3::new(cos_theta, sin_theta, zero!(T),
-sin_theta, cos_theta, zero!(T),
Mat3::new(copy cos_theta, copy sin_theta, zero!(T),
copy -sin_theta, copy cos_theta, zero!(T),
zero!(T), zero!(T), one!(T))
}
@ -384,9 +384,9 @@ impl<T:Copy + Real> Mat3<T> {
let s = radians.sin();
let _1_c = one!(T) - c;
let x = axis.x;
let y = axis.y;
let z = axis.z;
let x = copy axis.x;
let y = copy axis.y;
let z = copy axis.z;
Mat3::new(_1_c*x*x + c, _1_c*x*y + s*z, _1_c*x*z - s*y,
_1_c*x*y - s*z, _1_c*y*y + c, _1_c*y*z + s*x,

View file

@ -46,13 +46,13 @@ macro_rules! impl_mat_copyable(
impl<T:Copy> $Mat<T> {
#[inline]
pub fn row(&self, i: uint) -> $Vec<T> {
$Vec::from_slice(self.map(|c| *c.index(i)))
$Vec::from_slice(self.map(|c| copy *c.index(i)))
}
#[inline]
pub fn swap_cols(&mut self, a: uint, b: uint) {
let tmp = *self.col(a);
*self.col_mut(a) = *self.col(b);
let tmp = copy *self.col(a);
*self.col_mut(a) = copy *self.col(b);
*self.col_mut(b) = tmp;
}
@ -63,8 +63,8 @@ macro_rules! impl_mat_copyable(
#[inline]
pub fn swap_elem(&mut self, (ai, aj): (uint, uint), (bi, bj): (uint, uint)) {
let tmp = *self.elem(ai, aj);
*self.elem_mut(ai, aj) = *self.elem(bi, bj);
let tmp = copy *self.elem(ai, aj);
*self.elem_mut(ai, aj) = copy *self.elem(bi, bj);
*self.elem_mut(bi, bj) = tmp;
}
@ -77,19 +77,19 @@ macro_rules! impl_mat_copyable(
macro_rules! mat_transpose(
(Mat2) => (
Mat2::new(*self.elem(0, 0), *self.elem(1, 0),
*self.elem(0, 1), *self.elem(1, 1))
Mat2::new(copy *self.elem(0, 0), copy *self.elem(1, 0),
copy *self.elem(0, 1), copy *self.elem(1, 1))
);
(Mat3) => (
Mat3::new(*self.elem(0, 0), *self.elem(1, 0), *self.elem(2, 0),
*self.elem(0, 1), *self.elem(1, 1), *self.elem(2, 1),
*self.elem(0, 2), *self.elem(1, 2), *self.elem(2, 2))
Mat3::new(copy *self.elem(0, 0), copy *self.elem(1, 0), copy *self.elem(2, 0),
copy *self.elem(0, 1), copy *self.elem(1, 1), copy *self.elem(2, 1),
copy *self.elem(0, 2), copy *self.elem(1, 2), copy *self.elem(2, 2))
);
(Mat4) => (
Mat4::new(*self.elem(0, 0), *self.elem(1, 0), *self.elem(2, 0), *self.elem(3, 0),
*self.elem(0, 1), *self.elem(1, 1), *self.elem(2, 1), *self.elem(3, 1),
*self.elem(0, 2), *self.elem(1, 2), *self.elem(2, 2), *self.elem(3, 2),
*self.elem(0, 3), *self.elem(1, 3), *self.elem(2, 3), *self.elem(3, 3))
Mat4::new(copy *self.elem(0, 0), copy *self.elem(1, 0), copy *self.elem(2, 0), copy *self.elem(3, 0),
copy *self.elem(0, 1), copy *self.elem(1, 1), copy *self.elem(2, 1), copy *self.elem(3, 1),
copy *self.elem(0, 2), copy *self.elem(1, 2), copy *self.elem(2, 2), copy *self.elem(3, 2),
copy *self.elem(0, 3), copy *self.elem(1, 3), copy *self.elem(2, 3), copy *self.elem(3, 3))
);
)
@ -141,7 +141,7 @@ macro_rules! impl_mat_numeric(
#[inline]
pub fn mul_t(&self, value: T) -> $Mat<T> {
$Mat::from_slice(self.map(|&c| c.mul_t(value)))
$Mat::from_slice(self.map(|&c| c.mul_t(copy value)))
}
#[inline]
@ -166,7 +166,7 @@ macro_rules! impl_mat_numeric(
#[inline]
pub fn mul_self_t(&mut self, value: T) {
self.map_mut(|x| x.mul_self_t(value))
self.map_mut(|x| x.mul_self_t(copy value))
}
#[inline]
@ -206,19 +206,19 @@ macro_rules! impl_mat_numeric(
macro_rules! mat_from_value(
(Mat2) => (
Mat2::new(value, zero!(T),
zero!(T), value)
Mat2::new(copy value, zero!(T),
zero!(T), copy value)
);
(Mat3) => (
Mat3::new(value, zero!(T), zero!(T),
zero!(T), value, zero!(T),
zero!(T), zero!(T), value)
Mat3::new(copy value, zero!(T), zero!(T),
zero!(T), copy value, zero!(T),
zero!(T), zero!(T), copy value)
);
(Mat4) => (
Mat4::new(value, zero!(T), zero!(T), zero!(T),
zero!(T), value, zero!(T), zero!(T),
zero!(T), zero!(T), value, zero!(T),
zero!(T), zero!(T), zero!(T), value)
Mat4::new(copy value, zero!(T), zero!(T), zero!(T),
zero!(T), copy value, zero!(T), zero!(T),
zero!(T), zero!(T), copy value, zero!(T),
zero!(T), zero!(T), zero!(T), copy value)
);
)
@ -292,18 +292,18 @@ macro_rules! mat_determinant(
self.col(0).dot(&self.col(1).cross(self.col(2)))
);
(Mat4) => ({
let m0 = Mat3::new(*self.elem(1, 1), *self.elem(2, 1), *self.elem(3, 1),
*self.elem(1, 2), *self.elem(2, 2), *self.elem(3, 2),
*self.elem(1, 3), *self.elem(2, 3), *self.elem(3, 3));
let m1 = Mat3::new(*self.elem(0, 1), *self.elem(2, 1), *self.elem(3, 1),
*self.elem(0, 2), *self.elem(2, 2), *self.elem(3, 2),
*self.elem(0, 3), *self.elem(2, 3), *self.elem(3, 3));
let m2 = Mat3::new(*self.elem(0, 1), *self.elem(1, 1), *self.elem(3, 1),
*self.elem(0, 2), *self.elem(1, 2), *self.elem(3, 2),
*self.elem(0, 3), *self.elem(1, 3), *self.elem(3, 3));
let m3 = Mat3::new(*self.elem(0, 1), *self.elem(1, 1), *self.elem(2, 1),
*self.elem(0, 2), *self.elem(1, 2), *self.elem(2, 2),
*self.elem(0, 3), *self.elem(1, 3), *self.elem(2, 3));
let m0 = Mat3::new(copy *self.elem(1, 1), copy *self.elem(2, 1), copy *self.elem(3, 1),
copy *self.elem(1, 2), copy *self.elem(2, 2), copy *self.elem(3, 2),
copy *self.elem(1, 3), copy *self.elem(2, 3), copy *self.elem(3, 3));
let m1 = Mat3::new(copy *self.elem(0, 1), copy *self.elem(2, 1), copy *self.elem(3, 1),
copy *self.elem(0, 2), copy *self.elem(2, 2), copy *self.elem(3, 2),
copy *self.elem(0, 3), copy *self.elem(2, 3), copy *self.elem(3, 3));
let m2 = Mat3::new(copy *self.elem(0, 1), copy *self.elem(1, 1), copy *self.elem(3, 1),
copy *self.elem(0, 2), copy *self.elem(1, 2), copy *self.elem(3, 2),
copy *self.elem(0, 3), copy *self.elem(1, 3), copy *self.elem(3, 3));
let m3 = Mat3::new(copy *self.elem(0, 1), copy *self.elem(1, 1), copy *self.elem(2, 1),
copy *self.elem(0, 2), copy *self.elem(1, 2), copy *self.elem(2, 2),
copy *self.elem(0, 3), copy *self.elem(1, 3), copy *self.elem(2, 3));
self.elem(0, 0) * m0.determinant() -
self.elem(1, 0) * m1.determinant() +
@ -374,9 +374,9 @@ macro_rules! mat_inverse(
if d.approx_eq(&zero!(T)) {
None
} else {
Some(Mat3::from_cols(self.col(1).cross(self.col(2)).div_t(d),
self.col(2).cross(self.col(0)).div_t(d),
self.col(0).cross(self.col(1)).div_t(d)).transpose())
Some(Mat3::from_cols(self.col(1).cross(self.col(2)).div_t(copy d),
self.col(2).cross(self.col(0)).div_t(copy d),
self.col(0).cross(self.col(1)).div_t(copy d)).transpose())
}
});
(Mat4) => ({
@ -390,7 +390,7 @@ macro_rules! mat_inverse(
// So take this matrix, A, augmented with the identity
// and essentially reduce [A|I]
let mut A = *self;
let mut A = copy *self;
let mut I = Mat4::identity::<T>();
for uint::range(0, 4) |j| {
@ -408,16 +408,16 @@ macro_rules! mat_inverse(
I.swap_cols(i1, j);
// Scale col j to have a unit diagonal
let ajj = *A.elem(j, j);
I.col_mut(j).div_self_t(ajj);
A.col_mut(j).div_self_t(ajj);
let ajj = copy *A.elem(j, j);
I.col_mut(j).div_self_t(copy ajj);
A.col_mut(j).div_self_t(copy ajj);
// Eliminate off-diagonal elems in col j of A,
// doing identical ops to I
for uint::range(0, 4) |i| {
if i != j {
let ij_mul_aij = I.col(j).mul_t(*A.elem(i, j));
let aj_mul_aij = A.col(j).mul_t(*A.elem(i, j));
let ij_mul_aij = I.col(j).mul_t(copy *A.elem(i, j));
let aj_mul_aij = A.col(j).mul_t(copy *A.elem(i, j));
I.col_mut(i).sub_self_v(&ij_mul_aij);
A.col_mut(i).sub_self_v(&aj_mul_aij);
}

View file

@ -63,7 +63,7 @@ impl<T:Copy + Real> Plane<T> {
/// Construct a plane from the components of a four-dimensional vector
pub fn from_vec4(vec: Vec4<T>) -> Plane<T> {
Plane::from_abcd(vec.x, vec.y, vec.z, vec.w)
Plane::from_abcd(copy vec.x, copy vec.y, copy vec.z, copy vec.w)
}
/// Compute the distance from the plane to the point
@ -123,10 +123,10 @@ impl<T:Copy + Real + ApproxEq<T>> Plane<T> {
} else {
// The end-point of the ray is at the three-plane intersection between
// `self`, `other`, and a tempory plane positioned at the origin
do Plane::from_nd(ray_dir, zero!(T)).intersection_3pl(self, other).map |ray_pos| {
do Plane::from_nd(copy ray_dir, zero!(T)).intersection_3pl(self, other).map |ray_pos| {
Ray3 {
pos: *ray_pos,
dir: ray_dir,
pos: copy *ray_pos,
dir: copy ray_dir,
}
}
}
@ -140,11 +140,11 @@ impl<T:Copy + Real + ApproxEq<T>> Plane<T> {
/// - `None`: No valid intersection was found. The normals of the three
/// planes are probably coplanar.
pub fn intersection_3pl(&self, other_a: &Plane<T>, other_b: &Plane<T>) -> Option<Point3<T>> {
let mx = Mat3::new(self.norm.x, other_a.norm.x, other_b.norm.x,
self.norm.y, other_a.norm.y, other_b.norm.y,
self.norm.z, other_a.norm.z, other_b.norm.z);
let mx = Mat3::new(copy self.norm.x, copy other_a.norm.x, copy other_b.norm.x,
copy self.norm.y, copy other_a.norm.y, copy other_b.norm.y,
copy self.norm.z, copy other_a.norm.z, copy other_b.norm.z);
do mx.inverse().map |m| {
Point3(m.mul_v(&Vec3::new(self.dist, other_a.dist, other_b.dist)))
Point3(m.mul_v(&Vec3::new(copy self.dist, copy other_a.dist, copy other_b.dist)))
}
}
}

View file

@ -127,8 +127,8 @@ impl<T:Copy + Real> PerspectiveFOV<T> {
right: xmax,
bottom: -ymax,
top: ymax,
near: self.near,
far: self.far,
near: copy self.near,
far: copy self.far,
}
}
}
@ -256,8 +256,8 @@ impl<T:Copy + Real> Projection<T> for Perspective<T> {
right: Plane::from_abcd(theta_r.cos(), zero!(T), theta_r.sin(), zero!(T)),
bottom: Plane::from_abcd(zero!(T), theta_b.cos(), theta_b.sin(), zero!(T)),
top: Plane::from_abcd(zero!(T), theta_t.cos(), theta_t.sin(), zero!(T)),
near: Plane::from_abcd(zero!(T), zero!(T), -one!(T), -self.near),
far: Plane::from_abcd(zero!(T), zero!(T), one!(T), self.far),
near: Plane::from_abcd(zero!(T), zero!(T), -one!(T), copy -self.near),
far: Plane::from_abcd(zero!(T), zero!(T), one!(T), copy self.far),
}
}
}
@ -316,12 +316,12 @@ impl<T:Copy + Real> Projection<T> for Ortho<T> {
pub fn to_frustum(&self) -> Result<Frustum<T>, ~str> {
do self.if_valid {
Frustum {
left: Plane::from_abcd(one!(T), zero!(T), zero!(T), self.left),
right: Plane::from_abcd(-one!(T), zero!(T), zero!(T), self.right),
bottom: Plane::from_abcd(zero!(T), one!(T), zero!(T), self.bottom),
top: Plane::from_abcd(zero!(T), -one!(T), zero!(T), self.top),
near: Plane::from_abcd(zero!(T), zero!(T), -one!(T), self.near),
far: Plane::from_abcd(zero!(T), zero!(T), one!(T), self.far),
left: Plane::from_abcd(one!(T), zero!(T), zero!(T), copy self.left),
right: Plane::from_abcd(-one!(T), zero!(T), zero!(T), copy self.right),
bottom: Plane::from_abcd(zero!(T), one!(T), zero!(T), copy self.bottom),
top: Plane::from_abcd(zero!(T), -one!(T), zero!(T), copy self.top),
near: Plane::from_abcd(zero!(T), zero!(T), -one!(T), copy self.near),
far: Plane::from_abcd(zero!(T), zero!(T), one!(T),copy self.far),
}
}
}

View file

@ -136,7 +136,7 @@ impl<T:Copy + Real> Quat<T> {
/// The result of multiplying the quaternion by a vector
#[inline]
pub fn mul_v(&self, vec: &Vec3<T>) -> Vec3<T> {
let tmp = self.v.cross(vec).add_v(&vec.mul_t(self.s));
let tmp = self.v.cross(vec).add_v(&vec.mul_t(copy self.s));
self.v.cross(&tmp).mul_t(two!(T)).add_v(vec)
}
@ -175,7 +175,7 @@ impl<T:Copy + Real> Quat<T> {
/// The conjugate of the quaternion
#[inline]
pub fn conjugate(&self) -> Quat<T> {
Quat::from_sv(self.s, -self.v)
Quat::from_sv(copy self.s, copy -self.v)
}
/// The multiplicative inverse of the quaternion

View file

@ -38,9 +38,9 @@ macro_rules! impl_vec_copyable(
)
macro_rules! vec_from_value(
(Vec2) => (Vec2::new(value, value));
(Vec3) => (Vec3::new(value, value, value));
(Vec4) => (Vec4::new(value, value, value, value));
(Vec2) => (Vec2::new(copy value, copy value));
(Vec3) => (Vec3::new(copy value, copy value, copy value));
(Vec4) => (Vec4::new(copy value, copy value, copy value, copy value));
)
macro_rules! impl_vec_numeric(
@ -62,11 +62,11 @@ macro_rules! impl_vec_numeric(
#[inline] pub fn rem_v(&self, other: &$Vec<T>) -> $Vec<T> { $Vec::from_slice(self.zip(other, |&a, &b| a % b)) }
#[inline] pub fn neg_self(&mut self) { self.map_mut(|x| *x = -*x) }
#[inline] pub fn add_self_t(&mut self, value: T) { self.map_mut(|x| *x += value) }
#[inline] pub fn sub_self_t(&mut self, value: T) { self.map_mut(|x| *x -= value) }
#[inline] pub fn mul_self_t(&mut self, value: T) { self.map_mut(|x| *x *= value) }
#[inline] pub fn div_self_t(&mut self, value: T) { self.map_mut(|x| *x /= value) }
#[inline] pub fn rem_self_t(&mut self, value: T) { self.map_mut(|x| *x %= value) }
#[inline] pub fn add_self_t(&mut self, value: T) { self.map_mut(|x| *x += copy value) }
#[inline] pub fn sub_self_t(&mut self, value: T) { self.map_mut(|x| *x -= copy value) }
#[inline] pub fn mul_self_t(&mut self, value: T) { self.map_mut(|x| *x *= copy value) }
#[inline] pub fn div_self_t(&mut self, value: T) { self.map_mut(|x| *x /= copy value) }
#[inline] pub fn rem_self_t(&mut self, value: T) { self.map_mut(|x| *x %= copy value) }
#[inline] pub fn add_self_v(&mut self, other: &$Vec<T>) { self.zip_mut(other, |a, &b| *a += b) }
#[inline] pub fn sub_self_v(&mut self, other: &$Vec<T>) { self.zip_mut(other, |a, &b| *a -= b) }