From ceed733e25fa264a53b46cd3171d0006aeb1dfd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Sat, 18 May 2013 20:03:45 +0000 Subject: [PATCH] Functions to build objects dont shadow constructors any more. --- src/adaptors/rotmat.rs | 18 +++++++++--------- src/adaptors/transform.rs | 4 ++-- src/dim1/mat1.rs | 16 ++++++++-------- src/dim1/vec1.rs | 16 ++++++++-------- src/dim2/mat2.rs | 20 ++++++++++---------- src/dim2/vec2.rs | 24 ++++++++++++------------ src/dim3/mat3.rs | 20 ++++++++++---------- src/dim3/vec3.rs | 26 +++++++++++++------------- 8 files changed, 72 insertions(+), 72 deletions(-) diff --git a/src/adaptors/rotmat.rs b/src/adaptors/rotmat.rs index 0ce391d6..d1967487 100644 --- a/src/adaptors/rotmat.rs +++ b/src/adaptors/rotmat.rs @@ -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 priv submat: M } -pub fn Rotmat2>(angle: T) -> Rotmat> +pub fn rotmat2>(angle: T) -> Rotmat> { 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 + One + Sub + Add + +pub fn rotmat3 + One + Sub + Add + Mul> (axis: &Vec3, angle: T) -> Rotmat> { @@ -42,7 +42,7 @@ pub fn Rotmat3 + One + Sub + Add + 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 + One + Sub + Add + impl> Rand for Rotmat> { fn rand(rng: &R) -> Rotmat> - { Rotmat2(rng.gen()) } + { rotmat2(rng.gen()) } } impl + One + Sub + Add + @@ -68,7 +68,7 @@ impl + One + Sub + Add + Rand for Rotmat> { fn rand(rng: &R) -> Rotmat> - { Rotmat3(&rng.gen(), rng.gen()) } + { rotmat3(&rng.gen(), rng.gen()) } } impl Dim for Rotmat diff --git a/src/adaptors/transform.rs b/src/adaptors/transform.rs index a2161c78..60b2c278 100644 --- a/src/adaptors/transform.rs +++ b/src/adaptors/transform.rs @@ -12,7 +12,7 @@ pub struct Transform subtrans : V } -pub fn Transform(mat: &M, trans: &V) -> Transform +pub fn transform(mat: &M, trans: &V) -> Transform { Transform { submat: *mat, subtrans: *trans } } impl Dim for Transform @@ -95,7 +95,7 @@ impl, V:FuzzyEq> FuzzyEq for Transform impl Rand for Transform { fn rand(rng: &R) -> Transform - { Transform(&rng.gen(), &rng.gen()) } + { transform(&rng.gen(), &rng.gen()) } } impl ToStr for Transform diff --git a/src/dim1/mat1.rs b/src/dim1/mat1.rs index 8348af18..296dbc30 100644 --- a/src/dim1/mat1.rs +++ b/src/dim1/mat1.rs @@ -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 { m11: T } -pub fn Mat1(m11: T) -> Mat1 +pub fn mat1(m11: T) -> Mat1 { Mat1 { m11: m11 } @@ -26,13 +26,13 @@ impl Dim for Mat1 impl One for Mat1 { fn one() -> Mat1 - { return Mat1(One::one()) } + { return mat1(One::one()) } } impl Zero for Mat1 { fn zero() -> Mat1 - { Mat1(Zero::zero()) } + { mat1(Zero::zero()) } fn is_zero(&self) -> bool { self.m11.is_zero() } @@ -41,19 +41,19 @@ impl Zero for Mat1 impl + Add> Mul, Mat1> for Mat1 { fn mul(&self, other: &Mat1) -> Mat1 - { Mat1 (self.m11 * other.m11) } + { mat1(self.m11 * other.m11) } } impl + Mul> RMul> for Mat1 { fn rmul(&self, other: &Vec1) -> Vec1 - { Vec1(self.m11 * other.x) } + { vec1(self.m11 * other.x) } } impl + Mul> LMul> for Mat1 { fn lmul(&self, other: &Vec1) -> Vec1 - { Vec1(self.m11 * other.x) } + { vec1(self.m11 * other.x) } } impl + Quot + Sub + Neg + Zero + One> @@ -97,7 +97,7 @@ impl> FuzzyEq for Mat1 impl Rand for Mat1 { fn rand(rng: &R) -> Mat1 - { Mat1(rng.gen()) } + { mat1(rng.gen()) } } impl ToStr for Mat1 diff --git a/src/dim1/vec1.rs b/src/dim1/vec1.rs index 27780bdd..05c0c151 100644 --- a/src/dim1/vec1.rs +++ b/src/dim1/vec1.rs @@ -11,7 +11,7 @@ use traits::workarounds::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub} pub struct Vec1 { x : T } -pub fn Vec1(x: T) -> Vec1 +pub fn vec1(x: T) -> Vec1 { Vec1 {x: x} } impl Dim for Vec1 @@ -23,13 +23,13 @@ impl Dim for Vec1 impl> Add, Vec1> for Vec1 { fn add(&self, other: &Vec1) -> Vec1 - { Vec1(self.x + other.x) } + { vec1(self.x + other.x) } } impl> Sub, Vec1> for Vec1 { fn sub(&self, other: &Vec1) -> Vec1 - { Vec1(self.x - other.x) } + { vec1(self.x - other.x) } } impl> @@ -89,7 +89,7 @@ Norm for Vec1 { self.sqnorm().sqrt() } fn normalized(&self) -> Vec1 - { Vec1(self.x / self.norm()) } + { vec1(self.x / self.norm()) } fn normalize(&mut self) -> T { @@ -104,7 +104,7 @@ Norm for Vec1 impl> Neg> for Vec1 { fn neg(&self) -> Vec1 - { Vec1(-self.x) } + { vec1(-self.x) } } impl Zero for Vec1 @@ -112,7 +112,7 @@ impl Zero for Vec1 fn zero() -> Vec1 { let _0 = Zero::zero(); - Vec1(_0) + vec1(_0) } fn is_zero(&self) -> bool @@ -122,7 +122,7 @@ impl Zero for Vec1 impl Basis for Vec1 { fn canonical_basis() -> ~[Vec1] - { ~[ Vec1(One::one()) ] } // FIXME: this should be static + { ~[ vec1(One::one()) ] } // FIXME: this should be static fn orthogonal_subspace_basis(&self) -> ~[Vec1] { ~[] } @@ -140,7 +140,7 @@ impl> FuzzyEq for Vec1 impl Rand for Vec1 { fn rand(rng: &R) -> Vec1 - { Vec1(rng.gen()) } + { vec1(rng.gen()) } } impl ToStr for Vec1 diff --git a/src/dim2/mat2.rs b/src/dim2/mat2.rs index 6d2e6603..31033787 100644 --- a/src/dim2/mat2.rs +++ b/src/dim2/mat2.rs @@ -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 @@ -14,7 +14,7 @@ pub struct Mat2 m21: T, m22: T } -pub fn Mat2(m11: T, m12: T, m21: T, m22: T) -> Mat2 +pub fn mat2(m11: T, m12: T, m21: T, m22: T) -> Mat2 { Mat2 { @@ -34,7 +34,7 @@ impl One for Mat2 fn one() -> Mat2 { let (_0, _1) = (Zero::zero(), One::one()); - return Mat2(_1, _0, + return mat2(_1, _0, _0, _1) } } @@ -44,7 +44,7 @@ impl Zero for Mat2 fn zero() -> Mat2 { let _0 = Zero::zero(); - return Mat2(_0, _0, + return mat2(_0, _0, _0, _0) } @@ -59,7 +59,7 @@ impl + Add> Mul, Mat2> for Mat2 { fn mul(&self, other: &Mat2) -> Mat2 { - 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 + Mul> RMul> for Mat2 { fn rmul(&self, other: &Vec2) -> Vec2 { - Vec2( + vec2( self.m11 * other.x + self.m12 * other.y, self.m21 * other.x + self.m22 * other.y ) @@ -82,7 +82,7 @@ impl + Mul> LMul> for Mat2 { fn lmul(&self, other: &Vec2) -> Vec2 { - 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 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 Transpose for Mat2 { fn transposed(&self) -> Mat2 { - Mat2(self.m11, self.m21, + mat2(self.m11, self.m21, self.m12, self.m22) } @@ -148,7 +148,7 @@ impl> FuzzyEq for Mat2 impl Rand for Mat2 { fn rand(rng: &R) -> Mat2 - { Mat2(rng.gen(), rng.gen(), rng.gen(), rng.gen()) } + { mat2(rng.gen(), rng.gen(), rng.gen(), rng.gen()) } } impl ToStr for Mat2 diff --git a/src/dim2/vec2.rs b/src/dim2/vec2.rs index a8e38591..2b40e694 100644 --- a/src/dim2/vec2.rs +++ b/src/dim2/vec2.rs @@ -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 y : T } -pub fn Vec2(x: T, y: T) -> Vec2 +pub fn vec2(x: T, y: T) -> Vec2 { Vec2 {x: x, y: y} } impl Dim for Vec2 @@ -28,13 +28,13 @@ impl Dim for Vec2 impl> Add, Vec2> for Vec2 { fn add(&self, other: &Vec2) -> Vec2 - { Vec2(self.x + other.x, self.y + other.y) } + { vec2(self.x + other.x, self.y + other.y) } } impl> Sub, Vec2> for Vec2 { fn sub(&self, other: &Vec2) -> Vec2 - { Vec2(self.x - other.x, self.y - other.y) } + { vec2(self.x - other.x, self.y - other.y) } } impl> @@ -109,7 +109,7 @@ Norm for Vec2 { 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 for Vec2 impl + Sub> Cross> for Vec2 { fn cross(&self, other : &Vec2) -> Vec1 - { Vec1(self.x * other.y - self.y * other.x) } + { vec1(self.x * other.y - self.y * other.x) } } impl> Neg> for Vec2 { fn neg(&self) -> Vec2 - { Vec2(-self.x, -self.y) } + { vec2(-self.x, -self.y) } } impl Zero for Vec2 @@ -140,7 +140,7 @@ impl Zero for Vec2 fn zero() -> Vec2 { let _0 = Zero::zero(); - Vec2(_0, _0) + vec2(_0, _0) } fn is_zero(&self) -> bool @@ -152,12 +152,12 @@ impl> Basis for Vec2 fn canonical_basis() -> ~[Vec2] { // 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] - { ~[ Vec2(-self.y, self.x) ] } + { ~[ vec2(-self.y, self.x) ] } } impl> FuzzyEq for Vec2 @@ -175,7 +175,7 @@ impl> FuzzyEq for Vec2 impl Rand for Vec2 { fn rand(rng: &R) -> Vec2 - { Vec2(rng.gen(), rng.gen()) } + { vec2(rng.gen(), rng.gen()) } } impl ToStr for Vec2 diff --git a/src/dim3/mat3.rs b/src/dim3/mat3.rs index 81c3cc54..9f90c28e 100644 --- a/src/dim3/mat3.rs +++ b/src/dim3/mat3.rs @@ -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 @@ -15,7 +15,7 @@ pub struct Mat3 m31: T, m32: T, m33: T } -pub fn Mat3(m11: T, m12: T, m13: T, +pub fn mat3(m11: T, m12: T, m13: T, m21: T, m22: T, m23: T, m31: T, m32: T, m33: T) -> Mat3 { @@ -38,7 +38,7 @@ impl One for Mat3 fn one() -> Mat3 { 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 Zero for Mat3 fn zero() -> Mat3 { 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 + Add> Mul, Mat3> for Mat3 { fn mul(&self, other: &Mat3) -> Mat3 { - 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 + Mul> RMul> for Mat3 { fn rmul(&self, other: &Vec3) -> Vec3 { - 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 + Mul> LMul> for Mat3 { fn lmul(&self, other: &Vec3) -> Vec3 { - 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 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 Transpose for Mat3 { fn transposed(&self) -> Mat3 { - 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 Rand for Mat3 { fn rand(rng: &R) -> Mat3 { - 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()) } diff --git a/src/dim3/vec3.rs b/src/dim3/vec3.rs index c165e86b..b2b14028 100644 --- a/src/dim3/vec3.rs +++ b/src/dim3/vec3.rs @@ -16,7 +16,7 @@ pub struct Vec3 z : T } -pub fn Vec3(x: T, y: T, z: T) -> Vec3 +pub fn vec3(x: T, y: T, z: T) -> Vec3 { Vec3 {x: x, y: y, z: z} } impl Dim for Vec3 @@ -28,13 +28,13 @@ impl Dim for Vec3 impl> Add, Vec3> for Vec3 { fn add(&self, other: &Vec3) -> Vec3 - { 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> Sub, Vec3> for Vec3 { fn sub(&self, other: &Vec3) -> Vec3 - { 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> @@ -98,7 +98,7 @@ ScalarSub for Vec3 impl> Neg> for Vec3 { fn neg(&self) -> Vec3 - { Vec3(-self.x, -self.y, -self.z) } + { vec3(-self.x, -self.y, -self.z) } } impl + Add + Algebraic> Dot for Vec3 @@ -120,7 +120,7 @@ Norm for Vec3 { 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 + Sub> Cross> for Vec3 { fn cross(&self, other : &Vec3) -> Vec3 { - 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 Zero for Vec3 fn zero() -> Vec3 { let _0 = Zero::zero(); - Vec3(_0, _0, _0) + vec3(_0, _0, _0) } fn is_zero(&self) -> bool @@ -166,18 +166,18 @@ Basis for Vec3 fn canonical_basis() -> ~[Vec3] { // 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] { 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> FuzzyEq for Vec3 impl Rand for Vec3 { fn rand(rng: &R) -> Vec3 - { Vec3(rng.gen(), rng.gen(), rng.gen()) } + { vec3(rng.gen(), rng.gen(), rng.gen()) } } impl ToStr for Vec3