dotzuki_engine/render/
geometry.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
3#[non_exhaustive]
4pub struct TilePos {
5 pub tx: u32,
7 pub ty: u32,
9}
10
11impl TilePos {
12 #[inline]
14 pub const fn new(tx: u32, ty: u32) -> Self {
15 Self { tx, ty }
16 }
17
18 #[inline]
20 pub const fn to_pixels(self) -> (u32, u32) {
21 (self.tx * 8, self.ty * 8)
22 }
23}
24
25#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
27#[non_exhaustive]
28pub struct TileRect {
29 pub tx: u32,
31 pub ty: u32,
33 pub tw: u32,
35 pub th: u32,
37}
38
39impl TileRect {
40 #[inline]
42 pub const fn new(tx: u32, ty: u32, tw: u32, th: u32) -> Self {
43 Self { tx, ty, tw, th }
44 }
45
46 #[inline]
48 pub const fn pos(&self) -> TilePos {
49 TilePos::new(self.tx, self.ty)
50 }
51
52 #[inline]
54 pub fn translated(&self, dx: u32, dy: u32) -> Self {
55 Self::new(self.tx + dx, self.ty + dy, self.tw, self.th)
56 }
57}
58
59#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
61pub struct BracketSides {
62 pub top: bool,
64 pub bottom: bool,
66 pub left: bool,
68 pub right: bool,
70}
71
72impl BracketSides {
73 pub const RIGHT_BOTTOM: Self = Self { top: false, bottom: true, left: false, right: true };
75 pub const ALL: Self = Self { top: true, bottom: true, left: true, right: true };
77}