Add ratio method to Size
Co-authored-by: tigerros <tigerros@users.noreply.github.com>
This commit is contained in:
parent
8bfd099c59
commit
47eb1942c9
1 changed files with 10 additions and 1 deletions
|
|
@ -52,7 +52,7 @@ impl Size {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Rotates the given [`Size`] and returns the minimum [`Size`]
|
/// Rotates this [`Size`] and returns the minimum [`Size`]
|
||||||
/// containing it.
|
/// containing it.
|
||||||
pub fn rotate(self, rotation: Radians) -> Size {
|
pub fn rotate(self, rotation: Radians) -> Size {
|
||||||
let radians = f32::from(rotation);
|
let radians = f32::from(rotation);
|
||||||
|
|
@ -64,6 +64,15 @@ impl Size {
|
||||||
+ (self.height * radians.cos()).abs(),
|
+ (self.height * radians.cos()).abs(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Applies an aspect ratio to this [`Size`] without
|
||||||
|
/// exceeding its bounds.
|
||||||
|
pub const fn ratio(self, aspect_ratio: f32) -> Size {
|
||||||
|
Size {
|
||||||
|
width: (self.height * aspect_ratio).min(self.width),
|
||||||
|
height: (self.width / aspect_ratio).min(self.height),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Size<Length> {
|
impl Size<Length> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue