Skip to content

Commit

Permalink
Auto merge of #274 - paulrouget:to_u32, r=nical
Browse files Browse the repository at this point in the history
Implement to_u32()

Fix #237

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/euclid/274)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo authored Feb 27, 2018
2 parents 981ac39 + 658b05c commit c711061
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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/"
Expand Down
20 changes: 20 additions & 0 deletions src/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,16 @@ impl<T: NumCast + Copy, U> TypedPoint2D<T, U> {
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<u32, U> {
self.cast().unwrap()
}

/// Cast into an i32 point, truncating decimals if any.
///
/// When casting from floating point points, it is worth considering whether
Expand Down Expand Up @@ -673,6 +683,16 @@ impl<T: NumCast + Copy, U> TypedPoint3D<T, U> {
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<u32, U> {
self.cast().unwrap()
}

/// Cast into an `i32` point, truncating decimals if any.
///
/// When casting from floating point points, it is worth considering whether
Expand Down
9 changes: 9 additions & 0 deletions src/rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,15 @@ impl<T: NumCast + Copy, Unit> TypedRect<T, Unit> {
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<u32, Unit> {
self.cast().unwrap()
}

/// Cast into an `i32` rectangle, truncating decimals if any.
///
/// When casting from floating point rectangles, it is worth considering whether
Expand Down
9 changes: 9 additions & 0 deletions src/size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,15 @@ impl<T: NumCast + Copy, Unit> TypedSize2D<T, Unit> {
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<u32, Unit> {
self.cast().unwrap()
}

/// Cast into an `i32` size, truncating decimals if any.
///
/// When casting from floating point sizes, it is worth considering whether
Expand Down
20 changes: 20 additions & 0 deletions src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,16 @@ impl<T: NumCast + Copy, U> TypedVector2D<T, U> {
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<u32, U> {
self.cast().unwrap()
}

/// Cast into an i32 vector, truncating decimals if any.
///
/// When casting from floating vector vectors, it is worth considering whether
Expand Down Expand Up @@ -769,6 +779,16 @@ impl<T: NumCast + Copy, U> TypedVector3D<T, U> {
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<u32, U> {
self.cast().unwrap()
}

/// Cast into an `i32` vector, truncating decimals if any.
///
/// When casting from floating vector vectors, it is worth considering whether
Expand Down

0 comments on commit c711061

Please sign in to comment.