use std::fmt;
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct CGSize {
pub width: f64,
pub height: f64,
}
impl std::hash::Hash for CGSize {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.width.to_bits().hash(state);
self.height.to_bits().hash(state);
}
}
impl Eq for CGSize {}
impl CGSize {
pub const fn new(width: f64, height: f64) -> Self {
Self { width, height }
}
pub const fn zero() -> Self {
Self::new(0.0, 0.0)
}
pub const fn area(&self) -> f64 {
self.width * self.height
}
pub fn aspect_ratio(&self) -> f64 {
if self.height == 0.0 {
0.0
} else {
self.width / self.height
}
}
#[allow(clippy::float_cmp)]
pub const fn is_square(&self) -> bool {
self.width == self.height
}
pub fn is_empty(&self) -> bool {
self.width <= 0.0 || self.height <= 0.0
}
pub const fn is_null(&self) -> bool {
self.width == 0.0 && self.height == 0.0
}
}
impl Default for CGSize {
fn default() -> Self {
Self::zero()
}
}
impl fmt::Display for CGSize {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}x{}", self.width, self.height)
}
}