Use capitalised Self type

This commit is contained in:
Brendan Zabarauskas 2013-01-29 21:23:22 +11:00
parent 58cfe4d32c
commit c89053f6ee
2 changed files with 70 additions and 70 deletions

View file

@ -36,28 +36,28 @@ pub trait Matrix<T,V>: Index<uint, V> Eq Neg<self> {
/** /**
* Construct a diagonal matrix with the major diagonal set to `value` * 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 * # Return value
* *
* The identity matrix * The identity matrix
*/ */
static pure fn identity() -> self; static pure fn identity() -> Self;
/** /**
* # Return value * # Return value
* *
* A matrix with all elements set to zero * A matrix with all elements set to zero
*/ */
static pure fn zero() -> self; static pure fn zero() -> Self;
/** /**
* # Return value * # Return value
* *
* The scalar multiplication of this matrix and `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 * # Return value
@ -71,28 +71,28 @@ pub trait Matrix<T,V>: Index<uint, V> Eq Neg<self> {
* *
* The matrix addition of the matrix and `other` * 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 * # Return value
* *
* The difference between the matrix and `other` * 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 * # Return value
* *
* The matrix product of the matrix and `other` * 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 * # Return value
* *
* The matrix dot product of the matrix and `other` * 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 * # Return value
@ -116,14 +116,14 @@ pub trait Matrix<T,V>: Index<uint, V> Eq Neg<self> {
* * `Some(m)` - if the inversion was successful, where `m` is the inverted matrix * * `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) * * `None` - if the inversion was unsuccessful (because the matrix was not invertable)
*/ */
pure fn inverse(&self) -> Option<self>; pure fn inverse(&self) -> Option<Self>;
/** /**
* # Return value * # Return value
* *
* The transposed matrix * The transposed matrix
*/ */
pure fn transpose(&self) -> self; pure fn transpose(&self) -> Self;
/** /**
* Check to see if the matrix is an identity matrix * Check to see if the matrix is an identity matrix
@ -184,11 +184,11 @@ pub trait Matrix<T,V>: Index<uint, V> Eq Neg<self> {
*/ */
pub trait Matrix2<T,V>: Matrix<T,V> { pub trait Matrix2<T,V>: Matrix<T,V> {
static pure fn new(c0r0: T, c0r1: T, 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<T>; pure fn to_mat3(&self) -> Mat3<T>;
@ -201,23 +201,23 @@ pub trait Matrix2<T,V>: Matrix<T,V> {
pub trait Matrix3<T,V>: Matrix<T,V> { pub trait Matrix3<T,V>: Matrix<T,V> {
static pure fn new(c0r0:T, c0r1:T, c0r2:T, static pure fn new(c0r0:T, c0r1:T, c0r2:T,
c1r0:T, c1r1:T, c1r2: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<T>) -> self; static pure fn from_angle_axis(radians: T, axis: &Vec3<T>) -> 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<T>, up: &Vec3<T>) -> self; static pure fn look_at(dir: &Vec3<T>, up: &Vec3<T>) -> Self;
pure fn to_mat4(&self) -> Mat4<T>; pure fn to_mat4(&self) -> Mat4<T>;
@ -231,9 +231,9 @@ pub trait Matrix4<T,V>: Matrix<T,V> {
static pure fn new(c0r0: T, c0r1: T, c0r2: T, c0r3: T, static pure fn new(c0r0: T, c0r1: T, c0r2: T, c0r3: T,
c1r0: T, c1r1: T, c1r2: T, c1r3: T, c1r0: T, c1r1: T, c1r2: T, c1r3: T,
c2r0: T, c2r1: T, c2r2: T, c2r3: 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<T,V>: Matrix<T,V> {
/** /**
* Sets the matrix to `other` * Sets the matrix to `other`
*/ */
fn set(&mut self, other: &self); fn set(&mut self, other: &Self);
/** /**
* Sets the matrix to the identity matrix * Sets the matrix to the identity matrix
@ -280,12 +280,12 @@ pub trait MutableMatrix<T,V>: Matrix<T,V> {
/** /**
* Add the matrix `other` to `self` * 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` * 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 * Sets the matrix to its inverse

View file

@ -21,7 +21,7 @@ pub trait Vector<T>: Index<uint, T> Eq {
/** /**
* Construct the vector from a single value, copying it to each component * 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 * # Return value
@ -47,21 +47,21 @@ pub trait MutableVector<T>: Vector<T> {
* A generic 2-dimensional vector * A generic 2-dimensional vector
*/ */
pub trait Vector2<T>: Vector<T> { pub trait Vector2<T>: Vector<T> {
static pure fn new(x: T, y: T) -> self; static pure fn new(x: T, y: T) -> Self;
} }
/** /**
* A generic 3-dimensional vector * A generic 3-dimensional vector
*/ */
pub trait Vector3<T>: Vector<T> { pub trait Vector3<T>: Vector<T> {
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 * A generic 4-dimensional vector
*/ */
pub trait Vector4<T>: Vector<T> { pub trait Vector4<T>: Vector<T> {
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<T>: Vector<T> Neg<self> {
* *
* A vector with each component set to one * A vector with each component set to one
*/ */
static pure fn identity() -> self; static pure fn identity() -> Self;
/** /**
* The null vector * The null vector
@ -84,7 +84,7 @@ pub trait NumericVector<T>: Vector<T> Neg<self> {
* *
* A vector with each component set to zero * A vector with each component set to zero
*/ */
static pure fn zero() -> self; static pure fn zero() -> Self;
/** /**
* # Return value * # Return value
@ -98,82 +98,82 @@ pub trait NumericVector<T>: Vector<T> Neg<self> {
* *
* The scalar multiplication of the vector and `value` * 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 * # Return value
* *
* The scalar division of the vector and `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 * Component-wise vector addition
*/ */
pure fn add_v(&self, other: &self) -> self; pure fn add_v(&self, other: &Self) -> Self;
/** /**
* Component-wise vector subtraction * Component-wise vector subtraction
*/ */
pure fn sub_v(&self, other: &self) -> self; pure fn sub_v(&self, other: &Self) -> Self;
/** /**
* Component-wise vector multiplication * Component-wise vector multiplication
*/ */
pure fn mul_v(&self, other: &self) -> self; pure fn mul_v(&self, other: &Self) -> Self;
/** /**
* Component-wise vector division * Component-wise vector division
*/ */
pure fn div_v(&self, other: &self) -> self; pure fn div_v(&self, other: &Self) -> Self;
/** /**
* # Return value * # Return value
* *
* The dot product of the vector and `other` * 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 * A 2-dimensional vector with numeric components
*/ */
pub trait NumericVector2<T>: NumericVector<T> { pub trait NumericVector2<T>: NumericVector<T> {
static pure fn unit_x() -> self; static pure fn unit_x() -> Self;
static pure fn unit_y() -> self; static pure fn unit_y() -> Self;
/** /**
* # Return value * # Return value
* *
* The perp dot product of the vector and `other` * 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 * A 3-dimensional vector with numeric components
*/ */
pub trait NumericVector3<T>: NumericVector<T> { pub trait NumericVector3<T>: NumericVector<T> {
static pure fn unit_x() -> self; static pure fn unit_x() -> Self;
static pure fn unit_y() -> self; static pure fn unit_y() -> Self;
static pure fn unit_z() -> self; static pure fn unit_z() -> Self;
/** /**
* # Return value * # Return value
* *
* The cross product of the vector and `other` * 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 * A 4-dimensional vector with numeric components
*/ */
pub trait NumericVector4<T>: NumericVector<T> { pub trait NumericVector4<T>: NumericVector<T> {
static pure fn unit_x() -> self; static pure fn unit_x() -> Self;
static pure fn unit_y() -> self; static pure fn unit_y() -> Self;
static pure fn unit_z() -> self; static pure fn unit_z() -> Self;
static pure fn unit_w() -> self; static pure fn unit_w() -> Self;
} }
/** /**
@ -199,22 +199,22 @@ pub trait MutableNumericVector<T>: MutableVector<&self/T>
/** /**
* Set the vector to the component-wise vector sum * 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 * 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 * 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 * 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<T>: MutableNumericVector<&self/T> {
/** /**
* Set to the cross product of the vector and `other` * 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<H> { pub trait ToHomogeneous<H> {
@ -268,33 +268,33 @@ pub trait EuclideanVector<T>: NumericVector<T> {
* *
* The squared distance between the vector and `other`. * The squared distance between the vector and `other`.
*/ */
pure fn distance2(&self, other: &self) -> T; pure fn distance2(&self, other: &Self) -> T;
/** /**
* # Return value * # Return value
* *
* The distance between the vector and `other` * The distance between the vector and `other`
*/ */
pure fn distance(&self, other: &self) -> T; pure fn distance(&self, other: &Self) -> T;
/** /**
* # Return value * # Return value
* *
* The angle between the vector and `other` in radians * 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 * # Return value
* *
* The normalized vector * The normalized vector
*/ */
pure fn normalize(&self) -> self; pure fn normalize(&self) -> Self;
/** /**
* Set the length of the vector whilst preserving the direction * 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` * Linearly intoperlate between the vector and `other`
@ -303,7 +303,7 @@ pub trait EuclideanVector<T>: NumericVector<T> {
* *
* The intoperlated vector * 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<T>: MutableNumericVector<&self/T>
/** /**
* Linearly intoperlate the vector towards `other` * 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<T, BoolVec>: Vector<T> {
/** /**
* Component-wise compare of `self < other` * 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` * 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` * 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` * 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<T, BoolVec>: Vector<T> {
/** /**
* Component-wise compare of `self == other` * 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` * 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<bool> {
* *
* the component-wise logical complement * the component-wise logical complement
*/ */
pure fn not(&self) -> self; pure fn not(&self) -> Self;
} }