Fix Image::bounds when rotation present in iced_graphics

This commit is contained in:
Héctor Ramón Jiménez 2024-05-03 07:04:57 +02:00
parent 568ac66486
commit eac5bcb64f
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
5 changed files with 37 additions and 17 deletions

View file

@ -36,20 +36,12 @@ impl Rotation {
Degrees(self.radians().0.to_degrees())
}
/// Rotates the given [`Size`].
/// Applies the [`Rotation`] to the given [`Size`], returning
/// the minimum [`Size`] containing the rotated one.
pub fn apply(self, size: Size) -> Size {
match self {
Self::Floating(_) => size,
Self::Solid(rotation) => {
let radians = f32::from(rotation);
Size {
width: (size.width * radians.cos()).abs()
+ (size.height * radians.sin()).abs(),
height: (size.width * radians.sin()).abs()
+ (size.height * radians.cos()).abs(),
}
}
Self::Solid(rotation) => size.rotate(rotation),
}
}
}