Update to work with the last compiler.
Because of the unfortunate changes on type parameters resolution: - the Dim trait now needs an useless parameter to infer the Self type. - ApproxEps::epsilon() is broken.
This commit is contained in:
parent
f465928085
commit
82ddda154f
|
@ -54,7 +54,7 @@ impl<N: Clone + Trigonometric + Num + Algebraic> Rotmat<Mat3<N>> {
|
||||||
else {
|
else {
|
||||||
let mut axis = axisangle;
|
let mut axis = axisangle;
|
||||||
let angle = axis.normalize();
|
let angle = axis.normalize();
|
||||||
let _1 = One::one::<N>();
|
let _1: N = One::one();
|
||||||
let ux = axis.x.clone();
|
let ux = axis.x.clone();
|
||||||
let uy = axis.y.clone();
|
let uy = axis.y.clone();
|
||||||
let uz = axis.z.clone();
|
let uz = axis.z.clone();
|
||||||
|
@ -208,8 +208,9 @@ Rand for Rotmat<Mat3<N>> {
|
||||||
|
|
||||||
impl<M: Dim> Dim for Rotmat<M> {
|
impl<M: Dim> Dim for Rotmat<M> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn dim() -> uint {
|
fn dim(_: Option<Rotmat<M>>) -> uint {
|
||||||
Dim::dim::<M>()
|
let _dim: Option<M> = None;
|
||||||
|
Dim::dim(_dim)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,7 +279,8 @@ impl<M: ToHomogeneous<M2>, M2> ToHomogeneous<M2> for Rotmat<M> {
|
||||||
impl<N: ApproxEq<N>, M: ApproxEq<N>> ApproxEq<N> for Rotmat<M> {
|
impl<N: ApproxEq<N>, M: ApproxEq<N>> ApproxEq<N> for Rotmat<M> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn approx_epsilon() -> N {
|
fn approx_epsilon() -> N {
|
||||||
ApproxEq::approx_epsilon::<N, N>()
|
// ApproxEq::<N>::approx_epsilon()
|
||||||
|
fail!("approx_epsilon is broken since rust revision 8693943676487c01fa09f5f3daf0df6a1f71e24d.")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -85,8 +85,9 @@ impl<N: Clone + Num + Algebraic> Transform<Rotmat<Mat3<N>>, Vec3<N>> {
|
||||||
|
|
||||||
impl<M: Dim, V> Dim for Transform<M, V> {
|
impl<M: Dim, V> Dim for Transform<M, V> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn dim() -> uint {
|
fn dim(_: Option<Transform<M, V>>) -> uint {
|
||||||
Dim::dim::<M>()
|
let _dim: Option<M> = None;
|
||||||
|
Dim::dim(_dim)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,7 +189,7 @@ Rotation<AV> for Transform<M, V> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rotate_by(&mut self, rot: &AV) {
|
fn rotate_by(&mut self, rot: &AV) {
|
||||||
// FIXME: this does not seem opitmal
|
// FIXME: this does not seem opitmal
|
||||||
let mut delta = One::one::<M>();
|
let mut delta: M = One::one();
|
||||||
delta.rotate_by(rot);
|
delta.rotate_by(rot);
|
||||||
self.submat.rotate_by(rot);
|
self.submat.rotate_by(rot);
|
||||||
self.subtrans = delta.rmul(&self.subtrans);
|
self.subtrans = delta.rmul(&self.subtrans);
|
||||||
|
@ -197,7 +198,8 @@ Rotation<AV> for Transform<M, V> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rotated(&self, rot: &AV) -> Transform<M, V> {
|
fn rotated(&self, rot: &AV) -> Transform<M, V> {
|
||||||
// FIXME: this does not seem opitmal
|
// FIXME: this does not seem opitmal
|
||||||
let delta = One::one::<M>().rotated(rot);
|
let _1: M = One::one();
|
||||||
|
let delta = _1.rotated(rot);
|
||||||
|
|
||||||
Transform::new(self.submat.rotated(rot), delta.rmul(&self.subtrans))
|
Transform::new(self.submat.rotated(rot), delta.rmul(&self.subtrans))
|
||||||
}
|
}
|
||||||
|
@ -283,7 +285,8 @@ ToHomogeneous<M2> for Transform<M, V> {
|
||||||
let mut res = self.submat.to_homogeneous();
|
let mut res = self.submat.to_homogeneous();
|
||||||
|
|
||||||
// copy the translation
|
// copy the translation
|
||||||
let dim = Dim::dim::<M2>();
|
let _dim: Option<M2> = None;
|
||||||
|
let dim = Dim::dim(_dim);
|
||||||
|
|
||||||
res.set_column(dim - 1, self.subtrans.to_homogeneous());
|
res.set_column(dim - 1, self.subtrans.to_homogeneous());
|
||||||
|
|
||||||
|
@ -294,7 +297,8 @@ ToHomogeneous<M2> for Transform<M, V> {
|
||||||
impl<M: Column<V> + Dim, M2: FromHomogeneous<M>, V>
|
impl<M: Column<V> + Dim, M2: FromHomogeneous<M>, V>
|
||||||
FromHomogeneous<M> for Transform<M2, V> {
|
FromHomogeneous<M> for Transform<M2, V> {
|
||||||
fn from(m: &M) -> Transform<M2, V> {
|
fn from(m: &M) -> Transform<M2, V> {
|
||||||
Transform::new(FromHomogeneous::from(m), m.column(Dim::dim::<M>() - 1))
|
let _dim: Option<M> = None;
|
||||||
|
Transform::new(FromHomogeneous::from(m), m.column(Dim::dim(_dim) - 1))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,7 +306,8 @@ impl<N: ApproxEq<N>, M:ApproxEq<N>, V:ApproxEq<N>>
|
||||||
ApproxEq<N> for Transform<M, V> {
|
ApproxEq<N> for Transform<M, V> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn approx_epsilon() -> N {
|
fn approx_epsilon() -> N {
|
||||||
ApproxEq::approx_epsilon::<N, N>()
|
fail!("approx_epsilon is broken since rust revision 8693943676487c01fa09f5f3daf0df6a1f71e24d.")
|
||||||
|
// ApproxEq::<N>::approx_epsilon()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
11
src/dmat.rs
11
src/dmat.rs
|
@ -37,7 +37,7 @@ pub fn is_zero_mat<N: Zero>(mat: &DMat<N>) -> bool {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn one_mat_with_dim<N: Clone + One + Zero>(dim: uint) -> DMat<N> {
|
pub fn one_mat_with_dim<N: Clone + One + Zero>(dim: uint) -> DMat<N> {
|
||||||
let mut res = zero_mat_with_dim(dim);
|
let mut res = zero_mat_with_dim(dim);
|
||||||
let _1 = One::one::<N>();
|
let _1: N = One::one();
|
||||||
|
|
||||||
for i in range(0u, dim) {
|
for i in range(0u, dim) {
|
||||||
res.set(i, i, &_1);
|
res.set(i, i, &_1);
|
||||||
|
@ -94,7 +94,7 @@ Mul<DMat<N>, DMat<N>> for DMat<N> {
|
||||||
|
|
||||||
for i in range(0u, dim) {
|
for i in range(0u, dim) {
|
||||||
for j in range(0u, dim) {
|
for j in range(0u, dim) {
|
||||||
let mut acc = Zero::zero::<N>();
|
let mut acc: N = Zero::zero();
|
||||||
|
|
||||||
for k in range(0u, dim) {
|
for k in range(0u, dim) {
|
||||||
acc = acc + self.at(i, k) * other.at(k, j);
|
acc = acc + self.at(i, k) * other.at(k, j);
|
||||||
|
@ -161,7 +161,7 @@ Inv for DMat<N> {
|
||||||
fn inplace_inverse(&mut self) -> bool {
|
fn inplace_inverse(&mut self) -> bool {
|
||||||
let dim = self.dim;
|
let dim = self.dim;
|
||||||
let mut res = one_mat_with_dim::<N>(dim);
|
let mut res = one_mat_with_dim::<N>(dim);
|
||||||
let _0T = Zero::zero::<N>();
|
let _0T: N = Zero::zero();
|
||||||
|
|
||||||
// inversion using Gauss-Jordan elimination
|
// inversion using Gauss-Jordan elimination
|
||||||
for k in range(0u, dim) {
|
for k in range(0u, dim) {
|
||||||
|
@ -256,7 +256,10 @@ impl<N: Clone> Transpose for DMat<N> {
|
||||||
impl<N: ApproxEq<N>> ApproxEq<N> for DMat<N> {
|
impl<N: ApproxEq<N>> ApproxEq<N> for DMat<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn approx_epsilon() -> N {
|
fn approx_epsilon() -> N {
|
||||||
ApproxEq::approx_epsilon::<N, N>()
|
fail!("Fix this.")
|
||||||
|
// let res: N = ApproxEq::<N>::approx_epsilon();
|
||||||
|
|
||||||
|
// res
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
11
src/dvec.rs
11
src/dvec.rs
|
@ -21,7 +21,7 @@ pub struct DVec<N> {
|
||||||
/// * `dim` - The dimension of the vector.
|
/// * `dim` - The dimension of the vector.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn zero_vec_with_dim<N: Zero + Clone>(dim: uint) -> DVec<N> {
|
pub fn zero_vec_with_dim<N: Zero + Clone>(dim: uint) -> DVec<N> {
|
||||||
DVec { at: from_elem(dim, Zero::zero::<N>()) }
|
DVec { at: from_elem(dim, Zero::zero()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tests if all components of the vector are zeroes.
|
/// Tests if all components of the vector are zeroes.
|
||||||
|
@ -140,7 +140,7 @@ impl<N: Num> DVec<N> {
|
||||||
fn dot(&self, other: &DVec<N>) -> N {
|
fn dot(&self, other: &DVec<N>) -> N {
|
||||||
assert!(self.at.len() == other.at.len());
|
assert!(self.at.len() == other.at.len());
|
||||||
|
|
||||||
let mut res = Zero::zero::<N>();
|
let mut res: N = Zero::zero();
|
||||||
|
|
||||||
for i in range(0u, self.at.len()) {
|
for i in range(0u, self.at.len()) {
|
||||||
res = res + self.at[i] * other.at[i];
|
res = res + self.at[i] * other.at[i];
|
||||||
|
@ -151,7 +151,7 @@ impl<N: Num> DVec<N> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sub_dot(&self, a: &DVec<N>, b: &DVec<N>) -> N {
|
fn sub_dot(&self, a: &DVec<N>, b: &DVec<N>) -> N {
|
||||||
let mut res = Zero::zero::<N>();
|
let mut res: N = Zero::zero();
|
||||||
|
|
||||||
for i in range(0u, self.at.len()) {
|
for i in range(0u, self.at.len()) {
|
||||||
res = res + (self.at[i] - a.at[i]) * b.at[i];
|
res = res + (self.at[i] - a.at[i]) * b.at[i];
|
||||||
|
@ -261,7 +261,10 @@ impl<N: Num + Algebraic + Clone> DVec<N> {
|
||||||
impl<N: ApproxEq<N>> ApproxEq<N> for DVec<N> {
|
impl<N: ApproxEq<N>> ApproxEq<N> for DVec<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn approx_epsilon() -> N {
|
fn approx_epsilon() -> N {
|
||||||
ApproxEq::approx_epsilon::<N, N>()
|
fail!("Fix me.")
|
||||||
|
// let res: N = ApproxEq::<N>::approx_epsilon();
|
||||||
|
|
||||||
|
// res
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -136,7 +136,7 @@ macro_rules! one_impl(
|
||||||
impl<N: Clone + One + Zero> One for $t<N> {
|
impl<N: Clone + One + Zero> One for $t<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn one() -> $t<N> {
|
fn one() -> $t<N> {
|
||||||
let (_0, _1) = (Zero::zero::<N>(), One::one::<N>());
|
let (_0, _1): (N, N) = (Zero::zero(), One::one());
|
||||||
return $t::new($value0.clone() $(, $valueN.clone() )*)
|
return $t::new($value0.clone() $(, $valueN.clone() )*)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@ macro_rules! dim_impl(
|
||||||
($t: ident, $dim: expr) => (
|
($t: ident, $dim: expr) => (
|
||||||
impl<N> Dim for $t<N> {
|
impl<N> Dim for $t<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn dim() -> uint {
|
fn dim(_: Option<$t<N>>) -> uint {
|
||||||
$dim
|
$dim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -194,7 +194,7 @@ macro_rules! column_impl(
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn column(&self, col: uint) -> $tv<N> {
|
fn column(&self, col: uint) -> $tv<N> {
|
||||||
let mut res = Zero::zero::<$tv<N>>();
|
let mut res: $tv<N> = Zero::zero();
|
||||||
|
|
||||||
for (i, e) in res.mut_iter().enumerate() {
|
for (i, e) in res.mut_iter().enumerate() {
|
||||||
*e = self.at((i, col));
|
*e = self.at((i, col));
|
||||||
|
@ -218,7 +218,7 @@ macro_rules! row_impl(
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn row(&self, row: uint) -> $tv<N> {
|
fn row(&self, row: uint) -> $tv<N> {
|
||||||
let mut res = Zero::zero::<$tv<N>>();
|
let mut res: $tv<N> = Zero::zero();
|
||||||
|
|
||||||
for (i, e) in res.mut_iter().enumerate() {
|
for (i, e) in res.mut_iter().enumerate() {
|
||||||
*e = self.at((row, i));
|
*e = self.at((row, i));
|
||||||
|
@ -239,7 +239,7 @@ macro_rules! mul_impl(
|
||||||
|
|
||||||
for i in range(0u, $dim) {
|
for i in range(0u, $dim) {
|
||||||
for j in range(0u, $dim) {
|
for j in range(0u, $dim) {
|
||||||
let mut acc = Zero::zero::<N>();
|
let mut acc: N = Zero::zero();
|
||||||
|
|
||||||
for k in range(0u, $dim) {
|
for k in range(0u, $dim) {
|
||||||
acc = acc + self.at((i, k)) * other.at((k, j));
|
acc = acc + self.at((i, k)) * other.at((k, j));
|
||||||
|
@ -429,7 +429,8 @@ macro_rules! approx_eq_impl(
|
||||||
impl<N: ApproxEq<N>> ApproxEq<N> for $t<N> {
|
impl<N: ApproxEq<N>> ApproxEq<N> for $t<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn approx_epsilon() -> N {
|
fn approx_epsilon() -> N {
|
||||||
ApproxEq::approx_epsilon::<N, N>()
|
fail!("approx_epsilon is broken since rust revision 8693943676487c01fa09f5f3daf0df6a1f71e24d.")
|
||||||
|
// ApproxEq::<N>::approx_epsilon()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -499,10 +500,12 @@ macro_rules! outer_impl(
|
||||||
impl<N: Mul<N, N> + Zero + Clone> Outer<$t<N>, $m<N>> for $t<N> {
|
impl<N: Mul<N, N> + Zero + Clone> Outer<$t<N>, $m<N>> for $t<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn outer(&self, other: &$t<N>) -> $m<N> {
|
fn outer(&self, other: &$t<N>) -> $m<N> {
|
||||||
let mut res = Zero::zero::<$m<N>>();
|
let mut res: $m<N> = Zero::zero();
|
||||||
|
|
||||||
for i in range(0u, Dim::dim::<$t<N>>()) {
|
let _dim: Option<$t<N>> = None;
|
||||||
for j in range(0u, Dim::dim::<$t<N>>()) {
|
for i in range(0u, Dim::dim(_dim)) {
|
||||||
|
let _dim: Option<$t<N>> = None;
|
||||||
|
for j in range(0u, Dim::dim(_dim)) {
|
||||||
res.set((i, j), self.at(i) * other.at(j))
|
res.set((i, j), self.at(i) * other.at(j))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,8 @@ Inv for Mat1<N> {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
self.m11 = One::one::<N>() / self.m11;
|
let _1: N = One::one();
|
||||||
|
self.m11 = _1 / self.m11;
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,7 +104,7 @@ fn test_inv_mat6() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rotation2() {
|
fn test_rotation2() {
|
||||||
do 10000.times {
|
do 10000.times {
|
||||||
let randmat = One::one::<Rotmat<Mat2<f64>>>();
|
let randmat: Rotmat<Mat2<f64>> = One::one();
|
||||||
let ang = &Vec1::new(abs::<f64>(random()) % Real::pi());
|
let ang = &Vec1::new(abs::<f64>(random()) % Real::pi());
|
||||||
|
|
||||||
assert!(randmat.rotated(ang).rotation().approx_eq(ang));
|
assert!(randmat.rotated(ang).rotation().approx_eq(ang));
|
||||||
|
@ -121,7 +121,7 @@ fn test_index_mat2() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_inv_rotation3() {
|
fn test_inv_rotation3() {
|
||||||
do 10000.times {
|
do 10000.times {
|
||||||
let randmat = One::one::<Rotmat<Mat3<f64>>>();
|
let randmat: Rotmat<Mat3<f64>> = One::one();
|
||||||
let dir: Vec3<f64> = random();
|
let dir: Vec3<f64> = random();
|
||||||
let ang = &(dir.normalized() * (abs::<f64>(random()) % Real::pi()));
|
let ang = &(dir.normalized() * (abs::<f64>(random()) % Real::pi()));
|
||||||
let rot = randmat.rotated(ang);
|
let rot = randmat.rotated(ang);
|
||||||
|
|
|
@ -76,8 +76,8 @@ macro_rules! test_scalar_op_impl(
|
||||||
macro_rules! test_basis_impl(
|
macro_rules! test_basis_impl(
|
||||||
($t: ty) => (
|
($t: ty) => (
|
||||||
do 10000.times {
|
do 10000.times {
|
||||||
do Basis::canonical_basis::<$t> |e1| {
|
do Basis::canonical_basis |e1: $t| {
|
||||||
do Basis::canonical_basis::<$t> |e2| {
|
do Basis::canonical_basis |e2: $t| {
|
||||||
assert!(e1 == e2 || e1.dot(&e2).approx_eq(&Zero::zero()));
|
assert!(e1 == e2 || e1.dot(&e2).approx_eq(&Zero::zero()));
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|
|
@ -11,7 +11,7 @@ pub trait Basis {
|
||||||
fn canonical_basis_list() -> ~[Self] {
|
fn canonical_basis_list() -> ~[Self] {
|
||||||
let mut res = ~[];
|
let mut res = ~[];
|
||||||
|
|
||||||
do Basis::canonical_basis::<Self> |elem| {
|
do Basis::canonical_basis |elem| {
|
||||||
res.push(elem);
|
res.push(elem);
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|
|
@ -3,5 +3,5 @@
|
||||||
*/
|
*/
|
||||||
pub trait Dim {
|
pub trait Dim {
|
||||||
/// The dimension of the object.
|
/// The dimension of the object.
|
||||||
fn dim() -> uint;
|
fn dim(unused_self: Option<Self>) -> uint;
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ impl<N> IterableMut<N> for vec::Vec0<N> {
|
||||||
|
|
||||||
impl<N> Dim for vec::Vec0<N> {
|
impl<N> Dim for vec::Vec0<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn dim() -> uint {
|
fn dim(_: Option<vec::Vec0<N>>) -> uint {
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,8 @@ impl<N: Clone + Num + Algebraic> AlgebraicVec<N> for vec::Vec0<N> {
|
||||||
impl<N: ApproxEq<N>> ApproxEq<N> for vec::Vec0<N> {
|
impl<N: ApproxEq<N>> ApproxEq<N> for vec::Vec0<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn approx_epsilon() -> N {
|
fn approx_epsilon() -> N {
|
||||||
ApproxEq::approx_epsilon::<N, N>()
|
fail!("approx_epsilon is broken since rust revision 8693943676487c01fa09f5f3daf0df6a1f71e24d.")
|
||||||
|
// ApproxEq::<N>::approx_epsilon()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -174,7 +174,7 @@ macro_rules! dim_impl(
|
||||||
($t: ident, $dim: expr) => (
|
($t: ident, $dim: expr) => (
|
||||||
impl<N> Dim for $t<N> {
|
impl<N> Dim for $t<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn dim() -> uint {
|
fn dim(_: Option<$t<N>>) -> uint {
|
||||||
$dim
|
$dim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -427,7 +427,8 @@ macro_rules! approx_eq_impl(
|
||||||
impl<N: ApproxEq<N>> ApproxEq<N> for $t<N> {
|
impl<N: ApproxEq<N>> ApproxEq<N> for $t<N> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn approx_epsilon() -> N {
|
fn approx_epsilon() -> N {
|
||||||
ApproxEq::approx_epsilon::<N, N>()
|
fail!("approx_epsilon is broken since rust revision 8693943676487c01fa09f5f3daf0df6a1f71e24d.")
|
||||||
|
// ApproxEq::<N>::approx_epsilon()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
Loading…
Reference in New Issue