cgmath/src/vector.rs

615 lines
14 KiB
Rust
Raw Normal View History

2012-10-29 05:47:53 +00:00
use cast::transmute;
2012-11-01 01:34:38 +00:00
use cmp::{Eq, Ord};
2012-11-01 14:01:06 +00:00
use vec::raw::buf_as_slice;
use ptr::to_unsafe_ptr;
2012-10-29 05:47:53 +00:00
use std::cmp::FuzzyEq;
2012-11-01 01:34:38 +00:00
use funs::exp::Exp;
use ncast::*;
2012-11-01 01:34:38 +00:00
use math::*;
2012-09-07 10:48:47 +00:00
2012-11-05 02:39:58 +00:00
// GLSL equivalent type aliases
2012-11-06 02:23:06 +00:00
pub type vec2 = Vec2<f32>; /// a two-component single-precision floating-point vector
pub type vec3 = Vec3<f32>; /// a three-component single-precision floating-point vector
pub type vec4 = Vec4<f32>; /// a four-component single-precision floating-point vector
2012-11-05 02:39:58 +00:00
2012-11-06 02:23:06 +00:00
pub type dvec2 = Vec2<f64>; /// a two-component double-precision floating-point vector
pub type dvec3 = Vec3<f64>; /// a three-component double-precision floating-point vector
pub type dvec4 = Vec4<f64>; /// a four-component double-precision floating-point vector
2012-11-05 02:39:58 +00:00
2012-11-06 02:23:06 +00:00
pub type bvec2 = Vec2<bool>; /// a two-component Boolean vector
pub type bvec3 = Vec3<bool>; /// a three-component Boolean vector
pub type bvec4 = Vec4<bool>; /// a four-component Boolean vector
2012-11-05 02:39:58 +00:00
2012-11-06 02:23:06 +00:00
pub type ivec2 = Vec2<i32>; /// a two-component signed integer vector
pub type ivec3 = Vec3<i32>; /// a three-component signed integer vector
pub type ivec4 = Vec4<i32>; /// a four-component signed integer vector
2012-11-05 02:39:58 +00:00
2012-11-06 02:23:06 +00:00
pub type uvec2 = Vec2<u32>; /// a two-component unsigned integer vector
pub type uvec3 = Vec3<u32>; /// a three-component unsigned integer vector
pub type uvec4 = Vec4<u32>; /// a four-component unsigned integer vector
2012-11-05 02:39:58 +00:00
pub trait Vector {
2012-09-08 05:54:31 +00:00
static pure fn dim() -> uint;
}
pub trait NumericVector<T> {
2012-10-30 04:35:02 +00:00
pure fn mul_t(value: T) -> self;
pure fn div_t(value: T) -> self;
2012-09-07 10:48:47 +00:00
2012-10-01 06:23:49 +00:00
pure fn add_v(other: &self) -> self;
pure fn sub_v(other: &self) -> self;
2012-09-07 10:48:47 +00:00
2012-10-01 06:23:49 +00:00
pure fn dot(other: &self) -> T;
}
pub trait GeometricVector<T> {
2012-11-05 07:40:31 +00:00
pure fn length2() -> T;
pure fn length() -> T;
2012-09-07 10:48:47 +00:00
pure fn normalize() -> self;
2012-11-08 07:05:53 +00:00
pure fn lerp(other: &self, amount: T) -> self;
2012-09-07 10:48:47 +00:00
}
pub trait Vector2<T> {
2012-11-06 02:01:39 +00:00
// static pure fn new(x: T, y: T) -> self;
// static pure fn from_value(value: T) -> self;
}
2012-09-29 08:41:48 +00:00
pub trait Vector3<T> {
2012-11-06 02:01:39 +00:00
// static pure fn new(x: T, y: T, z: T) -> self;
// static pure fn from_value(value: T) -> self;
2012-11-05 03:25:11 +00:00
pure fn cross(other: &self) -> self;
2012-09-07 10:48:47 +00:00
}
2012-11-05 03:25:11 +00:00
pub trait Vector4<T> {
// pub static pure fn new(x: T, y: T, z: T, w: T) -> self;
// pub static pure fn from_value(value: T) -> self;
}
2012-09-07 10:48:47 +00:00
2012-09-07 10:48:47 +00:00
//
2012-09-07 18:49:52 +00:00
// Vec2
2012-09-07 10:48:47 +00:00
//
2012-11-01 01:34:38 +00:00
pub struct Vec2<T> { x: T, y: T }
2012-09-07 10:48:47 +00:00
2012-10-29 14:11:27 +00:00
pub mod Vec2 {
2012-11-01 07:41:42 +00:00
#[inline(always)]
2012-11-01 14:01:06 +00:00
pub pure fn new<T>(x: T, y: T) -> Vec2<T> {
Vec2 { x: move x, y: move y }
2012-11-01 07:41:42 +00:00
}
2012-11-05 00:05:16 +00:00
#[inline(always)]
pub pure fn from_value<T:Copy>(value: T) -> Vec2<T> {
Vec2::new(value, value)
}
2012-11-04 04:39:33 +00:00
#[inline(always)]
pub pure fn zero<T:Copy NumCast>() -> Vec2<T> {
let _0 = cast(0);
Vec2::new(_0, _0)
}
#[inline(always)]
pub pure fn unit_x<T:Copy NumCast>() -> Vec2<T> {
let _0 = cast(0);
let _1 = cast(1);
Vec2::new(_1, _0)
}
#[inline(always)]
pub pure fn unit_y<T:Copy NumCast>() -> Vec2<T> {
let _0 = cast(0);
let _1 = cast(1);
Vec2::new(_0, _1)
}
#[inline(always)]
pub pure fn identity<T:Copy NumCast>() -> Vec2<T> {
let _1 = cast(1);
Vec2::new(_1, _1)
}
2012-10-29 14:11:27 +00:00
}
pub impl<T> Vec2<T>: Vector {
#[inline(always)]
2012-09-08 05:54:31 +00:00
static pure fn dim() -> uint { 2 }
}
2012-09-07 10:48:47 +00:00
pub impl<T:Copy Num> Vec2<T>: NumericVector<T> {
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn mul_t(value: T) -> Vec2<T> {
2012-11-01 07:41:42 +00:00
Vec2::new(self[0] * value,
self[1] * value)
2012-09-07 10:48:47 +00:00
}
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn div_t(value: T) -> Vec2<T> {
2012-11-01 07:41:42 +00:00
Vec2::new(self[0] / value,
self[1] / value)
2012-09-07 10:48:47 +00:00
}
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn add_v(other: &Vec2<T>) -> Vec2<T> {
2012-11-01 07:41:42 +00:00
Vec2::new(self[0] + other[0],
self[1] + other[1])
2012-09-07 10:48:47 +00:00
}
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn sub_v(other: &Vec2<T>) -> Vec2<T> {
2012-11-01 07:41:42 +00:00
Vec2::new(self[0] - other[0],
self[1] - other[1])
2012-09-07 10:48:47 +00:00
}
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn dot(other: &Vec2<T>) -> T {
2012-09-07 15:18:18 +00:00
self[0] * other[0] +
self[1] * other[1]
}
}
2012-09-07 15:18:18 +00:00
pub impl<T:Copy Num NumCast Exp> Vec2<T>: GeometricVector<T> {
#[inline(always)]
2012-11-05 07:40:31 +00:00
pure fn length2() -> T {
2012-09-07 10:48:47 +00:00
self[0] * self[0] +
self[1] * self[1]
}
#[inline(always)]
2012-11-05 07:40:31 +00:00
pure fn length() -> T {
self.length2().sqrt()
2012-09-07 10:48:47 +00:00
}
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn normalize() -> Vec2<T> {
let mut n: T = cast(1);
2012-11-05 07:40:31 +00:00
n /= self.length();
2012-10-30 04:35:02 +00:00
return self.mul_t(n);
2012-09-07 10:48:47 +00:00
}
2012-09-07 18:45:07 +00:00
#[inline(always)]
2012-11-08 07:05:53 +00:00
pure fn lerp(other: &Vec2<T>, amount: T) -> Vec2<T> {
self.add_v(&other.sub_v(&self).mul_t(amount))
2012-09-07 18:45:07 +00:00
}
2012-11-01 01:34:38 +00:00
}
pub impl<T:Copy> Vec2<T>: Index<uint, T> {
#[inline(always)]
pure fn index(i: uint) -> T {
unsafe { do buf_as_slice(
transmute::<*Vec2<T>, *T>(
to_unsafe_ptr(&self)), 2) |slice| { slice[i] }
}
}
}
pub impl<T:Copy Neg<T>> Vec2<T>: Neg<Vec2<T>> {
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn neg() -> Vec2<T> {
2012-11-01 07:41:42 +00:00
Vec2::new(-self[0], -self[1])
2012-09-29 10:25:49 +00:00
}
}
2012-11-01 01:34:38 +00:00
// TODO: make work for T:Integer
pub impl<T:Copy FuzzyEq> Vec2<T>: Eq {
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn eq(other: &Vec2<T>) -> bool {
2012-09-29 10:25:49 +00:00
self.fuzzy_eq(other)
}
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn ne(other: &Vec2<T>) -> bool {
2012-09-29 10:25:49 +00:00
!(self == *other)
}
}
2012-11-01 01:34:38 +00:00
impl<T:Copy Eq> Vec2<T>: ExactEq {
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn exact_eq(other: &Vec2<T>) -> bool {
2012-10-30 02:45:18 +00:00
self[0] == other[0] &&
self[1] == other[1]
}
}
2012-11-01 01:34:38 +00:00
pub impl<T:Copy FuzzyEq> Vec2<T>: FuzzyEq {
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn fuzzy_eq(other: &Vec2<T>) -> bool {
2012-09-29 10:25:49 +00:00
self[0].fuzzy_eq(&other[0]) &&
self[1].fuzzy_eq(&other[1])
}
}
2012-11-01 01:34:38 +00:00
pub impl<T:Copy> Vec2<T>: ToPtr<T> {
2012-10-30 03:24:50 +00:00
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn to_ptr() -> *T {
2012-10-30 03:24:50 +00:00
to_unsafe_ptr(&self[0])
}
}
2012-09-07 10:48:47 +00:00
//
2012-09-07 18:49:52 +00:00
// Vec3
2012-09-07 10:48:47 +00:00
//
2012-11-01 01:34:38 +00:00
pub struct Vec3<T> { x: T, y: T, z: T }
2012-09-07 10:48:47 +00:00
2012-10-29 14:11:27 +00:00
pub mod Vec3 {
2012-11-01 07:41:42 +00:00
#[inline(always)]
2012-11-01 14:01:06 +00:00
pub pure fn new<T>(x: T, y: T, z: T) -> Vec3<T> {
Vec3 { x: move x, y: move y, z: move z }
2012-11-01 07:41:42 +00:00
}
2012-11-04 04:39:33 +00:00
2012-11-05 00:05:16 +00:00
#[inline(always)]
pub pure fn from_value<T:Copy>(value: T) -> Vec3<T> {
Vec3::new(value, value, value)
}
2012-11-04 04:39:33 +00:00
#[inline(always)]
pub pure fn zero<T:Copy NumCast>() -> Vec3<T> {
let _0 = cast(0);
Vec3::new(_0, _0, _0)
}
#[inline(always)]
pub pure fn unit_x<T:Copy NumCast>() -> Vec3<T> {
let _0 = cast(0);
let _1 = cast(1);
Vec3::new(_1, _0, _0)
}
#[inline(always)]
pub pure fn unit_y<T:Copy NumCast>() -> Vec3<T> {
let _0 = cast(0);
let _1 = cast(1);
Vec3::new(_0, _1, _0)
}
#[inline(always)]
pub pure fn unit_z<T:Copy NumCast>() -> Vec3<T> {
let _0 = cast(0);
let _1 = cast(1);
Vec3::new(_0, _0, _1)
}
#[inline(always)]
pub pure fn identity<T:Copy NumCast>() -> Vec3<T> {
let _1 = cast(1);
Vec3::new(_1, _1, _1)
}
2012-10-29 14:11:27 +00:00
}
2012-11-01 01:34:38 +00:00
pub impl<T:Copy Num> Vec3<T>: Vector3<T> {
#[inline(always)]
pure fn cross(other: &Vec3<T>) -> Vec3<T> {
2012-11-01 07:41:42 +00:00
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]))
2012-09-07 10:48:47 +00:00
}
}
pub impl<T> Vec3<T>: Vector {
#[inline(always)]
2012-09-08 05:54:31 +00:00
static pure fn dim() -> uint { 3 }
}
pub impl<T:Copy Num> Vec3<T>: NumericVector<T> {
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn mul_t(value: T) -> Vec3<T> {
2012-11-01 07:41:42 +00:00
Vec3::new(self[0] * value,
self[1] * value,
self[2] * value)
2012-09-07 10:48:47 +00:00
}
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn div_t(value: T) -> Vec3<T> {
2012-11-01 07:41:42 +00:00
Vec3::new(self[0] / value,
self[1] / value,
self[2] / value)
2012-09-07 10:48:47 +00:00
}
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn add_v(other: &Vec3<T>) -> Vec3<T>{
2012-11-01 07:41:42 +00:00
Vec3::new(self[0] + other[0],
self[1] + other[1],
self[2] + other[2])
2012-09-07 10:48:47 +00:00
}
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn sub_v(other: &Vec3<T>) -> Vec3<T>{
2012-11-01 07:41:42 +00:00
Vec3::new(self[0] - other[0],
self[1] - other[1],
self[2] - other[2])
2012-09-07 10:48:47 +00:00
}
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn dot(other: &Vec3<T>) -> T {
2012-09-07 15:18:18 +00:00
self[0] * other[0] +
self[1] * other[1] +
self[2] * other[2]
}
}
pub impl<T:Copy Num NumCast Exp> Vec3<T>: GeometricVector<T> {
#[inline(always)]
2012-11-05 07:40:31 +00:00
pure fn length2() -> T {
2012-09-07 10:48:47 +00:00
self[0] * self[0] +
self[1] * self[1] +
self[2] * self[2]
}
#[inline(always)]
2012-11-05 07:40:31 +00:00
pure fn length() -> T {
self.length2().sqrt()
2012-09-07 10:48:47 +00:00
}
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn normalize() -> Vec3<T> {
let mut n: T = cast(1);
2012-11-05 07:40:31 +00:00
n /= self.length();
2012-10-30 04:35:02 +00:00
return self.mul_t(n);
2012-09-07 10:48:47 +00:00
}
2012-09-07 18:45:07 +00:00
#[inline(always)]
2012-11-08 07:05:53 +00:00
pure fn lerp(other: &Vec3<T>, amount: T) -> Vec3<T> {
self.add_v(&other.sub_v(&self).mul_t(amount))
2012-09-07 18:45:07 +00:00
}
2012-11-01 01:34:38 +00:00
}
pub impl<T:Copy> Vec3<T>: Index<uint, T> {
#[inline(always)]
pure fn index(i: uint) -> T {
unsafe { do buf_as_slice(
transmute::<*Vec3<T>, *T>(
to_unsafe_ptr(&self)), 3) |slice| { slice[i] }
}
}
}
pub impl<T:Copy Neg<T>> Vec3<T>: Neg<Vec3<T>> {
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn neg() -> Vec3<T> {
2012-11-01 07:41:42 +00:00
Vec3::new(-self[0], -self[1], -self[2])
2012-09-29 10:25:49 +00:00
}
}
2012-11-01 01:34:38 +00:00
// TODO: make work for T:Integer
pub impl<T:Copy FuzzyEq> Vec3<T>: Eq {
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn eq(other: &Vec3<T>) -> bool {
2012-09-29 10:25:49 +00:00
self.fuzzy_eq(other)
}
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn ne(other: &Vec3<T>) -> bool {
2012-09-29 10:25:49 +00:00
!(self == *other)
}
}
2012-11-01 01:34:38 +00:00
pub impl<T:Copy Eq> Vec3<T>: ExactEq {
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn exact_eq(other: &Vec3<T>) -> bool {
2012-10-30 02:45:18 +00:00
self[0] == other[0] &&
self[1] == other[1] &&
self[2] == other[2]
}
}
2012-11-01 01:34:38 +00:00
pub impl<T:Copy FuzzyEq> Vec3<T>: FuzzyEq {
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn fuzzy_eq(other: &Vec3<T>) -> bool {
2012-09-29 10:25:49 +00:00
self[0].fuzzy_eq(&other[0]) &&
self[1].fuzzy_eq(&other[1]) &&
self[2].fuzzy_eq(&other[2])
}
}
2012-11-01 01:34:38 +00:00
pub impl<T:Copy> Vec3<T>: ToPtr<T> {
2012-10-30 03:24:50 +00:00
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn to_ptr() -> *T {
2012-10-30 03:24:50 +00:00
to_unsafe_ptr(&self[0])
}
}
2012-09-07 10:48:47 +00:00
//
2012-09-07 18:49:52 +00:00
// Vec4
2012-09-07 10:48:47 +00:00
//
2012-11-01 01:34:38 +00:00
pub struct Vec4<T> { x: T, y: T, z: T, w: T }
2012-09-07 10:48:47 +00:00
2012-10-29 14:11:27 +00:00
pub mod Vec4 {
2012-11-01 07:41:42 +00:00
#[inline(always)]
2012-11-01 14:01:06 +00:00
pub pure fn new<T>(x: T, y: T, z: T, w: T) -> Vec4<T> {
Vec4 { x: move x, y: move y, z: move z, w: move w }
2012-11-01 07:41:42 +00:00
}
2012-11-04 04:39:33 +00:00
2012-11-05 00:05:16 +00:00
#[inline(always)]
pub pure fn from_value<T:Copy>(value: T) -> Vec4<T> {
Vec4::new(value, value, value, value)
}
2012-11-04 04:39:33 +00:00
#[inline(always)]
pub pure fn zero<T:Copy NumCast>() -> Vec4<T> {
let _0 = cast(0);
Vec4::new(_0, _0, _0, _0)
}
#[inline(always)]
pub pure fn unit_x<T:Copy NumCast>() -> Vec4<T> {
let _0 = cast(0);
let _1 = cast(1);
Vec4::new(_1, _0, _0, _0)
}
#[inline(always)]
pub pure fn unit_y<T:Copy NumCast>() -> Vec4<T> {
let _0 = cast(0);
let _1 = cast(1);
Vec4::new(_0, _1, _0, _0)
}
#[inline(always)]
pub pure fn unit_z<T:Copy NumCast>() -> Vec4<T> {
let _0 = cast(0);
let _1 = cast(1);
Vec4::new(_0, _0, _1, _0)
}
#[inline(always)]
pub pure fn unit_w<T:Copy NumCast>() -> Vec4<T> {
let _0 = cast(0);
let _1 = cast(1);
Vec4::new(_0, _0, _0, _1)
}
#[inline(always)]
pub pure fn identity<T:Copy NumCast>() -> Vec4<T> {
let _1 = cast(1);
Vec4::new(_1, _1, _1, _1)
}
2012-10-29 14:11:27 +00:00
}
2012-09-07 10:48:47 +00:00
pub impl<T> Vec4<T>: Vector {
#[inline(always)]
2012-09-08 05:54:31 +00:00
static pure fn dim() -> uint { 4 }
}
pub impl<T:Copy Num> Vec4<T>: NumericVector<T> {
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn mul_t(value: T) -> Vec4<T> {
2012-11-01 07:41:42 +00:00
Vec4::new(self[0] * value,
self[1] * value,
self[2] * value,
self[3] * value)
2012-09-07 10:48:47 +00:00
}
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn div_t(value: T) -> Vec4<T> {
2012-11-01 07:41:42 +00:00
Vec4::new(self[0] / value,
self[1] / value,
self[2] / value,
self[3] / value)
2012-09-07 10:48:47 +00:00
}
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn add_v(other: &Vec4<T>) -> Vec4<T> {
2012-11-01 07:41:42 +00:00
Vec4::new(self[0] + other[0],
self[1] + other[1],
self[2] + other[2],
self[3] + other[3])
2012-09-07 10:48:47 +00:00
}
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn sub_v(other: &Vec4<T>) -> Vec4<T> {
2012-11-01 07:41:42 +00:00
Vec4::new(self[0] - other[0],
self[1] - other[1],
self[2] - other[2],
self[3] - other[3])
2012-09-07 10:48:47 +00:00
}
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn dot(other: &Vec4<T>) -> T {
2012-09-07 15:18:18 +00:00
self[0] * other[0] +
self[1] * other[1] +
self[2] * other[2] +
self[3] * other[3]
}
}
pub impl<T:Copy Num NumCast Exp> Vec4<T>: GeometricVector<T> {
#[inline(always)]
2012-11-05 07:40:31 +00:00
pure fn length2() -> T {
2012-09-07 10:48:47 +00:00
self[0] * self[0] +
self[1] * self[1] +
self[2] * self[2] +
2012-09-07 18:45:07 +00:00
self[3] * self[3]
2012-09-07 10:48:47 +00:00
}
#[inline(always)]
2012-11-05 07:40:31 +00:00
pure fn length() -> T {
self.length2().sqrt()
2012-09-07 10:48:47 +00:00
}
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn normalize() -> Vec4<T> {
let mut n: T = cast(1);
2012-11-05 07:40:31 +00:00
n /= self.length();
2012-10-30 04:35:02 +00:00
return self.mul_t(n);
2012-09-07 10:48:47 +00:00
}
2012-09-07 18:45:07 +00:00
#[inline(always)]
2012-11-08 07:05:53 +00:00
pure fn lerp(other: &Vec4<T>, amount: T) -> Vec4<T> {
self.add_v(&other.sub_v(&self).mul_t(amount))
2012-09-07 18:45:07 +00:00
}
2012-11-01 01:34:38 +00:00
}
pub impl<T:Copy> Vec4<T>: Index<uint, T> {
#[inline(always)]
pure fn index(i: uint) -> T {
2012-11-09 07:29:25 +00:00
unsafe { do buf_as_slice(
transmute::<*Vec4<T>, *T>(
to_unsafe_ptr(&self)), 4) |slice| { slice[i] }
2012-11-01 01:34:38 +00:00
}
}
}
pub impl<T:Copy Neg<T>> Vec4<T>: Neg<Vec4<T>> {
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn neg() -> Vec4<T> {
2012-11-01 07:41:42 +00:00
Vec4::new(-self[0], -self[1], -self[2], -self[3])
2012-09-29 10:25:49 +00:00
}
}
2012-11-01 01:34:38 +00:00
pub impl<T:Copy FuzzyEq> Vec4<T>: Eq {
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn eq(other: &Vec4<T>) -> bool {
2012-09-29 10:25:49 +00:00
self.fuzzy_eq(other)
}
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn ne(other: &Vec4<T>) -> bool {
2012-09-29 10:25:49 +00:00
!(self == *other)
}
}
2012-11-01 01:34:38 +00:00
// TODO: make work for T:Integer
pub impl<T:Copy Eq> Vec4<T>: ExactEq {
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn exact_eq(other: &Vec4<T>) -> bool {
2012-10-30 02:45:18 +00:00
self[0] == other[0] &&
self[1] == other[1] &&
self[2] == other[2] &&
self[3] == other[3]
}
}
2012-11-01 01:34:38 +00:00
pub impl<T:Copy FuzzyEq> Vec4<T>: FuzzyEq {
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn fuzzy_eq(other: &Vec4<T>) -> bool {
2012-09-29 10:25:49 +00:00
self[0].fuzzy_eq(&other[0]) &&
self[1].fuzzy_eq(&other[1]) &&
self[2].fuzzy_eq(&other[2]) &&
self[3].fuzzy_eq(&other[3])
}
}
2012-11-01 01:34:38 +00:00
pub impl<T:Copy> Vec4<T>: ToPtr<T> {
2012-10-30 03:24:50 +00:00
#[inline(always)]
2012-11-01 01:34:38 +00:00
pure fn to_ptr() -> *T {
2012-10-30 03:24:50 +00:00
to_unsafe_ptr(&self[0])
}
2012-09-07 10:48:47 +00:00
}