diff options
author | 2024-05-03 07:04:57 +0200 | |
---|---|---|
committer | 2024-05-03 07:04:57 +0200 | |
commit | eac5bcb64f17dfbb52b64ea4f95693462986bb69 (patch) | |
tree | a4941797a889c47c05f563b7251f315f968357f5 /core/src/rectangle.rs | |
parent | 568ac66486937a294f2a79cefea277e4eb46b81e (diff) | |
download | iced-eac5bcb64f17dfbb52b64ea4f95693462986bb69.tar.gz iced-eac5bcb64f17dfbb52b64ea4f95693462986bb69.tar.bz2 iced-eac5bcb64f17dfbb52b64ea4f95693462986bb69.zip |
Fix `Image::bounds` when rotation present in `iced_graphics`
Diffstat (limited to 'core/src/rectangle.rs')
-rw-r--r-- | core/src/rectangle.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/core/src/rectangle.rs b/core/src/rectangle.rs index fb66131a..1556e072 100644 --- a/core/src/rectangle.rs +++ b/core/src/rectangle.rs @@ -1,6 +1,6 @@ -use crate::{Point, Size, Vector}; +use crate::{Point, Radians, Size, Vector}; -/// A rectangle. +/// An axis-aligned rectangle. #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] pub struct Rectangle<T = f32> { /// X coordinate of the top-left corner. @@ -172,6 +172,18 @@ impl Rectangle<f32> { height: self.height + amount * 2.0, } } + + /// Rotates the [`Rectangle`] and returns the smallest [`Rectangle`] + /// containing it. + pub fn rotate(self, rotation: Radians) -> Self { + let size = self.size().rotate(rotation); + let position = Point::new( + self.center_x() - size.width / 2.0, + self.center_y() - size.height / 2.0, + ); + + Self::new(position, size) + } } impl std::ops::Mul<f32> for Rectangle<f32> { |