Debian Codegraph @

debian/missing-sources/glam-0.20.5/tests/vec4.rs

raw
1 #[macro_use]
2 mod support;
3
4 macro_rules! impl_vec4_tests {
5 ($t:ident, $const_new:ident, $new:ident, $vec4:ident, $vec3:ident, $vec2:ident, $mask:ident) => {
6 glam_test!(test_const, {
7 const V: $vec4 = $const_new!([1 as $t, 2 as $t, 3 as $t, 4 as $t]);
8 assert_eq!($vec4::new(1 as $t, 2 as $t, 3 as $t, 4 as $t), V);
9 });
10
11 glam_test!(test_vec4_consts, {
12 assert_eq!($vec4::ZERO, $new(0 as $t, 0 as $t, 0 as $t, 0 as $t));
13 assert_eq!($vec4::ONE, $new(1 as $t, 1 as $t, 1 as $t, 1 as $t));
14 assert_eq!($vec4::X, $new(1 as $t, 0 as $t, 0 as $t, 0 as $t));
15 assert_eq!($vec4::Y, $new(0 as $t, 1 as $t, 0 as $t, 0 as $t));
16 assert_eq!($vec4::Z, $new(0 as $t, 0 as $t, 1 as $t, 0 as $t));
17 assert_eq!($vec4::W, $new(0 as $t, 0 as $t, 0 as $t, 1 as $t));
18 });
19
20 glam_test!(test_new, {
21 let v = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t);
22
23 assert_eq!(v.x, 1 as $t);
24 assert_eq!(v.y, 2 as $t);
25 assert_eq!(v.z, 3 as $t);
26 assert_eq!(v.w, 4 as $t);
27
28 let t = (1 as $t, 2 as $t, 3 as $t, 4 as $t);
29 let v = $vec4::from(t);
30 assert_eq!(t, v.into());
31
32 let a = [1 as $t, 2 as $t, 3 as $t, 4 as $t];
33 let v = $vec4::from(a);
34 let a1: [$t; 4] = v.into();
35 assert_eq!(a, a1);
36
37 let v = $vec4::new(t.0, t.1, t.2, t.3);
38 assert_eq!(t, v.into());
39
40 assert_eq!($vec4::new(1 as $t, 0 as $t, 0 as $t, 0 as $t), $vec4::X);
41 assert_eq!($vec4::new(0 as $t, 1 as $t, 0 as $t, 0 as $t), $vec4::Y);
42 assert_eq!($vec4::new(0 as $t, 0 as $t, 1 as $t, 0 as $t), $vec4::Z);
43 assert_eq!($vec4::new(0 as $t, 0 as $t, 0 as $t, 1 as $t), $vec4::W);
44
45 assert_eq!(
46 v,
47 $vec4::from(($vec3::new(1 as $t, 2 as $t, 3 as $t), 4 as $t))
48 );
49
50 assert_eq!(
51 v,
52 $vec4::from((1 as $t, $vec3::new(2 as $t, 3 as $t, 4 as $t)))
53 );
54
55 assert_eq!(
56 v,
57 $vec4::from(($vec2::new(1 as $t, 2 as $t), 3 as $t, 4 as $t))
58 );
59 assert_eq!(
60 v,
61 $vec4::from(($vec2::new(1 as $t, 2 as $t), $vec2::new(3 as $t, 4 as $t)))
62 );
63 });
64
65 glam_test!(test_fmt, {
66 let a = $vec4::new(1 as $t, 2 as $t, 3 as $t, 4 as $t);
67 assert_eq!(
68 format!("{:?}", a),
69 format!(
70 "{}({:?}, {:?}, {:?}, {:?})",
71 stringify!($vec4),
72 a.x,
73 a.y,
74 a.z,
75 a.w
76 )
77 );
78 // assert_eq!(
79 // format!("{:#?}", a),
80 // "$vec4(\n 1.0,\n 2.0,\n 3.0,\n 4.0\n)"
81 // );
82 assert_eq!(format!("{}", a), "[1, 2, 3, 4]");
83 });
84
85 glam_test!(test_zero, {
86 let v = $vec4::ZERO;
87 assert_eq!((0 as $t, 0 as $t, 0 as $t, 0 as $t), v.into());
88 assert_eq!(v, $vec4::default());
89 });
90
91 glam_test!(test_splat, {
92 let v = $vec4::splat(1 as $t);
93 assert_eq!($vec4::ONE, v);
94 });
95
96 glam_test!(test_accessors, {
97 let mut a = $vec4::ZERO;
98 a.x = 1 as $t;
99 a.y = 2 as $t;
100 a.z = 3 as $t;
101 a.w = 4 as $t;
102 assert_eq!(1 as $t, a.x);
103 assert_eq!(2 as $t, a.y);
104 assert_eq!(3 as $t, a.z);
105 assert_eq!(4 as $t, a.w);
106 assert_eq!((1 as $t, 2 as $t, 3 as $t, 4 as $t), a.into());
107
108 let mut a = $vec4::ZERO;
109 a[0] = 1 as $t;
110 a[1] = 2 as $t;
111 a[2] = 3 as $t;
112 a[3] = 4 as $t;
113 assert_eq!(1 as $t, a[0]);
114 assert_eq!(2 as $t, a[1]);
115 assert_eq!(3 as $t, a[2]);
116 assert_eq!(4 as $t, a[3]);
117 assert_eq!((1 as $t, 2 as $t, 3 as $t, 4 as $t), a.into());
118 });
119
120 glam_test!(test_dot_unsigned, {
121 let x = $new(1 as $t, 0 as $t, 0 as $t, 0 as $t);
122 let y = $new(0 as $t, 1 as $t, 0 as $t, 0 as $t);
123 let z = $new(0 as $t, 0 as $t, 1 as $t, 0 as $t);
124 let w = $new(0 as $t, 0 as $t, 0 as $t, 1 as $t);
125 assert_eq!(1 as $t, x.dot(x));
126 assert_eq!(0 as $t, x.dot(y));
127 assert_eq!(0 as $t, y.dot(z));
128 assert_eq!(0 as $t, z.dot(w));
129 });
130
131 glam_test!(test_ops, {
132 let a = $new(2 as $t, 4 as $t, 8 as $t, 16 as $t);
133 assert_eq!($new(4 as $t, 8 as $t, 16 as $t, 32 as $t), a + a);
134 assert_eq!($new(0 as $t, 0 as $t, 0 as $t, 0 as $t), a - a);
135 assert_eq!($new(4 as $t, 16 as $t, 64 as $t, 256 as $t), a * a);
136 assert_eq!($new(4 as $t, 8 as $t, 16 as $t, 32 as $t), a * 2 as $t);
137 assert_eq!($new(4 as $t, 8 as $t, 16 as $t, 32 as $t), 2 as $t * a);
138 assert_eq!($new(1 as $t, 1 as $t, 1 as $t, 1 as $t), a / a);
139 assert_eq!($new(1 as $t, 2 as $t, 4 as $t, 8 as $t), a / 2 as $t);
140 assert_eq!($new(8 as $t, 4 as $t, 2 as $t, 1 as $t), 16 as $t / a);
141 assert_eq!($new(0 as $t, 0 as $t, 0 as $t, 0 as $t), a % a);
142 assert_eq!($new(0 as $t, 1 as $t, 1 as $t, 1 as $t), a % (a - 1 as $t));
143 assert_eq!($new(0 as $t, 0 as $t, 0 as $t, 0 as $t), a % 1 as $t);
144 assert_eq!($new(2 as $t, 1 as $t, 2 as $t, 1 as $t), a % 3 as $t);
145 assert_eq!($new(1 as $t, 1 as $t, 1 as $t, 1 as $t), 17 as $t % a);
146 assert_eq!($new(2 as $t, 4 as $t, 0 as $t, 0 as $t), a % 8 as $t);
147 });
148
149 glam_test!(test_assign_ops, {
150 let a = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t);
151 let mut b = a;
152 b += a;
153 assert_eq!($new(2 as $t, 4 as $t, 6 as $t, 8 as $t), b);
154 b -= a;
155 assert_eq!($new(1 as $t, 2 as $t, 3 as $t, 4 as $t), b);
156 b *= a;
157 assert_eq!($new(1 as $t, 4 as $t, 9 as $t, 16 as $t), b);
158 b /= a;
159 assert_eq!($new(1 as $t, 2 as $t, 3 as $t, 4 as $t), b);
160 b *= 2 as $t;
161 assert_eq!($new(2 as $t, 4 as $t, 6 as $t, 8 as $t), b);
162 b /= 2 as $t;
163 assert_eq!($new(1 as $t, 2 as $t, 3 as $t, 4 as $t), b);
164 b %= (b + 1 as $t);
165 assert_eq!($new(1 as $t, 2 as $t, 3 as $t, 4 as $t), b);
166 b %= b;
167 assert_eq!($new(0 as $t, 0 as $t, 0 as $t, 0 as $t), b);
168 });
169
170 glam_test!(test_min_max, {
171 let a = $new(4 as $t, 6 as $t, 2 as $t, 8 as $t);
172 let b = $new(5 as $t, 3 as $t, 7 as $t, 1 as $t);
173 assert_eq!((4 as $t, 3 as $t, 2 as $t, 1 as $t), a.min(b).into());
174 assert_eq!((4 as $t, 3 as $t, 2 as $t, 1 as $t), b.min(a).into());
175 assert_eq!((5 as $t, 6 as $t, 7 as $t, 8 as $t), a.max(b).into());
176 assert_eq!((5 as $t, 6 as $t, 7 as $t, 8 as $t), b.max(a).into());
177 });
178
179 glam_test!(test_clamp, {
180 fn vec(x: i32, y: i32, z: i32, w: i32) -> $vec4 {
181 $vec4::new(x as $t, y as $t, z as $t, w as $t)
182 }
183 let min = vec(1, 1, 3, 3);
184 let max = vec(6, 6, 8, 8);
185 assert_eq!(vec(0, 0, 0, 0).clamp(min, max), vec(1, 1, 3, 3));
186 assert_eq!(vec(2, 2, 2, 2).clamp(min, max), vec(2, 2, 3, 3));
187 assert_eq!(vec(4, 4, 5, 5).clamp(min, max), vec(4, 4, 5, 5));
188 assert_eq!(vec(6, 6, 6, 6).clamp(min, max), vec(6, 6, 6, 6));
189 assert_eq!(vec(7, 7, 7, 7).clamp(min, max), vec(6, 6, 7, 7));
190 assert_eq!(vec(9, 9, 9, 9).clamp(min, max), vec(6, 6, 8, 8));
191
192 should_glam_assert!({ $vec4::clamp($vec4::ZERO, $vec4::ONE, $vec4::ZERO) });
193 });
194
195 glam_test!(test_hmin_hmax, {
196 assert_eq!(
197 1 as $t,
198 $new(1 as $t, 2 as $t, 3 as $t, 4 as $t).min_element()
199 );
200 assert_eq!(
201 1 as $t,
202 $new(4 as $t, 1 as $t, 2 as $t, 3 as $t).min_element()
203 );
204 assert_eq!(
205 1 as $t,
206 $new(3 as $t, 4 as $t, 1 as $t, 2 as $t).min_element()
207 );
208 assert_eq!(
209 1 as $t,
210 $new(2 as $t, 3 as $t, 4 as $t, 1 as $t).min_element()
211 );
212 assert_eq!(
213 4 as $t,
214 $new(1 as $t, 2 as $t, 3 as $t, 4 as $t).max_element()
215 );
216 assert_eq!(
217 4 as $t,
218 $new(4 as $t, 1 as $t, 2 as $t, 3 as $t).max_element()
219 );
220 assert_eq!(
221 4 as $t,
222 $new(3 as $t, 4 as $t, 1 as $t, 2 as $t).max_element()
223 );
224 assert_eq!(
225 4 as $t,
226 $new(2 as $t, 3 as $t, 4 as $t, 1 as $t).max_element()
227 );
228 assert_eq!(
229 3 as $t,
230 $new(1 as $t, 2 as $t, 3 as $t, 4 as $t)
231 .truncate()
232 .max_element()
233 );
234 assert_eq!(
235 2 as $t,
236 $new(4 as $t, 3 as $t, 2 as $t, 1 as $t)
237 .truncate()
238 .min_element()
239 );
240 });
241
242 glam_test!(test_eq, {
243 let a = $new(1 as $t, 1 as $t, 1 as $t, 1 as $t);
244 let b = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t);
245 assert!(a.cmpeq(a).all());
246 assert!(b.cmpeq(b).all());
247 assert!(a.cmpne(b).any());
248 assert!(b.cmpne(a).any());
249 assert!(b.cmpeq(a).any());
250 });
251
252 glam_test!(test_cmp, {
253 assert!(!$mask::default().any());
254 assert!(!$mask::default().all());
255 assert_eq!($mask::default().bitmask(), 0x0);
256 let a = $new(1 as $t, 1 as $t, 1 as $t, 1 as $t);
257 let b = $new(2 as $t, 2 as $t, 2 as $t, 2 as $t);
258 let c = $new(1 as $t, 1 as $t, 2 as $t, 2 as $t);
259 let d = $new(2 as $t, 1 as $t, 1 as $t, 2 as $t);
260 assert_eq!(a.cmplt(a).bitmask(), 0x0);
261 assert_eq!(a.cmplt(b).bitmask(), 0xf);
262 assert_eq!(a.cmplt(c).bitmask(), 0xc);
263 assert_eq!(c.cmple(a).bitmask(), 0x3);
264 assert_eq!(a.cmplt(d).bitmask(), 0x9);
265 assert!(a.cmplt(b).all());
266 assert!(a.cmplt(c).any());
267 assert!(a.cmple(b).all());
268 assert!(a.cmple(a).all());
269 assert!(b.cmpgt(a).all());
270 assert!(b.cmpge(a).all());
271 assert!(b.cmpge(b).all());
272 assert!(!(a.cmpge(c).all()));
273 assert!(c.cmple(c).all());
274 assert!(c.cmpge(c).all());
275 assert!(a.cmpeq(a).all());
276 assert!(!a.cmpeq(b).all());
277 assert!(a.cmpeq(c).any());
278 assert!(!a.cmpne(a).all());
279 assert!(a.cmpne(b).all());
280 assert!(a.cmpne(c).any());
281 assert!(a == a);
282 });
283
284 glam_test!(test_slice, {
285 let a = [1 as $t, 2 as $t, 3 as $t, 4 as $t];
286 let b = $vec4::from_slice(&a);
287 let c: [$t; 4] = b.into();
288 assert_eq!(a, c);
289 let mut d = [0 as $t, 0 as $t, 0 as $t, 0 as $t];
290 b.write_to_slice(&mut d[..]);
291 assert_eq!(a, d);
292
293 should_panic!({ $vec4::ONE.write_to_slice(&mut [0 as $t; 3]) });
294 should_panic!({ $vec4::from_slice(&[0 as $t; 3]) });
295 });
296
297 // #[test]
298 // fn test_mask_as_ref() {
299 // assert_eq!(
300 // $mask::new(false, false, false, false).as_ref(),
301 // &[0, 0, 0, 0]
302 // );
303 // assert_eq!(
304 // $mask::new(false, false, true, true).as_ref(),
305 // &[0, 0, !0, !0]
306 // );
307 // assert_eq!(
308 // $mask::new(true, true, false, false).as_ref(),
309 // &[!0, !0, 0, 0]
310 // );
311 // assert_eq!(
312 // $mask::new(false, true, false, true).as_ref(),
313 // &[0, !0, 0, !0]
314 // );
315 // assert_eq!(
316 // $mask::new(true, false, true, false).as_ref(),
317 // &[!0, 0, !0, 0]
318 // );
319 // assert_eq!(
320 // $mask::new(true, true, true, true).as_ref(),
321 // &[!0, !0, !0, !0]
322 // );
323 // }
324
325 glam_test!(test_mask_from, {
326 assert_eq!(
327 Into::<[u32; 4]>::into($mask::new(false, false, false, false)),
328 [0, 0, 0, 0]
329 );
330 assert_eq!(
331 Into::<[u32; 4]>::into($mask::new(false, false, true, true)),
332 [0, 0, !0, !0]
333 );
334 assert_eq!(
335 Into::<[u32; 4]>::into($mask::new(true, true, false, false)),
336 [!0, !0, 0, 0]
337 );
338 assert_eq!(
339 Into::<[u32; 4]>::into($mask::new(false, true, false, true)),
340 [0, !0, 0, !0]
341 );
342 assert_eq!(
343 Into::<[u32; 4]>::into($mask::new(true, false, true, false)),
344 [!0, 0, !0, 0]
345 );
346 assert_eq!(
347 Into::<[u32; 4]>::into($mask::new(true, true, true, true)),
348 [!0, !0, !0, !0]
349 );
350 });
351
352 glam_test!(test_mask_bitmask, {
353 assert_eq!($mask::new(false, false, false, false).bitmask(), 0b0000);
354 assert_eq!($mask::new(false, false, true, true).bitmask(), 0b1100);
355 assert_eq!($mask::new(true, true, false, false).bitmask(), 0b0011);
356 assert_eq!($mask::new(false, true, false, true).bitmask(), 0b1010);
357 assert_eq!($mask::new(true, false, true, false).bitmask(), 0b0101);
358 assert_eq!($mask::new(true, true, true, true).bitmask(), 0b1111);
359 });
360
361 glam_test!(test_mask_any, {
362 assert_eq!($mask::new(false, false, false, false).any(), false);
363 assert_eq!($mask::new(true, false, false, false).any(), true);
364 assert_eq!($mask::new(false, true, false, false).any(), true);
365 assert_eq!($mask::new(false, false, true, false).any(), true);
366 assert_eq!($mask::new(false, false, false, true).any(), true);
367 });
368
369 glam_test!(test_mask_all, {
370 assert_eq!($mask::new(true, true, true, true).all(), true);
371 assert_eq!($mask::new(false, true, true, true).all(), false);
372 assert_eq!($mask::new(true, false, true, true).all(), false);
373 assert_eq!($mask::new(true, true, false, true).all(), false);
374 assert_eq!($mask::new(true, true, true, false).all(), false);
375 });
376
377 glam_test!(test_mask_select, {
378 let a = $vec4::new(1 as $t, 2 as $t, 3 as $t, 4 as $t);
379 let b = $vec4::new(5 as $t, 6 as $t, 7 as $t, 8 as $t);
380 assert_eq!(
381 $vec4::select($mask::new(true, true, true, true), a, b),
382 $vec4::new(1 as $t, 2 as $t, 3 as $t, 4 as $t),
383 );
384 assert_eq!(
385 $vec4::select($mask::new(true, false, true, false), a, b),
386 $vec4::new(1 as $t, 6 as $t, 3 as $t, 8 as $t),
387 );
388 assert_eq!(
389 $vec4::select($mask::new(false, true, false, true), a, b),
390 $vec4::new(5 as $t, 2 as $t, 7 as $t, 4 as $t),
391 );
392 assert_eq!(
393 $vec4::select($mask::new(false, false, false, false), a, b),
394 $vec4::new(5 as $t, 6 as $t, 7 as $t, 8 as $t),
395 );
396 });
397
398 glam_test!(test_mask_and, {
399 assert_eq!(
400 ($mask::new(false, false, false, false) & $mask::new(false, false, false, false))
401 .bitmask(),
402 0b0000,
403 );
404 assert_eq!(
405 ($mask::new(true, true, true, true) & $mask::new(true, true, true, true)).bitmask(),
406 0b1111,
407 );
408 assert_eq!(
409 ($mask::new(true, false, true, false) & $mask::new(false, true, false, true))
410 .bitmask(),
411 0b0000,
412 );
413 assert_eq!(
414 ($mask::new(true, false, true, true) & $mask::new(true, true, true, false))
415 .bitmask(),
416 0b0101,
417 );
418
419 let mut mask = $mask::new(true, true, false, false);
420 mask &= $mask::new(true, false, true, false);
421 assert_eq!(mask.bitmask(), 0b0001);
422 });
423
424 glam_test!(test_mask_or, {
425 assert_eq!(
426 ($mask::new(false, false, false, false) | $mask::new(false, false, false, false))
427 .bitmask(),
428 0b0000,
429 );
430 assert_eq!(
431 ($mask::new(true, true, true, true) | $mask::new(true, true, true, true)).bitmask(),
432 0b1111,
433 );
434 assert_eq!(
435 ($mask::new(true, false, true, false) | $mask::new(false, true, false, true))
436 .bitmask(),
437 0b1111,
438 );
439 assert_eq!(
440 ($mask::new(true, false, true, false) | $mask::new(true, false, true, false))
441 .bitmask(),
442 0b0101,
443 );
444
445 let mut mask = $mask::new(true, true, false, false);
446 mask |= $mask::new(true, false, true, false);
447 assert_eq!(mask.bitmask(), 0b0111);
448 });
449
450 glam_test!(test_mask_not, {
451 assert_eq!((!$mask::new(false, false, false, false)).bitmask(), 0b1111);
452 assert_eq!((!$mask::new(true, true, true, true)).bitmask(), 0b0000);
453 assert_eq!((!$mask::new(true, false, true, false)).bitmask(), 0b1010);
454 assert_eq!((!$mask::new(false, true, false, true)).bitmask(), 0b0101);
455 });
456
457 glam_test!(test_mask_fmt, {
458 let a = $mask::new(true, false, true, false);
459
460 assert_eq!(format!("{}", a), "[true, false, true, false]");
461 // assert_eq!(
462 // format!("{:?}", a),
463 // format!("{}(0xffffffff, 0x0, 0xffffffff, 0x0)", stringify!($mask))
464 // );
465 });
466
467 glam_test!(test_mask_eq, {
468 let a = $mask::new(true, false, true, false);
469 let b = $mask::new(true, false, true, false);
470 let c = $mask::new(false, true, true, false);
471
472 assert_eq!(a, b);
473 assert_eq!(b, a);
474 assert_ne!(a, c);
475 assert_ne!(b, c);
476 });
477
478 glam_test!(test_mask_hash, {
479 use std::collections::hash_map::DefaultHasher;
480 use std::hash::Hash;
481 use std::hash::Hasher;
482
483 let a = $mask::new(true, false, true, false);
484 let b = $mask::new(true, false, true, false);
485 let c = $mask::new(false, true, true, false);
486
487 let mut hasher = DefaultHasher::new();
488 a.hash(&mut hasher);
489 let a_hashed = hasher.finish();
490
491 let mut hasher = DefaultHasher::new();
492 b.hash(&mut hasher);
493 let b_hashed = hasher.finish();
494
495 let mut hasher = DefaultHasher::new();
496 c.hash(&mut hasher);
497 let c_hashed = hasher.finish();
498
499 assert_eq!(a, b);
500 assert_eq!(a_hashed, b_hashed);
501 assert_ne!(a, c);
502 assert_ne!(a_hashed, c_hashed);
503 });
504
505 glam_test!(test_to_from_slice, {
506 let v = $vec4::new(1 as $t, 2 as $t, 3 as $t, 4 as $t);
507 let mut a = [0 as $t, 0 as $t, 0 as $t, 0 as $t];
508 v.write_to_slice(&mut a);
509 assert_eq!(v, $vec4::from_slice(&a));
510 });
511
512 glam_test!(test_sum, {
513 let one = $vec4::ONE;
514 assert_eq!(vec![one, one].iter().sum::<$vec4>(), one + one);
515 });
516
517 glam_test!(test_product, {
518 let two = $vec4::new(2 as $t, 2 as $t, 2 as $t, 2 as $t);
519 assert_eq!(vec![two, two].iter().product::<$vec4>(), two * two);
520 });
521 };
522 }
523
524 macro_rules! impl_vec4_signed_tests {
525 ($t:ident, $const_new:ident, $new:ident, $vec4:ident, $vec3:ident, $vec2:ident, $mask:ident) => {
526 impl_vec4_tests!($t, $const_new, $new, $vec4, $vec3, $vec2, $mask);
527
528 glam_test!(test_neg, {
529 let a = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t);
530 assert_eq!((-1 as $t, -2 as $t, -3 as $t, -4 as $t), (-a).into());
531 });
532
533 glam_test!(test_dot_signed, {
534 let x = $new(1 as $t, 0 as $t, 0 as $t, 0 as $t);
535 let y = $new(0 as $t, 1 as $t, 0 as $t, 0 as $t);
536 let z = $new(0 as $t, 0 as $t, 1 as $t, 0 as $t);
537 let w = $new(0 as $t, 0 as $t, 0 as $t, 1 as $t);
538 assert_eq!(1 as $t, x.dot(x));
539 assert_eq!(0 as $t, x.dot(y));
540 assert_eq!(0 as $t, x.dot(-z));
541 assert_eq!(-1 as $t, w.dot(-w));
542 });
543 };
544 }
545
546 macro_rules! impl_vec4_eq_hash_tests {
547 ($t:ident, $new:ident) => {
548 glam_test!(test_ve2_hash, {
549 use std::collections::hash_map::DefaultHasher;
550 use std::hash::Hash;
551 use std::hash::Hasher;
552
553 let a = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t);
554 let b = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t);
555 let c = $new(3 as $t, 2 as $t, 1 as $t, 4 as $t);
556
557 let mut hasher = DefaultHasher::new();
558 a.hash(&mut hasher);
559 let a_hashed = hasher.finish();
560
561 let mut hasher = DefaultHasher::new();
562 b.hash(&mut hasher);
563 let b_hashed = hasher.finish();
564
565 let mut hasher = DefaultHasher::new();
566 c.hash(&mut hasher);
567 let c_hashed = hasher.finish();
568
569 assert_eq!(a, b);
570 assert_eq!(a_hashed, b_hashed);
571 assert_ne!(a, c);
572 assert_ne!(a_hashed, c_hashed);
573 });
574 };
575 }
576
577 macro_rules! impl_vec4_float_tests {
578 ($t:ident, $const_new:ident, $new:ident, $vec4:ident, $vec3:ident, $vec2:ident, $mask:ident) => {
579 impl_vec4_signed_tests!($t, $const_new, $new, $vec4, $vec3, $vec2, $mask);
580 impl_vec_float_normalize_tests!($t, $vec4);
581
582 use core::$t::INFINITY;
583 use core::$t::NAN;
584 use core::$t::NEG_INFINITY;
585
586 glam_test!(test_vec4_nan, {
587 assert!($vec4::NAN.is_nan());
588 assert!(!$vec4::NAN.is_finite());
589 });
590
591 glam_test!(test_funcs, {
592 let x = $new(1.0, 0.0, 0.0, 0.0);
593 let y = $new(0.0, 1.0, 0.0, 0.0);
594 let z = $new(0.0, 0.0, 1.0, 0.0);
595 let w = $new(0.0, 0.0, 0.0, 1.0);
596 assert_eq!(4.0, (2.0 * x).length_squared());
597 assert_eq!(9.0, (-3.0 * y).length_squared());
598 assert_eq!(16.0, (4.0 * z).length_squared());
599 assert_eq!(64.0, (8.0 * w).length_squared());
600 assert_eq!(2.0, (-2.0 * x).length());
601 assert_eq!(3.0, (3.0 * y).length());
602 assert_eq!(4.0, (-4.0 * z).length());
603 assert_eq!(5.0, (-5.0 * w).length());
604 assert_eq!(2.0, x.distance_squared(y));
605 assert_eq!(13.0, (2.0 * x).distance_squared(-3.0 * z));
606 assert_eq!((2.0 as $t).sqrt(), w.distance(y));
607 assert_eq!(5.0, (3.0 * x).distance(-4.0 * y));
608 assert_eq!(13.0, (-5.0 * w).distance(12.0 * y));
609 assert_eq!(x, (2.0 * x).normalize());
610 assert_eq!(
611 1.0 * 5.0 + 2.0 * 6.0 + 3.0 * 7.0 + 4.0 * 8.0,
612 $new(1.0, 2.0, 3.0, 4.0).dot($new(5.0, 6.0, 7.0, 8.0))
613 );
614 assert_eq!(
615 2.0 * 2.0 + 3.0 * 3.0 + 4.0 * 4.0 + 5.0 * 5.0,
616 $new(2.0, 3.0, 4.0, 5.0).length_squared()
617 );
618 assert_eq!(
619 (2.0 as $t * 2.0 + 3.0 * 3.0 + 4.0 * 4.0 + 5.0 * 5.0).sqrt(),
620 $new(2.0, 3.0, 4.0, 5.0).length()
621 );
622 assert_eq!(
623 1.0 / (2.0 as $t * 2.0 + 3.0 * 3.0 + 4.0 * 4.0 + 5.0 * 5.0).sqrt(),
624 $new(2.0, 3.0, 4.0, 5.0).length_recip()
625 );
626 assert!($new(2.0, 3.0, 4.0, 5.0).normalize().is_normalized());
627 assert_approx_eq!(
628 $new(2.0, 3.0, 4.0, 5.0)
629 / (2.0 as $t * 2.0 + 3.0 * 3.0 + 4.0 * 4.0 + 5.0 * 5.0).sqrt(),
630 $new(2.0, 3.0, 4.0, 5.0).normalize()
631 );
632 assert_eq!(
633 $new(0.5, 0.25, 0.125, 0.0625),
634 $new(2.0, 4.0, 8.0, 16.0).recip()
635 );
636 });
637
638 glam_test!(test_project_reject, {
639 assert_eq!(
640 $new(0.0, 0.0, 0.0, 1.0),
641 $new(0.0, 1.0, 0.0, 1.0).project_onto($new(0.0, 0.0, 0.0, 2.0))
642 );
643 assert_eq!(
644 $new(0.0, 1.0, 0.0, 0.0),
645 $new(0.0, 1.0, 0.0, 1.0).reject_from($new(0.0, 0.0, 0.0, 2.0))
646 );
647 assert_eq!(
648 $new(0.0, 0.0, 0.0, 1.0),
649 $new(0.0, 1.0, 0.0, 1.0).project_onto_normalized($new(0.0, 0.0, 0.0, 1.0))
650 );
651 assert_eq!(
652 $new(0.0, 1.0, 0.0, 0.0),
653 $new(0.0, 1.0, 0.0, 1.0).reject_from_normalized($new(0.0, 0.0, 0.0, 1.0))
654 );
655 should_glam_assert!({ $vec4::ONE.project_onto($vec4::ZERO) });
656 should_glam_assert!({ $vec4::ONE.reject_from($vec4::ZERO) });
657 should_glam_assert!({ $vec4::ONE.project_onto_normalized($vec4::ONE) });
658 should_glam_assert!({ $vec4::ONE.reject_from_normalized($vec4::ONE) });
659 });
660
661 glam_test!(test_signum, {
662 assert_eq!($vec4::ZERO.signum(), $vec4::ONE);
663 assert_eq!(-$vec4::ZERO.signum(), -$vec4::ONE);
664 assert_eq!($vec4::ONE.signum(), $vec4::ONE);
665 assert_eq!((-$vec4::ONE).signum(), -$vec4::ONE);
666 assert_eq!($vec4::splat(INFINITY).signum(), $vec4::ONE);
667 assert_eq!($vec4::splat(NEG_INFINITY).signum(), -$vec4::ONE);
668 assert!($vec4::splat(NAN).signum().is_nan_mask().all());
669 });
670
671 glam_test!(test_abs, {
672 assert_eq!($vec4::ZERO.abs(), $vec4::ZERO);
673 assert_eq!($vec4::ONE.abs(), $vec4::ONE);
674 assert_eq!((-$vec4::ONE).abs(), $vec4::ONE);
675 });
676
677 glam_test!(test_round, {
678 assert_eq!($vec4::new(1.35, 0.0, 0.0, 0.0).round().x, 1.0);
679 assert_eq!($vec4::new(0.0, 1.5, 0.0, 0.0).round().y, 2.0);
680 assert_eq!($vec4::new(0.0, 0.0, -15.5, 0.0).round().z, -16.0);
681 assert_eq!($vec4::new(0.0, 0.0, 0.0, 0.0).round().z, 0.0);
682 assert_eq!($vec4::new(0.0, 21.1, 0.0, 0.0).round().y, 21.0);
683 assert_eq!($vec4::new(0.0, 0.0, 0.0, 11.123).round().w, 11.0);
684 assert_eq!($vec4::new(0.0, 0.0, 11.501, 0.0).round().z, 12.0);
685 assert_eq!(
686 $vec4::new(NEG_INFINITY, INFINITY, 1.0, -1.0).round(),
687 $vec4::new(NEG_INFINITY, INFINITY, 1.0, -1.0)
688 );
689 assert!($vec4::new(NAN, 0.0, 0.0, 1.0).round().x.is_nan());
690 });
691
692 glam_test!(test_floor, {
693 assert_eq!(
694 $vec4::new(1.35, 1.5, -1.5, 1.999).floor(),
695 $vec4::new(1.0, 1.0, -2.0, 1.0)
696 );
697 assert_eq!(
698 $vec4::new(INFINITY, NEG_INFINITY, 0.0, 0.0).floor(),
699 $vec4::new(INFINITY, NEG_INFINITY, 0.0, 0.0)
700 );
701 assert!($vec4::new(0.0, NAN, 0.0, 0.0).floor().y.is_nan());
702 assert_eq!(
703 $vec4::new(-0.0, -2000000.123, 10000000.123, 1000.9).floor(),
704 $vec4::new(-0.0, -2000001.0, 10000000.0, 1000.0)
705 );
706 });
707
708 glam_test!(test_fract, {
709 assert_approx_eq!(
710 $vec4::new(1.35, 1.5, -1.5, 1.999).fract(),
711 $vec4::new(0.35, 0.5, 0.5, 0.999)
712 );
713 assert_approx_eq!(
714 $vec4::new(-0.0, -200000.123, 1000000.123, 1000.9).fract(),
715 $vec4::new(0.0, 0.877, 0.123, 0.9),
716 0.002
717 );
718 });
719
720 glam_test!(test_ceil, {
721 assert_eq!(
722 $vec4::new(1.35, 1.5, -1.5, 1234.1234).ceil(),
723 $vec4::new(2.0, 2.0, -1.0, 1235.0)
724 );
725 assert_eq!(
726 $vec4::new(INFINITY, NEG_INFINITY, 0.0, 0.0).ceil(),
727 $vec4::new(INFINITY, NEG_INFINITY, 0.0, 0.0)
728 );
729 assert!($vec4::new(0.0, 0.0, NAN, 0.0).ceil().z.is_nan());
730 assert_eq!(
731 $vec4::new(-1234.1234, -2000000.123, 1000000.123, 1000.9).ceil(),
732 $vec4::new(-1234.0, -2000000.0, 1000001.0, 1001.0)
733 );
734 });
735
736 glam_test!(test_lerp, {
737 let v0 = $vec4::new(-1.0, -1.0, -1.0, -1.0);
738 let v1 = $vec4::new(1.0, 1.0, 1.0, 1.0);
739 assert_approx_eq!(v0, v0.lerp(v1, 0.0));
740 assert_approx_eq!(v1, v0.lerp(v1, 1.0));
741 assert_approx_eq!($vec4::ZERO, v0.lerp(v1, 0.5));
742 });
743
744 glam_test!(test_is_finite, {
745 assert!($vec4::new(0.0, 0.0, 0.0, 0.0).is_finite());
746 assert!($vec4::new(-1e-10, 1.0, 1e10, 42.0).is_finite());
747 assert!(!$vec4::new(INFINITY, 0.0, 0.0, 0.0).is_finite());
748 assert!(!$vec4::new(0.0, NAN, 0.0, 0.0).is_finite());
749 assert!(!$vec4::new(0.0, 0.0, NEG_INFINITY, 0.0).is_finite());
750 assert!(!$vec4::new(0.0, 0.0, 0.0, NAN).is_finite());
751 });
752
753 glam_test!(test_powf, {
754 assert_eq!(
755 $vec4::new(2.0, 4.0, 8.0, 16.0).powf(2.0),
756 $vec4::new(4.0, 16.0, 64.0, 256.0)
757 );
758 });
759
760 glam_test!(test_exp, {
761 assert_eq!(
762 $vec4::new(1.0, 2.0, 3.0, 4.0).exp(),
763 $vec4::new(
764 (1.0 as $t).exp(),
765 (2.0 as $t).exp(),
766 (3.0 as $t).exp(),
767 (4.0 as $t).exp()
768 )
769 );
770 });
771
772 glam_test!(test_clamp_length, {
773 // Too long gets shortened
774 assert_eq!(
775 $vec4::new(12.0, 16.0, 0.0, 0.0).clamp_length(7.0, 10.0),
776 $vec4::new(6.0, 8.0, 0.0, 0.0) // shortened to length 10.0
777 );
778 // In the middle is unchanged
779 assert_eq!(
780 $vec4::new(2.0, 1.0, 0.0, 0.0).clamp_length(0.5, 5.0),
781 $vec4::new(2.0, 1.0, 0.0, 0.0) // unchanged
782 );
783 // Too short gets lengthened
784 assert_eq!(
785 $vec4::new(0.6, 0.8, 0.0, 0.0).clamp_length(10.0, 20.0),
786 $vec4::new(6.0, 8.0, 0.0, 0.0) // lengthened to length 10.0
787 );
788 should_glam_assert!({ $vec4::ONE.clamp_length(1.0, 0.0) });
789 });
790
791 glam_test!(test_clamp_length_max, {
792 // Too long gets shortened
793 assert_eq!(
794 $vec4::new(12.0, 16.0, 0.0, 0.0).clamp_length_max(10.0),
795 $vec4::new(6.0, 8.0, 0.0, 0.0) // shortened to length 10.0
796 );
797 // Not too long is unchanged
798 assert_eq!(
799 $vec4::new(2.0, 1.0, 0.0, 0.0).clamp_length_max(5.0),
800 $vec4::new(2.0, 1.0, 0.0, 0.0) // unchanged
801 );
802 });
803
804 glam_test!(test_clamp_length_min, {
805 // Not too short is unchanged
806 assert_eq!(
807 $vec4::new(2.0, 1.0, 0.0, 0.0).clamp_length_min(0.5),
808 $vec4::new(2.0, 1.0, 0.0, 0.0) // unchanged
809 );
810 // Too short gets lengthened
811 assert_eq!(
812 $vec4::new(0.6, 0.8, 0.0, 0.0).clamp_length_min(10.0),
813 $vec4::new(6.0, 8.0, 0.0, 0.0) // lengthened to length 10.0
814 );
815 });
816
817 glam_test!(test_mul_add, {
818 assert_eq!(
819 $vec4::new(1.0, 1.0, 1.0, 1.0).mul_add(
820 $vec4::new(0.5, 2.0, -4.0, 0.0),
821 $vec4::new(-1.0, -1.0, -1.0, -1.0)
822 ),
823 $vec4::new(-0.5, 1.0, -5.0, -1.0)
824 );
825 });
826 };
827 }
828
829 macro_rules! impl_vec4_scalar_shift_op_test {
830 ($vec4:ident, $t_min:literal, $t_max:literal, $rhs_min:literal, $rhs_max:literal) => {
831 glam_test!(test_vec4_scalar_shift_ops, {
832 for x in $t_min..$t_max {
833 for y in $t_min..$t_max {
834 for z in $t_min..$t_max {
835 for w in $t_min..$t_max {
836 for rhs in $rhs_min..$rhs_max {
837 assert_eq!(
838 $vec4::new(x, y, z, w) << rhs,
839 $vec4::new(x << rhs, y << rhs, z << rhs, w << rhs)
840 );
841 assert_eq!(
842 $vec4::new(x, y, z, w) >> rhs,
843 $vec4::new(x >> rhs, y >> rhs, z >> rhs, w >> rhs)
844 );
845 }
846 }
847 }
848 }
849 }
850 });
851 };
852 }
853
854 macro_rules! impl_vec4_scalar_shift_op_tests {
855 ($vec4:ident, $t_min:literal, $t_max:literal) => {
856 mod shift_by_i8 {
857 use glam::$vec4;
858 impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0i8, 2);
859 }
860 mod shift_by_i16 {
861 use glam::$vec4;
862 impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0i16, 2);
863 }
864 mod shift_by_i32 {
865 use glam::$vec4;
866 impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0i32, 2);
867 }
868 mod shift_by_u8 {
869 use glam::$vec4;
870 impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0u8, 2);
871 }
872 mod shift_by_u16 {
873 use glam::$vec4;
874 impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0u16, 2);
875 }
876 mod shift_by_u32 {
877 use glam::$vec4;
878 impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0u32, 2);
879 }
880 };
881 }
882
883 macro_rules! impl_vec4_shift_op_test {
884 ($vec4:ident, $rhs:ident, $t_min:literal, $t_max:literal) => {
885 glam_test!(test_vec4_shift_ops, {
886 for x1 in $t_min..$t_max {
887 for y1 in $t_min..$t_max {
888 for z1 in $t_min..$t_max {
889 for w1 in $t_min..$t_max {
890 for x2 in $t_min..$t_max {
891 for y2 in $t_min..$t_max {
892 for z2 in $t_min..$t_max {
893 for w2 in $t_min..$t_max {
894 assert_eq!(
895 $vec4::new(x1, y1, z1, w1)
896 << $rhs::new(x2, y2, z2, w2),
897 $vec4::new(x1 << x2, y1 << y2, z1 << z2, w1 << w2)
898 );
899 assert_eq!(
900 $vec4::new(x1, y1, z1, w1)
901 >> $rhs::new(x2, y2, z2, w2),
902 $vec4::new(x1 >> x2, y1 >> y2, z1 >> z2, w1 >> w2)
903 );
904 }
905 }
906 }
907 }
908 }
909 }
910 }
911 }
912 });
913 };
914 }
915
916 macro_rules! impl_vec4_shift_op_tests {
917 ($vec4:ident) => {
918 mod shift_ivec4_by_ivec4 {
919 use super::*;
920 impl_vec4_shift_op_test!($vec4, IVec4, 0, 2);
921 }
922 mod shift_ivec4_by_uvec4 {
923 use super::*;
924 impl_vec4_shift_op_test!($vec4, UVec4, 0, 2);
925 }
926 };
927 }
928
929 macro_rules! impl_vec4_scalar_bit_op_tests {
930 ($vec4:ident, $t_min:literal, $t_max:literal) => {
931 glam_test!(test_vec4_scalar_bit_ops, {
932 for x in $t_min..$t_max {
933 for y in $t_min..$t_max {
934 for z in $t_min..$t_max {
935 for w in $t_min..$t_max {
936 for rhs in $t_min..$t_max {
937 assert_eq!(
938 $vec4::new(x, y, z, w) & rhs,
939 $vec4::new(x & rhs, y & rhs, z & rhs, w & rhs)
940 );
941 assert_eq!(
942 $vec4::new(x, y, z, w) | rhs,
943 $vec4::new(x | rhs, y | rhs, z | rhs, w | rhs)
944 );
945 assert_eq!(
946 $vec4::new(x, y, z, w) ^ rhs,
947 $vec4::new(x ^ rhs, y ^ rhs, z ^ rhs, w ^ rhs)
948 );
949 }
950 }
951 }
952 }
953 }
954 });
955 };
956 }
957
958 macro_rules! impl_vec4_bit_op_tests {
959 ($vec4:ident, $t_min:literal, $t_max:literal) => {
960 glam_test!(test_vec4_bit_ops, {
961 for x1 in $t_min..$t_max {
962 for y1 in $t_min..$t_max {
963 for z1 in $t_min..$t_max {
964 for w1 in $t_min..$t_max {
965 assert_eq!(!$vec4::new(x1, y1, z1, w1), $vec4::new(!x1, !y1, !z1, !w1));
966
967 for x2 in $t_min..$t_max {
968 for y2 in $t_min..$t_max {
969 for z2 in $t_min..$t_max {
970 for w2 in $t_min..$t_max {
971 assert_eq!(
972 $vec4::new(x1, y1, z1, w1)
973 & $vec4::new(x2, y2, z2, w2),
974 $vec4::new(x1 & x2, y1 & y2, z1 & z2, w1 & w2)
975 );
976 assert_eq!(
977 $vec4::new(x1, y1, z1, w1)
978 | $vec4::new(x2, y2, z2, w2),
979 $vec4::new(x1 | x2, y1 | y2, z1 | z2, w1 | w2)
980 );
981 assert_eq!(
982 $vec4::new(x1, y1, z1, w1)
983 ^ $vec4::new(x2, y2, z2, w2),
984 $vec4::new(x1 ^ x2, y1 ^ y2, z1 ^ z2, w1 ^ w2)
985 );
986 }
987 }
988 }
989 }
990 }
991 }
992 }
993 }
994 });
995 };
996 }
997 mod vec4 {
998 use glam::{const_vec4, vec4, Vec2, Vec3, Vec4};
999
1000 #[cfg(all(
1001 any(target_feature = "sse2", target_feature = "simd128"),
1002 not(feature = "scalar-math")
1003 ))]
1004 type Vec4Mask = glam::BVec4A;
1005
1006 #[cfg(any(
1007 not(any(target_feature = "sse2", target_feature = "simd128")),
1008 feature = "scalar-math"
1009 ))]
1010 type Vec4Mask = glam::BVec4;
1011
1012 glam_test!(test_align, {
1013 use std::mem;
1014 assert_eq!(16, mem::size_of::<Vec4>());
1015 if cfg!(any(not(feature = "scalar-math"), feature = "cuda")) {
1016 assert_eq!(16, mem::align_of::<Vec4>());
1017 } else {
1018 assert_eq!(4, mem::align_of::<Vec4>());
1019 }
1020 if cfg!(all(
1021 any(target_feature = "sse2", target_feature = "simd128"),
1022 not(feature = "scalar-math")
1023 )) {
1024 assert_eq!(16, mem::size_of::<Vec4Mask>());
1025 assert_eq!(16, mem::align_of::<Vec4Mask>());
1026 } else {
1027 assert_eq!(4, mem::size_of::<Vec4Mask>());
1028 assert_eq!(1, mem::align_of::<Vec4Mask>());
1029 }
1030 });
1031
1032 #[cfg(all(target_feature = "sse2", not(feature = "scalar-math")))]
1033 #[test]
1034 fn test_m128() {
1035 #[cfg(target_arch = "x86")]
1036 use core::arch::x86::*;
1037 #[cfg(target_arch = "x86_64")]
1038 use core::arch::x86_64::*;
1039
1040 #[repr(C, align(16))]
1041 struct F32x4_A16([f32; 4]);
1042
1043 let v0 = Vec4::new(1.0, 2.0, 3.0, 4.0);
1044 let m0: __m128 = v0.into();
1045 let mut a0 = F32x4_A16([0.0, 0.0, 0.0, 0.0]);
1046 unsafe {
1047 _mm_store_ps(a0.0.as_mut_ptr(), m0);
1048 }
1049 assert_eq!([1.0, 2.0, 3.0, 4.0], a0.0);
1050 let v1 = Vec4::from(m0);
1051 assert_eq!(v0, v1);
1052
1053 #[repr(C, align(16))]
1054 struct U32x4_A16([u32; 4]);
1055
1056 let v0 = Vec4Mask::new(true, false, true, false);
1057 let m0: __m128 = v0.into();
1058 let mut a0 = U32x4_A16([1, 2, 3, 4]);
1059 unsafe {
1060 _mm_store_ps(a0.0.as_mut_ptr() as *mut f32, m0);
1061 }
1062 assert_eq!([0xffffffff, 0, 0xffffffff, 0], a0.0);
1063 }
1064
1065 glam_test!(test_as, {
1066 use glam::{DVec4, IVec4, UVec4};
1067 assert_eq!(
1068 DVec4::new(-1.0, -2.0, -3.0, -4.0),
1069 Vec4::new(-1.0, -2.0, -3.0, -4.0).as_dvec4()
1070 );
1071 assert_eq!(
1072 IVec4::new(-1, -2, -3, -4),
1073 Vec4::new(-1.0, -2.0, -3.0, -4.0).as_ivec4()
1074 );
1075 assert_eq!(
1076 UVec4::new(1, 2, 3, 4),
1077 Vec4::new(1.0, 2.0, 3.0, 4.0).as_uvec4()
1078 );
1079
1080 assert_eq!(
1081 IVec4::new(-1, -2, -3, -4),
1082 DVec4::new(-1.0, -2.0, -3.0, -4.0).as_ivec4()
1083 );
1084 assert_eq!(
1085 UVec4::new(1, 2, 3, 4),
1086 DVec4::new(1.0, 2.0, 3.0, 4.0).as_uvec4()
1087 );
1088 assert_eq!(
1089 Vec4::new(-1.0, -2.0, -3.0, -4.0),
1090 DVec4::new(-1.0, -2.0, -3.0, -4.0).as_vec4()
1091 );
1092
1093 assert_eq!(
1094 DVec4::new(-1.0, -2.0, -3.0, -4.0),
1095 IVec4::new(-1, -2, -3, -4).as_dvec4()
1096 );
1097 assert_eq!(UVec4::new(1, 2, 3, 4), IVec4::new(1, 2, 3, 4).as_uvec4());
1098 assert_eq!(
1099 Vec4::new(-1.0, -2.0, -3.0, -4.0),
1100 IVec4::new(-1, -2, -3, -4).as_vec4()
1101 );
1102
1103 assert_eq!(
1104 DVec4::new(1.0, 2.0, 3.0, 4.0),
1105 UVec4::new(1, 2, 3, 4).as_dvec4()
1106 );
1107 assert_eq!(IVec4::new(1, 2, 3, 4), UVec4::new(1, 2, 3, 4).as_ivec4());
1108 assert_eq!(
1109 Vec4::new(1.0, 2.0, 3.0, 4.0),
1110 UVec4::new(1, 2, 3, 4).as_vec4()
1111 );
1112 });
1113
1114 glam_test!(test_vec3a, {
1115 use glam::Vec3A;
1116 assert_eq!(
1117 Vec4::new(1.0, 2.0, 3.0, 4.0),
1118 Vec4::from((Vec3A::new(1.0, 2.0, 3.0), 4.0))
1119 );
1120 assert_eq!(
1121 Vec4::new(1.0, 2.0, 3.0, 4.0),
1122 Vec4::from((1.0, Vec3A::new(2.0, 3.0, 4.0)))
1123 );
1124 });
1125
1126 impl_vec4_float_tests!(f32, const_vec4, vec4, Vec4, Vec3, Vec2, Vec4Mask);
1127 }
1128
1129 mod dvec4 {
1130 use glam::{const_dvec4, dvec4, BVec4, DVec2, DVec3, DVec4};
1131
1132 glam_test!(test_align, {
1133 use std::mem;
1134 assert_eq!(32, mem::size_of::<DVec4>());
1135 #[cfg(not(feature = "cuda"))]
1136 assert_eq!(mem::align_of::<f64>(), mem::align_of::<DVec4>());
1137 #[cfg(feature = "cuda")]
1138 assert_eq!(16, mem::align_of::<DVec4>());
1139 assert_eq!(4, mem::size_of::<BVec4>());
1140 assert_eq!(1, mem::align_of::<BVec4>());
1141 });
1142
1143 impl_vec4_float_tests!(f64, const_dvec4, dvec4, DVec4, DVec3, DVec2, BVec4);
1144 }
1145
1146 mod ivec4 {
1147 use glam::{const_ivec4, ivec4, BVec4, IVec2, IVec3, IVec4, UVec4};
1148
1149 glam_test!(test_align, {
1150 use std::mem;
1151 assert_eq!(16, mem::size_of::<IVec4>());
1152 #[cfg(not(feature = "cuda"))]
1153 assert_eq!(4, mem::align_of::<IVec4>());
1154 #[cfg(feature = "cuda")]
1155 assert_eq!(16, mem::align_of::<IVec4>());
1156 assert_eq!(4, mem::size_of::<BVec4>());
1157 assert_eq!(1, mem::align_of::<BVec4>());
1158 });
1159
1160 impl_vec4_signed_tests!(i32, const_ivec4, ivec4, IVec4, IVec3, IVec2, BVec4);
1161 impl_vec4_eq_hash_tests!(i32, ivec4);
1162
1163 impl_vec4_scalar_shift_op_tests!(IVec4, -2, 2);
1164 impl_vec4_shift_op_tests!(IVec4);
1165
1166 impl_vec4_scalar_bit_op_tests!(IVec4, -2, 2);
1167 impl_vec4_bit_op_tests!(IVec4, -2, 2);
1168 }
1169
1170 mod uvec4 {
1171 use glam::{const_uvec4, uvec4, BVec4, IVec4, UVec2, UVec3, UVec4};
1172
1173 glam_test!(test_align, {
1174 use std::mem;
1175 assert_eq!(16, mem::size_of::<UVec4>());
1176 #[cfg(not(feature = "cuda"))]
1177 assert_eq!(4, mem::align_of::<UVec4>());
1178 #[cfg(feature = "cuda")]
1179 assert_eq!(16, mem::align_of::<UVec4>());
1180 assert_eq!(4, mem::size_of::<BVec4>());
1181 assert_eq!(1, mem::align_of::<BVec4>());
1182 });
1183
1184 impl_vec4_tests!(u32, const_uvec4, uvec4, UVec4, UVec3, UVec2, BVec4);
1185 impl_vec4_eq_hash_tests!(u32, uvec4);
1186
1187 impl_vec4_scalar_shift_op_tests!(UVec4, 0, 2);
1188 impl_vec4_shift_op_tests!(UVec4);
1189
1190 impl_vec4_scalar_bit_op_tests!(UVec4, 0, 2);
1191 impl_vec4_bit_op_tests!(UVec4, 0, 2);
1192 }