explicit copy
This commit is contained in:
parent
6cfb244b41
commit
547ac400fd
7 changed files with 96 additions and 95 deletions
|
@ -192,8 +192,8 @@ macro_rules! impl_swap(
|
||||||
impl<T:Copy> $Self<T> {
|
impl<T:Copy> $Self<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn swap(&mut self, a: uint, b: uint) {
|
pub fn swap(&mut self, a: uint, b: uint) {
|
||||||
let tmp = *self.index(a);
|
let tmp = copy *self.index(a);
|
||||||
*self.index_mut(a) = *self.index(b);
|
*self.index_mut(a) = copy *self.index(b);
|
||||||
*self.index_mut(b) = tmp;
|
*self.index_mut(b) = tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -215,7 +215,8 @@ macro_rules! impl_approx(
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn approx_eq_eps(&self, other: &$Self<T>, epsilon: &T) -> bool {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
36
src/mat.rs
36
src/mat.rs
|
@ -69,8 +69,8 @@ impl<T> Mat2<T> {
|
||||||
impl<T:Copy + Num> ToMat3<T> for Mat2<T> {
|
impl<T:Copy + Num> ToMat3<T> for Mat2<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_mat3(&self) -> Mat3<T> {
|
pub fn to_mat3(&self) -> Mat3<T> {
|
||||||
Mat3::new(*self.elem(0, 0), *self.elem(0, 1), zero!(T),
|
Mat3::new(copy *self.elem(0, 0), copy *self.elem(0, 1), zero!(T),
|
||||||
*self.elem(1, 0), *self.elem(1, 1), zero!(T),
|
copy *self.elem(1, 0), copy *self.elem(1, 1), zero!(T),
|
||||||
zero!(T), zero!(T), one!(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> {
|
impl<T:Copy + Num> ToMat4<T> for Mat2<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_mat4(&self) -> Mat4<T> {
|
pub fn to_mat4(&self) -> Mat4<T> {
|
||||||
Mat4::new(*self.elem(0, 0), *self.elem(0, 1), zero!(T), zero!(T),
|
Mat4::new(copy *self.elem(0, 0), copy *self.elem(0, 1), zero!(T), zero!(T),
|
||||||
*self.elem(1, 0), *self.elem(1, 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), one!(T), zero!(T),
|
||||||
zero!(T), zero!(T), zero!(T), one!(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 cos_theta = radians.cos();
|
||||||
let sin_theta = radians.sin();
|
let sin_theta = radians.sin();
|
||||||
|
|
||||||
Mat2::new(cos_theta, -sin_theta,
|
Mat2::new(copy cos_theta, copy -sin_theta,
|
||||||
sin_theta, cos_theta)
|
copy sin_theta, copy cos_theta)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,9 +316,9 @@ impl<T> Mat3<T> {
|
||||||
impl<T:Copy + Num> ToMat4<T> for Mat3<T> {
|
impl<T:Copy + Num> ToMat4<T> for Mat3<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_mat4(&self) -> Mat4<T> {
|
pub fn to_mat4(&self) -> Mat4<T> {
|
||||||
Mat4::new(*self.elem(0, 0), *self.elem(0, 1), *self.elem(0, 2), zero!(T),
|
Mat4::new(copy *self.elem(0, 0), copy *self.elem(0, 1), copy *self.elem(0, 2), zero!(T),
|
||||||
*self.elem(1, 0), *self.elem(1, 1), *self.elem(1, 2), zero!(T),
|
copy *self.elem(1, 0), copy *self.elem(1, 1), copy *self.elem(1, 2), zero!(T),
|
||||||
*self.elem(2, 0), *self.elem(2, 1), *self.elem(2, 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))
|
zero!(T), zero!(T), zero!(T), one!(T))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -331,8 +331,8 @@ impl<T:Copy + Real> Mat3<T> {
|
||||||
let sin_theta = radians.sin();
|
let sin_theta = radians.sin();
|
||||||
|
|
||||||
Mat3::new(one!(T), zero!(T), zero!(T),
|
Mat3::new(one!(T), zero!(T), zero!(T),
|
||||||
zero!(T), cos_theta, sin_theta,
|
zero!(T), copy cos_theta, copy sin_theta,
|
||||||
zero!(T), -sin_theta, cos_theta)
|
zero!(T), copy -sin_theta, copy cos_theta)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a matrix from an angular rotation around the `y` axis
|
/// 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 cos_theta = radians.cos();
|
||||||
let sin_theta = radians.sin();
|
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),
|
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
|
/// 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 cos_theta = radians.cos();
|
||||||
let sin_theta = radians.sin();
|
let sin_theta = radians.sin();
|
||||||
|
|
||||||
Mat3::new(cos_theta, sin_theta, zero!(T),
|
Mat3::new(copy cos_theta, copy sin_theta, zero!(T),
|
||||||
-sin_theta, cos_theta, zero!(T),
|
copy -sin_theta, copy cos_theta, zero!(T),
|
||||||
zero!(T), zero!(T), one!(T))
|
zero!(T), zero!(T), one!(T))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -384,9 +384,9 @@ impl<T:Copy + Real> Mat3<T> {
|
||||||
let s = radians.sin();
|
let s = radians.sin();
|
||||||
let _1_c = one!(T) - c;
|
let _1_c = one!(T) - c;
|
||||||
|
|
||||||
let x = axis.x;
|
let x = copy axis.x;
|
||||||
let y = axis.y;
|
let y = copy axis.y;
|
||||||
let z = axis.z;
|
let z = copy axis.z;
|
||||||
|
|
||||||
Mat3::new(_1_c*x*x + c, _1_c*x*y + s*z, _1_c*x*z - s*y,
|
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,
|
_1_c*x*y - s*z, _1_c*y*y + c, _1_c*y*z + s*x,
|
||||||
|
|
|
@ -46,13 +46,13 @@ macro_rules! impl_mat_copyable(
|
||||||
impl<T:Copy> $Mat<T> {
|
impl<T:Copy> $Mat<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn row(&self, i: uint) -> $Vec<T> {
|
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]
|
#[inline]
|
||||||
pub fn swap_cols(&mut self, a: uint, b: uint) {
|
pub fn swap_cols(&mut self, a: uint, b: uint) {
|
||||||
let tmp = *self.col(a);
|
let tmp = copy *self.col(a);
|
||||||
*self.col_mut(a) = *self.col(b);
|
*self.col_mut(a) = copy *self.col(b);
|
||||||
*self.col_mut(b) = tmp;
|
*self.col_mut(b) = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,8 +63,8 @@ macro_rules! impl_mat_copyable(
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn swap_elem(&mut self, (ai, aj): (uint, uint), (bi, bj): (uint, uint)) {
|
pub fn swap_elem(&mut self, (ai, aj): (uint, uint), (bi, bj): (uint, uint)) {
|
||||||
let tmp = *self.elem(ai, aj);
|
let tmp = copy *self.elem(ai, aj);
|
||||||
*self.elem_mut(ai, aj) = *self.elem(bi, bj);
|
*self.elem_mut(ai, aj) = copy *self.elem(bi, bj);
|
||||||
*self.elem_mut(bi, bj) = tmp;
|
*self.elem_mut(bi, bj) = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,19 +77,19 @@ macro_rules! impl_mat_copyable(
|
||||||
|
|
||||||
macro_rules! mat_transpose(
|
macro_rules! mat_transpose(
|
||||||
(Mat2) => (
|
(Mat2) => (
|
||||||
Mat2::new(*self.elem(0, 0), *self.elem(1, 0),
|
Mat2::new(copy *self.elem(0, 0), copy *self.elem(1, 0),
|
||||||
*self.elem(0, 1), *self.elem(1, 1))
|
copy *self.elem(0, 1), copy *self.elem(1, 1))
|
||||||
);
|
);
|
||||||
(Mat3) => (
|
(Mat3) => (
|
||||||
Mat3::new(*self.elem(0, 0), *self.elem(1, 0), *self.elem(2, 0),
|
Mat3::new(copy *self.elem(0, 0), copy *self.elem(1, 0), copy *self.elem(2, 0),
|
||||||
*self.elem(0, 1), *self.elem(1, 1), *self.elem(2, 1),
|
copy *self.elem(0, 1), copy *self.elem(1, 1), copy *self.elem(2, 1),
|
||||||
*self.elem(0, 2), *self.elem(1, 2), *self.elem(2, 2))
|
copy *self.elem(0, 2), copy *self.elem(1, 2), copy *self.elem(2, 2))
|
||||||
);
|
);
|
||||||
(Mat4) => (
|
(Mat4) => (
|
||||||
Mat4::new(*self.elem(0, 0), *self.elem(1, 0), *self.elem(2, 0), *self.elem(3, 0),
|
Mat4::new(copy *self.elem(0, 0), copy *self.elem(1, 0), copy *self.elem(2, 0), copy *self.elem(3, 0),
|
||||||
*self.elem(0, 1), *self.elem(1, 1), *self.elem(2, 1), *self.elem(3, 1),
|
copy *self.elem(0, 1), copy *self.elem(1, 1), copy *self.elem(2, 1), copy *self.elem(3, 1),
|
||||||
*self.elem(0, 2), *self.elem(1, 2), *self.elem(2, 2), *self.elem(3, 2),
|
copy *self.elem(0, 2), copy *self.elem(1, 2), copy *self.elem(2, 2), copy *self.elem(3, 2),
|
||||||
*self.elem(0, 3), *self.elem(1, 3), *self.elem(2, 3), *self.elem(3, 3))
|
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]
|
#[inline]
|
||||||
pub fn mul_t(&self, value: T) -> $Mat<T> {
|
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]
|
#[inline]
|
||||||
|
@ -166,7 +166,7 @@ macro_rules! impl_mat_numeric(
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn mul_self_t(&mut self, value: T) {
|
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]
|
#[inline]
|
||||||
|
@ -206,19 +206,19 @@ macro_rules! impl_mat_numeric(
|
||||||
|
|
||||||
macro_rules! mat_from_value(
|
macro_rules! mat_from_value(
|
||||||
(Mat2) => (
|
(Mat2) => (
|
||||||
Mat2::new(value, zero!(T),
|
Mat2::new(copy value, zero!(T),
|
||||||
zero!(T), value)
|
zero!(T), copy value)
|
||||||
);
|
);
|
||||||
(Mat3) => (
|
(Mat3) => (
|
||||||
Mat3::new(value, zero!(T), zero!(T),
|
Mat3::new(copy value, zero!(T), zero!(T),
|
||||||
zero!(T), value, zero!(T),
|
zero!(T), copy value, zero!(T),
|
||||||
zero!(T), zero!(T), value)
|
zero!(T), zero!(T), copy value)
|
||||||
);
|
);
|
||||||
(Mat4) => (
|
(Mat4) => (
|
||||||
Mat4::new(value, zero!(T), zero!(T), zero!(T),
|
Mat4::new(copy value, zero!(T), zero!(T), zero!(T),
|
||||||
zero!(T), value, zero!(T), zero!(T),
|
zero!(T), copy value, zero!(T), zero!(T),
|
||||||
zero!(T), zero!(T), value, zero!(T),
|
zero!(T), zero!(T), copy value, zero!(T),
|
||||||
zero!(T), zero!(T), zero!(T), value)
|
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)))
|
self.col(0).dot(&self.col(1).cross(self.col(2)))
|
||||||
);
|
);
|
||||||
(Mat4) => ({
|
(Mat4) => ({
|
||||||
let m0 = Mat3::new(*self.elem(1, 1), *self.elem(2, 1), *self.elem(3, 1),
|
let m0 = Mat3::new(copy *self.elem(1, 1), copy *self.elem(2, 1), copy *self.elem(3, 1),
|
||||||
*self.elem(1, 2), *self.elem(2, 2), *self.elem(3, 2),
|
copy *self.elem(1, 2), copy *self.elem(2, 2), copy *self.elem(3, 2),
|
||||||
*self.elem(1, 3), *self.elem(2, 3), *self.elem(3, 3));
|
copy *self.elem(1, 3), copy *self.elem(2, 3), copy *self.elem(3, 3));
|
||||||
let m1 = Mat3::new(*self.elem(0, 1), *self.elem(2, 1), *self.elem(3, 1),
|
let m1 = Mat3::new(copy *self.elem(0, 1), copy *self.elem(2, 1), copy *self.elem(3, 1),
|
||||||
*self.elem(0, 2), *self.elem(2, 2), *self.elem(3, 2),
|
copy *self.elem(0, 2), copy *self.elem(2, 2), copy *self.elem(3, 2),
|
||||||
*self.elem(0, 3), *self.elem(2, 3), *self.elem(3, 3));
|
copy *self.elem(0, 3), copy *self.elem(2, 3), copy *self.elem(3, 3));
|
||||||
let m2 = Mat3::new(*self.elem(0, 1), *self.elem(1, 1), *self.elem(3, 1),
|
let m2 = Mat3::new(copy *self.elem(0, 1), copy *self.elem(1, 1), copy *self.elem(3, 1),
|
||||||
*self.elem(0, 2), *self.elem(1, 2), *self.elem(3, 2),
|
copy *self.elem(0, 2), copy *self.elem(1, 2), copy *self.elem(3, 2),
|
||||||
*self.elem(0, 3), *self.elem(1, 3), *self.elem(3, 3));
|
copy *self.elem(0, 3), copy *self.elem(1, 3), copy *self.elem(3, 3));
|
||||||
let m3 = Mat3::new(*self.elem(0, 1), *self.elem(1, 1), *self.elem(2, 1),
|
let m3 = Mat3::new(copy *self.elem(0, 1), copy *self.elem(1, 1), copy *self.elem(2, 1),
|
||||||
*self.elem(0, 2), *self.elem(1, 2), *self.elem(2, 2),
|
copy *self.elem(0, 2), copy *self.elem(1, 2), copy *self.elem(2, 2),
|
||||||
*self.elem(0, 3), *self.elem(1, 3), *self.elem(2, 3));
|
copy *self.elem(0, 3), copy *self.elem(1, 3), copy *self.elem(2, 3));
|
||||||
|
|
||||||
self.elem(0, 0) * m0.determinant() -
|
self.elem(0, 0) * m0.determinant() -
|
||||||
self.elem(1, 0) * m1.determinant() +
|
self.elem(1, 0) * m1.determinant() +
|
||||||
|
@ -374,9 +374,9 @@ macro_rules! mat_inverse(
|
||||||
if d.approx_eq(&zero!(T)) {
|
if d.approx_eq(&zero!(T)) {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(Mat3::from_cols(self.col(1).cross(self.col(2)).div_t(d),
|
Some(Mat3::from_cols(self.col(1).cross(self.col(2)).div_t(copy d),
|
||||||
self.col(2).cross(self.col(0)).div_t(d),
|
self.col(2).cross(self.col(0)).div_t(copy d),
|
||||||
self.col(0).cross(self.col(1)).div_t(d)).transpose())
|
self.col(0).cross(self.col(1)).div_t(copy d)).transpose())
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
(Mat4) => ({
|
(Mat4) => ({
|
||||||
|
@ -390,7 +390,7 @@ macro_rules! mat_inverse(
|
||||||
// So take this matrix, A, augmented with the identity
|
// So take this matrix, A, augmented with the identity
|
||||||
// and essentially reduce [A|I]
|
// and essentially reduce [A|I]
|
||||||
|
|
||||||
let mut A = *self;
|
let mut A = copy *self;
|
||||||
let mut I = Mat4::identity::<T>();
|
let mut I = Mat4::identity::<T>();
|
||||||
|
|
||||||
for uint::range(0, 4) |j| {
|
for uint::range(0, 4) |j| {
|
||||||
|
@ -408,16 +408,16 @@ macro_rules! mat_inverse(
|
||||||
I.swap_cols(i1, j);
|
I.swap_cols(i1, j);
|
||||||
|
|
||||||
// Scale col j to have a unit diagonal
|
// Scale col j to have a unit diagonal
|
||||||
let ajj = *A.elem(j, j);
|
let ajj = copy *A.elem(j, j);
|
||||||
I.col_mut(j).div_self_t(ajj);
|
I.col_mut(j).div_self_t(copy ajj);
|
||||||
A.col_mut(j).div_self_t(ajj);
|
A.col_mut(j).div_self_t(copy ajj);
|
||||||
|
|
||||||
// Eliminate off-diagonal elems in col j of A,
|
// Eliminate off-diagonal elems in col j of A,
|
||||||
// doing identical ops to I
|
// doing identical ops to I
|
||||||
for uint::range(0, 4) |i| {
|
for uint::range(0, 4) |i| {
|
||||||
if i != j {
|
if i != j {
|
||||||
let ij_mul_aij = I.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(*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);
|
I.col_mut(i).sub_self_v(&ij_mul_aij);
|
||||||
A.col_mut(i).sub_self_v(&aj_mul_aij);
|
A.col_mut(i).sub_self_v(&aj_mul_aij);
|
||||||
}
|
}
|
||||||
|
|
16
src/plane.rs
16
src/plane.rs
|
@ -63,7 +63,7 @@ impl<T:Copy + Real> Plane<T> {
|
||||||
|
|
||||||
/// Construct a plane from the components of a four-dimensional vector
|
/// Construct a plane from the components of a four-dimensional vector
|
||||||
pub fn from_vec4(vec: Vec4<T>) -> Plane<T> {
|
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
|
/// Compute the distance from the plane to the point
|
||||||
|
@ -123,10 +123,10 @@ impl<T:Copy + Real + ApproxEq<T>> Plane<T> {
|
||||||
} else {
|
} else {
|
||||||
// The end-point of the ray is at the three-plane intersection between
|
// The end-point of the ray is at the three-plane intersection between
|
||||||
// `self`, `other`, and a tempory plane positioned at the origin
|
// `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 {
|
Ray3 {
|
||||||
pos: *ray_pos,
|
pos: copy *ray_pos,
|
||||||
dir: ray_dir,
|
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
|
/// - `None`: No valid intersection was found. The normals of the three
|
||||||
/// planes are probably coplanar.
|
/// planes are probably coplanar.
|
||||||
pub fn intersection_3pl(&self, other_a: &Plane<T>, other_b: &Plane<T>) -> Option<Point3<T>> {
|
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,
|
let mx = Mat3::new(copy self.norm.x, copy other_a.norm.x, copy other_b.norm.x,
|
||||||
self.norm.y, other_a.norm.y, other_b.norm.y,
|
copy self.norm.y, copy other_a.norm.y, copy other_b.norm.y,
|
||||||
self.norm.z, other_a.norm.z, other_b.norm.z);
|
copy self.norm.z, copy other_a.norm.z, copy other_b.norm.z);
|
||||||
do mx.inverse().map |m| {
|
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)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,8 +127,8 @@ impl<T:Copy + Real> PerspectiveFOV<T> {
|
||||||
right: xmax,
|
right: xmax,
|
||||||
bottom: -ymax,
|
bottom: -ymax,
|
||||||
top: ymax,
|
top: ymax,
|
||||||
near: self.near,
|
near: copy self.near,
|
||||||
far: self.far,
|
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)),
|
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)),
|
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)),
|
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),
|
near: Plane::from_abcd(zero!(T), zero!(T), -one!(T), copy -self.near),
|
||||||
far: Plane::from_abcd(zero!(T), zero!(T), one!(T), self.far),
|
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> {
|
pub fn to_frustum(&self) -> Result<Frustum<T>, ~str> {
|
||||||
do self.if_valid {
|
do self.if_valid {
|
||||||
Frustum {
|
Frustum {
|
||||||
left: Plane::from_abcd(one!(T), zero!(T), zero!(T), self.left),
|
left: Plane::from_abcd(one!(T), zero!(T), zero!(T), copy self.left),
|
||||||
right: Plane::from_abcd(-one!(T), zero!(T), zero!(T), self.right),
|
right: Plane::from_abcd(-one!(T), zero!(T), zero!(T), copy self.right),
|
||||||
bottom: Plane::from_abcd(zero!(T), one!(T), zero!(T), self.bottom),
|
bottom: Plane::from_abcd(zero!(T), one!(T), zero!(T), copy self.bottom),
|
||||||
top: Plane::from_abcd(zero!(T), -one!(T), zero!(T), self.top),
|
top: Plane::from_abcd(zero!(T), -one!(T), zero!(T), copy self.top),
|
||||||
near: Plane::from_abcd(zero!(T), zero!(T), -one!(T), self.near),
|
near: Plane::from_abcd(zero!(T), zero!(T), -one!(T), copy self.near),
|
||||||
far: Plane::from_abcd(zero!(T), zero!(T), one!(T), self.far),
|
far: Plane::from_abcd(zero!(T), zero!(T), one!(T),copy self.far),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,7 +136,7 @@ impl<T:Copy + Real> Quat<T> {
|
||||||
/// The result of multiplying the quaternion by a vector
|
/// The result of multiplying the quaternion by a vector
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn mul_v(&self, vec: &Vec3<T>) -> Vec3<T> {
|
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)
|
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
|
/// The conjugate of the quaternion
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn conjugate(&self) -> Quat<T> {
|
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
|
/// The multiplicative inverse of the quaternion
|
||||||
|
|
|
@ -38,9 +38,9 @@ macro_rules! impl_vec_copyable(
|
||||||
)
|
)
|
||||||
|
|
||||||
macro_rules! vec_from_value(
|
macro_rules! vec_from_value(
|
||||||
(Vec2) => (Vec2::new(value, value));
|
(Vec2) => (Vec2::new(copy value, copy value));
|
||||||
(Vec3) => (Vec3::new(value, value, value));
|
(Vec3) => (Vec3::new(copy value, copy value, copy value));
|
||||||
(Vec4) => (Vec4::new(value, value, value, value));
|
(Vec4) => (Vec4::new(copy value, copy value, copy value, copy value));
|
||||||
)
|
)
|
||||||
|
|
||||||
macro_rules! impl_vec_numeric(
|
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 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 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 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 -= 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 *= 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 /= 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 %= 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 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) }
|
#[inline] pub fn sub_self_v(&mut self, other: &$Vec<T>) { self.zip_mut(other, |a, &b| *a -= b) }
|
||||||
|
|
Loading…
Reference in a new issue