summaryrefslogtreecommitdiffstats
path: root/core/src/rectangle.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-05-29 02:00:28 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-05-29 02:00:28 +0200
commit0cde20b3550ede81bc7ddef628b91eec225aa8af (patch)
tree56920437979012cceb49718f2dd4ce27d5ba5d40 /core/src/rectangle.rs
parent67b6f044e870df41be92cdc79f571682b97a5d0d (diff)
parente11b5c614f5bf73c137b8b4f24f56047617527eb (diff)
downloadiced-0cde20b3550ede81bc7ddef628b91eec225aa8af.tar.gz
iced-0cde20b3550ede81bc7ddef628b91eec225aa8af.tar.bz2
iced-0cde20b3550ede81bc7ddef628b91eec225aa8af.zip
Merge branch 'master' into improvement/update-wgpu_glyph
Diffstat (limited to 'core/src/rectangle.rs')
-rw-r--r--core/src/rectangle.rs33
1 files changed, 17 insertions, 16 deletions
diff --git a/core/src/rectangle.rs b/core/src/rectangle.rs
index 8bc89a44..aa23372e 100644
--- a/core/src/rectangle.rs
+++ b/core/src/rectangle.rs
@@ -125,17 +125,29 @@ impl Rectangle<f32> {
None
}
}
+
+ /// Rounds the [`Rectangle`] to __unsigned__ integer coordinates.
+ ///
+ /// [`Rectangle`]: struct.Rectangle.html
+ pub fn round(self) -> Rectangle<u32> {
+ Rectangle {
+ x: self.x as u32,
+ y: self.y as u32,
+ width: (self.width + 0.5).round() as u32,
+ height: (self.height + 0.5).round() as u32,
+ }
+ }
}
-impl std::ops::Mul<f32> for Rectangle<u32> {
+impl std::ops::Mul<f32> for Rectangle<f32> {
type Output = Self;
fn mul(self, scale: f32) -> Self {
Self {
- x: (self.x as f32 * scale).round() as u32,
- y: (self.y as f32 * scale).round() as u32,
- width: (self.width as f32 * scale).round() as u32,
- height: (self.height as f32 * scale).round() as u32,
+ x: self.x as f32 * scale,
+ y: self.y as f32 * scale,
+ width: self.width * scale,
+ height: self.height * scale,
}
}
}
@@ -151,17 +163,6 @@ impl From<Rectangle<u32>> for Rectangle<f32> {
}
}
-impl From<Rectangle<f32>> for Rectangle<u32> {
- fn from(rectangle: Rectangle<f32>) -> Rectangle<u32> {
- Rectangle {
- x: rectangle.x as u32,
- y: rectangle.y as u32,
- width: (rectangle.width + 0.5).round() as u32,
- height: (rectangle.height + 0.5).round() as u32,
- }
- }
-}
-
impl<T> std::ops::Add<Vector<T>> for Rectangle<T>
where
T: std::ops::Add<Output = T>,