Functions to build objects dont shadow constructors any more.

This commit is contained in:
Sébastien Crozet 2013-05-18 20:03:45 +00:00
parent 01d37a1b56
commit ceed733e25
8 changed files with 72 additions and 72 deletions

View File

@ -6,9 +6,9 @@ use traits::workarounds::trigonometric::Trigonometric;
use traits::dim::Dim;
use traits::inv::Inv;
use traits::transpose::Transpose;
use dim2::mat2::Mat2;
use dim3::mat3::Mat3;
use dim3::vec3::Vec3;
use dim2::mat2::{Mat2, mat2};
use dim3::mat3::{Mat3, mat3};
use dim3::vec3::{Vec3};
// FIXME: use a newtype here?
#[deriving(Eq)]
@ -17,16 +17,16 @@ pub struct Rotmat<M>
priv submat: M
}
pub fn Rotmat2<T: Copy + Trigonometric + Neg<T>>(angle: T) -> Rotmat<Mat2<T>>
pub fn rotmat2<T: Copy + Trigonometric + Neg<T>>(angle: T) -> Rotmat<Mat2<T>>
{
let coa = Trigonometric::cos(angle);
let sia = Trigonometric::sin(angle);
Rotmat
{ submat: Mat2(coa, -sia, sia, coa) }
{ submat: mat2(coa, -sia, sia, coa) }
}
pub fn Rotmat3<T: Copy + Trigonometric + Neg<T> + One + Sub<T, T> + Add<T, T> +
pub fn rotmat3<T: Copy + Trigonometric + Neg<T> + One + Sub<T, T> + Add<T, T> +
Mul<T, T>>
(axis: &Vec3<T>, angle: T) -> Rotmat<Mat3<T>>
{
@ -42,7 +42,7 @@ pub fn Rotmat3<T: Copy + Trigonometric + Neg<T> + One + Sub<T, T> + Add<T, T> +
let sin = Trigonometric::sin(angle);
Rotmat {
submat: Mat3(
submat: mat3(
(sqx + (_1 - sqx) * cos),
(ux * uy * one_m_cos - uz * sin),
(ux * uz * one_m_cos + uy * sin),
@ -60,7 +60,7 @@ pub fn Rotmat3<T: Copy + Trigonometric + Neg<T> + One + Sub<T, T> + Add<T, T> +
impl<T:Copy + Rand + Trigonometric + Neg<T>> Rand for Rotmat<Mat2<T>>
{
fn rand<R: Rng>(rng: &R) -> Rotmat<Mat2<T>>
{ Rotmat2(rng.gen()) }
{ rotmat2(rng.gen()) }
}
impl<T:Copy + Rand + Trigonometric + Neg<T> + One + Sub<T, T> + Add<T, T> +
@ -68,7 +68,7 @@ impl<T:Copy + Rand + Trigonometric + Neg<T> + One + Sub<T, T> + Add<T, T> +
Rand for Rotmat<Mat3<T>>
{
fn rand<R: Rng>(rng: &R) -> Rotmat<Mat3<T>>
{ Rotmat3(&rng.gen(), rng.gen()) }
{ rotmat3(&rng.gen(), rng.gen()) }
}
impl<M: Dim> Dim for Rotmat<M>

View File

@ -12,7 +12,7 @@ pub struct Transform<M, V>
subtrans : V
}
pub fn Transform<M: Copy, V: Copy>(mat: &M, trans: &V) -> Transform<M, V>
pub fn transform<M: Copy, V: Copy>(mat: &M, trans: &V) -> Transform<M, V>
{ Transform { submat: *mat, subtrans: *trans } }
impl<M:Dim, V> Dim for Transform<M, V>
@ -95,7 +95,7 @@ impl<T, M:FuzzyEq<T>, V:FuzzyEq<T>> FuzzyEq<T> for Transform<M, V>
impl<M: Rand + Copy, V: Rand + Copy> Rand for Transform<M, V>
{
fn rand<R: Rng>(rng: &R) -> Transform<M, V>
{ Transform(&rng.gen(), &rng.gen()) }
{ transform(&rng.gen(), &rng.gen()) }
}
impl<M:ToStr, V:ToStr> ToStr for Transform<M, V>

View File

@ -5,13 +5,13 @@ use traits::dim::Dim;
use traits::inv::Inv;
use traits::transpose::Transpose;
use traits::workarounds::rlmul::{RMul, LMul};
use dim1::vec1::Vec1;
use dim1::vec1::{Vec1, vec1};
#[deriving(Eq)]
pub struct Mat1<T>
{ m11: T }
pub fn Mat1<T:Copy>(m11: T) -> Mat1<T>
pub fn mat1<T:Copy>(m11: T) -> Mat1<T>
{
Mat1
{ m11: m11 }
@ -26,13 +26,13 @@ impl<T> Dim for Mat1<T>
impl<T:Copy + One> One for Mat1<T>
{
fn one() -> Mat1<T>
{ return Mat1(One::one()) }
{ return mat1(One::one()) }
}
impl<T:Copy + Zero> Zero for Mat1<T>
{
fn zero() -> Mat1<T>
{ Mat1(Zero::zero()) }
{ mat1(Zero::zero()) }
fn is_zero(&self) -> bool
{ self.m11.is_zero() }
@ -41,19 +41,19 @@ impl<T:Copy + Zero> Zero for Mat1<T>
impl<T:Copy + Mul<T, T> + Add<T, T>> Mul<Mat1<T>, Mat1<T>> for Mat1<T>
{
fn mul(&self, other: &Mat1<T>) -> Mat1<T>
{ Mat1 (self.m11 * other.m11) }
{ mat1(self.m11 * other.m11) }
}
impl<T:Copy + Add<T, T> + Mul<T, T>> RMul<Vec1<T>> for Mat1<T>
{
fn rmul(&self, other: &Vec1<T>) -> Vec1<T>
{ Vec1(self.m11 * other.x) }
{ vec1(self.m11 * other.x) }
}
impl<T:Copy + Add<T, T> + Mul<T, T>> LMul<Vec1<T>> for Mat1<T>
{
fn lmul(&self, other: &Vec1<T>) -> Vec1<T>
{ Vec1(self.m11 * other.x) }
{ vec1(self.m11 * other.x) }
}
impl<T:Copy + Mul<T, T> + Quot<T, T> + Sub<T, T> + Neg<T> + Zero + One>
@ -97,7 +97,7 @@ impl<T:FuzzyEq<T>> FuzzyEq<T> for Mat1<T>
impl<T:Rand + Copy> Rand for Mat1<T>
{
fn rand<R: Rng>(rng: &R) -> Mat1<T>
{ Mat1(rng.gen()) }
{ mat1(rng.gen()) }
}
impl<T:ToStr> ToStr for Mat1<T>

View File

@ -11,7 +11,7 @@ use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub}
pub struct Vec1<T>
{ x : T }
pub fn Vec1<T:Copy>(x: T) -> Vec1<T>
pub fn vec1<T:Copy>(x: T) -> Vec1<T>
{ Vec1 {x: x} }
impl<T> Dim for Vec1<T>
@ -23,13 +23,13 @@ impl<T> Dim for Vec1<T>
impl<T:Copy + Add<T,T>> Add<Vec1<T>, Vec1<T>> for Vec1<T>
{
fn add(&self, other: &Vec1<T>) -> Vec1<T>
{ Vec1(self.x + other.x) }
{ vec1(self.x + other.x) }
}
impl<T:Copy + Sub<T,T>> Sub<Vec1<T>, Vec1<T>> for Vec1<T>
{
fn sub(&self, other: &Vec1<T>) -> Vec1<T>
{ Vec1(self.x - other.x) }
{ vec1(self.x - other.x) }
}
impl<T: Copy + Mul<T, T>>
@ -89,7 +89,7 @@ Norm<T> for Vec1<T>
{ self.sqnorm().sqrt() }
fn normalized(&self) -> Vec1<T>
{ Vec1(self.x / self.norm()) }
{ vec1(self.x / self.norm()) }
fn normalize(&mut self) -> T
{
@ -104,7 +104,7 @@ Norm<T> for Vec1<T>
impl<T:Copy + Neg<T>> Neg<Vec1<T>> for Vec1<T>
{
fn neg(&self) -> Vec1<T>
{ Vec1(-self.x) }
{ vec1(-self.x) }
}
impl<T:Copy + Zero> Zero for Vec1<T>
@ -112,7 +112,7 @@ impl<T:Copy + Zero> Zero for Vec1<T>
fn zero() -> Vec1<T>
{
let _0 = Zero::zero();
Vec1(_0)
vec1(_0)
}
fn is_zero(&self) -> bool
@ -122,7 +122,7 @@ impl<T:Copy + Zero> Zero for Vec1<T>
impl<T: Copy + One> Basis for Vec1<T>
{
fn canonical_basis() -> ~[Vec1<T>]
{ ~[ Vec1(One::one()) ] } // FIXME: this should be static
{ ~[ vec1(One::one()) ] } // FIXME: this should be static
fn orthogonal_subspace_basis(&self) -> ~[Vec1<T>]
{ ~[] }
@ -140,7 +140,7 @@ impl<T:FuzzyEq<T>> FuzzyEq<T> for Vec1<T>
impl<T:Rand + Copy> Rand for Vec1<T>
{
fn rand<R: Rng>(rng: &R) -> Vec1<T>
{ Vec1(rng.gen()) }
{ vec1(rng.gen()) }
}
impl<T:ToStr> ToStr for Vec1<T>

View File

@ -5,7 +5,7 @@ use traits::dim::Dim;
use traits::inv::Inv;
use traits::transpose::Transpose;
use traits::workarounds::rlmul::{RMul, LMul};
use dim2::vec2::Vec2;
use dim2::vec2::{Vec2, vec2};
#[deriving(Eq)]
pub struct Mat2<T>
@ -14,7 +14,7 @@ pub struct Mat2<T>
m21: T, m22: T
}
pub fn Mat2<T:Copy>(m11: T, m12: T, m21: T, m22: T) -> Mat2<T>
pub fn mat2<T:Copy>(m11: T, m12: T, m21: T, m22: T) -> Mat2<T>
{
Mat2
{
@ -34,7 +34,7 @@ impl<T:Copy + One + Zero> One for Mat2<T>
fn one() -> Mat2<T>
{
let (_0, _1) = (Zero::zero(), One::one());
return Mat2(_1, _0,
return mat2(_1, _0,
_0, _1)
}
}
@ -44,7 +44,7 @@ impl<T:Copy + Zero> Zero for Mat2<T>
fn zero() -> Mat2<T>
{
let _0 = Zero::zero();
return Mat2(_0, _0,
return mat2(_0, _0,
_0, _0)
}
@ -59,7 +59,7 @@ impl<T:Copy + Mul<T, T> + Add<T, T>> Mul<Mat2<T>, Mat2<T>> for Mat2<T>
{
fn mul(&self, other: &Mat2<T>) -> Mat2<T>
{
Mat2
mat2
(self.m11 * other.m11 + self.m12 * other.m21,
self.m11 * other.m12 + self.m12 * other.m22,
self.m21 * other.m11 + self.m22 * other.m21,
@ -71,7 +71,7 @@ impl<T:Copy + Add<T, T> + Mul<T, T>> RMul<Vec2<T>> for Mat2<T>
{
fn rmul(&self, other: &Vec2<T>) -> Vec2<T>
{
Vec2(
vec2(
self.m11 * other.x + self.m12 * other.y,
self.m21 * other.x + self.m22 * other.y
)
@ -82,7 +82,7 @@ impl<T:Copy + Add<T, T> + Mul<T, T>> LMul<Vec2<T>> for Mat2<T>
{
fn lmul(&self, other: &Vec2<T>) -> Vec2<T>
{
Vec2(
vec2(
self.m11 * other.x + self.m21 * other.y,
self.m12 * other.x + self.m22 * other.y
)
@ -107,7 +107,7 @@ Inv for Mat2<T>
assert!(!det.is_zero());
*self = Mat2(self.m22 / det , -self.m12 / det,
*self = mat2(self.m22 / det , -self.m12 / det,
-self.m21 / det, self.m11 / det)
}
}
@ -116,7 +116,7 @@ impl<T:Copy> Transpose for Mat2<T>
{
fn transposed(&self) -> Mat2<T>
{
Mat2(self.m11, self.m21,
mat2(self.m11, self.m21,
self.m12, self.m22)
}
@ -148,7 +148,7 @@ impl<T:FuzzyEq<T>> FuzzyEq<T> for Mat2<T>
impl<T:Rand + Copy> Rand for Mat2<T>
{
fn rand<R: Rng>(rng: &R) -> Mat2<T>
{ Mat2(rng.gen(), rng.gen(), rng.gen(), rng.gen()) }
{ mat2(rng.gen(), rng.gen(), rng.gen(), rng.gen()) }
}
impl<T:ToStr> ToStr for Mat2<T>

View File

@ -6,7 +6,7 @@ use traits::dim::Dim;
use traits::cross::Cross;
use traits::basis::Basis;
use traits::norm::Norm;
use dim1::vec1::Vec1;
use dim1::vec1::{Vec1, vec1};
use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub};
#[deriving(Eq)]
@ -16,7 +16,7 @@ pub struct Vec2<T>
y : T
}
pub fn Vec2<T:Copy>(x: T, y: T) -> Vec2<T>
pub fn vec2<T:Copy>(x: T, y: T) -> Vec2<T>
{ Vec2 {x: x, y: y} }
impl<T> Dim for Vec2<T>
@ -28,13 +28,13 @@ impl<T> Dim for Vec2<T>
impl<T:Copy + Add<T,T>> Add<Vec2<T>, Vec2<T>> for Vec2<T>
{
fn add(&self, other: &Vec2<T>) -> Vec2<T>
{ Vec2(self.x + other.x, self.y + other.y) }
{ vec2(self.x + other.x, self.y + other.y) }
}
impl<T:Copy + Sub<T,T>> Sub<Vec2<T>, Vec2<T>> for Vec2<T>
{
fn sub(&self, other: &Vec2<T>) -> Vec2<T>
{ Vec2(self.x - other.x, self.y - other.y) }
{ vec2(self.x - other.x, self.y - other.y) }
}
impl<T: Copy + Mul<T, T>>
@ -109,7 +109,7 @@ Norm<T> for Vec2<T>
{
let l = self.norm();
Vec2(self.x / l, self.y / l)
vec2(self.x / l, self.y / l)
}
fn normalize(&mut self) -> T
@ -126,13 +126,13 @@ Norm<T> for Vec2<T>
impl<T:Copy + Mul<T, T> + Sub<T, T>> Cross<Vec1<T>> for Vec2<T>
{
fn cross(&self, other : &Vec2<T>) -> Vec1<T>
{ Vec1(self.x * other.y - self.y * other.x) }
{ vec1(self.x * other.y - self.y * other.x) }
}
impl<T:Copy + Neg<T>> Neg<Vec2<T>> for Vec2<T>
{
fn neg(&self) -> Vec2<T>
{ Vec2(-self.x, -self.y) }
{ vec2(-self.x, -self.y) }
}
impl<T:Copy + Zero> Zero for Vec2<T>
@ -140,7 +140,7 @@ impl<T:Copy + Zero> Zero for Vec2<T>
fn zero() -> Vec2<T>
{
let _0 = Zero::zero();
Vec2(_0, _0)
vec2(_0, _0)
}
fn is_zero(&self) -> bool
@ -152,12 +152,12 @@ impl<T: Copy + One + Zero + Neg<T>> Basis for Vec2<T>
fn canonical_basis() -> ~[Vec2<T>]
{
// FIXME: this should be static
~[ Vec2(One::one(), Zero::zero()),
Vec2(Zero::zero(), One::one()) ]
~[ vec2(One::one(), Zero::zero()),
vec2(Zero::zero(), One::one()) ]
}
fn orthogonal_subspace_basis(&self) -> ~[Vec2<T>]
{ ~[ Vec2(-self.y, self.x) ] }
{ ~[ vec2(-self.y, self.x) ] }
}
impl<T:FuzzyEq<T>> FuzzyEq<T> for Vec2<T>
@ -175,7 +175,7 @@ impl<T:FuzzyEq<T>> FuzzyEq<T> for Vec2<T>
impl<T:Rand + Copy> Rand for Vec2<T>
{
fn rand<R: Rng>(rng: &R) -> Vec2<T>
{ Vec2(rng.gen(), rng.gen()) }
{ vec2(rng.gen(), rng.gen()) }
}
impl<T:ToStr> ToStr for Vec2<T>

View File

@ -5,7 +5,7 @@ use traits::dim::Dim;
use traits::inv::Inv;
use traits::transpose::Transpose;
use traits::workarounds::rlmul::{RMul, LMul};
use dim3::vec3::Vec3;
use dim3::vec3::{Vec3, vec3};
#[deriving(Eq)]
pub struct Mat3<T>
@ -15,7 +15,7 @@ pub struct Mat3<T>
m31: T, m32: T, m33: T
}
pub fn Mat3<T:Copy>(m11: T, m12: T, m13: T,
pub fn mat3<T:Copy>(m11: T, m12: T, m13: T,
m21: T, m22: T, m23: T,
m31: T, m32: T, m33: T) -> Mat3<T>
{
@ -38,7 +38,7 @@ impl<T:Copy + One + Zero> One for Mat3<T>
fn one() -> Mat3<T>
{
let (_0, _1) = (Zero::zero(), One::one());
return Mat3(_1, _0, _0,
return mat3(_1, _0, _0,
_0, _1, _0,
_0, _0, _1)
}
@ -49,7 +49,7 @@ impl<T:Copy + Zero> Zero for Mat3<T>
fn zero() -> Mat3<T>
{
let _0 = Zero::zero();
return Mat3(_0, _0, _0,
return mat3(_0, _0, _0,
_0, _0, _0,
_0, _0, _0)
}
@ -66,7 +66,7 @@ impl<T:Copy + Mul<T, T> + Add<T, T>> Mul<Mat3<T>, Mat3<T>> for Mat3<T>
{
fn mul(&self, other: &Mat3<T>) -> Mat3<T>
{
Mat3(
mat3(
self.m11 * other.m11 + self.m12 * other.m21 + self.m13 * other.m31,
self.m11 * other.m12 + self.m12 * other.m22 + self.m13 * other.m32,
self.m11 * other.m13 + self.m12 * other.m23 + self.m13 * other.m33,
@ -86,7 +86,7 @@ impl<T:Copy + Add<T, T> + Mul<T, T>> RMul<Vec3<T>> for Mat3<T>
{
fn rmul(&self, other: &Vec3<T>) -> Vec3<T>
{
Vec3(
vec3(
self.m11 * other.x + self.m12 * other.y + self.m13 * other.z,
self.m21 * other.x + self.m22 * other.y + self.m33 * other.z,
self.m31 * other.x + self.m32 * other.y + self.m33 * other.z
@ -98,7 +98,7 @@ impl<T:Copy + Add<T, T> + Mul<T, T>> LMul<Vec3<T>> for Mat3<T>
{
fn lmul(&self, other: &Vec3<T>) -> Vec3<T>
{
Vec3(
vec3(
self.m11 * other.x + self.m21 * other.y + self.m31 * other.z,
self.m12 * other.x + self.m22 * other.y + self.m32 * other.z,
self.m13 * other.x + self.m23 * other.y + self.m33 * other.z
@ -130,7 +130,7 @@ Inv for Mat3<T>
assert!(!det.is_zero());
*self = Mat3(
*self = mat3(
(minor_m22_m33 / det),
((self.m13 * self.m32 - self.m33 * self.m12) / det),
((self.m12 * self.m23 - self.m22 * self.m13) / det),
@ -150,7 +150,7 @@ impl<T:Copy> Transpose for Mat3<T>
{
fn transposed(&self) -> Mat3<T>
{
Mat3(self.m11, self.m21, self.m31,
mat3(self.m11, self.m21, self.m31,
self.m12, self.m22, self.m32,
self.m13, self.m23, self.m33)
}
@ -200,7 +200,7 @@ impl<T:Rand + Copy> Rand for Mat3<T>
{
fn rand<R: Rng>(rng: &R) -> Mat3<T>
{
Mat3(rng.gen(), rng.gen(), rng.gen(),
mat3(rng.gen(), rng.gen(), rng.gen(),
rng.gen(), rng.gen(), rng.gen(),
rng.gen(), rng.gen(), rng.gen())
}

View File

@ -16,7 +16,7 @@ pub struct Vec3<T>
z : T
}
pub fn Vec3<T:Copy>(x: T, y: T, z: T) -> Vec3<T>
pub fn vec3<T:Copy>(x: T, y: T, z: T) -> Vec3<T>
{ Vec3 {x: x, y: y, z: z} }
impl<T> Dim for Vec3<T>
@ -28,13 +28,13 @@ impl<T> Dim for Vec3<T>
impl<T:Copy + Add<T,T>> Add<Vec3<T>, Vec3<T>> for Vec3<T>
{
fn add(&self, other: &Vec3<T>) -> Vec3<T>
{ Vec3(self.x + other.x, self.y + other.y, self.z + other.z) }
{ vec3(self.x + other.x, self.y + other.y, self.z + other.z) }
}
impl<T:Copy + Sub<T,T>> Sub<Vec3<T>, Vec3<T>> for Vec3<T>
{
fn sub(&self, other: &Vec3<T>) -> Vec3<T>
{ Vec3(self.x - other.x, self.y - other.y, self.z - other.z) }
{ vec3(self.x - other.x, self.y - other.y, self.z - other.z) }
}
impl<T: Copy + Mul<T, T>>
@ -98,7 +98,7 @@ ScalarSub<T> for Vec3<T>
impl<T:Copy + Neg<T>> Neg<Vec3<T>> for Vec3<T>
{
fn neg(&self) -> Vec3<T>
{ Vec3(-self.x, -self.y, -self.z) }
{ vec3(-self.x, -self.y, -self.z) }
}
impl<T:Copy + Mul<T, T> + Add<T, T> + Algebraic> Dot<T> for Vec3<T>
@ -120,7 +120,7 @@ Norm<T> for Vec3<T>
{
let l = self.norm();
Vec3(self.x / l, self.y / l, self.z / l)
vec3(self.x / l, self.y / l, self.z / l)
}
fn normalize(&mut self) -> T
@ -139,7 +139,7 @@ impl<T:Copy + Mul<T, T> + Sub<T, T>> Cross<Vec3<T>> for Vec3<T>
{
fn cross(&self, other : &Vec3<T>) -> Vec3<T>
{
Vec3(
vec3(
self.y * other.z - self.z * other.y,
self.z * other.x - self.x * other.z,
self.x * other.y - self.y * other.x
@ -152,7 +152,7 @@ impl<T:Copy + Zero> Zero for Vec3<T>
fn zero() -> Vec3<T>
{
let _0 = Zero::zero();
Vec3(_0, _0, _0)
vec3(_0, _0, _0)
}
fn is_zero(&self) -> bool
@ -166,18 +166,18 @@ Basis for Vec3<T>
fn canonical_basis() -> ~[Vec3<T>]
{
// FIXME: this should be static
~[ Vec3(One::one(), Zero::zero(), Zero::zero()),
Vec3(Zero::zero(), One::one(), Zero::zero()),
Vec3(Zero::zero(), Zero::zero(), One::one()) ]
~[ vec3(One::one(), Zero::zero(), Zero::zero()),
vec3(Zero::zero(), One::one(), Zero::zero()),
vec3(Zero::zero(), Zero::zero(), One::one()) ]
}
fn orthogonal_subspace_basis(&self) -> ~[Vec3<T>]
{
let a =
if (abs(self.x) > abs(self.y))
{ Vec3(self.z, Zero::zero(), -self.x).normalized() }
{ vec3(self.z, Zero::zero(), -self.x).normalized() }
else
{ Vec3(Zero::zero(), -self.z, self.y).normalized() };
{ vec3(Zero::zero(), -self.z, self.y).normalized() };
~[ a, a.cross(self) ]
}
@ -203,7 +203,7 @@ impl<T:FuzzyEq<T>> FuzzyEq<T> for Vec3<T>
impl<T:Copy + Rand> Rand for Vec3<T>
{
fn rand<R: Rng>(rng: &R) -> Vec3<T>
{ Vec3(rng.gen(), rng.gen(), rng.gen()) }
{ vec3(rng.gen(), rng.gen(), rng.gen()) }
}
impl<T:ToStr> ToStr for Vec3<T>