Skip to content

Instantly share code, notes, and snippets.

@nikomatsakis
Created April 4, 2013 22:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikomatsakis/5314896 to your computer and use it in GitHub Desktop.
Save nikomatsakis/5314896 to your computer and use it in GitHub Desktop.
pub trait BaseVec: Index<uint,Self::T>
+ Eq {
type T;
static LEN: uint;
fn from_value(value: Self::T) -> Self;
}
pub trait BaseVec3: BaseVec {
fn new(x: Self::T, y: Self::T, z: Self::T) -> Self;
}
pub trait NumVec: BaseVec
+ Neg<Self> {
static IDENT: Self;
static ZERO: Self;
}
pub trait NumVec3: BaseVec
+ NumVec {
static UNIT_X: Self;
static UNIT_Y: Self;
static UNIT_Z: Self;
}
#[deriving(Eq)]
pub struct Vec3<T> { x: T, y: T, z: T }
type Vec3f = Vec3<float>
impl<T:Copy> BaseVec for Vec3<T> {
type T = T;
static LEN: uint = 3;
fn from_value(value: T) -> Vec3<T> {
Vec3 { x: value, y: value, z: value }
}
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment