Add ToStr impls for point, vector and quaternion types

This commit is contained in:
Brendan Zabarauskas 2013-09-03 17:33:33 +10:00
parent 00991e00f3
commit 0325af9a69
3 changed files with 36 additions and 0 deletions

View file

@ -78,3 +78,15 @@ array!(impl<S> Point3<S> -> [S, ..3])
impl<S: Clone + Num> Point<S, Vec2<S>, [S, ..2]> for Point2<S>;
impl<S: Clone + Num> Point<S, Vec3<S>, [S, ..3]> for Point3<S>;
impl<S> ToStr for Point2<S> {
fn to_str(&self) -> ~str {
fmt!("[%?, %?]", self.x, self.y)
}
}
impl<S> ToStr for Point3<S> {
fn to_str(&self) -> ~str {
fmt!("[%?, %?, %?]", self.x, self.y, self.z)
}
}

View file

@ -233,3 +233,9 @@ impl<S: Clone + Float> Neg<Quat<S>> for Quat<S> {
Quat::from_sv(-self.s, -self.v)
}
}
impl<S> ToStr for Quat<S> {
fn to_str(&self) -> ~str {
fmt!("%? + %?i + %?j + %?k", self.s, self.v.x, self.v.y, self.v.z)
}
}

View file

@ -219,3 +219,21 @@ impl<S: Clone + Float> EuclideanVector<S, [S, ..3]> for Vec3<S> {
atan2(self.cross(other).length(), self.dot(other))
}
}
impl<S> ToStr for Vec2<S> {
fn to_str(&self) -> ~str {
fmt!("[%?, %?]", self.x, self.y)
}
}
impl<S> ToStr for Vec3<S> {
fn to_str(&self) -> ~str {
fmt!("[%?, %?, %?]", self.x, self.y, self.z)
}
}
impl<S> ToStr for Vec4<S> {
fn to_str(&self) -> ~str {
fmt!("[%?, %?, %?, %?]", self.x, self.y, self.z, self.w)
}
}