Add vector constants for axis units
This commit is contained in:
parent
ddc617c925
commit
9b69ea222c
5 changed files with 164 additions and 58 deletions
|
@ -22,8 +22,18 @@
|
|||
|
||||
use core::sys::size_of;
|
||||
|
||||
use vec::{
|
||||
Vector,
|
||||
NumericVector,
|
||||
NumericVector2,
|
||||
NumericVector3,
|
||||
NumericVector4,
|
||||
Vec2,
|
||||
Vec3,
|
||||
Vec4,
|
||||
};
|
||||
|
||||
use mat::{Matrix, Mat2, Mat3, Mat4};
|
||||
use vec::{Vector, NumericVector, Vec2, Vec3, Vec4};
|
||||
use quat::{/*Quaternion, */Quat};
|
||||
|
||||
use numeric::*;
|
||||
|
@ -61,6 +71,9 @@ pub impl vec2 {
|
|||
#[inline(always)] static pure fn identity() -> vec2 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> vec2 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> vec2 { NumericVector2::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> vec2 { NumericVector2::unit_y() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 2 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<vec2>() }
|
||||
}
|
||||
|
@ -71,6 +84,10 @@ pub impl vec3 {
|
|||
#[inline(always)] static pure fn identity() -> vec3 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> vec3 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> vec3 { NumericVector3::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> vec3 { NumericVector3::unit_y() }
|
||||
#[inline(always)] static pure fn unit_z() -> vec3 { NumericVector3::unit_z() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 3 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<vec3>() }
|
||||
}
|
||||
|
@ -81,6 +98,11 @@ pub impl vec4 {
|
|||
#[inline(always)] static pure fn identity() -> vec4 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> vec4 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> vec4 { NumericVector4::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> vec4 { NumericVector4::unit_y() }
|
||||
#[inline(always)] static pure fn unit_z() -> vec4 { NumericVector4::unit_z() }
|
||||
#[inline(always)] static pure fn unit_w() -> vec4 { NumericVector4::unit_w() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 4 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<vec4>() }
|
||||
}
|
||||
|
@ -92,6 +114,9 @@ pub impl dvec2 {
|
|||
#[inline(always)] static pure fn identity() -> dvec2 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dvec2 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> dvec2 { NumericVector2::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> dvec2 { NumericVector2::unit_y() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 2 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<dvec2>() }
|
||||
}
|
||||
|
@ -102,6 +127,10 @@ pub impl dvec3 {
|
|||
#[inline(always)] static pure fn identity() -> dvec3 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dvec3 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> dvec3 { NumericVector3::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> dvec3 { NumericVector3::unit_y() }
|
||||
#[inline(always)] static pure fn unit_z() -> dvec3 { NumericVector3::unit_z() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 3 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<dvec3>() }
|
||||
}
|
||||
|
@ -112,6 +141,11 @@ pub impl dvec4 {
|
|||
#[inline(always)] static pure fn identity() -> dvec4 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dvec4 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> dvec4 { NumericVector4::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> dvec4 { NumericVector4::unit_y() }
|
||||
#[inline(always)] static pure fn unit_z() -> dvec4 { NumericVector4::unit_z() }
|
||||
#[inline(always)] static pure fn unit_w() -> dvec4 { NumericVector4::unit_w() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 4 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<dvec4>() }
|
||||
}
|
||||
|
@ -150,6 +184,9 @@ pub impl ivec2 {
|
|||
#[inline(always)] static pure fn identity() -> ivec2 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> ivec2 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> ivec2 { NumericVector2::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> ivec2 { NumericVector2::unit_y() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 2 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<ivec2>() }
|
||||
}
|
||||
|
@ -160,6 +197,10 @@ pub impl ivec3 {
|
|||
#[inline(always)] static pure fn identity() -> ivec3 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> ivec3 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> ivec3 { NumericVector3::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> ivec3 { NumericVector3::unit_y() }
|
||||
#[inline(always)] static pure fn unit_z() -> ivec3 { NumericVector3::unit_z() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 3 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<ivec3>() }
|
||||
}
|
||||
|
@ -170,6 +211,11 @@ pub impl ivec4 {
|
|||
#[inline(always)] static pure fn identity() -> ivec4 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> ivec4 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> ivec4 { NumericVector4::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> ivec4 { NumericVector4::unit_y() }
|
||||
#[inline(always)] static pure fn unit_z() -> ivec4 { NumericVector4::unit_z() }
|
||||
#[inline(always)] static pure fn unit_w() -> ivec4 { NumericVector4::unit_w() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 4 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<ivec4>() }
|
||||
}
|
||||
|
@ -181,6 +227,9 @@ pub impl uvec2 {
|
|||
#[inline(always)] static pure fn identity() -> uvec2 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> uvec2 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> uvec2 { NumericVector2::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> uvec2 { NumericVector2::unit_y() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 2 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<uvec2>() }
|
||||
}
|
||||
|
@ -191,6 +240,10 @@ pub impl uvec3 {
|
|||
#[inline(always)] static pure fn identity() -> uvec3 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> uvec3 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> uvec3 { NumericVector3::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> uvec3 { NumericVector3::unit_y() }
|
||||
#[inline(always)] static pure fn unit_z() -> uvec3 { NumericVector3::unit_z() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 3 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<uvec3>() }
|
||||
}
|
||||
|
@ -201,6 +254,11 @@ pub impl uvec4 {
|
|||
#[inline(always)] static pure fn identity() -> uvec4 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> uvec4 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> uvec4 { NumericVector4::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> uvec4 { NumericVector4::unit_y() }
|
||||
#[inline(always)] static pure fn unit_z() -> uvec4 { NumericVector4::unit_z() }
|
||||
#[inline(always)] static pure fn unit_w() -> uvec4 { NumericVector4::unit_w() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 4 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<uvec4>() }
|
||||
}
|
||||
|
|
82
src/vec.rs
82
src/vec.rs
|
@ -135,6 +135,47 @@ pub trait NumericVector<T>: Vector<T> Neg<self> {
|
|||
pure fn dot(&self, other: &self) -> T;
|
||||
}
|
||||
|
||||
/**
|
||||
* A 2-dimensional vector with numeric components
|
||||
*/
|
||||
pub trait NumericVector2<T>: NumericVector<T> {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* A 3-dimensional vector with numeric components
|
||||
*/
|
||||
pub trait NumericVector3<T>: NumericVector<T> {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* A 4-dimensional vector with numeric components
|
||||
*/
|
||||
pub trait NumericVector4<T>: NumericVector<T> {
|
||||
static pure fn unit_x() -> self;
|
||||
static pure fn unit_y() -> self;
|
||||
static pure fn unit_z() -> self;
|
||||
static pure fn unit_w() -> self;
|
||||
}
|
||||
|
||||
/**
|
||||
* A mutable vector with numeric components
|
||||
*/
|
||||
|
@ -176,37 +217,6 @@ pub trait MutableNumericVector<T>: MutableVector<&self/T>
|
|||
fn div_self_v(&mut self, other: &self);
|
||||
}
|
||||
|
||||
/**
|
||||
* A 2-dimensional vector with numeric components
|
||||
*/
|
||||
pub trait NumericVector2<T>: NumericVector<T> {
|
||||
// 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* A 3-dimensional vector with numeric components
|
||||
*/
|
||||
pub trait NumericVector3<T>: NumericVector<T> {
|
||||
// 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* A mutable 3-dimensional vector with numeric components
|
||||
*/
|
||||
|
@ -217,16 +227,6 @@ pub trait MutableNumericVector3<T>: MutableNumericVector<&self/T> {
|
|||
fn cross_self(&mut self, other: &self);
|
||||
}
|
||||
|
||||
/**
|
||||
* A 4-dimensional vector with numeric components
|
||||
*/
|
||||
pub trait NumericVector4<T>: NumericVector<T> {
|
||||
// static pure fn unit_x() -> self;
|
||||
// static pure fn unit_y() -> self;
|
||||
// static pure fn unit_z() -> self;
|
||||
// static pure fn unit_w() -> self;
|
||||
}
|
||||
|
||||
pub trait ToHomogeneous<H> {
|
||||
/**
|
||||
* Convert to a homogenous coordinate
|
||||
|
|
24
src/vec2.rs
24
src/vec2.rs
|
@ -153,6 +153,23 @@ pub impl<T:Copy Number> Vec2<T>: Neg<Vec2<T>> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Number> Vec2<T>: NumericVector2<T> {
|
||||
#[inline(always)]
|
||||
static pure fn unit_x() -> Vec2<T> {
|
||||
Vec2::new(one(), zero())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn unit_y() -> Vec2<T> {
|
||||
Vec2::new(zero(), one())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn perp_dot(&self, other: &Vec2<T>) ->T {
|
||||
(self[0] * other[1]) - (self[1] * other[0])
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Number> Vec2<T>: MutableNumericVector<&self/T> {
|
||||
#[inline(always)]
|
||||
fn neg_self(&mut self) {
|
||||
|
@ -197,13 +214,6 @@ pub impl<T:Copy Number> Vec2<T>: MutableNumericVector<&self/T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Number> Vec2<T>: NumericVector2<T> {
|
||||
#[inline(always)]
|
||||
pure fn perp_dot(&self, other: &Vec2<T>) ->T {
|
||||
(self[0] * other[1]) - (self[1] * other[0])
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Number> Vec2<T>: ToHomogeneous<Vec3<T>> {
|
||||
#[inline(always)]
|
||||
pure fn to_homogeneous(&self) -> Vec3<T> {
|
||||
|
|
33
src/vec3.rs
33
src/vec3.rs
|
@ -164,6 +164,30 @@ pub impl<T:Copy Number> Vec3<T>: Neg<Vec3<T>> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Number> Vec3<T>: NumericVector3<T> {
|
||||
#[inline(always)]
|
||||
static pure fn unit_x() -> Vec3<T> {
|
||||
Vec3::new(one(), zero(), zero())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn unit_y() -> Vec3<T> {
|
||||
Vec3::new(zero(), one(), zero())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn unit_z() -> Vec3<T> {
|
||||
Vec3::new(zero(), zero(), one())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn cross(&self, other: &Vec3<T>) -> Vec3<T> {
|
||||
Vec3::new((self[1] * other[2]) - (self[2] * other[1]),
|
||||
(self[2] * other[0]) - (self[0] * other[2]),
|
||||
(self[0] * other[1]) - (self[1] * other[0]))
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Number> Vec3<T>: MutableNumericVector<&self/T> {
|
||||
#[inline(always)]
|
||||
fn neg_self(&mut self) {
|
||||
|
@ -215,15 +239,6 @@ pub impl<T:Copy Number> Vec3<T>: MutableNumericVector<&self/T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Number> Vec3<T>: NumericVector3<T> {
|
||||
#[inline(always)]
|
||||
pure fn cross(&self, other: &Vec3<T>) -> Vec3<T> {
|
||||
Vec3::new((self[1] * other[2]) - (self[2] * other[1]),
|
||||
(self[2] * other[0]) - (self[0] * other[2]),
|
||||
(self[0] * other[1]) - (self[1] * other[0]))
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Number> Vec3<T>: MutableNumericVector3<&self/T> {
|
||||
#[inline(always)]
|
||||
fn cross_self(&mut self, other: &Vec3<T>) {
|
||||
|
|
23
src/vec4.rs
23
src/vec4.rs
|
@ -12,6 +12,7 @@ use vec::{
|
|||
Vector,
|
||||
MutableVector,
|
||||
NumericVector,
|
||||
NumericVector4,
|
||||
MutableNumericVector,
|
||||
ToHomogeneous,
|
||||
EuclideanVector,
|
||||
|
@ -171,6 +172,28 @@ pub impl<T:Copy Number> Vec4<T>: Neg<Vec4<T>> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Number> Vec4<T>: NumericVector4<T> {
|
||||
#[inline(always)]
|
||||
static pure fn unit_x() -> Vec4<T> {
|
||||
Vec4::new(one(), zero(), zero(), zero())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn unit_y() -> Vec4<T> {
|
||||
Vec4::new(zero(), one(), zero(), zero())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn unit_z() -> Vec4<T> {
|
||||
Vec4::new(zero(), zero(), one(), zero())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn unit_w() -> Vec4<T> {
|
||||
Vec4::new(zero(), zero(), zero(), one())
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Number> Vec4<T>: MutableNumericVector<&self/T> {
|
||||
#[inline(always)]
|
||||
fn neg_self(&mut self) {
|
||||
|
|
Loading…
Reference in a new issue