diff --git a/Cargo.toml b/Cargo.toml index 6450a52..9160eb9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "euclid" -version = "0.14.1" +version = "0.14.2" authors = ["The Servo Project Developers"] description = "Geometry primitives" documentation = "https://docs.rs/euclid/" diff --git a/src/point.rs b/src/point.rs index 085740e..bb4613d 100644 --- a/src/point.rs +++ b/src/point.rs @@ -430,7 +430,7 @@ impl TypedPoint3D { /// Equivalent to substracting the origin to this point. #[inline] pub fn to_vector(&self) -> TypedVector3D { - vec3(self.x, self.y, self.y) + vec3(self.x, self.y, self.z) } /// Returns self.x as a Length carrying the unit. @@ -736,6 +736,19 @@ mod typedpoint2d { assert_eq!(result, Point2DCm::new(0.1, 0.2)); } + + #[test] + pub fn test_conv_vector() { + use {Point2D, point2}; + + for i in 0..100 { + // We don't care about these values as long as they are not the same. + let x = i as f32 *0.012345; + let y = i as f32 *0.987654; + let p: Point2D = point2(x, y); + assert_eq!(p.to_vector().to_point(), p); + } + } } #[cfg(test)] @@ -761,4 +774,17 @@ mod point3d { assert_eq!(result, Point3D::new(2.0, 3.0, 5.0)); } + + #[test] + pub fn test_conv_vector() { + use point3; + for i in 0..100 { + // We don't care about these values as long as they are not the same. + let x = i as f32 *0.012345; + let y = i as f32 *0.987654; + let z = x * y; + let p: Point3D = point3(x, y, z); + assert_eq!(p.to_vector().to_point(), p); + } + } }