From 658b05ccd0902c307d471b73541c05ba3d7e53e4 Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Tue, 27 Feb 2018 06:18:20 +0100 Subject: [PATCH] to_u32() --- Cargo.toml | 2 +- src/point.rs | 20 ++++++++++++++++++++ src/rect.rs | 9 +++++++++ src/size.rs | 9 +++++++++ src/vector.rs | 20 ++++++++++++++++++++ 5 files changed, 59 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index ec88ce7f..3e8e7012 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "euclid" -version = "0.17.0" +version = "0.17.1" authors = ["The Servo Project Developers"] description = "Geometry primitives" documentation = "https://docs.rs/euclid/" diff --git a/src/point.rs b/src/point.rs index 23ba2ae8..6bb17361 100644 --- a/src/point.rs +++ b/src/point.rs @@ -315,6 +315,16 @@ impl TypedPoint2D { self.cast().unwrap() } + /// Cast into an `u32` point, truncating decimals if any. + /// + /// When casting from floating point points, it is worth considering whether + /// to `round()`, `ceil()` or `floor()` before the cast in order to obtain + /// the desired conversion behavior. + #[inline] + pub fn to_u32(&self) -> TypedPoint2D { + self.cast().unwrap() + } + /// Cast into an i32 point, truncating decimals if any. /// /// When casting from floating point points, it is worth considering whether @@ -673,6 +683,16 @@ impl TypedPoint3D { self.cast().unwrap() } + /// Cast into an `u32` point, truncating decimals if any. + /// + /// When casting from floating point points, it is worth considering whether + /// to `round()`, `ceil()` or `floor()` before the cast in order to obtain + /// the desired conversion behavior. + #[inline] + pub fn to_u32(&self) -> TypedPoint3D { + self.cast().unwrap() + } + /// Cast into an `i32` point, truncating decimals if any. /// /// When casting from floating point points, it is worth considering whether diff --git a/src/rect.rs b/src/rect.rs index 620c4468..03d4ffc7 100644 --- a/src/rect.rs +++ b/src/rect.rs @@ -521,6 +521,15 @@ impl TypedRect { self.cast().unwrap() } + /// Cast into an `u32` rectangle, truncating decimals if any. + /// + /// When casting from floating point rectangles, it is worth considering whether + /// to `round()`, `round_in()` or `round_out()` before the cast in order to + /// obtain the desired conversion behavior. + pub fn to_u32(&self) -> TypedRect { + self.cast().unwrap() + } + /// Cast into an `i32` rectangle, truncating decimals if any. /// /// When casting from floating point rectangles, it is worth considering whether diff --git a/src/size.rs b/src/size.rs index 6f8a5d32..c9c03c66 100644 --- a/src/size.rs +++ b/src/size.rs @@ -244,6 +244,15 @@ impl TypedSize2D { self.cast().unwrap() } + /// Cast into an `u32` size, truncating decimals if any. + /// + /// When casting from floating point sizes, it is worth considering whether + /// to `round()`, `ceil()` or `floor()` before the cast in order to obtain + /// the desired conversion behavior. + pub fn to_u32(&self) -> TypedSize2D { + self.cast().unwrap() + } + /// Cast into an `i32` size, truncating decimals if any. /// /// When casting from floating point sizes, it is worth considering whether diff --git a/src/vector.rs b/src/vector.rs index c9e8ac01..6e055fa4 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -366,6 +366,16 @@ impl TypedVector2D { self.cast().unwrap() } + /// Cast into an `u32` vector, truncating decimals if any. + /// + /// When casting from floating vector vectors, it is worth considering whether + /// to `round()`, `ceil()` or `floor()` before the cast in order to obtain + /// the desired conversion behavior. + #[inline] + pub fn to_u32(&self) -> TypedVector2D { + self.cast().unwrap() + } + /// Cast into an i32 vector, truncating decimals if any. /// /// When casting from floating vector vectors, it is worth considering whether @@ -769,6 +779,16 @@ impl TypedVector3D { self.cast().unwrap() } + /// Cast into an `u32` vector, truncating decimals if any. + /// + /// When casting from floating vector vectors, it is worth considering whether + /// to `round()`, `ceil()` or `floor()` before the cast in order to obtain + /// the desired conversion behavior. + #[inline] + pub fn to_u32(&self) -> TypedVector3D { + self.cast().unwrap() + } + /// Cast into an `i32` vector, truncating decimals if any. /// /// When casting from floating vector vectors, it is worth considering whether