srs2dge_core/packer/
rect.rs

1use wgpu::Extent3d;
2use winit::dpi::PhysicalSize;
3
4//
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
7pub struct Rect {
8    pub width: u32,
9    pub height: u32,
10}
11
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
13pub struct PositionedRect {
14    pub x: u32,
15    pub y: u32,
16
17    pub width: u32,
18    pub height: u32,
19}
20
21//
22
23impl Rect {
24    #[inline]
25    pub const fn new(width: u32, height: u32) -> Self {
26        Self { width, height }
27    }
28
29    #[inline]
30    pub const fn positioned(self, x: u32, y: u32) -> PositionedRect {
31        PositionedRect {
32            x,
33            y,
34            width: self.width,
35            height: self.height,
36        }
37    }
38}
39
40impl PositionedRect {
41    #[inline]
42    pub const fn new(x: u32, y: u32, width: u32, height: u32) -> Self {
43        Self {
44            x,
45            y,
46            width,
47            height,
48        }
49    }
50
51    #[inline]
52    pub const fn rect(self) -> Rect {
53        Rect {
54            width: self.width,
55            height: self.height,
56        }
57    }
58}
59
60//
61
62impl From<Rect> for (u32, u32) {
63    fn from(rect: Rect) -> Self {
64        (rect.width, rect.height)
65    }
66}
67
68impl From<Rect> for (usize, usize) {
69    fn from(rect: Rect) -> Self {
70        (rect.width as _, rect.height as _)
71    }
72}
73
74impl From<Rect> for PhysicalSize<u32> {
75    fn from(rect: Rect) -> Self {
76        Self::new(rect.width, rect.height)
77    }
78}
79
80impl From<(u32, u32)> for Rect {
81    fn from((width, height): (u32, u32)) -> Self {
82        Self { width, height }
83    }
84}
85
86impl From<(usize, usize)> for Rect {
87    fn from((width, height): (usize, usize)) -> Self {
88        Self {
89            width: width as _,
90            height: height as _,
91        }
92    }
93}
94
95impl From<PhysicalSize<u32>> for Rect {
96    fn from(rect: PhysicalSize<u32>) -> Self {
97        Self::new(rect.width, rect.height)
98    }
99}
100
101impl From<Rect> for Extent3d {
102    fn from(rect: Rect) -> Self {
103        Self {
104            width: rect.width,
105            height: rect.height,
106            depth_or_array_layers: 1,
107        }
108    }
109}