From 0325af9a69e09339f068f2cf01c8bcd30b1e9084 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Tue, 3 Sep 2013 17:33:33 +1000 Subject: [PATCH] Add ToStr impls for point, vector and quaternion types --- src/cgmath/point.rs | 12 ++++++++++++ src/cgmath/quaternion.rs | 6 ++++++ src/cgmath/vector.rs | 18 ++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/src/cgmath/point.rs b/src/cgmath/point.rs index 7da336b..3994a43 100644 --- a/src/cgmath/point.rs +++ b/src/cgmath/point.rs @@ -78,3 +78,15 @@ array!(impl Point3 -> [S, ..3]) impl Point, [S, ..2]> for Point2; impl Point, [S, ..3]> for Point3; + +impl ToStr for Point2 { + fn to_str(&self) -> ~str { + fmt!("[%?, %?]", self.x, self.y) + } +} + +impl ToStr for Point3 { + fn to_str(&self) -> ~str { + fmt!("[%?, %?, %?]", self.x, self.y, self.z) + } +} diff --git a/src/cgmath/quaternion.rs b/src/cgmath/quaternion.rs index 592080a..e48f7fa 100644 --- a/src/cgmath/quaternion.rs +++ b/src/cgmath/quaternion.rs @@ -233,3 +233,9 @@ impl Neg> for Quat { Quat::from_sv(-self.s, -self.v) } } + +impl ToStr for Quat { + fn to_str(&self) -> ~str { + fmt!("%? + %?i + %?j + %?k", self.s, self.v.x, self.v.y, self.v.z) + } +} diff --git a/src/cgmath/vector.rs b/src/cgmath/vector.rs index 9baec6d..2dbd804 100644 --- a/src/cgmath/vector.rs +++ b/src/cgmath/vector.rs @@ -219,3 +219,21 @@ impl EuclideanVector for Vec3 { atan2(self.cross(other).length(), self.dot(other)) } } + +impl ToStr for Vec2 { + fn to_str(&self) -> ~str { + fmt!("[%?, %?]", self.x, self.y) + } +} + +impl ToStr for Vec3 { + fn to_str(&self) -> ~str { + fmt!("[%?, %?, %?]", self.x, self.y, self.z) + } +} + +impl ToStr for Vec4 { + fn to_str(&self) -> ~str { + fmt!("[%?, %?, %?, %?]", self.x, self.y, self.z, self.w) + } +}