Add and implement ToPtr trait
This commit is contained in:
parent
819c092321
commit
28a9265568
4 changed files with 57 additions and 3 deletions
|
@ -1,6 +1,11 @@
|
||||||
use cmp::Ord;
|
use cmp::Ord;
|
||||||
use num::{Num, from_int};
|
use num::{Num, from_int};
|
||||||
|
|
||||||
|
// TODO: move to a more appropriate module
|
||||||
|
pub trait ToPtr<T> {
|
||||||
|
pure fn to_ptr() -> *T;
|
||||||
|
}
|
||||||
|
|
||||||
pub trait ExactEq {
|
pub trait ExactEq {
|
||||||
pure fn exact_eq(other: &self) -> bool;
|
pure fn exact_eq(other: &self) -> bool;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::cmp::FuzzyEq;
|
use std::cmp::FuzzyEq;
|
||||||
use cmp::Eq;
|
use cmp::Eq;
|
||||||
use math::{ExactEq, Sqrt};
|
use math::{ToPtr, ExactEq, Sqrt};
|
||||||
use quaternion::Quat;
|
use quaternion::Quat;
|
||||||
use vector::{Vec2, Vec3, Vec4};
|
use vector::{Vec2, Vec3, Vec4};
|
||||||
|
|
||||||
|
@ -219,6 +219,13 @@ pub impl Mat2: FuzzyEq {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub impl Mat2: ToPtr<float> {
|
||||||
|
#[inline(always)]
|
||||||
|
pure fn to_ptr() -> *float {
|
||||||
|
self[0].to_ptr()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -473,6 +480,13 @@ pub impl Mat3: FuzzyEq {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub impl Mat3: ToPtr<float> {
|
||||||
|
#[inline(always)]
|
||||||
|
pure fn to_ptr() -> *float {
|
||||||
|
self[0].to_ptr()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -723,4 +737,11 @@ pub impl Mat4: FuzzyEq {
|
||||||
self[2].fuzzy_eq(&other[2]) &&
|
self[2].fuzzy_eq(&other[2]) &&
|
||||||
self[3].fuzzy_eq(&other[3])
|
self[3].fuzzy_eq(&other[3])
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub impl Mat4: ToPtr<float> {
|
||||||
|
#[inline(always)]
|
||||||
|
pure fn to_ptr() -> *float {
|
||||||
|
self[0].to_ptr()
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -3,7 +3,7 @@ use vec::raw::buf_as_slice;
|
||||||
use ptr::to_unsafe_ptr;
|
use ptr::to_unsafe_ptr;
|
||||||
use cmp::Eq;
|
use cmp::Eq;
|
||||||
use std::cmp::FuzzyEq;
|
use std::cmp::FuzzyEq;
|
||||||
use math::{ExactEq, Sqrt};
|
use math::{ToPtr, ExactEq, Sqrt};
|
||||||
use matrix::{Mat3, Mat4};
|
use matrix::{Mat3, Mat4};
|
||||||
use vector::Vec3;
|
use vector::Vec3;
|
||||||
|
|
||||||
|
@ -203,6 +203,13 @@ pub impl Quat: FuzzyEq {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub impl Quat: ToPtr<float> {
|
||||||
|
#[inline(always)]
|
||||||
|
pure fn to_ptr() -> *float {
|
||||||
|
to_unsafe_ptr(&self[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub impl Quat: ToStr {
|
pub impl Quat: ToStr {
|
||||||
pure fn to_str() -> ~str {
|
pure fn to_str() -> ~str {
|
||||||
fmt!("Quat[ %f, %f, %f, %f ]", self.w, self.x, self.y, self.z)
|
fmt!("Quat[ %f, %f, %f, %f ]", self.w, self.x, self.y, self.z)
|
||||||
|
|
|
@ -3,7 +3,7 @@ use vec::raw::buf_as_slice;
|
||||||
use ptr::to_unsafe_ptr;
|
use ptr::to_unsafe_ptr;
|
||||||
use cmp::Eq;
|
use cmp::Eq;
|
||||||
use std::cmp::FuzzyEq;
|
use std::cmp::FuzzyEq;
|
||||||
use math::{Abs, abs, ExactEq, max, min, Sqrt};
|
use math::{ToPtr, Abs, abs, ExactEq, max, min, Sqrt};
|
||||||
|
|
||||||
//
|
//
|
||||||
// N-dimensional Vector
|
// N-dimensional Vector
|
||||||
|
@ -201,6 +201,13 @@ pub impl Vec2: FuzzyEq {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub impl Vec2: ToPtr<float> {
|
||||||
|
#[inline(always)]
|
||||||
|
pure fn to_ptr() -> *float {
|
||||||
|
to_unsafe_ptr(&self[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub impl Vec2: ToStr {
|
pub impl Vec2: ToStr {
|
||||||
pure fn to_str() -> ~str {
|
pure fn to_str() -> ~str {
|
||||||
fmt!("Vec2[ %f, %f ]", self[0], self[1])
|
fmt!("Vec2[ %f, %f ]", self[0], self[1])
|
||||||
|
@ -392,6 +399,13 @@ pub impl Vec3: FuzzyEq {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub impl Vec3: ToPtr<float> {
|
||||||
|
#[inline(always)]
|
||||||
|
pure fn to_ptr() -> *float {
|
||||||
|
to_unsafe_ptr(&self[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub impl Vec3: ToStr {
|
pub impl Vec3: ToStr {
|
||||||
pure fn to_str() -> ~str {
|
pure fn to_str() -> ~str {
|
||||||
fmt!("Vec3[ %f, %f, %f ]", self[0], self[1], self[2])
|
fmt!("Vec3[ %f, %f, %f ]", self[0], self[1], self[2])
|
||||||
|
@ -589,6 +603,13 @@ pub impl Vec4: FuzzyEq {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub impl Vec4: ToPtr<float> {
|
||||||
|
#[inline(always)]
|
||||||
|
pure fn to_ptr() -> *float {
|
||||||
|
to_unsafe_ptr(&self[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub impl Vec4: ToStr {
|
pub impl Vec4: ToStr {
|
||||||
pure fn to_str() -> ~str {
|
pure fn to_str() -> ~str {
|
||||||
fmt!("Vec4[ %f, %f, %f, %f ]", self[0], self[1], self[2], self[3])
|
fmt!("Vec4[ %f, %f, %f, %f ]", self[0], self[1], self[2], self[3])
|
||||||
|
|
Loading…
Reference in a new issue