Add comments

This commit is contained in:
Brendan Zabarauskas 2012-11-20 21:37:10 +10:00
parent 16e687c25e
commit a030f4cf19
3 changed files with 31 additions and 5 deletions

View file

@ -13,7 +13,9 @@ use num::default_eq::DefaultEq;
use quat::{Quat, ToQuat}; use quat::{Quat, ToQuat};
use vec::{NumericVector, Vec2, Vec3, Vec4}; use vec::{NumericVector, Vec2, Vec3, Vec4};
///
/// The base Matrix trait
///
pub trait Matrix<T, Col, Row>: Dimensional<T>, Eq, DefaultEq { pub trait Matrix<T, Col, Row>: Dimensional<T>, Eq, DefaultEq {
pure fn rows() -> uint; pure fn rows() -> uint;
pure fn cols() -> uint; pure fn cols() -> uint;
@ -24,6 +26,9 @@ pub trait Matrix<T, Col, Row>: Dimensional<T>, Eq, DefaultEq {
pure fn row(i: uint) -> Row; pure fn row(i: uint) -> Row;
} }
///
/// A matrix with numeric elements
///
pub trait NumericMatrix<T, Col, Row>: Matrix<T, Col, Row>, Neg<self> { pub trait NumericMatrix<T, Col, Row>: Matrix<T, Col, Row>, Neg<self> {
static pure fn zero() -> self; static pure fn zero() -> self;
@ -33,6 +38,9 @@ pub trait NumericMatrix<T, Col, Row>: Matrix<T, Col, Row>, Neg<self> {
pure fn sub_m(other: &self) -> self; pure fn sub_m(other: &self) -> self;
} }
///
/// A square matrix with numeric elements
///
pub trait NumericMatrix_NxN<T, ColRow>: NumericMatrix<T, ColRow, ColRow> { pub trait NumericMatrix_NxN<T, ColRow>: NumericMatrix<T, ColRow, ColRow> {
static pure fn identity() -> self; static pure fn identity() -> self;
@ -50,15 +58,18 @@ pub trait NumericMatrix_NxN<T, ColRow>: NumericMatrix<T, ColRow, ColRow> {
pure fn is_invertible() -> bool; pure fn is_invertible() -> bool;
} }
/// A 2 x 2 square matrix with numeric elements
pub trait NumericMatrix2x2<T>: NumericMatrix_NxN<T, Mat2<T>> { pub trait NumericMatrix2x2<T>: NumericMatrix_NxN<T, Mat2<T>> {
pure fn to_Mat3() -> Mat3<T>; pure fn to_Mat3() -> Mat3<T>;
pure fn to_Mat4() -> Mat4<T>; pure fn to_Mat4() -> Mat4<T>;
} }
/// A 3 x 3 square matrix with numeric elements
pub trait NumericMatrix3x3<T>: NumericMatrix_NxN<T, Mat3<T>> { pub trait NumericMatrix3x3<T>: NumericMatrix_NxN<T, Mat3<T>> {
pure fn to_Mat4() -> Mat4<T>; pure fn to_Mat4() -> Mat4<T>;
} }
/// A 4 x 4 square matrix with numeric elements
pub trait NumericMatrix4x4<T>: NumericMatrix_NxN<T, Mat4<T>> { pub trait NumericMatrix4x4<T>: NumericMatrix_NxN<T, Mat4<T>> {
} }

View file

@ -15,9 +15,9 @@ use num::default_eq::DefaultEq;
use vec::Vec3; use vec::Vec3;
// ///
// Quaternion /// The base quaternion trait
// ///
pub trait Quaternion<T>: Dimensional<T>, Eq, DefaultEq, Neg<self> { pub trait Quaternion<T>: Dimensional<T>, Eq, DefaultEq, Neg<self> {
static pure fn identity() -> self; static pure fn identity() -> self;
static pure fn zero() -> self; static pure fn zero() -> self;

View file

@ -10,23 +10,32 @@ use funs::exp::Exp;
use num::cast::*; use num::cast::*;
use num::default_eq::DefaultEq; use num::default_eq::DefaultEq;
///
/// The base vector trait
///
pub trait Vector<T>: Dimensional<T>, Eq, DefaultEq { pub trait Vector<T>: Dimensional<T>, Eq, DefaultEq {
/// 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;
} }
// /// A 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 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 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;
// } // }
///
/// A vector with numeric components
///
pub trait NumericVector<T>: Vector<T>, Neg<self>{ pub trait NumericVector<T>: Vector<T>, Neg<self>{
static pure fn identity() -> self; static pure fn identity() -> self;
static pure fn zero() -> self; static pure fn zero() -> self;
@ -40,11 +49,13 @@ pub trait NumericVector<T>: Vector<T>, Neg<self>{
pure fn dot(other: &self) -> T; pure fn dot(other: &self) -> T;
} }
// /// A 2-dimensional vector with numeric components
// pub trait NumericVector2<T>: Vector<T> { // pub trait NumericVector2<T>: Vector<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;
// } // }
/// A 3-dimensional vector with numeric components
pub trait NumericVector3<T>: Vector<T> { pub trait NumericVector3<T>: Vector<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;
@ -52,6 +63,7 @@ pub trait NumericVector3<T>: Vector<T> {
pure fn cross(other: &self) -> self; pure fn cross(other: &self) -> self;
} }
// /// A 4-dimensional vector with numeric components
// pub trait NumericVector4<T>: Vector<T> { // pub trait NumericVector4<T>: Vector<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;
@ -59,6 +71,9 @@ pub trait NumericVector3<T>: Vector<T> {
// static pure fn unit_w() -> self; // static pure fn unit_w() -> self;
// } // }
///
/// A vector with geometric properties
///
pub trait GeometricVector<T>: NumericVector<T> { pub trait GeometricVector<T>: NumericVector<T> {
pure fn length2() -> T; pure fn length2() -> T;
pure fn length() -> T; pure fn length() -> T;