pub struct Size2D {
pub w: u32,
pub h: u32,
}Expand description
A 2D size with non-negative integer dimensions.
use optic_core::*;
let s = Size2D::from(1920, 1080);
assert_eq!(s.aspect_ratio(), 16.0 / 9.0);Supports Add, Sub (saturating), and Mul<f32> componentwise.
Conversion from/to [u32; 2] and (u32, u32) via Components.
Fields§
§w: u32§h: u32Implementations§
Source§impl Size2D
impl Size2D
Sourcepub fn aspect_ratio(&self) -> f32
pub fn aspect_ratio(&self) -> f32
Aspect ratio as w / h (f32). Returns 0 if height is 0.
Sourcepub fn fit_within(&self, max: Size2D) -> Size2D
pub fn fit_within(&self, max: Size2D) -> Size2D
Scale down to fit within max while preserving aspect ratio.
If already within bounds, returns unchanged.
Sourcepub fn scaled_to_width(&self, w: u32) -> Size2D
pub fn scaled_to_width(&self, w: u32) -> Size2D
Scale to a specific width, preserving aspect ratio.
Sourcepub fn scaled_to_height(&self, h: u32) -> Size2D
pub fn scaled_to_height(&self, h: u32) -> Size2D
Scale to a specific height, preserving aspect ratio.
Trait Implementations§
Source§impl Components<u32, 2> for Size2D
impl Components<u32, 2> for Size2D
impl Copy for Size2D
impl StructuralPartialEq for Size2D
Auto Trait Implementations§
impl Freeze for Size2D
impl RefUnwindSafe for Size2D
impl Send for Size2D
impl Sync for Size2D
impl Unpin for Size2D
impl UnsafeUnpin for Size2D
impl UnwindSafe for Size2D
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more