1use crate::macros::impl_element2;
2use crate::macros::impl_element2_op;
3use super::int3::Integer3;
4use super::int4::Integer4;
5
6
7
8#[repr(C)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11#[derive(Clone, Copy, PartialEq, Eq)]
12pub struct Integer2 {
13 pub x: i32,
14 pub y: i32,
15}
16
17impl Integer2 {
18 pub const ZERO: Self = Self::fill(0);
20
21 pub const ONE: Self = Self::fill(1);
23
24 pub const NEG_ONE: Self = Self::fill(-1);
26
27 pub const X: Self = Self::new(1, 0);
29
30 pub const Y: Self = Self::new(0, 1);
32
33 pub const NEG_X: Self = Self::new(-1, 0);
35
36 pub const NEG_Y: Self = Self::new(0, -1);
38
39 pub const MIN: Self = Self::fill(i32::MIN);
41
42 pub const MAX: Self = Self::fill(i32::MAX);
44}
45
46impl Integer2 {
48 #[inline]
49 pub const fn xx(self) -> Integer2 {
50 Integer2 { x: self.x, y: self.x }
51 }
52
53 #[inline]
54 pub const fn xy(self) -> Integer2 {
55 Integer2 { x: self.x, y: self.y }
56 }
57
58 #[inline]
59 pub const fn yx(self) -> Integer2 {
60 Integer2 { x: self.y, y: self.x }
61 }
62
63 #[inline]
64 pub const fn yy(self) -> Integer2 {
65 Integer2 { x: self.y, y: self.y }
66 }
67
68 #[inline]
69 pub const fn xxx(self) -> Integer3 {
70 Integer3 { x: self.x, y: self.x, z: self.x }
71 }
72
73 #[inline]
74 pub const fn xxy(self) -> Integer3 {
75 Integer3 { x: self.x, y: self.x, z: self.y }
76 }
77
78 #[inline]
79 pub const fn xyx(self) -> Integer3 {
80 Integer3 { x: self.x, y: self.y, z: self.x }
81 }
82
83 #[inline]
84 pub const fn xyy(self) -> Integer3 {
85 Integer3 { x: self.x, y: self.y, z: self.y }
86 }
87
88 #[inline]
89 pub const fn yxx(self) -> Integer3 {
90 Integer3 { x: self.y, y: self.x, z: self.x }
91 }
92
93 #[inline]
94 pub const fn yxy(self) -> Integer3 {
95 Integer3 { x: self.y, y: self.x, z: self.y }
96 }
97
98 #[inline]
99 pub const fn yyx(self) -> Integer3 {
100 Integer3 { x: self.y, y: self.y, z: self.x }
101 }
102
103 #[inline]
104 pub const fn yyy(self) -> Integer3 {
105 Integer3 { x: self.y, y: self.y, z: self.y }
106 }
107
108 #[inline]
109 pub const fn xxxx(self) -> Integer4 {
110 Integer4 { x: self.x, y: self.x, z: self.x, w: self.x }
111 }
112
113 #[inline]
114 pub const fn xxxy(self) -> Integer4 {
115 Integer4 { x: self.x, y: self.x, z: self.x, w: self.y }
116 }
117
118 #[inline]
119 pub const fn xxyx(self) -> Integer4 {
120 Integer4 { x: self.x, y: self.x, z: self.y, w: self.x }
121 }
122
123 #[inline]
124 pub const fn xxyy(self) -> Integer4 {
125 Integer4 { x: self.x, y: self.x, z: self.y, w: self.y }
126 }
127
128 #[inline]
129 pub const fn xyxx(self) -> Integer4 {
130 Integer4 { x: self.x, y: self.y, z: self.x, w: self.x }
131 }
132
133 #[inline]
134 pub const fn xyxy(self) -> Integer4 {
135 Integer4 { x: self.x, y: self.y, z: self.x, w: self.y }
136 }
137
138 #[inline]
139 pub const fn xyyx(self) -> Integer4 {
140 Integer4 { x: self.x, y: self.y, z: self.y, w: self.x }
141 }
142
143 #[inline]
144 pub const fn xyyy(self) -> Integer4 {
145 Integer4 { x: self.x, y: self.y, z: self.y, w: self.y }
146 }
147
148 #[inline]
149 pub const fn yxxx(self) -> Integer4 {
150 Integer4 { x: self.y, y: self.x, z: self.x, w: self.x }
151 }
152
153 #[inline]
154 pub const fn yxxy(self) -> Integer4 {
155 Integer4 { x: self.y, y: self.x, z: self.x, w: self.y }
156 }
157
158 #[inline]
159 pub const fn yxyx(self) -> Integer4 {
160 Integer4 { x: self.y, y: self.x, z: self.y, w: self.x }
161 }
162
163 #[inline]
164 pub const fn yxyy(self) -> Integer4 {
165 Integer4 { x: self.y, y: self.x, z: self.y, w: self.y }
166 }
167
168 #[inline]
169 pub const fn yyxx(self) -> Integer4 {
170 Integer4 { x: self.y, y: self.y, z: self.x, w: self.x }
171 }
172
173 #[inline]
174 pub const fn yyxy(self) -> Integer4 {
175 Integer4 { x: self.y, y: self.y, z: self.x, w: self.y }
176 }
177
178 #[inline]
179 pub const fn yyyx(self) -> Integer4 {
180 Integer4 { x: self.y, y: self.y, z: self.y, w: self.x }
181 }
182
183 #[inline]
184 pub const fn yyyy(self) -> Integer4 {
185 Integer4 { x: self.y, y: self.y, z: self.y, w: self.y }
186 }
187}
188
189impl Default for Integer2 {
190 #[inline(always)]
191 fn default() -> Self {
192 Self::ZERO
193 }
194}
195
196impl_element2!(i32, Integer2);
197
198impl_element2_op!(i32, Integer2);
199
200impl From<Integer3> for Integer2 {
201 #[inline]
202 fn from(value: Integer3) -> Self {
203 Integer2 { x: value.x, y: value.y }
204 }
205}
206
207impl From<Integer4> for Integer2 {
208 #[inline]
209 fn from(value: Integer4) -> Self {
210 Integer2 { x: value.x, y: value.y }
211 }
212}
213
214impl core::ops::Neg for Integer2 {
215 type Output = Self;
216 #[inline]
217 fn neg(self) -> Self::Output {
218 Self::Output {
219 x: -self.x,
220 y: -self.y,
221 }
222 }
223}
224
225impl core::ops::BitAnd<Self> for Integer2 {
226 type Output = Self;
227 #[inline]
229 fn bitand(self, rhs: Self) -> Self::Output {
230 Self {
231 x: self.x & rhs.x,
232 y: self.y & rhs.y
233 }
234 }
235}
236
237impl core::ops::BitAndAssign<Self> for Integer2 {
238 #[inline]
240 fn bitand_assign(&mut self, rhs: Self) {
241 *self = *self & rhs
242 }
243}
244
245impl core::ops::BitOr<Self> for Integer2 {
246 type Output = Self;
247 #[inline]
249 fn bitor(self, rhs: Self) -> Self::Output {
250 Self {
251 x: self.x | rhs.x,
252 y: self.y | rhs.y
253 }
254 }
255}
256
257impl core::ops::BitOrAssign<Self> for Integer2 {
258 #[inline]
260 fn bitor_assign(&mut self, rhs: Self) {
261 *self = *self | rhs
262 }
263}
264
265impl core::ops::BitXor<Self> for Integer2 {
266 type Output = Self;
267 #[inline]
269 fn bitxor(self, rhs: Self) -> Self::Output {
270 Self {
271 x: self.x ^ rhs.x,
272 y: self.y ^ rhs.y
273 }
274 }
275}
276
277impl core::ops::BitXorAssign<Self> for Integer2 {
278 #[inline]
280 fn bitxor_assign(&mut self, rhs: Self) {
281 *self = *self ^ rhs
282 }
283}
284
285impl core::ops::Not for Integer2 {
286 type Output = Self;
287 #[inline]
289 fn not(self) -> Self::Output {
290 Self {
291 x: !self.x,
292 y: !self.y
293 }
294 }
295}