Merge pull request #49 from ozkriff/master

Updated to latest Rust: ToStr -> fmt::Show
This commit is contained in:
Andrey Lesnikov 2014-02-25 12:18:32 +03:00
commit ada934f913
7 changed files with 49 additions and 34 deletions

View file

@ -93,9 +93,9 @@ impl<S: Primitive> Aabb<S, Vec2<S>, Point2<S>, [S, ..2]> for Aabb2<S> {
#[inline] fn max<'a>(&'a self) -> &'a Point2<S> { &self.max } #[inline] fn max<'a>(&'a self) -> &'a Point2<S> { &self.max }
} }
impl<S: fmt::Show> ToStr for Aabb2<S> { impl<S: fmt::Show> fmt::Show for Aabb2<S> {
fn to_str(&self) -> ~str { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
format!("[{} - {}]", self.min.to_str(), self.max.to_str()) write!(f.buf, "[{} - {}]", self.min, self.max)
} }
} }
@ -122,8 +122,8 @@ impl<S: Primitive> Aabb<S, Vec3<S>, Point3<S>, [S, ..3]> for Aabb3<S> {
#[inline] fn max<'a>(&'a self) -> &'a Point3<S> { &self.max } #[inline] fn max<'a>(&'a self) -> &'a Point3<S> { &self.max }
} }
impl<S: fmt::Show> ToStr for Aabb3<S> { impl<S: fmt::Show> fmt::Show for Aabb3<S> {
fn to_str(&self) -> ~str { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
format!("[{} - {}]", self.min.to_str(), self.max.to_str()) write!(f.buf, "[{} - {}]", self.min, self.max)
} }
} }

View file

@ -204,8 +204,19 @@ Angle<S> for Deg<S> {
#[inline] pub fn atan<S: Float>(s: S) -> Rad<S> { rad(s.atan()) } #[inline] pub fn atan<S: Float>(s: S) -> Rad<S> { rad(s.atan()) }
#[inline] pub fn atan2<S: Float>(a: S, b: S) -> Rad<S> { rad(a.atan2(&b)) } #[inline] pub fn atan2<S: Float>(a: S, b: S) -> Rad<S> { rad(a.atan2(&b)) }
impl<S: Float + fmt::Show> ToStr for Rad<S> { fn to_str(&self) -> ~str { format!("{} rad", self.s) } } impl<S: Float + fmt::Show>
impl<S: Float + fmt::Show> ToStr for Deg<S> { fn to_str(&self) -> ~str { format!("{}°", self.s) } } fmt::Show for Rad<S> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f.buf, "{} rad", self.s)
}
}
impl<S: Float + fmt::Show>
fmt::Show for Deg<S> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f.buf, "{}°", self.s)
}
}
impl<S: Float + ApproxEq<S>> impl<S: Float + ApproxEq<S>>
ApproxEq<S> for Rad<S> { ApproxEq<S> for Rad<S> {

View file

@ -121,9 +121,9 @@ ApproxEq<S> for Plane<S> {
} }
} }
impl<S: Clone + fmt::Float> ToStr for Plane<S> { impl<S: Clone + fmt::Float> fmt::Show for Plane<S> {
fn to_str(&self) -> ~str { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
format!("{:f}x + {:f}y + {:f}z - {:f} = 0", write!(f.buf, "{:f}x + {:f}y + {:f}z - {:f} = 0",
self.n.x, self.n.x,
self.n.y, self.n.y,
self.n.z, self.n.z,

View file

@ -99,14 +99,14 @@ array!(impl<S> Point3<S> -> [S, ..3] _3)
impl<S: Primitive> Point<S, Vec2<S>, [S, ..2]> for Point2<S> {} impl<S: Primitive> Point<S, Vec2<S>, [S, ..2]> for Point2<S> {}
impl<S: Primitive> Point<S, Vec3<S>, [S, ..3]> for Point3<S> {} impl<S: Primitive> Point<S, Vec3<S>, [S, ..3]> for Point3<S> {}
impl<S: fmt::Show> ToStr for Point2<S> { impl<S: fmt::Show> fmt::Show for Point2<S> {
fn to_str(&self) -> ~str { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
format!("[{}, {}]", self.x, self.y) write!(f.buf, "[{}, {}]", self.x, self.y)
} }
} }
impl<S: fmt::Show> ToStr for Point3<S> { impl<S: fmt::Show> fmt::Show for Point3<S> {
fn to_str(&self) -> ~str { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
format!("[{}, {}, {}]", self.x, self.y, self.z) write!(f.buf, "[{}, {}, {}]", self.x, self.y, self.z)
} }
} }

View file

@ -287,9 +287,13 @@ Neg<Quat<S>> for Quat<S> {
} }
} }
impl<S: fmt::Show> ToStr for Quat<S> { impl<S: fmt::Show> fmt::Show for Quat<S> {
fn to_str(&self) -> ~str { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
format!("{} + {}i + {}j + {}k", self.s, self.v.x, self.v.y, self.v.z) write!(f.buf, "{} + {}i + {}j + {}k",
self.s,
self.v.x,
self.v.y,
self.v.z)
} }
} }

View file

@ -157,11 +157,11 @@ ToMat4<S> for Decomposed<S, Vec3<S>, R> {
impl<S: Float + ApproxEq<S>, R: Rotation3<S>> impl<S: Float + ApproxEq<S>, R: Rotation3<S>>
Transform3<S> for Decomposed<S,Vec3<S>,R> {} Transform3<S> for Decomposed<S,Vec3<S>,R> {}
impl<S: fmt::Show + Float, R: ToStr + Rotation3<S>> impl<S: fmt::Show + Float, R: fmt::Show + Rotation3<S>>
ToStr for Decomposed<S,Vec3<S>,R> { fmt::Show for Decomposed<S,Vec3<S>,R> {
fn to_str(&self) -> ~str { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
format!("(scale({}), rot({:s}), disp{:s})", write!(f.buf, "(scale({}), rot({}), disp{})",
self.scale, self.rot.to_str(), self.disp.to_str()) self.scale, self.rot, self.disp)
} }
} }

View file

@ -302,20 +302,20 @@ EuclideanVector<S, [S, ..4]> for Vec4<S> {
} }
} }
impl<S: fmt::Show> ToStr for Vec2<S> { impl<S: fmt::Show> fmt::Show for Vec2<S> {
fn to_str(&self) -> ~str { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
format!("[{}, {}]", self.x, self.y) write!(f.buf, "[{}, {}]", self.x, self.y)
} }
} }
impl<S: fmt::Show> ToStr for Vec3<S> { impl<S: fmt::Show> fmt::Show for Vec3<S> {
fn to_str(&self) -> ~str { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
format!("[{}, {}, {}]", self.x, self.y, self.z) write!(f.buf, "[{}, {}, {}]", self.x, self.y, self.z)
} }
} }
impl<S: fmt::Show> ToStr for Vec4<S> { impl<S: fmt::Show> fmt::Show for Vec4<S> {
fn to_str(&self) -> ~str { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
format!("[{}, {}, {}, {}]", self.x, self.y, self.z, self.w) write!(f.buf, "[{}, {}, {}, {}]", self.x, self.y, self.z, self.w)
} }
} }