From a3cbcb31365292bce395f99fbb05e26c54a99eab Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Thu, 8 Jun 2017 17:18:57 +0200 Subject: [PATCH] Add extend method and get euclid to build with rustc 1.15. --- Cargo.toml | 2 +- src/point.rs | 10 ++++++++-- src/vector.rs | 6 ++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9160eb9..536ef14 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "euclid" -version = "0.14.2" +version = "0.14.3" authors = ["The Servo Project Developers"] description = "Geometry primitives" documentation = "https://docs.rs/euclid/" diff --git a/src/point.rs b/src/point.rs index 79491aa..7ff8779 100644 --- a/src/point.rs +++ b/src/point.rs @@ -76,6 +76,12 @@ impl TypedPoint2D { point2(x.0, y.0) } + /// Create a 3d point from this one, using the specified z value. + #[inline] + pub fn extend(&self, z: T) -> TypedPoint3D { + point3(self.x, self.y, z) + } + /// Cast this point into a vector. /// /// Equivalent to substracting the origin to this point. @@ -325,7 +331,7 @@ where T: Copy + One + Add + Sub + Mul { } } -impl, U> ApproxEq for TypedPoint2D { +impl, U> ApproxEq> for TypedPoint2D { #[inline] fn approx_epsilon() -> Self { point2(T::approx_epsilon(), T::approx_epsilon()) @@ -621,7 +627,7 @@ impl TypedPoint3D { } } -impl, U> ApproxEq for TypedPoint3D { +impl, U> ApproxEq> for TypedPoint3D { #[inline] fn approx_epsilon() -> Self { point3(T::approx_epsilon(), T::approx_epsilon(), T::approx_epsilon()) diff --git a/src/vector.rs b/src/vector.rs index 4003378..03629ac 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -71,6 +71,12 @@ impl TypedVector2D { vec2(x.0, y.0) } + /// Create a 3d vector from this one, using the specified z value. + #[inline] + pub fn extend(&self, z: T) -> TypedVector3D { + vec3(self.x, self.y, z) + } + /// Cast this vector into a point. /// /// Equivalent to adding this vector to the origin.