1use std::f32;
2
3#[derive(Debug, Clone, Copy, PartialEq)]
5pub struct Size<T = f32> {
6 pub width: T,
8 pub height: T,
10}
11
12impl<T> Size<T> {
13 pub const fn new(width: T, height: T) -> Self {
17 Self { width, height }
18 }
19}
20
21impl Size {
22 pub const ZERO: Self = Self::new(0., 0.);
26
27 pub const UNIT: Self = Self::new(1., 1.);
31
32 pub const INFINITY: Self = Self::new(f32::INFINITY, f32::INFINITY);
36
37 pub fn pad(&self, padding: f32) -> Self {
41 Self {
42 width: self.width + padding * 2.0,
43 height: self.height + padding * 2.0,
44 }
45 }
46}
47
48impl From<[f32; 2]> for Size {
49 fn from([width, height]: [f32; 2]) -> Self {
50 Self { width, height }
51 }
52}
53
54impl From<[u16; 2]> for Size {
55 fn from([width, height]: [u16; 2]) -> Self {
56 Self::new(width.into(), height.into())
57 }
58}