From c89053f6ee56fff91021d6f0de3c3751ac06bacb Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Tue, 29 Jan 2013 21:23:22 +1100 Subject: [PATCH] Use capitalised Self type --- src/mat.rs | 54 +++++++++++++++++----------------- src/vec.rs | 86 +++++++++++++++++++++++++++--------------------------- 2 files changed, 70 insertions(+), 70 deletions(-) diff --git a/src/mat.rs b/src/mat.rs index 260186e..d9f57ad 100644 --- a/src/mat.rs +++ b/src/mat.rs @@ -36,28 +36,28 @@ pub trait Matrix: Index Eq Neg { /** * Construct a diagonal matrix with the major diagonal set to `value` */ - static pure fn from_value(value: T) -> self; + static pure fn from_value(value: T) -> Self; /** * # Return value * * The identity matrix */ - static pure fn identity() -> self; + static pure fn identity() -> Self; /** * # Return value * * A matrix with all elements set to zero */ - static pure fn zero() -> self; + static pure fn zero() -> Self; /** * # Return value * * The scalar multiplication of this matrix and `value` */ - pure fn mul_t(&self, value: T) -> self; + pure fn mul_t(&self, value: T) -> Self; /** * # Return value @@ -71,28 +71,28 @@ pub trait Matrix: Index Eq Neg { * * The matrix addition of the matrix and `other` */ - pure fn add_m(&self, other: &self) -> self; + pure fn add_m(&self, other: &Self) -> Self; /** * # Return value * * The difference between the matrix and `other` */ - pure fn sub_m(&self, other: &self) -> self; + pure fn sub_m(&self, other: &Self) -> Self; /** * # Return value * * The matrix product of the matrix and `other` */ - pure fn mul_m(&self, other: &self) -> self; + pure fn mul_m(&self, other: &Self) -> Self; /** * # Return value * * The matrix dot product of the matrix and `other` */ - pure fn dot(&self, other: &self) -> T; + pure fn dot(&self, other: &Self) -> T; /** * # Return value @@ -116,14 +116,14 @@ pub trait Matrix: Index Eq Neg { * * `Some(m)` - if the inversion was successful, where `m` is the inverted matrix * * `None` - if the inversion was unsuccessful (because the matrix was not invertable) */ - pure fn inverse(&self) -> Option; + pure fn inverse(&self) -> Option; /** * # Return value * * The transposed matrix */ - pure fn transpose(&self) -> self; + pure fn transpose(&self) -> Self; /** * Check to see if the matrix is an identity matrix @@ -184,11 +184,11 @@ pub trait Matrix: Index Eq Neg { */ pub trait Matrix2: Matrix { static pure fn new(c0r0: T, c0r1: T, - c1r0: T, c1r1: T) -> self; + c1r0: T, c1r1: T) -> Self; - static pure fn from_cols(c0: V, c1: V) -> self; + static pure fn from_cols(c0: V, c1: V) -> Self; - static pure fn from_angle(radians: T) -> self; + static pure fn from_angle(radians: T) -> Self; pure fn to_mat3(&self) -> Mat3; @@ -201,23 +201,23 @@ pub trait Matrix2: Matrix { pub trait Matrix3: Matrix { static pure fn new(c0r0:T, c0r1:T, c0r2:T, c1r0:T, c1r1:T, c1r2:T, - c2r0:T, c2r1:T, c2r2:T) -> self; + c2r0:T, c2r1:T, c2r2:T) -> Self; - static pure fn from_cols(c0: V, c1: V, c2: V) -> self; + static pure fn from_cols(c0: V, c1: V, c2: V) -> Self; - static pure fn from_angle_x(radians: T) -> self; + static pure fn from_angle_x(radians: T) -> Self; - static pure fn from_angle_y(radians: T) -> self; + static pure fn from_angle_y(radians: T) -> Self; - static pure fn from_angle_z(radians: T) -> self; + static pure fn from_angle_z(radians: T) -> Self; - static pure fn from_angle_xyz(radians_x: T, radians_y: T, radians_z: T) -> self; + static pure fn from_angle_xyz(radians_x: T, radians_y: T, radians_z: T) -> Self; - static pure fn from_angle_axis(radians: T, axis: &Vec3) -> self; + static pure fn from_angle_axis(radians: T, axis: &Vec3) -> Self; - static pure fn from_axes(x: V, y: V, z: V) -> self; + static pure fn from_axes(x: V, y: V, z: V) -> Self; - static pure fn look_at(dir: &Vec3, up: &Vec3) -> self; + static pure fn look_at(dir: &Vec3, up: &Vec3) -> Self; pure fn to_mat4(&self) -> Mat4; @@ -231,9 +231,9 @@ pub trait Matrix4: Matrix { static pure fn new(c0r0: T, c0r1: T, c0r2: T, c0r3: T, c1r0: T, c1r1: T, c1r2: T, c1r3: T, c2r0: T, c2r1: T, c2r2: T, c2r3: T, - c3r0: T, c3r1: T, c3r2: T, c3r3: T) -> self; + c3r0: T, c3r1: T, c3r2: T, c3r3: T) -> Self; - static pure fn from_cols(c0: V, c1: V, c2: V, c3: V) -> self; + static pure fn from_cols(c0: V, c1: V, c2: V, c3: V) -> Self; } /** @@ -260,7 +260,7 @@ pub trait MutableMatrix: Matrix { /** * Sets the matrix to `other` */ - fn set(&mut self, other: &self); + fn set(&mut self, other: &Self); /** * Sets the matrix to the identity matrix @@ -280,12 +280,12 @@ pub trait MutableMatrix: Matrix { /** * Add the matrix `other` to `self` */ - fn add_self_m(&mut self, other: &self); + fn add_self_m(&mut self, other: &Self); /** * Subtract the matrix `other` from `self` */ - fn sub_self_m(&mut self, other: &self); + fn sub_self_m(&mut self, other: &Self); /** * Sets the matrix to its inverse diff --git a/src/vec.rs b/src/vec.rs index 1ab3374..b259ba9 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -21,7 +21,7 @@ pub trait Vector: Index Eq { /** * Construct the vector from a single value, copying it to each component */ - static pure fn from_value(value: T) -> self; + static pure fn from_value(value: T) -> Self; /** * # Return value @@ -47,21 +47,21 @@ pub trait MutableVector: Vector { * A generic 2-dimensional vector */ pub trait Vector2: Vector { - static pure fn new(x: T, y: T) -> self; + static pure fn new(x: T, y: T) -> Self; } /** * A generic 3-dimensional vector */ pub trait Vector3: Vector { - static pure fn new(x: T, y: T, z: T) -> self; + static pure fn new(x: T, y: T, z: T) -> Self; } /** * A generic 4-dimensional vector */ pub trait Vector4: Vector { - static pure fn new(x: T, y: T, z: T, w: T) -> self; + static pure fn new(x: T, y: T, z: T, w: T) -> Self; } /** @@ -75,7 +75,7 @@ pub trait NumericVector: Vector Neg { * * A vector with each component set to one */ - static pure fn identity() -> self; + static pure fn identity() -> Self; /** * The null vector @@ -84,7 +84,7 @@ pub trait NumericVector: Vector Neg { * * A vector with each component set to zero */ - static pure fn zero() -> self; + static pure fn zero() -> Self; /** * # Return value @@ -98,82 +98,82 @@ pub trait NumericVector: Vector Neg { * * The scalar multiplication of the vector and `value` */ - pure fn mul_t(&self, value: T) -> self; + pure fn mul_t(&self, value: T) -> Self; /** * # Return value * * The scalar division of the vector and `value` */ - pure fn div_t(&self, value: T) -> self; + pure fn div_t(&self, value: T) -> Self; /** * Component-wise vector addition */ - pure fn add_v(&self, other: &self) -> self; + pure fn add_v(&self, other: &Self) -> Self; /** * Component-wise vector subtraction */ - pure fn sub_v(&self, other: &self) -> self; + pure fn sub_v(&self, other: &Self) -> Self; /** * Component-wise vector multiplication */ - pure fn mul_v(&self, other: &self) -> self; + pure fn mul_v(&self, other: &Self) -> Self; /** * Component-wise vector division */ - pure fn div_v(&self, other: &self) -> self; + pure fn div_v(&self, other: &Self) -> Self; /** * # Return value * * The dot product of the vector and `other` */ - pure fn dot(&self, other: &self) -> T; + pure fn dot(&self, other: &Self) -> T; } /** * A 2-dimensional vector with numeric components */ pub trait NumericVector2: NumericVector { - static pure fn unit_x() -> self; - static pure fn unit_y() -> self; + static pure fn unit_x() -> Self; + static pure fn unit_y() -> Self; /** * # Return value * * The perp dot product of the vector and `other` */ - pure fn perp_dot(&self, other: &self) -> T; + pure fn perp_dot(&self, other: &Self) -> T; } /** * A 3-dimensional vector with numeric components */ pub trait NumericVector3: NumericVector { - static pure fn unit_x() -> self; - static pure fn unit_y() -> self; - static pure fn unit_z() -> self; + static pure fn unit_x() -> Self; + static pure fn unit_y() -> Self; + static pure fn unit_z() -> Self; /** * # Return value * * The cross product of the vector and `other` */ - pure fn cross(&self, other: &self) -> self; + pure fn cross(&self, other: &Self) -> Self; } /** * A 4-dimensional vector with numeric components */ pub trait NumericVector4: NumericVector { - static pure fn unit_x() -> self; - static pure fn unit_y() -> self; - static pure fn unit_z() -> self; - static pure fn unit_w() -> self; + static pure fn unit_x() -> Self; + static pure fn unit_y() -> Self; + static pure fn unit_z() -> Self; + static pure fn unit_w() -> Self; } /** @@ -199,22 +199,22 @@ pub trait MutableNumericVector: MutableVector<&self/T> /** * Set the vector to the component-wise vector sum */ - fn add_self_v(&mut self, other: &self); + fn add_self_v(&mut self, other: &Self); /** * Set the vector to the component-wise vector difference */ - fn sub_self_v(&mut self, other: &self); + fn sub_self_v(&mut self, other: &Self); /** * Set the vector to the component-wise vector product */ - fn mul_self_v(&mut self, other: &self); + fn mul_self_v(&mut self, other: &Self); /** * Set the vector to the component-wise vector quotient */ - fn div_self_v(&mut self, other: &self); + fn div_self_v(&mut self, other: &Self); } /** @@ -224,7 +224,7 @@ pub trait MutableNumericVector3: MutableNumericVector<&self/T> { /** * Set to the cross product of the vector and `other` */ - fn cross_self(&mut self, other: &self); + fn cross_self(&mut self, other: &Self); } pub trait ToHomogeneous { @@ -268,33 +268,33 @@ pub trait EuclideanVector: NumericVector { * * The squared distance between the vector and `other`. */ - pure fn distance2(&self, other: &self) -> T; + pure fn distance2(&self, other: &Self) -> T; /** * # Return value * * The distance between the vector and `other` */ - pure fn distance(&self, other: &self) -> T; + pure fn distance(&self, other: &Self) -> T; /** * # Return value * * The angle between the vector and `other` in radians */ - pure fn angle(&self, other: &self) -> T; + pure fn angle(&self, other: &Self) -> T; /** * # Return value * * The normalized vector */ - pure fn normalize(&self) -> self; + pure fn normalize(&self) -> Self; /** * Set the length of the vector whilst preserving the direction */ - pure fn normalize_to(&self, length: T) -> self; + pure fn normalize_to(&self, length: T) -> Self; /** * Linearly intoperlate between the vector and `other` @@ -303,7 +303,7 @@ pub trait EuclideanVector: NumericVector { * * The intoperlated vector */ - pure fn lerp(&self, other: &self, amount: T) -> self; + pure fn lerp(&self, other: &Self, amount: T) -> Self; } /** @@ -328,7 +328,7 @@ pub trait MutableEuclideanVector: MutableNumericVector<&self/T> /** * Linearly intoperlate the vector towards `other` */ - fn lerp_self(&mut self, other: &self, amount: T); + fn lerp_self(&mut self, other: &Self, amount: T); } /** @@ -342,22 +342,22 @@ pub trait OrdinalVector: Vector { /** * Component-wise compare of `self < other` */ - pure fn less_than(&self, other: &self) -> BoolVec; + pure fn less_than(&self, other: &Self) -> BoolVec; /** * Component-wise compare of `self <= other` */ - pure fn less_than_equal(&self, other: &self) -> BoolVec; + pure fn less_than_equal(&self, other: &Self) -> BoolVec; /** * Component-wise compare of `self > other` */ - pure fn greater_than(&self, other: &self) -> BoolVec; + pure fn greater_than(&self, other: &Self) -> BoolVec; /** * Component-wise compare of `self >= other` */ - pure fn greater_than_equal(&self, other: &self) -> BoolVec; + pure fn greater_than_equal(&self, other: &Self) -> BoolVec; } /** @@ -371,12 +371,12 @@ pub trait EquableVector: Vector { /** * Component-wise compare of `self == other` */ - pure fn equal(&self, other: &self) -> BoolVec; + pure fn equal(&self, other: &Self) -> BoolVec; /** * Component-wise compare of `self != other` */ - pure fn not_equal(&self, other: &self) -> BoolVec; + pure fn not_equal(&self, other: &Self) -> BoolVec; } /** @@ -406,5 +406,5 @@ pub trait BooleanVector: Vector { * * the component-wise logical complement */ - pure fn not(&self) -> self; + pure fn not(&self) -> Self; } \ No newline at end of file