enki/enki_api/space/
tile.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
3pub enum TileConfig {
4 #[default]
6 Auto,
7 Custom(u32, u32, u32),
9}
10
11impl TileConfig {
12 #[inline(always)]
14 pub const fn custom_x(x: u32) -> Self {
15 Self::Custom(x, 1, 1)
16 }
17
18 #[inline(always)]
20 pub const fn custom_xy(x: u32, y: u32) -> Self {
21 Self::Custom(x, y, 1)
22 }
23
24 #[inline(always)]
26 pub const fn custom_xyz(x: u32, y: u32, z: u32) -> Self {
27 Self::Custom(x, y, z)
28 }
29
30 #[inline(always)]
32 pub const fn custom_1d(x: u32) -> Self {
33 Self::custom_x(x)
34 }
35
36 #[inline(always)]
38 pub const fn custom_2d(x: u32, y: u32) -> Self {
39 Self::custom_xy(x, y)
40 }
41
42 #[inline(always)]
44 pub const fn custom_3d(x: u32, y: u32, z: u32) -> Self {
45 Self::custom_xyz(x, y, z)
46 }
47
48 #[inline(always)]
50 pub const fn is_auto(&self) -> bool {
51 matches!(self, Self::Auto)
52 }
53}
54
55pub trait IntoTile {
57 fn into_tile(self) -> TileConfig;
59}
60
61impl IntoTile for TileConfig {
62 #[inline(always)]
63 fn into_tile(self) -> TileConfig {
64 self
65 }
66}
67
68impl IntoTile for u32 {
69 #[inline(always)]
70 fn into_tile(self) -> TileConfig {
71 TileConfig::Custom(self.max(1), 1, 1)
72 }
73}
74
75impl IntoTile for i32 {
76 #[inline(always)]
77 fn into_tile(self) -> TileConfig {
78 TileConfig::Custom(self.max(1) as u32, 1, 1)
79 }
80}
81
82impl IntoTile for usize {
83 #[inline(always)]
84 fn into_tile(self) -> TileConfig {
85 TileConfig::Custom((self as u32).max(1), 1, 1)
86 }
87}
88
89impl IntoTile for [u32; 2] {
90 #[inline(always)]
91 fn into_tile(self) -> TileConfig {
92 TileConfig::Custom(self[0].max(1), self[1].max(1), 1)
93 }
94}
95
96impl IntoTile for (u32, u32) {
97 #[inline(always)]
98 fn into_tile(self) -> TileConfig {
99 TileConfig::Custom(self.0.max(1), self.1.max(1), 1)
100 }
101}
102
103impl IntoTile for [i32; 2] {
104 #[inline(always)]
105 fn into_tile(self) -> TileConfig {
106 TileConfig::Custom(self[0].max(1) as u32, self[1].max(1) as u32, 1)
107 }
108}
109
110impl IntoTile for (i32, i32) {
111 #[inline(always)]
112 fn into_tile(self) -> TileConfig {
113 TileConfig::Custom(self.0.max(1) as u32, self.1.max(1) as u32, 1)
114 }
115}
116
117impl IntoTile for [usize; 2] {
118 #[inline(always)]
119 fn into_tile(self) -> TileConfig {
120 TileConfig::Custom((self[0] as u32).max(1), (self[1] as u32).max(1), 1)
121 }
122}
123
124impl IntoTile for (usize, usize) {
125 #[inline(always)]
126 fn into_tile(self) -> TileConfig {
127 TileConfig::Custom((self.0 as u32).max(1), (self.1 as u32).max(1), 1)
128 }
129}
130
131impl IntoTile for [u32; 3] {
132 #[inline(always)]
133 fn into_tile(self) -> TileConfig {
134 TileConfig::Custom(self[0].max(1), self[1].max(1), self[2].max(1))
135 }
136}
137
138impl IntoTile for (u32, u32, u32) {
139 #[inline(always)]
140 fn into_tile(self) -> TileConfig {
141 TileConfig::Custom(self.0.max(1), self.1.max(1), self.2.max(1))
142 }
143}
144
145impl IntoTile for [i32; 3] {
146 #[inline(always)]
147 fn into_tile(self) -> TileConfig {
148 TileConfig::Custom(
149 self[0].max(1) as u32,
150 self[1].max(1) as u32,
151 self[2].max(1) as u32,
152 )
153 }
154}
155
156impl IntoTile for (i32, i32, i32) {
157 #[inline(always)]
158 fn into_tile(self) -> TileConfig {
159 TileConfig::Custom(
160 self.0.max(1) as u32,
161 self.1.max(1) as u32,
162 self.2.max(1) as u32,
163 )
164 }
165}
166
167impl IntoTile for [usize; 3] {
168 #[inline(always)]
169 fn into_tile(self) -> TileConfig {
170 TileConfig::Custom(
171 (self[0] as u32).max(1),
172 (self[1] as u32).max(1),
173 (self[2] as u32).max(1),
174 )
175 }
176}
177
178impl IntoTile for (usize, usize, usize) {
179 #[inline(always)]
180 fn into_tile(self) -> TileConfig {
181 TileConfig::Custom(
182 (self.0 as u32).max(1),
183 (self.1 as u32).max(1),
184 (self.2 as u32).max(1),
185 )
186 }
187}