From 8daf162b0495ba538e7582df84d7eaae9e02cdae Mon Sep 17 00:00:00 2001 From: n4n5 Date: Mon, 5 Oct 2026 19:53:06 +0200 Subject: [PATCH] feat: add utils methods to Rect (floor, round, ceil) (#8654) Add same method like `Pos2` and `Vec2`: `floor()`, `round()`, `ceil()` * Closes * [x] I have followed the instructions in the PR template --- crates/emath/src/rect.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/crates/emath/src/rect.rs b/crates/emath/src/rect.rs index f01387c1..215aed53 100644 --- a/crates/emath/src/rect.rs +++ b/crates/emath/src/rect.rs @@ -287,6 +287,33 @@ impl Rect { p.clamp(self.min, self.max) } + /// Floor the rect coordinates + #[inline(always)] + pub fn floor(self) -> Self { + Self { + min: self.min.floor(), + max: self.max.floor(), + } + } + + /// Round the rect coordinates + #[inline(always)] + pub fn round(self) -> Self { + Self { + min: self.min.round(), + max: self.max.round(), + } + } + + /// Ceil the rect coordinates + #[inline(always)] + pub fn ceil(self) -> Self { + Self { + min: self.min.ceil(), + max: self.max.ceil(), + } + } + #[inline(always)] pub fn extend_with(&mut self, p: Pos2) { self.min = self.min.min(p);