| 1 |
#![allow(clippy::excessive_precision)] |
| 2 |
|
| 3 |
#[macro_use] |
| 4 |
mod support; |
| 5 |
|
| 6 |
macro_rules! impl_vec4_tests { |
| 7 |
($t:ident, $new:ident, $vec4:ident, $vec3:ident, $vec2:ident, $mask:ident) => { |
| 8 |
glam_test!(test_const, { |
| 9 |
const V0: $vec4 = $vec4::splat(1 as $t); |
| 10 |
const V1: $vec4 = $vec4::new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 11 |
const V2: $vec4 = $vec4::from_array([1 as $t, 2 as $t, 3 as $t, 4 as $t]); |
| 12 |
assert_eq!([1 as $t, 1 as $t, 1 as $t, 1 as $t], *V0.as_ref()); |
| 13 |
assert_eq!([1 as $t, 2 as $t, 3 as $t, 4 as $t], *V1.as_ref()); |
| 14 |
assert_eq!([1 as $t, 2 as $t, 3 as $t, 4 as $t], *V2.as_ref()); |
| 15 |
}); |
| 16 |
|
| 17 |
glam_test!(test_vec4_consts, { |
| 18 |
assert_eq!($vec4::ZERO, $new(0 as $t, 0 as $t, 0 as $t, 0 as $t)); |
| 19 |
assert_eq!($vec4::ONE, $new(1 as $t, 1 as $t, 1 as $t, 1 as $t)); |
| 20 |
assert_eq!($vec4::X, $new(1 as $t, 0 as $t, 0 as $t, 0 as $t)); |
| 21 |
assert_eq!($vec4::Y, $new(0 as $t, 1 as $t, 0 as $t, 0 as $t)); |
| 22 |
assert_eq!($vec4::Z, $new(0 as $t, 0 as $t, 1 as $t, 0 as $t)); |
| 23 |
assert_eq!($vec4::W, $new(0 as $t, 0 as $t, 0 as $t, 1 as $t)); |
| 24 |
assert_eq!($vec4::MIN, $new($t::MIN, $t::MIN, $t::MIN, $t::MIN)); |
| 25 |
assert_eq!($vec4::MAX, $new($t::MAX, $t::MAX, $t::MAX, $t::MAX)); |
| 26 |
}); |
| 27 |
|
| 28 |
glam_test!(test_new, { |
| 29 |
let v = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 30 |
|
| 31 |
assert_eq!(v.x, 1 as $t); |
| 32 |
assert_eq!(v.y, 2 as $t); |
| 33 |
assert_eq!(v.z, 3 as $t); |
| 34 |
assert_eq!(v.w, 4 as $t); |
| 35 |
|
| 36 |
let t = (1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 37 |
let v = $vec4::from(t); |
| 38 |
assert_eq!(t, v.into()); |
| 39 |
|
| 40 |
let a = [1 as $t, 2 as $t, 3 as $t, 4 as $t]; |
| 41 |
let v = $vec4::from(a); |
| 42 |
let a1: [$t; 4] = v.into(); |
| 43 |
assert_eq!(a, a1); |
| 44 |
|
| 45 |
assert_eq!(a, v.to_array()); |
| 46 |
assert_eq!(a, *v.as_ref()); |
| 47 |
|
| 48 |
let mut v2 = $vec4::default(); |
| 49 |
*v2.as_mut() = a; |
| 50 |
assert_eq!(a, v2.to_array()); |
| 51 |
|
| 52 |
let v = $vec4::new(t.0, t.1, t.2, t.3); |
| 53 |
assert_eq!(t, v.into()); |
| 54 |
|
| 55 |
assert_eq!( |
| 56 |
$vec4::new(1 as $t, 0 as $t, 0 as $t, 0 as $t), |
| 57 |
glam::BVec4::new(true, false, false, false).into() |
| 58 |
); |
| 59 |
assert_eq!( |
| 60 |
$vec4::new(0 as $t, 1 as $t, 0 as $t, 0 as $t), |
| 61 |
glam::BVec4::new(false, true, false, false).into() |
| 62 |
); |
| 63 |
assert_eq!( |
| 64 |
$vec4::new(0 as $t, 0 as $t, 1 as $t, 0 as $t), |
| 65 |
glam::BVec4::new(false, false, true, false).into() |
| 66 |
); |
| 67 |
|
| 68 |
#[cfg(not(feature = "scalar-math"))] |
| 69 |
{ |
| 70 |
assert_eq!( |
| 71 |
$vec4::new(0 as $t, 0 as $t, 0 as $t, 1 as $t), |
| 72 |
glam::BVec4::new(false, false, false, true).into() |
| 73 |
); |
| 74 |
assert_eq!( |
| 75 |
$vec4::new(1 as $t, 0 as $t, 0 as $t, 0 as $t), |
| 76 |
glam::BVec4A::new(true, false, false, false).into() |
| 77 |
); |
| 78 |
assert_eq!( |
| 79 |
$vec4::new(0 as $t, 1 as $t, 0 as $t, 0 as $t), |
| 80 |
glam::BVec4A::new(false, true, false, false).into() |
| 81 |
); |
| 82 |
assert_eq!( |
| 83 |
$vec4::new(0 as $t, 0 as $t, 1 as $t, 0 as $t), |
| 84 |
glam::BVec4A::new(false, false, true, false).into() |
| 85 |
); |
| 86 |
assert_eq!( |
| 87 |
$vec4::new(0 as $t, 0 as $t, 0 as $t, 1 as $t), |
| 88 |
glam::BVec4A::new(false, false, false, true).into() |
| 89 |
); |
| 90 |
} |
| 91 |
|
| 92 |
assert_eq!($vec4::new(1 as $t, 0 as $t, 0 as $t, 0 as $t), $vec4::X); |
| 93 |
assert_eq!($vec4::new(0 as $t, 1 as $t, 0 as $t, 0 as $t), $vec4::Y); |
| 94 |
assert_eq!($vec4::new(0 as $t, 0 as $t, 1 as $t, 0 as $t), $vec4::Z); |
| 95 |
assert_eq!($vec4::new(0 as $t, 0 as $t, 0 as $t, 1 as $t), $vec4::W); |
| 96 |
|
| 97 |
assert_eq!( |
| 98 |
v, |
| 99 |
$vec4::from(($vec3::new(1 as $t, 2 as $t, 3 as $t), 4 as $t)) |
| 100 |
); |
| 101 |
|
| 102 |
assert_eq!( |
| 103 |
v, |
| 104 |
$vec4::from((1 as $t, $vec3::new(2 as $t, 3 as $t, 4 as $t))) |
| 105 |
); |
| 106 |
|
| 107 |
assert_eq!( |
| 108 |
v, |
| 109 |
$vec4::from(($vec2::new(1 as $t, 2 as $t), 3 as $t, 4 as $t)) |
| 110 |
); |
| 111 |
assert_eq!( |
| 112 |
v, |
| 113 |
$vec4::from(($vec2::new(1 as $t, 2 as $t), $vec2::new(3 as $t, 4 as $t))) |
| 114 |
); |
| 115 |
}); |
| 116 |
|
| 117 |
glam_test!(test_fmt, { |
| 118 |
let a = $vec4::new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 119 |
assert_eq!( |
| 120 |
format!("{:?}", a), |
| 121 |
format!( |
| 122 |
"{}({:?}, {:?}, {:?}, {:?})", |
| 123 |
stringify!($vec4), |
| 124 |
a.x, |
| 125 |
a.y, |
| 126 |
a.z, |
| 127 |
a.w |
| 128 |
) |
| 129 |
); |
| 130 |
assert_eq!( |
| 131 |
format!("{:#?}", a), |
| 132 |
format!( |
| 133 |
"{}(\n {:#?},\n {:#?},\n {:#?},\n {:#?},\n)", |
| 134 |
stringify!($vec4), |
| 135 |
a.x, |
| 136 |
a.y, |
| 137 |
a.z, |
| 138 |
a.w |
| 139 |
) |
| 140 |
); |
| 141 |
assert_eq!(format!("{}", a), "[1, 2, 3, 4]"); |
| 142 |
}); |
| 143 |
|
| 144 |
glam_test!(test_zero, { |
| 145 |
let v = $vec4::ZERO; |
| 146 |
assert_eq!((0 as $t, 0 as $t, 0 as $t, 0 as $t), v.into()); |
| 147 |
assert_eq!(v, $vec4::default()); |
| 148 |
}); |
| 149 |
|
| 150 |
glam_test!(test_splat, { |
| 151 |
let v = $vec4::splat(1 as $t); |
| 152 |
assert_eq!($vec4::ONE, v); |
| 153 |
}); |
| 154 |
|
| 155 |
glam_test!(test_with, { |
| 156 |
assert_eq!($vec4::X, $vec4::ZERO.with_x(1 as $t)); |
| 157 |
assert_eq!($vec4::Y, $vec4::ZERO.with_y(1 as $t)); |
| 158 |
assert_eq!($vec4::Z, $vec4::ZERO.with_z(1 as $t)); |
| 159 |
assert_eq!($vec4::W, $vec4::ZERO.with_w(1 as $t)); |
| 160 |
}); |
| 161 |
|
| 162 |
glam_test!(test_accessors, { |
| 163 |
let mut a = $vec4::ZERO; |
| 164 |
a.x = 1 as $t; |
| 165 |
a.y = 2 as $t; |
| 166 |
a.z = 3 as $t; |
| 167 |
a.w = 4 as $t; |
| 168 |
assert_eq!(1 as $t, a.x); |
| 169 |
assert_eq!(2 as $t, a.y); |
| 170 |
assert_eq!(3 as $t, a.z); |
| 171 |
assert_eq!(4 as $t, a.w); |
| 172 |
assert_eq!((1 as $t, 2 as $t, 3 as $t, 4 as $t), a.into()); |
| 173 |
|
| 174 |
let mut a = $vec4::ZERO; |
| 175 |
a[0] = 1 as $t; |
| 176 |
a[1] = 2 as $t; |
| 177 |
a[2] = 3 as $t; |
| 178 |
a[3] = 4 as $t; |
| 179 |
assert_eq!(1 as $t, a[0]); |
| 180 |
assert_eq!(2 as $t, a[1]); |
| 181 |
assert_eq!(3 as $t, a[2]); |
| 182 |
assert_eq!(4 as $t, a[3]); |
| 183 |
assert_eq!((1 as $t, 2 as $t, 3 as $t, 4 as $t), a.into()); |
| 184 |
}); |
| 185 |
|
| 186 |
glam_test!(test_dot_unsigned, { |
| 187 |
let x = $new(1 as $t, 0 as $t, 0 as $t, 0 as $t); |
| 188 |
let y = $new(0 as $t, 1 as $t, 0 as $t, 0 as $t); |
| 189 |
let z = $new(0 as $t, 0 as $t, 1 as $t, 0 as $t); |
| 190 |
let w = $new(0 as $t, 0 as $t, 0 as $t, 1 as $t); |
| 191 |
assert_eq!(1 as $t, x.dot(x)); |
| 192 |
assert_eq!(0 as $t, x.dot(y)); |
| 193 |
assert_eq!(0 as $t, y.dot(z)); |
| 194 |
assert_eq!(0 as $t, z.dot(w)); |
| 195 |
|
| 196 |
assert_eq!( |
| 197 |
$new(28 as $t, 28 as $t, 28 as $t, 28 as $t), |
| 198 |
$new(0 as $t, 5 as $t, 3 as $t, 6 as $t) |
| 199 |
.dot_into_vec($new(7 as $t, 2 as $t, 4 as $t, 1 as $t)) |
| 200 |
); |
| 201 |
}); |
| 202 |
|
| 203 |
glam_test!(test_length_squared_unsigned, { |
| 204 |
let x = $new(1 as $t, 0 as $t, 0 as $t, 0 as $t); |
| 205 |
let z = $new(0 as $t, 0 as $t, 1 as $t, 0 as $t); |
| 206 |
let w = $new(0 as $t, 0 as $t, 0 as $t, 1 as $t); |
| 207 |
assert_eq!(4 as $t, (2 as $t * x).length_squared()); |
| 208 |
assert_eq!(16 as $t, (4 as $t * z).length_squared()); |
| 209 |
assert_eq!(64 as $t, (8 as $t * w).length_squared()); |
| 210 |
assert_eq!( |
| 211 |
2 as $t * 2 as $t + 3 as $t * 3 as $t + 4 as $t * 4 as $t + 5 as $t * 5 as $t, |
| 212 |
$new(2 as $t, 3 as $t, 4 as $t, 5 as $t).length_squared() |
| 213 |
); |
| 214 |
}); |
| 215 |
|
| 216 |
glam_test!(test_ops, { |
| 217 |
let a = $new(2 as $t, 4 as $t, 8 as $t, 16 as $t); |
| 218 |
assert_eq!($new(4 as $t, 8 as $t, 16 as $t, 32 as $t), a + a); |
| 219 |
assert_eq!($new(2 as $t, 4 as $t, 8 as $t, 16 as $t), 0 as $t + a); |
| 220 |
assert_eq!($new(0 as $t, 0 as $t, 0 as $t, 0 as $t), a - a); |
| 221 |
assert_eq!($new(14 as $t, 12 as $t, 8 as $t, 0 as $t), 16 as $t - a); |
| 222 |
assert_eq!($new(4 as $t, 16 as $t, 64 as $t, 256 as $t), a * a); |
| 223 |
assert_eq!($new(4 as $t, 8 as $t, 16 as $t, 32 as $t), a * 2 as $t); |
| 224 |
assert_eq!($new(4 as $t, 8 as $t, 16 as $t, 32 as $t), 2 as $t * a); |
| 225 |
assert_eq!($new(1 as $t, 1 as $t, 1 as $t, 1 as $t), a / a); |
| 226 |
assert_eq!($new(1 as $t, 2 as $t, 4 as $t, 8 as $t), a / 2 as $t); |
| 227 |
assert_eq!($new(8 as $t, 4 as $t, 2 as $t, 1 as $t), 16 as $t / a); |
| 228 |
assert_eq!($new(0 as $t, 0 as $t, 0 as $t, 0 as $t), a % a); |
| 229 |
assert_eq!($new(0 as $t, 1 as $t, 1 as $t, 1 as $t), a % (a - 1 as $t)); |
| 230 |
assert_eq!($new(0 as $t, 0 as $t, 0 as $t, 0 as $t), a % 1 as $t); |
| 231 |
assert_eq!($new(2 as $t, 1 as $t, 2 as $t, 1 as $t), a % 3 as $t); |
| 232 |
assert_eq!($new(1 as $t, 1 as $t, 1 as $t, 1 as $t), 17 as $t % a); |
| 233 |
assert_eq!($new(2 as $t, 4 as $t, 0 as $t, 0 as $t), a % 8 as $t); |
| 234 |
}); |
| 235 |
|
| 236 |
glam_test!(test_assign_ops, { |
| 237 |
let a = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 238 |
let mut b = a; |
| 239 |
|
| 240 |
b += 2 as $t; |
| 241 |
assert_eq!($new(3 as $t, 4 as $t, 5 as $t, 6 as $t), b); |
| 242 |
b -= 2 as $t; |
| 243 |
assert_eq!($new(1 as $t, 2 as $t, 3 as $t, 4 as $t), b); |
| 244 |
b *= 2 as $t; |
| 245 |
assert_eq!($new(2 as $t, 4 as $t, 6 as $t, 8 as $t), b); |
| 246 |
b /= 2 as $t; |
| 247 |
assert_eq!($new(1 as $t, 2 as $t, 3 as $t, 4 as $t), b); |
| 248 |
b %= 2 as $t; |
| 249 |
assert_eq!($new(1 as $t, 0 as $t, 1 as $t, 0 as $t), b); |
| 250 |
|
| 251 |
b = a; |
| 252 |
b += a; |
| 253 |
assert_eq!($new(2 as $t, 4 as $t, 6 as $t, 8 as $t), b); |
| 254 |
b -= a; |
| 255 |
assert_eq!($new(1 as $t, 2 as $t, 3 as $t, 4 as $t), b); |
| 256 |
b *= a; |
| 257 |
assert_eq!($new(1 as $t, 4 as $t, 9 as $t, 16 as $t), b); |
| 258 |
b /= a; |
| 259 |
assert_eq!($new(1 as $t, 2 as $t, 3 as $t, 4 as $t), b); |
| 260 |
b *= 2 as $t; |
| 261 |
assert_eq!($new(2 as $t, 4 as $t, 6 as $t, 8 as $t), b); |
| 262 |
b /= 2 as $t; |
| 263 |
assert_eq!($new(1 as $t, 2 as $t, 3 as $t, 4 as $t), b); |
| 264 |
b %= (b + 1 as $t); |
| 265 |
assert_eq!($new(1 as $t, 2 as $t, 3 as $t, 4 as $t), b); |
| 266 |
b %= b; |
| 267 |
assert_eq!($new(0 as $t, 0 as $t, 0 as $t, 0 as $t), b); |
| 268 |
}); |
| 269 |
|
| 270 |
glam_test!(test_min_max, { |
| 271 |
let a = $new(4 as $t, 6 as $t, 2 as $t, 8 as $t); |
| 272 |
let b = $new(5 as $t, 3 as $t, 7 as $t, 1 as $t); |
| 273 |
assert_eq!((4 as $t, 3 as $t, 2 as $t, 1 as $t), a.min(b).into()); |
| 274 |
assert_eq!((4 as $t, 3 as $t, 2 as $t, 1 as $t), b.min(a).into()); |
| 275 |
assert_eq!((5 as $t, 6 as $t, 7 as $t, 8 as $t), a.max(b).into()); |
| 276 |
assert_eq!((5 as $t, 6 as $t, 7 as $t, 8 as $t), b.max(a).into()); |
| 277 |
}); |
| 278 |
|
| 279 |
glam_test!(test_clamp, { |
| 280 |
fn vec(x: i32, y: i32, z: i32, w: i32) -> $vec4 { |
| 281 |
$vec4::new(x as $t, y as $t, z as $t, w as $t) |
| 282 |
} |
| 283 |
let min = vec(1, 1, 3, 3); |
| 284 |
let max = vec(6, 6, 8, 8); |
| 285 |
assert_eq!(vec(0, 0, 0, 0).clamp(min, max), vec(1, 1, 3, 3)); |
| 286 |
assert_eq!(vec(2, 2, 2, 2).clamp(min, max), vec(2, 2, 3, 3)); |
| 287 |
assert_eq!(vec(4, 4, 5, 5).clamp(min, max), vec(4, 4, 5, 5)); |
| 288 |
assert_eq!(vec(6, 6, 6, 6).clamp(min, max), vec(6, 6, 6, 6)); |
| 289 |
assert_eq!(vec(7, 7, 7, 7).clamp(min, max), vec(6, 6, 7, 7)); |
| 290 |
assert_eq!(vec(9, 9, 9, 9).clamp(min, max), vec(6, 6, 8, 8)); |
| 291 |
|
| 292 |
should_glam_assert!({ $vec4::clamp($vec4::ZERO, $vec4::ONE, $vec4::ZERO) }); |
| 293 |
}); |
| 294 |
|
| 295 |
glam_test!(test_hmin_hmax, { |
| 296 |
assert_eq!( |
| 297 |
1 as $t, |
| 298 |
$new(1 as $t, 2 as $t, 3 as $t, 4 as $t).min_element() |
| 299 |
); |
| 300 |
assert_eq!( |
| 301 |
1 as $t, |
| 302 |
$new(4 as $t, 1 as $t, 2 as $t, 3 as $t).min_element() |
| 303 |
); |
| 304 |
assert_eq!( |
| 305 |
1 as $t, |
| 306 |
$new(3 as $t, 4 as $t, 1 as $t, 2 as $t).min_element() |
| 307 |
); |
| 308 |
assert_eq!( |
| 309 |
1 as $t, |
| 310 |
$new(2 as $t, 3 as $t, 4 as $t, 1 as $t).min_element() |
| 311 |
); |
| 312 |
assert_eq!( |
| 313 |
4 as $t, |
| 314 |
$new(1 as $t, 2 as $t, 3 as $t, 4 as $t).max_element() |
| 315 |
); |
| 316 |
assert_eq!( |
| 317 |
4 as $t, |
| 318 |
$new(4 as $t, 1 as $t, 2 as $t, 3 as $t).max_element() |
| 319 |
); |
| 320 |
assert_eq!( |
| 321 |
4 as $t, |
| 322 |
$new(3 as $t, 4 as $t, 1 as $t, 2 as $t).max_element() |
| 323 |
); |
| 324 |
assert_eq!( |
| 325 |
4 as $t, |
| 326 |
$new(2 as $t, 3 as $t, 4 as $t, 1 as $t).max_element() |
| 327 |
); |
| 328 |
assert_eq!( |
| 329 |
3 as $t, |
| 330 |
$new(1 as $t, 2 as $t, 3 as $t, 4 as $t) |
| 331 |
.truncate() |
| 332 |
.max_element() |
| 333 |
); |
| 334 |
assert_eq!( |
| 335 |
2 as $t, |
| 336 |
$new(4 as $t, 3 as $t, 2 as $t, 1 as $t) |
| 337 |
.truncate() |
| 338 |
.min_element() |
| 339 |
); |
| 340 |
}); |
| 341 |
|
| 342 |
glam_test!(test_sum_product, { |
| 343 |
let a = $new(2 as $t, 3 as $t, 5 as $t, 7 as $t); |
| 344 |
assert_eq!(a.element_sum(), 17 as $t); |
| 345 |
assert_eq!(a.element_product(), 210 as $t); |
| 346 |
}); |
| 347 |
|
| 348 |
glam_test!(test_eq, { |
| 349 |
let a = $new(1 as $t, 1 as $t, 1 as $t, 1 as $t); |
| 350 |
let b = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 351 |
assert!(a.cmpeq(a).all()); |
| 352 |
assert!(b.cmpeq(b).all()); |
| 353 |
assert!(a.cmpne(b).any()); |
| 354 |
assert!(b.cmpne(a).any()); |
| 355 |
assert!(b.cmpeq(a).any()); |
| 356 |
}); |
| 357 |
|
| 358 |
glam_test!(test_cmp, { |
| 359 |
assert!(!$mask::default().any()); |
| 360 |
assert!(!$mask::default().all()); |
| 361 |
assert_eq!($mask::default().bitmask(), 0x0); |
| 362 |
let a = $new(1 as $t, 1 as $t, 1 as $t, 1 as $t); |
| 363 |
let b = $new(2 as $t, 2 as $t, 2 as $t, 2 as $t); |
| 364 |
let c = $new(1 as $t, 1 as $t, 2 as $t, 2 as $t); |
| 365 |
let d = $new(2 as $t, 1 as $t, 1 as $t, 2 as $t); |
| 366 |
assert_eq!(a.cmplt(a).bitmask(), 0x0); |
| 367 |
assert_eq!(a.cmplt(b).bitmask(), 0xf); |
| 368 |
assert_eq!(a.cmplt(c).bitmask(), 0xc); |
| 369 |
assert_eq!(c.cmple(a).bitmask(), 0x3); |
| 370 |
assert_eq!(a.cmplt(d).bitmask(), 0x9); |
| 371 |
assert!(a.cmplt(b).all()); |
| 372 |
assert!(a.cmplt(c).any()); |
| 373 |
assert!(a.cmple(b).all()); |
| 374 |
assert!(a.cmple(a).all()); |
| 375 |
assert!(b.cmpgt(a).all()); |
| 376 |
assert!(b.cmpge(a).all()); |
| 377 |
assert!(b.cmpge(b).all()); |
| 378 |
assert!(!(a.cmpge(c).all())); |
| 379 |
assert!(c.cmple(c).all()); |
| 380 |
assert!(c.cmpge(c).all()); |
| 381 |
assert!(a.cmpeq(a).all()); |
| 382 |
assert!(!a.cmpeq(b).all()); |
| 383 |
assert!(a.cmpeq(c).any()); |
| 384 |
assert!(!a.cmpne(a).all()); |
| 385 |
assert!(a.cmpne(b).all()); |
| 386 |
assert!(a.cmpne(c).any()); |
| 387 |
assert!(a == a); |
| 388 |
}); |
| 389 |
|
| 390 |
glam_test!(test_slice, { |
| 391 |
let a = [1 as $t, 2 as $t, 3 as $t, 4 as $t]; |
| 392 |
let b = $vec4::from_slice(&a); |
| 393 |
let c: [$t; 4] = b.into(); |
| 394 |
assert_eq!(a, c); |
| 395 |
let mut d = [0 as $t, 0 as $t, 0 as $t, 0 as $t]; |
| 396 |
b.write_to_slice(&mut d[..]); |
| 397 |
assert_eq!(a, d); |
| 398 |
|
| 399 |
should_panic!({ $vec4::ONE.write_to_slice(&mut [0 as $t; 3]) }); |
| 400 |
should_panic!({ $vec4::from_slice(&[0 as $t; 3]) }); |
| 401 |
}); |
| 402 |
|
| 403 |
glam_test!(test_mask_from_array_bool, { |
| 404 |
assert_eq!( |
| 405 |
$mask::new(false, false, false, false), |
| 406 |
$mask::from([false, false, false, false]) |
| 407 |
); |
| 408 |
assert_eq!( |
| 409 |
$mask::new(false, false, true, true), |
| 410 |
$mask::from([false, false, true, true]) |
| 411 |
); |
| 412 |
assert_eq!( |
| 413 |
$mask::new(true, true, false, false), |
| 414 |
$mask::from([true, true, false, false]) |
| 415 |
); |
| 416 |
assert_eq!( |
| 417 |
$mask::new(false, true, false, true), |
| 418 |
$mask::from([false, true, false, true]) |
| 419 |
); |
| 420 |
assert_eq!( |
| 421 |
$mask::new(true, false, true, false), |
| 422 |
$mask::from([true, false, true, false]) |
| 423 |
); |
| 424 |
assert_eq!( |
| 425 |
$mask::new(true, true, true, true), |
| 426 |
$mask::from([true, true, true, true]) |
| 427 |
); |
| 428 |
}); |
| 429 |
glam_test!(test_mask_into_array_u32, { |
| 430 |
assert_eq!( |
| 431 |
Into::<[u32; 4]>::into($mask::new(false, false, false, false)), |
| 432 |
[0, 0, 0, 0] |
| 433 |
); |
| 434 |
assert_eq!( |
| 435 |
Into::<[u32; 4]>::into($mask::new(false, false, true, true)), |
| 436 |
[0, 0, !0, !0] |
| 437 |
); |
| 438 |
assert_eq!( |
| 439 |
Into::<[u32; 4]>::into($mask::new(true, true, false, false)), |
| 440 |
[!0, !0, 0, 0] |
| 441 |
); |
| 442 |
assert_eq!( |
| 443 |
Into::<[u32; 4]>::into($mask::new(false, true, false, true)), |
| 444 |
[0, !0, 0, !0] |
| 445 |
); |
| 446 |
assert_eq!( |
| 447 |
Into::<[u32; 4]>::into($mask::new(true, false, true, false)), |
| 448 |
[!0, 0, !0, 0] |
| 449 |
); |
| 450 |
assert_eq!( |
| 451 |
Into::<[u32; 4]>::into($mask::new(true, true, true, true)), |
| 452 |
[!0, !0, !0, !0] |
| 453 |
); |
| 454 |
}); |
| 455 |
|
| 456 |
glam_test!(test_mask_into_array_bool, { |
| 457 |
assert_eq!( |
| 458 |
Into::<[bool; 4]>::into($mask::new(false, false, false, false)), |
| 459 |
[false, false, false, false] |
| 460 |
); |
| 461 |
assert_eq!( |
| 462 |
Into::<[bool; 4]>::into($mask::new(false, false, true, true)), |
| 463 |
[false, false, true, true] |
| 464 |
); |
| 465 |
assert_eq!( |
| 466 |
Into::<[bool; 4]>::into($mask::new(true, true, false, false)), |
| 467 |
[true, true, false, false] |
| 468 |
); |
| 469 |
assert_eq!( |
| 470 |
Into::<[bool; 4]>::into($mask::new(false, true, false, true)), |
| 471 |
[false, true, false, true] |
| 472 |
); |
| 473 |
assert_eq!( |
| 474 |
Into::<[bool; 4]>::into($mask::new(true, false, true, false)), |
| 475 |
[true, false, true, false] |
| 476 |
); |
| 477 |
assert_eq!( |
| 478 |
Into::<[bool; 4]>::into($mask::new(true, true, true, true)), |
| 479 |
[true, true, true, true] |
| 480 |
); |
| 481 |
}); |
| 482 |
|
| 483 |
glam_test!(test_mask_splat, { |
| 484 |
assert_eq!($mask::splat(false), $mask::new(false, false, false, false)); |
| 485 |
assert_eq!($mask::splat(true), $mask::new(true, true, true, true)); |
| 486 |
}); |
| 487 |
|
| 488 |
glam_test!(test_mask_bitmask, { |
| 489 |
assert_eq!($mask::new(false, false, false, false).bitmask(), 0b0000); |
| 490 |
assert_eq!($mask::new(false, false, true, true).bitmask(), 0b1100); |
| 491 |
assert_eq!($mask::new(true, true, false, false).bitmask(), 0b0011); |
| 492 |
assert_eq!($mask::new(false, true, false, true).bitmask(), 0b1010); |
| 493 |
assert_eq!($mask::new(true, false, true, false).bitmask(), 0b0101); |
| 494 |
assert_eq!($mask::new(true, true, true, true).bitmask(), 0b1111); |
| 495 |
}); |
| 496 |
|
| 497 |
glam_test!(test_mask_any, { |
| 498 |
assert_eq!($mask::new(false, false, false, false).any(), false); |
| 499 |
assert_eq!($mask::new(true, false, false, false).any(), true); |
| 500 |
assert_eq!($mask::new(false, true, false, false).any(), true); |
| 501 |
assert_eq!($mask::new(false, false, true, false).any(), true); |
| 502 |
assert_eq!($mask::new(false, false, false, true).any(), true); |
| 503 |
}); |
| 504 |
|
| 505 |
glam_test!(test_mask_all, { |
| 506 |
assert_eq!($mask::new(true, true, true, true).all(), true); |
| 507 |
assert_eq!($mask::new(false, true, true, true).all(), false); |
| 508 |
assert_eq!($mask::new(true, false, true, true).all(), false); |
| 509 |
assert_eq!($mask::new(true, true, false, true).all(), false); |
| 510 |
assert_eq!($mask::new(true, true, true, false).all(), false); |
| 511 |
}); |
| 512 |
|
| 513 |
glam_test!(test_mask_select, { |
| 514 |
let a = $vec4::new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 515 |
let b = $vec4::new(5 as $t, 6 as $t, 7 as $t, 8 as $t); |
| 516 |
assert_eq!( |
| 517 |
$vec4::select($mask::new(true, true, true, true), a, b), |
| 518 |
$vec4::new(1 as $t, 2 as $t, 3 as $t, 4 as $t), |
| 519 |
); |
| 520 |
assert_eq!( |
| 521 |
$vec4::select($mask::new(true, false, true, false), a, b), |
| 522 |
$vec4::new(1 as $t, 6 as $t, 3 as $t, 8 as $t), |
| 523 |
); |
| 524 |
assert_eq!( |
| 525 |
$vec4::select($mask::new(false, true, false, true), a, b), |
| 526 |
$vec4::new(5 as $t, 2 as $t, 7 as $t, 4 as $t), |
| 527 |
); |
| 528 |
assert_eq!( |
| 529 |
$vec4::select($mask::new(false, false, false, false), a, b), |
| 530 |
$vec4::new(5 as $t, 6 as $t, 7 as $t, 8 as $t), |
| 531 |
); |
| 532 |
}); |
| 533 |
|
| 534 |
glam_test!(test_mask_and, { |
| 535 |
assert_eq!( |
| 536 |
($mask::new(false, false, false, false) & $mask::new(false, false, false, false)) |
| 537 |
.bitmask(), |
| 538 |
0b0000, |
| 539 |
); |
| 540 |
assert_eq!( |
| 541 |
($mask::new(true, true, true, true) & $mask::new(true, true, true, true)).bitmask(), |
| 542 |
0b1111, |
| 543 |
); |
| 544 |
assert_eq!( |
| 545 |
($mask::new(true, false, true, false) & $mask::new(false, true, false, true)) |
| 546 |
.bitmask(), |
| 547 |
0b0000, |
| 548 |
); |
| 549 |
assert_eq!( |
| 550 |
($mask::new(true, false, true, true) & $mask::new(true, true, true, false)) |
| 551 |
.bitmask(), |
| 552 |
0b0101, |
| 553 |
); |
| 554 |
|
| 555 |
let mut mask = $mask::new(true, true, false, false); |
| 556 |
mask &= $mask::new(true, false, true, false); |
| 557 |
assert_eq!(mask.bitmask(), 0b0001); |
| 558 |
}); |
| 559 |
|
| 560 |
glam_test!(test_mask_or, { |
| 561 |
assert_eq!( |
| 562 |
($mask::new(false, false, false, false) | $mask::new(false, false, false, false)) |
| 563 |
.bitmask(), |
| 564 |
0b0000, |
| 565 |
); |
| 566 |
assert_eq!( |
| 567 |
($mask::new(true, true, true, true) | $mask::new(true, true, true, true)).bitmask(), |
| 568 |
0b1111, |
| 569 |
); |
| 570 |
assert_eq!( |
| 571 |
($mask::new(true, false, true, false) | $mask::new(false, true, false, true)) |
| 572 |
.bitmask(), |
| 573 |
0b1111, |
| 574 |
); |
| 575 |
assert_eq!( |
| 576 |
($mask::new(true, false, true, false) | $mask::new(true, false, true, false)) |
| 577 |
.bitmask(), |
| 578 |
0b0101, |
| 579 |
); |
| 580 |
|
| 581 |
let mut mask = $mask::new(true, true, false, false); |
| 582 |
mask |= $mask::new(true, false, true, false); |
| 583 |
assert_eq!(mask.bitmask(), 0b0111); |
| 584 |
}); |
| 585 |
|
| 586 |
glam_test!(test_mask_xor, { |
| 587 |
assert_eq!( |
| 588 |
($mask::new(false, false, false, false) ^ $mask::new(false, false, false, false)) |
| 589 |
.bitmask(), |
| 590 |
0b0000, |
| 591 |
); |
| 592 |
assert_eq!( |
| 593 |
($mask::new(true, true, true, true) ^ $mask::new(true, true, true, true)).bitmask(), |
| 594 |
0b0000, |
| 595 |
); |
| 596 |
assert_eq!( |
| 597 |
($mask::new(true, false, true, false) ^ $mask::new(false, true, false, true)) |
| 598 |
.bitmask(), |
| 599 |
0b1111, |
| 600 |
); |
| 601 |
assert_eq!( |
| 602 |
($mask::new(true, false, true, false) ^ $mask::new(true, false, true, false)) |
| 603 |
.bitmask(), |
| 604 |
0b0000, |
| 605 |
); |
| 606 |
|
| 607 |
let mut mask = $mask::new(true, true, false, false); |
| 608 |
mask ^= $mask::new(true, false, true, false); |
| 609 |
assert_eq!(mask.bitmask(), 0b0110); |
| 610 |
}); |
| 611 |
|
| 612 |
glam_test!(test_mask_not, { |
| 613 |
assert_eq!((!$mask::new(false, false, false, false)).bitmask(), 0b1111); |
| 614 |
assert_eq!((!$mask::new(true, true, true, true)).bitmask(), 0b0000); |
| 615 |
assert_eq!((!$mask::new(true, false, true, false)).bitmask(), 0b1010); |
| 616 |
assert_eq!((!$mask::new(false, true, false, true)).bitmask(), 0b0101); |
| 617 |
}); |
| 618 |
|
| 619 |
glam_test!(test_mask_fmt, { |
| 620 |
let a = $mask::new(true, false, true, false); |
| 621 |
|
| 622 |
assert_eq!(format!("{}", a), "[true, false, true, false]"); |
| 623 |
assert_eq!( |
| 624 |
format!("{:?}", a), |
| 625 |
format!("{}(0xffffffff, 0x0, 0xffffffff, 0x0)", stringify!($mask)) |
| 626 |
); |
| 627 |
}); |
| 628 |
|
| 629 |
glam_test!(test_mask_eq, { |
| 630 |
let a = $mask::new(true, false, true, false); |
| 631 |
let b = $mask::new(true, false, true, false); |
| 632 |
let c = $mask::new(false, true, true, false); |
| 633 |
|
| 634 |
assert_eq!(a, b); |
| 635 |
assert_eq!(b, a); |
| 636 |
assert_ne!(a, c); |
| 637 |
assert_ne!(b, c); |
| 638 |
}); |
| 639 |
|
| 640 |
glam_test!(test_mask_test, { |
| 641 |
let a = $mask::new(true, false, true, false); |
| 642 |
assert_eq!(a.test(0), true); |
| 643 |
assert_eq!(a.test(1), false); |
| 644 |
assert_eq!(a.test(2), true); |
| 645 |
assert_eq!(a.test(3), false); |
| 646 |
|
| 647 |
let b = $mask::new(false, true, false, true); |
| 648 |
assert_eq!(b.test(0), false); |
| 649 |
assert_eq!(b.test(1), true); |
| 650 |
assert_eq!(b.test(2), false); |
| 651 |
assert_eq!(b.test(3), true); |
| 652 |
}); |
| 653 |
|
| 654 |
glam_test!(test_mask_set, { |
| 655 |
let mut a = $mask::new(false, true, false, true); |
| 656 |
a.set(0, true); |
| 657 |
assert_eq!(a.test(0), true); |
| 658 |
a.set(1, false); |
| 659 |
assert_eq!(a.test(1), false); |
| 660 |
a.set(2, true); |
| 661 |
assert_eq!(a.test(2), true); |
| 662 |
a.set(3, false); |
| 663 |
assert_eq!(a.test(3), false); |
| 664 |
|
| 665 |
let mut b = $mask::new(true, false, true, false); |
| 666 |
b.set(0, false); |
| 667 |
assert_eq!(b.test(0), false); |
| 668 |
b.set(1, true); |
| 669 |
assert_eq!(b.test(1), true); |
| 670 |
b.set(2, false); |
| 671 |
assert_eq!(b.test(2), false); |
| 672 |
b.set(3, true); |
| 673 |
assert_eq!(b.test(3), true); |
| 674 |
}); |
| 675 |
|
| 676 |
glam_test!(test_mask_hash, { |
| 677 |
use std::collections::hash_map::DefaultHasher; |
| 678 |
use std::hash::Hash; |
| 679 |
use std::hash::Hasher; |
| 680 |
|
| 681 |
let a = $mask::new(true, false, true, false); |
| 682 |
let b = $mask::new(true, false, true, false); |
| 683 |
let c = $mask::new(false, true, true, false); |
| 684 |
|
| 685 |
let mut hasher = DefaultHasher::new(); |
| 686 |
a.hash(&mut hasher); |
| 687 |
let a_hashed = hasher.finish(); |
| 688 |
|
| 689 |
let mut hasher = DefaultHasher::new(); |
| 690 |
b.hash(&mut hasher); |
| 691 |
let b_hashed = hasher.finish(); |
| 692 |
|
| 693 |
let mut hasher = DefaultHasher::new(); |
| 694 |
c.hash(&mut hasher); |
| 695 |
let c_hashed = hasher.finish(); |
| 696 |
|
| 697 |
assert_eq!(a, b); |
| 698 |
assert_eq!(a_hashed, b_hashed); |
| 699 |
assert_ne!(a, c); |
| 700 |
assert_ne!(a_hashed, c_hashed); |
| 701 |
}); |
| 702 |
|
| 703 |
glam_test!(test_to_from_slice, { |
| 704 |
let v = $vec4::new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 705 |
let mut a = [0 as $t, 0 as $t, 0 as $t, 0 as $t]; |
| 706 |
v.write_to_slice(&mut a); |
| 707 |
assert_eq!(v, $vec4::from_slice(&a)); |
| 708 |
}); |
| 709 |
|
| 710 |
glam_test!(test_sum, { |
| 711 |
let one = $vec4::ONE; |
| 712 |
assert_eq!([one, one].iter().sum::<$vec4>(), one + one); |
| 713 |
assert_eq!([one, one].into_iter().sum::<$vec4>(), one + one); |
| 714 |
}); |
| 715 |
|
| 716 |
glam_test!(test_product, { |
| 717 |
let two = $vec4::new(2 as $t, 2 as $t, 2 as $t, 2 as $t); |
| 718 |
assert_eq!([two, two].iter().product::<$vec4>(), two * two); |
| 719 |
assert_eq!([two, two].into_iter().product::<$vec4>(), two * two); |
| 720 |
}); |
| 721 |
}; |
| 722 |
} |
| 723 |
|
| 724 |
macro_rules! impl_vec4_signed_tests { |
| 725 |
($t:ident, $new:ident, $vec4:ident, $vec3:ident, $vec2:ident, $mask:ident) => { |
| 726 |
impl_vec4_tests!($t, $new, $vec4, $vec3, $vec2, $mask); |
| 727 |
|
| 728 |
glam_test!(test_neg, { |
| 729 |
let a = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 730 |
assert_eq!((-1 as $t, -2 as $t, -3 as $t, -4 as $t), (-a).into()); |
| 731 |
assert_eq!( |
| 732 |
$new(-0 as $t, -0 as $t, -0 as $t, -0 as $t), |
| 733 |
-$new(0 as $t, 0 as $t, 0 as $t, 0 as $t) |
| 734 |
); |
| 735 |
assert_eq!( |
| 736 |
$new(0 as $t, -0 as $t, -0 as $t, -0 as $t), |
| 737 |
-$new(-0 as $t, 0 as $t, 0 as $t, 0 as $t) |
| 738 |
); |
| 739 |
}); |
| 740 |
|
| 741 |
glam_test!(test_is_negative_bitmask, { |
| 742 |
assert_eq!($vec4::ZERO.is_negative_bitmask(), 0b0000); |
| 743 |
assert_eq!($vec4::ONE.is_negative_bitmask(), 0b0000); |
| 744 |
assert_eq!((-$vec4::ONE).is_negative_bitmask(), 0b1111); |
| 745 |
assert_eq!( |
| 746 |
$vec4::new(-1 as $t, 2 as $t, 3 as $t, -4 as $t).is_negative_bitmask(), |
| 747 |
0b1001 |
| 748 |
); |
| 749 |
assert_eq!( |
| 750 |
$vec4::new(1 as $t, 5 as $t, -3 as $t, 7 as $t).is_negative_bitmask(), |
| 751 |
0b0100 |
| 752 |
); |
| 753 |
assert_eq!( |
| 754 |
$vec4::new(3 as $t, -4 as $t, 1 as $t, 6 as $t).is_negative_bitmask(), |
| 755 |
0b0010 |
| 756 |
); |
| 757 |
assert_eq!( |
| 758 |
$vec4::new(2 as $t, -6 as $t, 5 as $t, -3 as $t).is_negative_bitmask(), |
| 759 |
0b1010 |
| 760 |
); |
| 761 |
}); |
| 762 |
|
| 763 |
glam_test!(test_abs, { |
| 764 |
assert_eq!($vec4::ZERO.abs(), $vec4::ZERO); |
| 765 |
assert_eq!($vec4::ONE.abs(), $vec4::ONE); |
| 766 |
assert_eq!((-$vec4::ONE).abs(), $vec4::ONE); |
| 767 |
}); |
| 768 |
|
| 769 |
glam_test!(test_dot_signed, { |
| 770 |
let x = $new(1 as $t, 0 as $t, 0 as $t, 0 as $t); |
| 771 |
let y = $new(0 as $t, 1 as $t, 0 as $t, 0 as $t); |
| 772 |
let z = $new(0 as $t, 0 as $t, 1 as $t, 0 as $t); |
| 773 |
let w = $new(0 as $t, 0 as $t, 0 as $t, 1 as $t); |
| 774 |
assert_eq!(1 as $t, x.dot(x)); |
| 775 |
assert_eq!(0 as $t, x.dot(y)); |
| 776 |
assert_eq!(0 as $t, x.dot(-z)); |
| 777 |
assert_eq!(-1 as $t, w.dot(-w)); |
| 778 |
}); |
| 779 |
|
| 780 |
glam_test!(test_length_squared_signed, { |
| 781 |
let x = $new(1 as $t, 0 as $t, 0 as $t, 0 as $t); |
| 782 |
let y = $new(0 as $t, 1 as $t, 0 as $t, 0 as $t); |
| 783 |
let z = $new(0 as $t, 0 as $t, 1 as $t, 0 as $t); |
| 784 |
let w = $new(0 as $t, 0 as $t, 0 as $t, 1 as $t); |
| 785 |
assert_eq!(4 as $t, (2 as $t * x).length_squared()); |
| 786 |
assert_eq!(9 as $t, (-3 as $t * y).length_squared()); |
| 787 |
assert_eq!(16 as $t, (4 as $t * z).length_squared()); |
| 788 |
assert_eq!(64 as $t, (8 as $t * w).length_squared()); |
| 789 |
assert_eq!( |
| 790 |
2 as $t * 2 as $t + 3 as $t * 3 as $t + 4 as $t * 4 as $t + 5 as $t * 5 as $t, |
| 791 |
$new(2 as $t, 3 as $t, 4 as $t, 5 as $t).length_squared() |
| 792 |
); |
| 793 |
assert_eq!(2 as $t, x.distance_squared(y)); |
| 794 |
assert_eq!(13 as $t, (2 as $t * x).distance_squared(-3 as $t * z)); |
| 795 |
}); |
| 796 |
|
| 797 |
glam_test!(test_div_euclid, { |
| 798 |
let one = $vec4::ONE; |
| 799 |
let two = one + one; |
| 800 |
let three = two + one; |
| 801 |
assert_eq!(three.div_euclid(two), one); |
| 802 |
assert_eq!((-three).div_euclid(two), -two); |
| 803 |
assert_eq!(three.div_euclid(-two), -one); |
| 804 |
assert_eq!((-three).div_euclid(-two), two); |
| 805 |
}); |
| 806 |
|
| 807 |
glam_test!(test_rem_euclid, { |
| 808 |
let one = $vec4::ONE; |
| 809 |
let two = one + one; |
| 810 |
let three = two + one; |
| 811 |
let four = three + one; |
| 812 |
assert_eq!(four.rem_euclid(three), one); |
| 813 |
assert_eq!((-four).rem_euclid(three), two); |
| 814 |
assert_eq!(four.rem_euclid(-three), one); |
| 815 |
assert_eq!((-four).rem_euclid(-three), two); |
| 816 |
}); |
| 817 |
}; |
| 818 |
} |
| 819 |
|
| 820 |
macro_rules! impl_vec4_signed_integer_tests { |
| 821 |
($t:ident, $new:ident, $vec4:ident, $vec3:ident, $vec2:ident, $mask:ident) => { |
| 822 |
impl_vec4_signed_tests!($t, $new, $vec4, $vec3, $vec2, $mask); |
| 823 |
|
| 824 |
glam_test!(test_signum, { |
| 825 |
assert_eq!($vec4::ZERO.signum(), $vec4::ZERO); |
| 826 |
assert_eq!($vec4::ONE.signum(), $vec4::ONE); |
| 827 |
assert_eq!((-$vec4::ONE).signum(), -$vec4::ONE); |
| 828 |
}); |
| 829 |
}; |
| 830 |
} |
| 831 |
|
| 832 |
macro_rules! impl_vec4_eq_hash_tests { |
| 833 |
($t:ident, $new:ident) => { |
| 834 |
glam_test!(test_ve2_hash, { |
| 835 |
use std::collections::hash_map::DefaultHasher; |
| 836 |
use std::hash::Hash; |
| 837 |
use std::hash::Hasher; |
| 838 |
|
| 839 |
let a = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 840 |
let b = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 841 |
let c = $new(3 as $t, 2 as $t, 1 as $t, 4 as $t); |
| 842 |
|
| 843 |
let mut hasher = DefaultHasher::new(); |
| 844 |
a.hash(&mut hasher); |
| 845 |
let a_hashed = hasher.finish(); |
| 846 |
|
| 847 |
let mut hasher = DefaultHasher::new(); |
| 848 |
b.hash(&mut hasher); |
| 849 |
let b_hashed = hasher.finish(); |
| 850 |
|
| 851 |
let mut hasher = DefaultHasher::new(); |
| 852 |
c.hash(&mut hasher); |
| 853 |
let c_hashed = hasher.finish(); |
| 854 |
|
| 855 |
assert_eq!(a, b); |
| 856 |
assert_eq!(a_hashed, b_hashed); |
| 857 |
assert_ne!(a, c); |
| 858 |
assert_ne!(a_hashed, c_hashed); |
| 859 |
}); |
| 860 |
}; |
| 861 |
} |
| 862 |
|
| 863 |
macro_rules! impl_vec4_float_tests { |
| 864 |
($t:ident, $new:ident, $vec4:ident, $vec3:ident, $vec2:ident, $mask:ident) => { |
| 865 |
impl_vec4_signed_tests!($t, $new, $vec4, $vec3, $vec2, $mask); |
| 866 |
impl_vec_float_normalize_tests!($t, $vec4); |
| 867 |
|
| 868 |
use core::$t::INFINITY; |
| 869 |
use core::$t::NAN; |
| 870 |
use core::$t::NEG_INFINITY; |
| 871 |
|
| 872 |
glam_test!(test_vec4_nan, { |
| 873 |
assert!($vec4::NAN.is_nan()); |
| 874 |
assert!(!$vec4::NAN.is_finite()); |
| 875 |
}); |
| 876 |
|
| 877 |
glam_test!(test_funcs, { |
| 878 |
let x = $new(1.0, 0.0, 0.0, 0.0); |
| 879 |
let y = $new(0.0, 1.0, 0.0, 0.0); |
| 880 |
let z = $new(0.0, 0.0, 1.0, 0.0); |
| 881 |
let w = $new(0.0, 0.0, 0.0, 1.0); |
| 882 |
assert_eq!(2.0, (-2.0 * x).length()); |
| 883 |
assert_eq!(3.0, (3.0 * y).length()); |
| 884 |
assert_eq!(4.0, (-4.0 * z).length()); |
| 885 |
assert_eq!(5.0, (-5.0 * w).length()); |
| 886 |
assert_eq!((2.0 as $t).sqrt(), w.distance(y)); |
| 887 |
assert_eq!(5.0, (3.0 * x).distance(-4.0 * y)); |
| 888 |
assert_eq!(13.0, (-5.0 * w).distance(12.0 * y)); |
| 889 |
assert_eq!(x, (2.0 * x).normalize()); |
| 890 |
assert_eq!( |
| 891 |
1.0 * 5.0 + 2.0 * 6.0 + 3.0 * 7.0 + 4.0 * 8.0, |
| 892 |
$new(1.0, 2.0, 3.0, 4.0).dot($new(5.0, 6.0, 7.0, 8.0)) |
| 893 |
); |
| 894 |
assert_eq!( |
| 895 |
(2.0 as $t * 2.0 + 3.0 * 3.0 + 4.0 * 4.0 + 5.0 * 5.0).sqrt(), |
| 896 |
$new(2.0, 3.0, 4.0, 5.0).length() |
| 897 |
); |
| 898 |
assert_eq!( |
| 899 |
1.0 / (2.0 as $t * 2.0 + 3.0 * 3.0 + 4.0 * 4.0 + 5.0 * 5.0).sqrt(), |
| 900 |
$new(2.0, 3.0, 4.0, 5.0).length_recip() |
| 901 |
); |
| 902 |
assert!($new(2.0, 3.0, 4.0, 5.0).normalize().is_normalized()); |
| 903 |
assert_approx_eq!( |
| 904 |
$new(2.0, 3.0, 4.0, 5.0) |
| 905 |
/ (2.0 as $t * 2.0 + 3.0 * 3.0 + 4.0 * 4.0 + 5.0 * 5.0).sqrt(), |
| 906 |
$new(2.0, 3.0, 4.0, 5.0).normalize() |
| 907 |
); |
| 908 |
assert_eq!( |
| 909 |
$new(0.5, 0.25, 0.125, 0.0625), |
| 910 |
$new(2.0, 4.0, 8.0, 16.0).recip() |
| 911 |
); |
| 912 |
}); |
| 913 |
|
| 914 |
glam_test!(test_project_reject, { |
| 915 |
assert_eq!( |
| 916 |
$new(0.0, 0.0, 0.0, 1.0), |
| 917 |
$new(0.0, 1.0, 0.0, 1.0).project_onto($new(0.0, 0.0, 0.0, 2.0)) |
| 918 |
); |
| 919 |
assert_eq!( |
| 920 |
$new(0.0, 1.0, 0.0, 0.0), |
| 921 |
$new(0.0, 1.0, 0.0, 1.0).reject_from($new(0.0, 0.0, 0.0, 2.0)) |
| 922 |
); |
| 923 |
assert_eq!( |
| 924 |
$new(0.0, 0.0, 0.0, 1.0), |
| 925 |
$new(0.0, 1.0, 0.0, 1.0).project_onto_normalized($new(0.0, 0.0, 0.0, 1.0)) |
| 926 |
); |
| 927 |
assert_eq!( |
| 928 |
$new(0.0, 1.0, 0.0, 0.0), |
| 929 |
$new(0.0, 1.0, 0.0, 1.0).reject_from_normalized($new(0.0, 0.0, 0.0, 1.0)) |
| 930 |
); |
| 931 |
should_glam_assert!({ $vec4::ONE.project_onto($vec4::ZERO) }); |
| 932 |
should_glam_assert!({ $vec4::ONE.reject_from($vec4::ZERO) }); |
| 933 |
should_glam_assert!({ $vec4::ONE.project_onto_normalized($vec4::ONE) }); |
| 934 |
should_glam_assert!({ $vec4::ONE.reject_from_normalized($vec4::ONE) }); |
| 935 |
}); |
| 936 |
|
| 937 |
glam_test!(test_signum, { |
| 938 |
assert_eq!($vec4::ZERO.signum(), $vec4::ONE); |
| 939 |
assert_eq!((-$vec4::ZERO).signum(), -$vec4::ONE); |
| 940 |
assert_eq!($vec4::ONE.signum(), $vec4::ONE); |
| 941 |
assert_eq!((-$vec4::ONE).signum(), -$vec4::ONE); |
| 942 |
assert_eq!($vec4::INFINITY.signum(), $vec4::ONE); |
| 943 |
assert_eq!($vec4::NEG_INFINITY.signum(), -$vec4::ONE); |
| 944 |
assert!($vec4::NAN.signum().is_nan_mask().all()); |
| 945 |
}); |
| 946 |
|
| 947 |
glam_test!(test_copysign, { |
| 948 |
assert_eq!($vec4::ZERO.copysign(-$vec4::ZERO), -$vec4::ZERO); |
| 949 |
assert_eq!((-$vec4::ZERO).copysign(-$vec4::ZERO), -$vec4::ZERO); |
| 950 |
assert_eq!($vec4::ZERO.copysign($vec4::ZERO), $vec4::ZERO); |
| 951 |
assert_eq!((-$vec4::ZERO).copysign($vec4::ZERO), $vec4::ZERO); |
| 952 |
assert_eq!($vec4::ONE.copysign(-$vec4::ZERO), -$vec4::ONE); |
| 953 |
assert_eq!((-$vec4::ONE).copysign(-$vec4::ZERO), -$vec4::ONE); |
| 954 |
assert_eq!($vec4::ONE.copysign($vec4::ZERO), $vec4::ONE); |
| 955 |
assert_eq!((-$vec4::ONE).copysign($vec4::ZERO), $vec4::ONE); |
| 956 |
assert_eq!($vec4::ZERO.copysign(-$vec4::ONE), -$vec4::ZERO); |
| 957 |
assert_eq!((-$vec4::ZERO).copysign(-$vec4::ONE), -$vec4::ZERO); |
| 958 |
assert_eq!($vec4::ZERO.copysign($vec4::ONE), $vec4::ZERO); |
| 959 |
assert_eq!((-$vec4::ZERO).copysign($vec4::ONE), $vec4::ZERO); |
| 960 |
assert_eq!($vec4::ONE.copysign(-$vec4::ONE), -$vec4::ONE); |
| 961 |
assert_eq!((-$vec4::ONE).copysign(-$vec4::ONE), -$vec4::ONE); |
| 962 |
assert_eq!($vec4::ONE.copysign($vec4::ONE), $vec4::ONE); |
| 963 |
assert_eq!((-$vec4::ONE).copysign($vec4::ONE), $vec4::ONE); |
| 964 |
assert_eq!($vec4::INFINITY.copysign($vec4::ONE), $vec4::INFINITY); |
| 965 |
assert_eq!($vec4::INFINITY.copysign(-$vec4::ONE), $vec4::NEG_INFINITY); |
| 966 |
assert_eq!($vec4::NEG_INFINITY.copysign($vec4::ONE), $vec4::INFINITY); |
| 967 |
assert_eq!( |
| 968 |
$vec4::NEG_INFINITY.copysign(-$vec4::ONE), |
| 969 |
$vec4::NEG_INFINITY |
| 970 |
); |
| 971 |
assert!($vec4::NAN.copysign($vec4::ONE).is_nan_mask().all()); |
| 972 |
assert!($vec4::NAN.copysign(-$vec4::ONE).is_nan_mask().all()); |
| 973 |
}); |
| 974 |
|
| 975 |
glam_test!(test_float_is_negative_bitmask, { |
| 976 |
assert_eq!($vec4::ZERO.is_negative_bitmask(), 0b0000); |
| 977 |
assert_eq!((-$vec4::ZERO).is_negative_bitmask(), 0b1111); |
| 978 |
assert_eq!($vec4::ONE.is_negative_bitmask(), 0b0000); |
| 979 |
assert_eq!((-$vec4::ONE).is_negative_bitmask(), 0b1111); |
| 980 |
assert_eq!( |
| 981 |
$vec4::new(-1.0, 2.0, 3.0, -4.0).is_negative_bitmask(), |
| 982 |
0b1001 |
| 983 |
); |
| 984 |
assert_eq!( |
| 985 |
$vec4::new(8.0, 3.0, 1.0, -0.0).is_negative_bitmask(), |
| 986 |
0b1000 |
| 987 |
); |
| 988 |
assert_eq!( |
| 989 |
$vec4::new(1.0, 5.0, -3.0, 7.0).is_negative_bitmask(), |
| 990 |
0b0100 |
| 991 |
); |
| 992 |
assert_eq!( |
| 993 |
$vec4::new(3.0, -4.0, 1.0, 6.0).is_negative_bitmask(), |
| 994 |
0b0010 |
| 995 |
); |
| 996 |
assert_eq!( |
| 997 |
$vec4::new(2.0, -6.0, 5.0, -3.0).is_negative_bitmask(), |
| 998 |
0b1010 |
| 999 |
); |
| 1000 |
}); |
| 1001 |
|
| 1002 |
glam_test!(test_round, { |
| 1003 |
assert_eq!($vec4::new(1.35, 0.0, 0.0, 0.0).round().x, 1.0); |
| 1004 |
assert_eq!($vec4::new(0.0, 1.5, 0.0, 0.0).round().y, 2.0); |
| 1005 |
assert_eq!($vec4::new(0.0, 0.0, -15.5, 0.0).round().z, -16.0); |
| 1006 |
assert_eq!($vec4::new(0.0, 0.0, 0.0, 0.0).round().z, 0.0); |
| 1007 |
assert_eq!($vec4::new(0.0, 21.1, 0.0, 0.0).round().y, 21.0); |
| 1008 |
assert_eq!($vec4::new(0.0, 0.0, 0.0, 11.123).round().w, 11.0); |
| 1009 |
assert_eq!($vec4::new(0.0, 0.0, 11.501, 0.0).round().z, 12.0); |
| 1010 |
assert_eq!( |
| 1011 |
$vec4::new(NEG_INFINITY, INFINITY, 1.0, -1.0).round(), |
| 1012 |
$vec4::new(NEG_INFINITY, INFINITY, 1.0, -1.0) |
| 1013 |
); |
| 1014 |
assert!($vec4::new(NAN, 0.0, 0.0, 1.0).round().x.is_nan()); |
| 1015 |
}); |
| 1016 |
|
| 1017 |
glam_test!(test_floor, { |
| 1018 |
assert_eq!( |
| 1019 |
$vec4::new(1.35, 1.5, -1.5, 1.999).floor(), |
| 1020 |
$vec4::new(1.0, 1.0, -2.0, 1.0) |
| 1021 |
); |
| 1022 |
assert_eq!( |
| 1023 |
$vec4::new(INFINITY, NEG_INFINITY, 0.0, 0.0).floor(), |
| 1024 |
$vec4::new(INFINITY, NEG_INFINITY, 0.0, 0.0) |
| 1025 |
); |
| 1026 |
assert!($vec4::new(0.0, NAN, 0.0, 0.0).floor().y.is_nan()); |
| 1027 |
assert_eq!( |
| 1028 |
$vec4::new(-0.0, -2000000.123, 10000000.123, 1000.9).floor(), |
| 1029 |
$vec4::new(-0.0, -2000001.0, 10000000.0, 1000.0) |
| 1030 |
); |
| 1031 |
}); |
| 1032 |
|
| 1033 |
glam_test!(test_fract_gl, { |
| 1034 |
assert_approx_eq!( |
| 1035 |
$vec4::new(1.35, 1.5, -1.5, 1.999).fract_gl(), |
| 1036 |
$vec4::new(0.35, 0.5, 0.5, 0.999) |
| 1037 |
); |
| 1038 |
assert_approx_eq!( |
| 1039 |
$vec4::new(-0.0, -200000.123, 1000000.123, 1000.9).fract_gl(), |
| 1040 |
$vec4::new(0.0, 0.877, 0.123, 0.9), |
| 1041 |
0.002 |
| 1042 |
); |
| 1043 |
}); |
| 1044 |
|
| 1045 |
glam_test!(test_fract, { |
| 1046 |
assert_approx_eq!( |
| 1047 |
$vec4::new(1.35, 1.5, -1.5, 1.999).fract(), |
| 1048 |
$vec4::new(0.35, 0.5, -0.5, 0.999) |
| 1049 |
); |
| 1050 |
assert_approx_eq!( |
| 1051 |
$vec4::new(-0.0, -200000.123, 1000000.123, 1000.9).fract(), |
| 1052 |
$vec4::new(0.0, -0.123, 0.123, 0.9), |
| 1053 |
0.002 |
| 1054 |
); |
| 1055 |
}); |
| 1056 |
|
| 1057 |
glam_test!(test_ceil, { |
| 1058 |
assert_eq!( |
| 1059 |
$vec4::new(1.35, 1.5, -1.5, 1234.1234).ceil(), |
| 1060 |
$vec4::new(2.0, 2.0, -1.0, 1235.0) |
| 1061 |
); |
| 1062 |
assert_eq!( |
| 1063 |
$vec4::new(INFINITY, NEG_INFINITY, 0.0, 0.0).ceil(), |
| 1064 |
$vec4::new(INFINITY, NEG_INFINITY, 0.0, 0.0) |
| 1065 |
); |
| 1066 |
assert!($vec4::new(0.0, 0.0, NAN, 0.0).ceil().z.is_nan()); |
| 1067 |
assert_eq!( |
| 1068 |
$vec4::new(-1234.1234, -2000000.123, 1000000.123, 1000.9).ceil(), |
| 1069 |
$vec4::new(-1234.0, -2000000.0, 1000001.0, 1001.0) |
| 1070 |
); |
| 1071 |
}); |
| 1072 |
|
| 1073 |
glam_test!(test_trunc, { |
| 1074 |
assert_eq!( |
| 1075 |
$vec4::new(1.35, 1.5, -1.5, 1.999).trunc(), |
| 1076 |
$vec4::new(1.0, 1.0, -1.0, 1.0) |
| 1077 |
); |
| 1078 |
assert_eq!( |
| 1079 |
$vec4::new(INFINITY, NEG_INFINITY, 0.0, 0.0).trunc(), |
| 1080 |
$vec4::new(INFINITY, NEG_INFINITY, 0.0, 0.0) |
| 1081 |
); |
| 1082 |
assert!($vec4::new(0.0, NAN, 0.0, 0.0).trunc().y.is_nan()); |
| 1083 |
assert_eq!( |
| 1084 |
$vec4::new(-0.0, -2000000.123, 10000000.123, 1000.9).trunc(), |
| 1085 |
$vec4::new(-0.0, -2000000.0, 10000000.0, 1000.0) |
| 1086 |
); |
| 1087 |
}); |
| 1088 |
|
| 1089 |
glam_test!(test_lerp, { |
| 1090 |
let v0 = $vec4::new(-1.0, -1.0, -1.0, -1.0); |
| 1091 |
let v1 = $vec4::new(1.0, 1.0, 1.0, 1.0); |
| 1092 |
assert_approx_eq!(v0, v0.lerp(v1, 0.0)); |
| 1093 |
assert_approx_eq!(v1, v0.lerp(v1, 1.0)); |
| 1094 |
assert_approx_eq!($vec4::ZERO, v0.lerp(v1, 0.5)); |
| 1095 |
}); |
| 1096 |
|
| 1097 |
glam_test!(test_move_towards, { |
| 1098 |
let v0 = $vec4::new(-1.0, -1.0, -1.0, -1.0); |
| 1099 |
let v1 = $vec4::new(1.0, 1.0, 1.0, 1.0); |
| 1100 |
assert_approx_eq!(v0, v0.move_towards(v1, 0.0)); |
| 1101 |
assert_approx_eq!(v1, v0.move_towards(v1, v0.distance(v1))); |
| 1102 |
assert_approx_eq!(v1, v0.move_towards(v1, v0.distance(v1) + 1.0)); |
| 1103 |
}); |
| 1104 |
|
| 1105 |
glam_test!(test_midpoint, { |
| 1106 |
let v0 = $vec4::new(-1.0, -1.0, -1.0, -1.0); |
| 1107 |
let v1 = $vec4::new(1.0, 1.0, 1.0, 1.0); |
| 1108 |
let v2 = $vec4::new(-1.5, 0.0, 1.0, 0.5); |
| 1109 |
assert_approx_eq!($vec4::ZERO, v0.midpoint(v1)); |
| 1110 |
assert_approx_eq!($vec4::new(-0.25, 0.5, 1.0, 0.75), v1.midpoint(v2)); |
| 1111 |
}); |
| 1112 |
|
| 1113 |
glam_test!(test_is_finite, { |
| 1114 |
assert!($vec4::new(0.0, 0.0, 0.0, 0.0).is_finite()); |
| 1115 |
assert!($vec4::new(-1e-10, 1.0, 1e10, 42.0).is_finite()); |
| 1116 |
assert!(!$vec4::new(INFINITY, 0.0, 0.0, 0.0).is_finite()); |
| 1117 |
assert!(!$vec4::new(0.0, NAN, 0.0, 0.0).is_finite()); |
| 1118 |
assert!(!$vec4::new(0.0, 0.0, NEG_INFINITY, 0.0).is_finite()); |
| 1119 |
assert!(!$vec4::new(0.0, 0.0, 0.0, NAN).is_finite()); |
| 1120 |
assert!(!$vec4::INFINITY.is_finite()); |
| 1121 |
assert!(!$vec4::NEG_INFINITY.is_finite()); |
| 1122 |
}); |
| 1123 |
|
| 1124 |
glam_test!(test_powf, { |
| 1125 |
assert_eq!( |
| 1126 |
$vec4::new(2.0, 4.0, 8.0, 16.0).powf(2.0), |
| 1127 |
$vec4::new(4.0, 16.0, 64.0, 256.0) |
| 1128 |
); |
| 1129 |
}); |
| 1130 |
|
| 1131 |
glam_test!(test_exp, { |
| 1132 |
assert_approx_eq!( |
| 1133 |
$vec4::new(1.0, 2.0, 3.0, 4.0).exp(), |
| 1134 |
$vec4::new( |
| 1135 |
(1.0 as $t).exp(), |
| 1136 |
(2.0 as $t).exp(), |
| 1137 |
(3.0 as $t).exp(), |
| 1138 |
(4.0 as $t).exp() |
| 1139 |
), |
| 1140 |
1e-5 |
| 1141 |
); |
| 1142 |
}); |
| 1143 |
|
| 1144 |
glam_test!(test_clamp_length, { |
| 1145 |
// Too long gets shortened |
| 1146 |
assert_eq!( |
| 1147 |
$vec4::new(12.0, 16.0, 0.0, 0.0).clamp_length(7.0, 10.0), |
| 1148 |
$vec4::new(6.0, 8.0, 0.0, 0.0) // shortened to length 10.0 |
| 1149 |
); |
| 1150 |
// In the middle is unchanged |
| 1151 |
assert_eq!( |
| 1152 |
$vec4::new(2.0, 1.0, 0.0, 0.0).clamp_length(0.5, 5.0), |
| 1153 |
$vec4::new(2.0, 1.0, 0.0, 0.0) // unchanged |
| 1154 |
); |
| 1155 |
// Too short gets lengthened |
| 1156 |
assert_eq!( |
| 1157 |
$vec4::new(0.6, 0.8, 0.0, 0.0).clamp_length(10.0, 20.0), |
| 1158 |
$vec4::new(6.0, 8.0, 0.0, 0.0) // lengthened to length 10.0 |
| 1159 |
); |
| 1160 |
should_glam_assert!({ $vec4::ONE.clamp_length(1.0, 0.0) }); |
| 1161 |
}); |
| 1162 |
|
| 1163 |
glam_test!(test_clamp_length_max, { |
| 1164 |
// Too long gets shortened |
| 1165 |
assert_eq!( |
| 1166 |
$vec4::new(12.0, 16.0, 0.0, 0.0).clamp_length_max(10.0), |
| 1167 |
$vec4::new(6.0, 8.0, 0.0, 0.0) // shortened to length 10.0 |
| 1168 |
); |
| 1169 |
// Not too long is unchanged |
| 1170 |
assert_eq!( |
| 1171 |
$vec4::new(2.0, 1.0, 0.0, 0.0).clamp_length_max(5.0), |
| 1172 |
$vec4::new(2.0, 1.0, 0.0, 0.0) // unchanged |
| 1173 |
); |
| 1174 |
}); |
| 1175 |
|
| 1176 |
glam_test!(test_clamp_length_min, { |
| 1177 |
// Not too short is unchanged |
| 1178 |
assert_eq!( |
| 1179 |
$vec4::new(2.0, 1.0, 0.0, 0.0).clamp_length_min(0.5), |
| 1180 |
$vec4::new(2.0, 1.0, 0.0, 0.0) // unchanged |
| 1181 |
); |
| 1182 |
// Too short gets lengthened |
| 1183 |
assert_eq!( |
| 1184 |
$vec4::new(0.6, 0.8, 0.0, 0.0).clamp_length_min(10.0), |
| 1185 |
$vec4::new(6.0, 8.0, 0.0, 0.0) // lengthened to length 10.0 |
| 1186 |
); |
| 1187 |
}); |
| 1188 |
|
| 1189 |
glam_test!(test_mul_add, { |
| 1190 |
assert_eq!( |
| 1191 |
$vec4::new(1.0, 1.0, 1.0, 1.0).mul_add( |
| 1192 |
$vec4::new(0.5, 2.0, -4.0, 0.0), |
| 1193 |
$vec4::new(-1.0, -1.0, -1.0, -1.0) |
| 1194 |
), |
| 1195 |
$vec4::new(-0.5, 1.0, -5.0, -1.0) |
| 1196 |
); |
| 1197 |
}); |
| 1198 |
|
| 1199 |
glam_test!(test_fmt_float, { |
| 1200 |
let a = $vec4::new(1.0, 2.0, 3.0, 4.0); |
| 1201 |
assert_eq!(format!("{:.2}", a), "[1.00, 2.00, 3.00, 4.00]"); |
| 1202 |
}); |
| 1203 |
}; |
| 1204 |
} |
| 1205 |
|
| 1206 |
macro_rules! impl_vec4_scalar_shift_op_test { |
| 1207 |
($vec4:ident, $t_min:literal, $t_max:literal, $rhs_min:literal, $rhs_max:literal) => { |
| 1208 |
glam_test!(test_vec4_scalar_shift_ops, { |
| 1209 |
for x in $t_min..$t_max { |
| 1210 |
for y in $t_min..$t_max { |
| 1211 |
for z in $t_min..$t_max { |
| 1212 |
for w in $t_min..$t_max { |
| 1213 |
for rhs in $rhs_min..$rhs_max { |
| 1214 |
assert_eq!( |
| 1215 |
$vec4::new(x, y, z, w) << rhs, |
| 1216 |
$vec4::new(x << rhs, y << rhs, z << rhs, w << rhs) |
| 1217 |
); |
| 1218 |
assert_eq!( |
| 1219 |
$vec4::new(x, y, z, w) >> rhs, |
| 1220 |
$vec4::new(x >> rhs, y >> rhs, z >> rhs, w >> rhs) |
| 1221 |
); |
| 1222 |
} |
| 1223 |
} |
| 1224 |
} |
| 1225 |
} |
| 1226 |
} |
| 1227 |
}); |
| 1228 |
}; |
| 1229 |
} |
| 1230 |
|
| 1231 |
macro_rules! impl_vec4_scalar_shift_op_tests { |
| 1232 |
($vec4:ident, $t_min:literal, $t_max:literal) => { |
| 1233 |
mod shift_by_i8 { |
| 1234 |
use glam::$vec4; |
| 1235 |
impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0i8, 2); |
| 1236 |
} |
| 1237 |
mod shift_by_i16 { |
| 1238 |
use glam::$vec4; |
| 1239 |
impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0i16, 2); |
| 1240 |
} |
| 1241 |
mod shift_by_i32 { |
| 1242 |
use glam::$vec4; |
| 1243 |
impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0i32, 2); |
| 1244 |
} |
| 1245 |
mod shift_by_i64 { |
| 1246 |
use glam::$vec4; |
| 1247 |
impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0i64, 2); |
| 1248 |
} |
| 1249 |
mod shift_by_u8 { |
| 1250 |
use glam::$vec4; |
| 1251 |
impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0u8, 2); |
| 1252 |
} |
| 1253 |
mod shift_by_u16 { |
| 1254 |
use glam::$vec4; |
| 1255 |
impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0u16, 2); |
| 1256 |
} |
| 1257 |
mod shift_by_u32 { |
| 1258 |
use glam::$vec4; |
| 1259 |
impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0u32, 2); |
| 1260 |
} |
| 1261 |
mod shift_by_u64 { |
| 1262 |
use glam::$vec4; |
| 1263 |
impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0u64, 2); |
| 1264 |
} |
| 1265 |
}; |
| 1266 |
} |
| 1267 |
|
| 1268 |
macro_rules! impl_vec4_shift_op_test { |
| 1269 |
($vec4:ident, $rhs:ident, $t_min:literal, $t_max:literal) => { |
| 1270 |
glam_test!(test_vec4_shift_ops, { |
| 1271 |
for x1 in $t_min..$t_max { |
| 1272 |
for y1 in $t_min..$t_max { |
| 1273 |
for z1 in $t_min..$t_max { |
| 1274 |
for w1 in $t_min..$t_max { |
| 1275 |
for x2 in $t_min..$t_max { |
| 1276 |
for y2 in $t_min..$t_max { |
| 1277 |
for z2 in $t_min..$t_max { |
| 1278 |
for w2 in $t_min..$t_max { |
| 1279 |
assert_eq!( |
| 1280 |
$vec4::new(x1, y1, z1, w1) |
| 1281 |
<< $rhs::new(x2, y2, z2, w2), |
| 1282 |
$vec4::new(x1 << x2, y1 << y2, z1 << z2, w1 << w2) |
| 1283 |
); |
| 1284 |
assert_eq!( |
| 1285 |
$vec4::new(x1, y1, z1, w1) |
| 1286 |
>> $rhs::new(x2, y2, z2, w2), |
| 1287 |
$vec4::new(x1 >> x2, y1 >> y2, z1 >> z2, w1 >> w2) |
| 1288 |
); |
| 1289 |
} |
| 1290 |
} |
| 1291 |
} |
| 1292 |
} |
| 1293 |
} |
| 1294 |
} |
| 1295 |
} |
| 1296 |
} |
| 1297 |
}); |
| 1298 |
}; |
| 1299 |
} |
| 1300 |
|
| 1301 |
macro_rules! impl_vec4_shift_op_tests { |
| 1302 |
($vec4:ident) => { |
| 1303 |
mod shift_ivec4_by_ivec4 { |
| 1304 |
use super::*; |
| 1305 |
impl_vec4_shift_op_test!($vec4, IVec4, 0, 2); |
| 1306 |
} |
| 1307 |
mod shift_ivec4_by_uvec4 { |
| 1308 |
use super::*; |
| 1309 |
impl_vec4_shift_op_test!($vec4, UVec4, 0, 2); |
| 1310 |
} |
| 1311 |
}; |
| 1312 |
} |
| 1313 |
|
| 1314 |
macro_rules! impl_vec4_scalar_bit_op_tests { |
| 1315 |
($vec4:ident, $t_min:literal, $t_max:literal) => { |
| 1316 |
glam_test!(test_vec4_scalar_bit_ops, { |
| 1317 |
for x in $t_min..$t_max { |
| 1318 |
for y in $t_min..$t_max { |
| 1319 |
for z in $t_min..$t_max { |
| 1320 |
for w in $t_min..$t_max { |
| 1321 |
for rhs in $t_min..$t_max { |
| 1322 |
assert_eq!( |
| 1323 |
$vec4::new(x, y, z, w) & rhs, |
| 1324 |
$vec4::new(x & rhs, y & rhs, z & rhs, w & rhs) |
| 1325 |
); |
| 1326 |
assert_eq!( |
| 1327 |
$vec4::new(x, y, z, w) | rhs, |
| 1328 |
$vec4::new(x | rhs, y | rhs, z | rhs, w | rhs) |
| 1329 |
); |
| 1330 |
assert_eq!( |
| 1331 |
$vec4::new(x, y, z, w) ^ rhs, |
| 1332 |
$vec4::new(x ^ rhs, y ^ rhs, z ^ rhs, w ^ rhs) |
| 1333 |
); |
| 1334 |
} |
| 1335 |
} |
| 1336 |
} |
| 1337 |
} |
| 1338 |
} |
| 1339 |
}); |
| 1340 |
}; |
| 1341 |
} |
| 1342 |
|
| 1343 |
macro_rules! impl_vec4_bit_op_tests { |
| 1344 |
($vec4:ident, $t_min:literal, $t_max:literal) => { |
| 1345 |
glam_test!(test_vec4_bit_ops, { |
| 1346 |
for x1 in $t_min..$t_max { |
| 1347 |
for y1 in $t_min..$t_max { |
| 1348 |
for z1 in $t_min..$t_max { |
| 1349 |
for w1 in $t_min..$t_max { |
| 1350 |
assert_eq!(!$vec4::new(x1, y1, z1, w1), $vec4::new(!x1, !y1, !z1, !w1)); |
| 1351 |
|
| 1352 |
for x2 in $t_min..$t_max { |
| 1353 |
for y2 in $t_min..$t_max { |
| 1354 |
for z2 in $t_min..$t_max { |
| 1355 |
for w2 in $t_min..$t_max { |
| 1356 |
assert_eq!( |
| 1357 |
$vec4::new(x1, y1, z1, w1) |
| 1358 |
& $vec4::new(x2, y2, z2, w2), |
| 1359 |
$vec4::new(x1 & x2, y1 & y2, z1 & z2, w1 & w2) |
| 1360 |
); |
| 1361 |
assert_eq!( |
| 1362 |
$vec4::new(x1, y1, z1, w1) |
| 1363 |
| $vec4::new(x2, y2, z2, w2), |
| 1364 |
$vec4::new(x1 | x2, y1 | y2, z1 | z2, w1 | w2) |
| 1365 |
); |
| 1366 |
assert_eq!( |
| 1367 |
$vec4::new(x1, y1, z1, w1) |
| 1368 |
^ $vec4::new(x2, y2, z2, w2), |
| 1369 |
$vec4::new(x1 ^ x2, y1 ^ y2, z1 ^ z2, w1 ^ w2) |
| 1370 |
); |
| 1371 |
} |
| 1372 |
} |
| 1373 |
} |
| 1374 |
} |
| 1375 |
} |
| 1376 |
} |
| 1377 |
} |
| 1378 |
} |
| 1379 |
}); |
| 1380 |
}; |
| 1381 |
} |
| 1382 |
|
| 1383 |
mod vec4 { |
| 1384 |
#[cfg(feature = "scalar-math")] |
| 1385 |
use glam::BVec4; |
| 1386 |
#[cfg(not(feature = "scalar-math"))] |
| 1387 |
use glam::BVec4A; |
| 1388 |
use glam::{vec4, Vec2, Vec3, Vec4}; |
| 1389 |
|
| 1390 |
glam_test!(test_align, { |
| 1391 |
use std::mem; |
| 1392 |
assert_eq!(16, mem::size_of::<Vec4>()); |
| 1393 |
if cfg!(any(not(feature = "scalar-math"), feature = "cuda")) { |
| 1394 |
assert_eq!(16, mem::align_of::<Vec4>()); |
| 1395 |
} else { |
| 1396 |
assert_eq!(4, mem::align_of::<Vec4>()); |
| 1397 |
} |
| 1398 |
#[cfg(not(feature = "scalar-math"))] |
| 1399 |
{ |
| 1400 |
assert_eq!(16, mem::size_of::<BVec4A>()); |
| 1401 |
assert_eq!(16, mem::align_of::<BVec4A>()); |
| 1402 |
} |
| 1403 |
#[cfg(feature = "scalar-math")] |
| 1404 |
{ |
| 1405 |
assert_eq!(4, mem::size_of::<BVec4>()); |
| 1406 |
assert_eq!(1, mem::align_of::<BVec4>()); |
| 1407 |
} |
| 1408 |
}); |
| 1409 |
|
| 1410 |
#[cfg(all( |
| 1411 |
target_feature = "sse2", |
| 1412 |
not(any(feature = "core-simd", feature = "scalar-math")) |
| 1413 |
))] |
| 1414 |
#[test] |
| 1415 |
fn test_m128() { |
| 1416 |
#[cfg(target_arch = "x86")] |
| 1417 |
use core::arch::x86::*; |
| 1418 |
#[cfg(target_arch = "x86_64")] |
| 1419 |
use core::arch::x86_64::*; |
| 1420 |
|
| 1421 |
#[repr(C, align(16))] |
| 1422 |
struct F32x4_A16([f32; 4]); |
| 1423 |
|
| 1424 |
let v0 = Vec4::new(1.0, 2.0, 3.0, 4.0); |
| 1425 |
let m0: __m128 = v0.into(); |
| 1426 |
let mut a0 = F32x4_A16([0.0, 0.0, 0.0, 0.0]); |
| 1427 |
unsafe { |
| 1428 |
_mm_store_ps(a0.0.as_mut_ptr(), m0); |
| 1429 |
} |
| 1430 |
assert_eq!([1.0, 2.0, 3.0, 4.0], a0.0); |
| 1431 |
let v1 = Vec4::from(m0); |
| 1432 |
assert_eq!(v0, v1); |
| 1433 |
|
| 1434 |
#[repr(C, align(16))] |
| 1435 |
struct U32x4_A16([u32; 4]); |
| 1436 |
|
| 1437 |
let v0 = BVec4A::new(true, false, true, false); |
| 1438 |
let m0: __m128 = v0.into(); |
| 1439 |
let mut a0 = U32x4_A16([1, 2, 3, 4]); |
| 1440 |
unsafe { |
| 1441 |
_mm_store_ps(a0.0.as_mut_ptr() as *mut f32, m0); |
| 1442 |
} |
| 1443 |
assert_eq!([0xffffffff, 0, 0xffffffff, 0], a0.0); |
| 1444 |
} |
| 1445 |
|
| 1446 |
glam_test!(test_as, { |
| 1447 |
use glam::{DVec4, I16Vec4, I64Vec4, IVec4, U16Vec4, U64Vec4, UVec4, Vec4}; |
| 1448 |
assert_eq!( |
| 1449 |
DVec4::new(-1.0, -2.0, -3.0, -4.0), |
| 1450 |
Vec4::new(-1.0, -2.0, -3.0, -4.0).as_dvec4() |
| 1451 |
); |
| 1452 |
assert_eq!( |
| 1453 |
I16Vec4::new(-1, -2, -3, -4), |
| 1454 |
Vec4::new(-1.0, -2.0, -3.0, -4.0).as_i16vec4() |
| 1455 |
); |
| 1456 |
assert_eq!( |
| 1457 |
U16Vec4::new(1, 2, 3, 4), |
| 1458 |
Vec4::new(1.0, 2.0, 3.0, 4.0).as_u16vec4() |
| 1459 |
); |
| 1460 |
assert_eq!( |
| 1461 |
IVec4::new(-1, -2, -3, -4), |
| 1462 |
Vec4::new(-1.0, -2.0, -3.0, -4.0).as_ivec4() |
| 1463 |
); |
| 1464 |
assert_eq!( |
| 1465 |
UVec4::new(1, 2, 3, 4), |
| 1466 |
Vec4::new(1.0, 2.0, 3.0, 4.0).as_uvec4() |
| 1467 |
); |
| 1468 |
assert_eq!( |
| 1469 |
I64Vec4::new(-1, -2, -3, -4), |
| 1470 |
Vec4::new(-1.0, -2.0, -3.0, -4.0).as_i64vec4() |
| 1471 |
); |
| 1472 |
assert_eq!( |
| 1473 |
U64Vec4::new(1, 2, 3, 4), |
| 1474 |
Vec4::new(1.0, 2.0, 3.0, 4.0).as_u64vec4() |
| 1475 |
); |
| 1476 |
|
| 1477 |
assert_eq!( |
| 1478 |
Vec4::new(-1.0, -2.0, -3.0, -4.0), |
| 1479 |
DVec4::new(-1.0, -2.0, -3.0, -4.0).as_vec4() |
| 1480 |
); |
| 1481 |
assert_eq!( |
| 1482 |
I16Vec4::new(-1, -2, -3, -4), |
| 1483 |
DVec4::new(-1.0, -2.0, -3.0, -4.0).as_i16vec4() |
| 1484 |
); |
| 1485 |
assert_eq!( |
| 1486 |
U16Vec4::new(1, 2, 3, 4), |
| 1487 |
DVec4::new(1.0, 2.0, 3.0, 4.0).as_u16vec4() |
| 1488 |
); |
| 1489 |
assert_eq!( |
| 1490 |
IVec4::new(-1, -2, -3, -4), |
| 1491 |
DVec4::new(-1.0, -2.0, -3.0, -4.0).as_ivec4() |
| 1492 |
); |
| 1493 |
assert_eq!( |
| 1494 |
UVec4::new(1, 2, 3, 4), |
| 1495 |
DVec4::new(1.0, 2.0, 3.0, 4.0).as_uvec4() |
| 1496 |
); |
| 1497 |
assert_eq!( |
| 1498 |
I64Vec4::new(-1, -2, -3, -4), |
| 1499 |
DVec4::new(-1.0, -2.0, -3.0, -4.0).as_i64vec4() |
| 1500 |
); |
| 1501 |
assert_eq!( |
| 1502 |
U64Vec4::new(1, 2, 3, 4), |
| 1503 |
DVec4::new(1.0, 2.0, 3.0, 4.0).as_u64vec4() |
| 1504 |
); |
| 1505 |
|
| 1506 |
assert_eq!( |
| 1507 |
Vec4::new(-1.0, -2.0, -3.0, -4.0), |
| 1508 |
I16Vec4::new(-1, -2, -3, -4).as_vec4() |
| 1509 |
); |
| 1510 |
assert_eq!( |
| 1511 |
DVec4::new(-1.0, -2.0, -3.0, -4.0), |
| 1512 |
I16Vec4::new(-1, -2, -3, -4).as_dvec4() |
| 1513 |
); |
| 1514 |
assert_eq!( |
| 1515 |
U16Vec4::new(1, 2, 3, 4), |
| 1516 |
I16Vec4::new(1, 2, 3, 4).as_u16vec4() |
| 1517 |
); |
| 1518 |
assert_eq!( |
| 1519 |
IVec4::new(-1, -2, -3, -4), |
| 1520 |
I16Vec4::new(-1, -2, -3, -4).as_ivec4() |
| 1521 |
); |
| 1522 |
assert_eq!(UVec4::new(1, 2, 3, 4), I16Vec4::new(1, 2, 3, 4).as_uvec4()); |
| 1523 |
assert_eq!( |
| 1524 |
I64Vec4::new(-1, -2, -3, -4), |
| 1525 |
I16Vec4::new(-1, -2, -3, -4).as_i64vec4() |
| 1526 |
); |
| 1527 |
assert_eq!( |
| 1528 |
U64Vec4::new(1, 2, 3, 4), |
| 1529 |
I16Vec4::new(1, 2, 3, 4).as_u64vec4() |
| 1530 |
); |
| 1531 |
|
| 1532 |
assert_eq!( |
| 1533 |
Vec4::new(1.0, 2.0, 3.0, 4.0), |
| 1534 |
U16Vec4::new(1, 2, 3, 4).as_vec4() |
| 1535 |
); |
| 1536 |
assert_eq!( |
| 1537 |
DVec4::new(1.0, 2.0, 3.0, 4.0), |
| 1538 |
U16Vec4::new(1, 2, 3, 4).as_dvec4() |
| 1539 |
); |
| 1540 |
assert_eq!( |
| 1541 |
I16Vec4::new(1, 2, 3, 4), |
| 1542 |
U16Vec4::new(1, 2, 3, 4).as_i16vec4() |
| 1543 |
); |
| 1544 |
assert_eq!(IVec4::new(1, 2, 3, 4), U16Vec4::new(1, 2, 3, 4).as_ivec4()); |
| 1545 |
assert_eq!(UVec4::new(1, 2, 3, 4), U16Vec4::new(1, 2, 3, 4).as_uvec4()); |
| 1546 |
assert_eq!( |
| 1547 |
I64Vec4::new(1, 2, 3, 4), |
| 1548 |
U16Vec4::new(1, 2, 3, 4).as_i64vec4() |
| 1549 |
); |
| 1550 |
assert_eq!( |
| 1551 |
U64Vec4::new(1, 2, 3, 4), |
| 1552 |
U16Vec4::new(1, 2, 3, 4).as_u64vec4() |
| 1553 |
); |
| 1554 |
|
| 1555 |
assert_eq!( |
| 1556 |
Vec4::new(-1.0, -2.0, -3.0, -4.0), |
| 1557 |
IVec4::new(-1, -2, -3, -4).as_vec4() |
| 1558 |
); |
| 1559 |
assert_eq!( |
| 1560 |
DVec4::new(-1.0, -2.0, -3.0, -4.0), |
| 1561 |
IVec4::new(-1, -2, -3, -4).as_dvec4() |
| 1562 |
); |
| 1563 |
assert_eq!(UVec4::new(1, 2, 3, 4), IVec4::new(1, 2, 3, 4).as_uvec4()); |
| 1564 |
assert_eq!( |
| 1565 |
I16Vec4::new(-1, -2, -3, -4), |
| 1566 |
IVec4::new(-1, -2, -3, -4).as_i16vec4() |
| 1567 |
); |
| 1568 |
assert_eq!( |
| 1569 |
U16Vec4::new(1, 2, 3, 4), |
| 1570 |
IVec4::new(1, 2, 3, 4).as_u16vec4() |
| 1571 |
); |
| 1572 |
assert_eq!( |
| 1573 |
I64Vec4::new(-1, -2, -3, -4), |
| 1574 |
IVec4::new(-1, -2, -3, -4).as_i64vec4() |
| 1575 |
); |
| 1576 |
assert_eq!( |
| 1577 |
U64Vec4::new(1, 2, 3, 4), |
| 1578 |
IVec4::new(1, 2, 3, 4).as_u64vec4() |
| 1579 |
); |
| 1580 |
|
| 1581 |
assert_eq!( |
| 1582 |
Vec4::new(1.0, 2.0, 3.0, 4.0), |
| 1583 |
UVec4::new(1, 2, 3, 4).as_vec4() |
| 1584 |
); |
| 1585 |
assert_eq!( |
| 1586 |
DVec4::new(1.0, 2.0, 3.0, 4.0), |
| 1587 |
UVec4::new(1, 2, 3, 4).as_dvec4() |
| 1588 |
); |
| 1589 |
assert_eq!( |
| 1590 |
I16Vec4::new(1, 2, 3, 4), |
| 1591 |
UVec4::new(1, 2, 3, 4).as_i16vec4() |
| 1592 |
); |
| 1593 |
assert_eq!( |
| 1594 |
U16Vec4::new(1, 2, 3, 4), |
| 1595 |
UVec4::new(1, 2, 3, 4).as_u16vec4() |
| 1596 |
); |
| 1597 |
assert_eq!(IVec4::new(1, 2, 3, 4), UVec4::new(1, 2, 3, 4).as_ivec4()); |
| 1598 |
assert_eq!( |
| 1599 |
I64Vec4::new(1, 2, 3, 4), |
| 1600 |
UVec4::new(1, 2, 3, 4).as_i64vec4() |
| 1601 |
); |
| 1602 |
assert_eq!( |
| 1603 |
U64Vec4::new(1, 2, 3, 4), |
| 1604 |
UVec4::new(1, 2, 3, 4).as_u64vec4() |
| 1605 |
); |
| 1606 |
|
| 1607 |
assert_eq!( |
| 1608 |
Vec4::new(-1.0, -2.0, -3.0, -4.0), |
| 1609 |
I64Vec4::new(-1, -2, -3, -4).as_vec4() |
| 1610 |
); |
| 1611 |
assert_eq!( |
| 1612 |
DVec4::new(-1.0, -2.0, -3.0, -4.0), |
| 1613 |
I64Vec4::new(-1, -2, -3, -4).as_dvec4() |
| 1614 |
); |
| 1615 |
assert_eq!( |
| 1616 |
U16Vec4::new(1, 2, 3, 4), |
| 1617 |
I64Vec4::new(1, 2, 3, 4).as_u16vec4() |
| 1618 |
); |
| 1619 |
assert_eq!( |
| 1620 |
I16Vec4::new(-1, -2, -3, -4), |
| 1621 |
I64Vec4::new(-1, -2, -3, -4).as_i16vec4() |
| 1622 |
); |
| 1623 |
assert_eq!(UVec4::new(1, 2, 3, 4), I64Vec4::new(1, 2, 3, 4).as_uvec4()); |
| 1624 |
assert_eq!( |
| 1625 |
IVec4::new(-1, -2, -3, -4), |
| 1626 |
I64Vec4::new(-1, -2, -3, -4).as_ivec4() |
| 1627 |
); |
| 1628 |
assert_eq!( |
| 1629 |
U64Vec4::new(1, 2, 3, 4), |
| 1630 |
I64Vec4::new(1, 2, 3, 4).as_u64vec4() |
| 1631 |
); |
| 1632 |
|
| 1633 |
assert_eq!( |
| 1634 |
Vec4::new(1.0, 2.0, 3.0, 4.0), |
| 1635 |
U64Vec4::new(1, 2, 3, 4).as_vec4() |
| 1636 |
); |
| 1637 |
assert_eq!( |
| 1638 |
DVec4::new(1.0, 2.0, 3.0, 4.0), |
| 1639 |
U64Vec4::new(1, 2, 3, 4).as_dvec4() |
| 1640 |
); |
| 1641 |
assert_eq!( |
| 1642 |
I16Vec4::new(1, 2, 3, 4), |
| 1643 |
U64Vec4::new(1, 2, 3, 4).as_i16vec4() |
| 1644 |
); |
| 1645 |
assert_eq!( |
| 1646 |
U16Vec4::new(1, 2, 3, 4), |
| 1647 |
U64Vec4::new(1, 2, 3, 4).as_u16vec4() |
| 1648 |
); |
| 1649 |
assert_eq!(IVec4::new(1, 2, 3, 4), U64Vec4::new(1, 2, 3, 4).as_ivec4()); |
| 1650 |
assert_eq!(UVec4::new(1, 2, 3, 4), U64Vec4::new(1, 2, 3, 4).as_uvec4()); |
| 1651 |
assert_eq!( |
| 1652 |
I64Vec4::new(1, 2, 3, 4), |
| 1653 |
U64Vec4::new(1, 2, 3, 4).as_i64vec4() |
| 1654 |
); |
| 1655 |
}); |
| 1656 |
|
| 1657 |
glam_test!(test_vec3a, { |
| 1658 |
use glam::Vec3A; |
| 1659 |
assert_eq!( |
| 1660 |
Vec4::new(1.0, 2.0, 3.0, 4.0), |
| 1661 |
Vec4::from((Vec3A::new(1.0, 2.0, 3.0), 4.0)) |
| 1662 |
); |
| 1663 |
assert_eq!( |
| 1664 |
Vec4::new(1.0, 2.0, 3.0, 4.0), |
| 1665 |
Vec4::from((1.0, Vec3A::new(2.0, 3.0, 4.0))) |
| 1666 |
); |
| 1667 |
}); |
| 1668 |
|
| 1669 |
#[cfg(not(feature = "scalar-math"))] |
| 1670 |
impl_vec4_float_tests!(f32, vec4, Vec4, Vec3, Vec2, BVec4A); |
| 1671 |
|
| 1672 |
#[cfg(feature = "scalar-math")] |
| 1673 |
impl_vec4_float_tests!(f32, vec4, Vec4, Vec3, Vec2, BVec4); |
| 1674 |
} |
| 1675 |
|
| 1676 |
mod dvec4 { |
| 1677 |
use glam::{dvec4, BVec4, DVec2, DVec3, DVec4, IVec4, UVec4, Vec4}; |
| 1678 |
|
| 1679 |
glam_test!(test_align, { |
| 1680 |
use std::mem; |
| 1681 |
assert_eq!(32, mem::size_of::<DVec4>()); |
| 1682 |
#[cfg(not(feature = "cuda"))] |
| 1683 |
assert_eq!(mem::align_of::<f64>(), mem::align_of::<DVec4>()); |
| 1684 |
#[cfg(feature = "cuda")] |
| 1685 |
assert_eq!(16, mem::align_of::<DVec4>()); |
| 1686 |
assert_eq!(4, mem::size_of::<BVec4>()); |
| 1687 |
assert_eq!(1, mem::align_of::<BVec4>()); |
| 1688 |
}); |
| 1689 |
|
| 1690 |
glam_test!(test_try_from, { |
| 1691 |
assert_eq!( |
| 1692 |
DVec4::new(1.0, 2.0, 3.0, 4.0), |
| 1693 |
DVec4::from(Vec4::new(1.0, 2.0, 3.0, 4.0)) |
| 1694 |
); |
| 1695 |
assert_eq!( |
| 1696 |
DVec4::new(1.0, 2.0, 3.0, 4.0), |
| 1697 |
DVec4::from(IVec4::new(1, 2, 3, 4)) |
| 1698 |
); |
| 1699 |
assert_eq!( |
| 1700 |
DVec4::new(1.0, 2.0, 3.0, 4.0), |
| 1701 |
DVec4::from(UVec4::new(1, 2, 3, 4)) |
| 1702 |
); |
| 1703 |
}); |
| 1704 |
|
| 1705 |
impl_vec4_float_tests!(f64, dvec4, DVec4, DVec3, DVec2, BVec4); |
| 1706 |
} |
| 1707 |
|
| 1708 |
mod i16vec4 { |
| 1709 |
use glam::{ |
| 1710 |
i16vec4, BVec4, I16Vec2, I16Vec3, I16Vec4, I64Vec4, IVec4, U16Vec4, U64Vec4, UVec4, |
| 1711 |
}; |
| 1712 |
|
| 1713 |
glam_test!(test_align, { |
| 1714 |
use std::mem; |
| 1715 |
assert_eq!(8, mem::size_of::<I16Vec4>()); |
| 1716 |
#[cfg(not(feature = "cuda"))] |
| 1717 |
assert_eq!(2, mem::align_of::<I16Vec4>()); |
| 1718 |
#[cfg(feature = "cuda")] |
| 1719 |
assert_eq!(8, mem::align_of::<I16Vec4>()); |
| 1720 |
}); |
| 1721 |
|
| 1722 |
glam_test!(test_try_from, { |
| 1723 |
assert_eq!( |
| 1724 |
I16Vec4::new(1, 2, 3, 4), |
| 1725 |
I16Vec4::try_from(U16Vec4::new(1, 2, 3, 4)).unwrap() |
| 1726 |
); |
| 1727 |
assert!(I16Vec4::try_from(U16Vec4::new(u16::MAX, 2, 3, 4)).is_err()); |
| 1728 |
assert!(I16Vec4::try_from(U16Vec4::new(1, u16::MAX, 3, 4)).is_err()); |
| 1729 |
assert!(I16Vec4::try_from(U16Vec4::new(1, 2, u16::MAX, 4)).is_err()); |
| 1730 |
assert!(I16Vec4::try_from(U16Vec4::new(1, 2, 3, u16::MAX)).is_err()); |
| 1731 |
|
| 1732 |
assert_eq!( |
| 1733 |
I16Vec4::new(1, 2, 3, 4), |
| 1734 |
I16Vec4::try_from(IVec4::new(1, 2, 3, 4)).unwrap() |
| 1735 |
); |
| 1736 |
assert!(I16Vec4::try_from(IVec4::new(i32::MAX, 2, 3, 4)).is_err()); |
| 1737 |
assert!(I16Vec4::try_from(IVec4::new(1, i32::MAX, 3, 4)).is_err()); |
| 1738 |
assert!(I16Vec4::try_from(IVec4::new(1, 2, i32::MAX, 4)).is_err()); |
| 1739 |
assert!(I16Vec4::try_from(IVec4::new(1, 2, 3, i32::MAX)).is_err()); |
| 1740 |
|
| 1741 |
assert_eq!( |
| 1742 |
I16Vec4::new(1, 2, 3, 4), |
| 1743 |
I16Vec4::try_from(UVec4::new(1, 2, 3, 4)).unwrap() |
| 1744 |
); |
| 1745 |
assert!(I16Vec4::try_from(UVec4::new(u32::MAX, 2, 3, 4)).is_err()); |
| 1746 |
assert!(I16Vec4::try_from(UVec4::new(1, u32::MAX, 3, 4)).is_err()); |
| 1747 |
assert!(I16Vec4::try_from(UVec4::new(1, 2, u32::MAX, 4)).is_err()); |
| 1748 |
assert!(I16Vec4::try_from(UVec4::new(1, 2, 3, u32::MAX)).is_err()); |
| 1749 |
|
| 1750 |
assert_eq!( |
| 1751 |
I16Vec4::new(1, 2, 3, 4), |
| 1752 |
I16Vec4::try_from(I64Vec4::new(1, 2, 3, 4)).unwrap() |
| 1753 |
); |
| 1754 |
assert!(I16Vec4::try_from(I64Vec4::new(i64::MAX, 2, 3, 4)).is_err()); |
| 1755 |
assert!(I16Vec4::try_from(I64Vec4::new(1, i64::MAX, 3, 4)).is_err()); |
| 1756 |
assert!(I16Vec4::try_from(I64Vec4::new(1, 2, i64::MAX, 4)).is_err()); |
| 1757 |
assert!(I16Vec4::try_from(I64Vec4::new(1, 2, 3, i64::MAX)).is_err()); |
| 1758 |
|
| 1759 |
assert_eq!( |
| 1760 |
I16Vec4::new(1, 2, 3, 4), |
| 1761 |
I16Vec4::try_from(U64Vec4::new(1, 2, 3, 4)).unwrap() |
| 1762 |
); |
| 1763 |
assert!(I16Vec4::try_from(U64Vec4::new(u64::MAX, 2, 3, 4)).is_err()); |
| 1764 |
assert!(I16Vec4::try_from(U64Vec4::new(1, u64::MAX, 3, 4)).is_err()); |
| 1765 |
assert!(I16Vec4::try_from(U64Vec4::new(1, 2, u64::MAX, 4)).is_err()); |
| 1766 |
assert!(I16Vec4::try_from(U64Vec4::new(1, 2, 3, u64::MAX)).is_err()); |
| 1767 |
}); |
| 1768 |
|
| 1769 |
glam_test!(test_wrapping_add, { |
| 1770 |
assert_eq!( |
| 1771 |
I16Vec4::new(i16::MAX, 5, i16::MIN, 0).wrapping_add(I16Vec4::new(1, 3, i16::MAX, 0)), |
| 1772 |
I16Vec4::new(i16::MIN, 8, -1, 0), |
| 1773 |
); |
| 1774 |
}); |
| 1775 |
|
| 1776 |
glam_test!(test_wrapping_sub, { |
| 1777 |
assert_eq!( |
| 1778 |
I16Vec4::new(i16::MAX, 5, i16::MIN, 0).wrapping_sub(I16Vec4::new(1, 3, i16::MAX, 0)), |
| 1779 |
I16Vec4::new(32766, 2, 1, 0) |
| 1780 |
); |
| 1781 |
}); |
| 1782 |
|
| 1783 |
glam_test!(test_wrapping_mul, { |
| 1784 |
assert_eq!( |
| 1785 |
I16Vec4::new(i16::MAX, 5, i16::MIN, 0).wrapping_mul(I16Vec4::new(3, 3, 5, 1)), |
| 1786 |
I16Vec4::new(32765, 15, -32768, 0) |
| 1787 |
); |
| 1788 |
}); |
| 1789 |
|
| 1790 |
glam_test!(test_wrapping_div, { |
| 1791 |
assert_eq!( |
| 1792 |
I16Vec4::new(i16::MAX, 5, i16::MIN, 0).wrapping_div(I16Vec4::new(3, 3, 5, 1)), |
| 1793 |
I16Vec4::new(10922, 1, -6553, 0) |
| 1794 |
); |
| 1795 |
}); |
| 1796 |
|
| 1797 |
glam_test!(test_saturating_add, { |
| 1798 |
assert_eq!( |
| 1799 |
I16Vec4::new(i16::MAX, i16::MIN, 0, 0).saturating_add(I16Vec4::new(1, -1, 2, 3)), |
| 1800 |
I16Vec4::new(i16::MAX, i16::MIN, 2, 3) |
| 1801 |
); |
| 1802 |
}); |
| 1803 |
|
| 1804 |
glam_test!(test_saturating_sub, { |
| 1805 |
assert_eq!( |
| 1806 |
I16Vec4::new(i16::MIN, i16::MAX, 0, 0).saturating_sub(I16Vec4::new(1, -1, 2, 3)), |
| 1807 |
I16Vec4::new(i16::MIN, i16::MAX, -2, -3) |
| 1808 |
); |
| 1809 |
}); |
| 1810 |
|
| 1811 |
glam_test!(test_saturating_mul, { |
| 1812 |
assert_eq!( |
| 1813 |
I16Vec4::new(i16::MAX, i16::MIN, 0, 0).saturating_mul(I16Vec4::new(2, 2, 0, 0)), |
| 1814 |
I16Vec4::new(i16::MAX, i16::MIN, 0, 0) |
| 1815 |
); |
| 1816 |
}); |
| 1817 |
|
| 1818 |
glam_test!(test_saturating_div, { |
| 1819 |
assert_eq!( |
| 1820 |
I16Vec4::new(i16::MAX, i16::MIN, 0, 0).saturating_div(I16Vec4::new(2, 2, 3, 4)), |
| 1821 |
I16Vec4::new(16383, -16384, 0, 0) |
| 1822 |
); |
| 1823 |
}); |
| 1824 |
|
| 1825 |
glam_test!(test_wrapping_add_unsigned, { |
| 1826 |
assert_eq!( |
| 1827 |
I16Vec4::new(i16::MAX, i16::MAX, i16::MAX, i16::MAX) |
| 1828 |
.wrapping_add_unsigned(U16Vec4::new(1, 1, 1, 1)), |
| 1829 |
I16Vec4::new(i16::MIN, i16::MIN, i16::MIN, i16::MIN) |
| 1830 |
); |
| 1831 |
}); |
| 1832 |
|
| 1833 |
glam_test!(test_wrapping_sub_unsigned, { |
| 1834 |
assert_eq!( |
| 1835 |
I16Vec4::new(i16::MIN, i16::MIN, i16::MIN, i16::MIN) |
| 1836 |
.wrapping_sub_unsigned(U16Vec4::new(1, 1, 1, 1)), |
| 1837 |
I16Vec4::new(i16::MAX, i16::MAX, i16::MAX, i16::MAX) |
| 1838 |
); |
| 1839 |
}); |
| 1840 |
|
| 1841 |
glam_test!(test_saturating_add_unsigned, { |
| 1842 |
assert_eq!( |
| 1843 |
I16Vec4::new(i16::MAX, i16::MAX, i16::MAX, i16::MAX) |
| 1844 |
.saturating_add_unsigned(U16Vec4::new(1, 1, 1, 1)), |
| 1845 |
I16Vec4::new(i16::MAX, i16::MAX, i16::MAX, i16::MAX) |
| 1846 |
); |
| 1847 |
}); |
| 1848 |
|
| 1849 |
glam_test!(test_saturating_sub_unsigned, { |
| 1850 |
assert_eq!( |
| 1851 |
I16Vec4::new(i16::MIN, i16::MIN, i16::MIN, i16::MIN) |
| 1852 |
.saturating_sub_unsigned(U16Vec4::new(1, 1, 1, 1)), |
| 1853 |
I16Vec4::new(i16::MIN, i16::MIN, i16::MIN, i16::MIN) |
| 1854 |
); |
| 1855 |
}); |
| 1856 |
|
| 1857 |
impl_vec4_signed_integer_tests!(i16, i16vec4, I16Vec4, I16Vec3, I16Vec2, BVec4); |
| 1858 |
impl_vec4_eq_hash_tests!(i16, i16vec4); |
| 1859 |
|
| 1860 |
impl_vec4_scalar_shift_op_tests!(I16Vec4, -2, 2); |
| 1861 |
impl_vec4_shift_op_tests!(I16Vec4); |
| 1862 |
|
| 1863 |
impl_vec4_scalar_bit_op_tests!(I16Vec4, -2, 2); |
| 1864 |
impl_vec4_bit_op_tests!(I16Vec4, -2, 2); |
| 1865 |
} |
| 1866 |
|
| 1867 |
mod u16vec4 { |
| 1868 |
use glam::{ |
| 1869 |
u16vec4, BVec4, I16Vec4, I64Vec4, IVec4, U16Vec2, U16Vec3, U16Vec4, U64Vec4, UVec4, |
| 1870 |
}; |
| 1871 |
|
| 1872 |
glam_test!(test_align, { |
| 1873 |
use std::mem; |
| 1874 |
assert_eq!(8, mem::size_of::<U16Vec4>()); |
| 1875 |
#[cfg(not(feature = "cuda"))] |
| 1876 |
assert_eq!(2, mem::align_of::<U16Vec4>()); |
| 1877 |
#[cfg(feature = "cuda")] |
| 1878 |
assert_eq!(8, mem::align_of::<U16Vec4>()); |
| 1879 |
}); |
| 1880 |
|
| 1881 |
glam_test!(test_try_from, { |
| 1882 |
assert_eq!( |
| 1883 |
U16Vec4::new(1, 2, 3, 4), |
| 1884 |
U16Vec4::try_from(I16Vec4::new(1, 2, 3, 4)).unwrap() |
| 1885 |
); |
| 1886 |
assert!(U16Vec4::try_from(I16Vec4::new(-1, 2, 3, 4)).is_err()); |
| 1887 |
assert!(U16Vec4::try_from(I16Vec4::new(1, -2, 3, 4)).is_err()); |
| 1888 |
assert!(U16Vec4::try_from(I16Vec4::new(1, 2, -3, 4)).is_err()); |
| 1889 |
assert!(U16Vec4::try_from(I16Vec4::new(1, 2, 3, -4)).is_err()); |
| 1890 |
|
| 1891 |
assert_eq!( |
| 1892 |
U16Vec4::new(1, 2, 3, 4), |
| 1893 |
U16Vec4::try_from(IVec4::new(1, 2, 3, 4)).unwrap() |
| 1894 |
); |
| 1895 |
assert!(U16Vec4::try_from(IVec4::new(-1, 2, 3, 4)).is_err()); |
| 1896 |
assert!(U16Vec4::try_from(IVec4::new(1, -2, 3, 4)).is_err()); |
| 1897 |
assert!(U16Vec4::try_from(IVec4::new(1, 2, -3, 4)).is_err()); |
| 1898 |
assert!(U16Vec4::try_from(IVec4::new(1, 2, 3, -4)).is_err()); |
| 1899 |
|
| 1900 |
assert!(U16Vec4::try_from(IVec4::new(i32::MAX, 2, 3, 4)).is_err()); |
| 1901 |
assert!(U16Vec4::try_from(IVec4::new(1, i32::MAX, 3, 4)).is_err()); |
| 1902 |
assert!(U16Vec4::try_from(IVec4::new(1, 2, i32::MAX, 4)).is_err()); |
| 1903 |
assert!(U16Vec4::try_from(IVec4::new(1, 2, 3, i32::MAX)).is_err()); |
| 1904 |
|
| 1905 |
assert_eq!( |
| 1906 |
U16Vec4::new(1, 2, 3, 4), |
| 1907 |
U16Vec4::try_from(UVec4::new(1, 2, 3, 4)).unwrap() |
| 1908 |
); |
| 1909 |
assert!(U16Vec4::try_from(UVec4::new(u32::MAX, 2, 3, 4)).is_err()); |
| 1910 |
assert!(U16Vec4::try_from(UVec4::new(1, u32::MAX, 3, 4)).is_err()); |
| 1911 |
assert!(U16Vec4::try_from(UVec4::new(1, 2, u32::MAX, 4)).is_err()); |
| 1912 |
assert!(U16Vec4::try_from(UVec4::new(1, 2, 3, u32::MAX)).is_err()); |
| 1913 |
|
| 1914 |
assert_eq!( |
| 1915 |
U16Vec4::new(1, 2, 3, 4), |
| 1916 |
U16Vec4::try_from(I64Vec4::new(1, 2, 3, 4)).unwrap() |
| 1917 |
); |
| 1918 |
assert!(U16Vec4::try_from(I64Vec4::new(-1, 2, 3, 4)).is_err()); |
| 1919 |
assert!(U16Vec4::try_from(I64Vec4::new(1, -2, 3, 4)).is_err()); |
| 1920 |
assert!(U16Vec4::try_from(I64Vec4::new(1, 2, -3, 4)).is_err()); |
| 1921 |
assert!(U16Vec4::try_from(I64Vec4::new(1, 2, 3, -4)).is_err()); |
| 1922 |
|
| 1923 |
assert!(U16Vec4::try_from(I64Vec4::new(i64::MAX, 2, 3, 4)).is_err()); |
| 1924 |
assert!(U16Vec4::try_from(I64Vec4::new(1, i64::MAX, 3, 4)).is_err()); |
| 1925 |
assert!(U16Vec4::try_from(I64Vec4::new(1, 2, i64::MAX, 4)).is_err()); |
| 1926 |
assert!(U16Vec4::try_from(I64Vec4::new(1, 2, 3, i64::MAX)).is_err()); |
| 1927 |
|
| 1928 |
assert_eq!( |
| 1929 |
U16Vec4::new(1, 2, 3, 4), |
| 1930 |
U16Vec4::try_from(U64Vec4::new(1, 2, 3, 4)).unwrap() |
| 1931 |
); |
| 1932 |
assert!(U16Vec4::try_from(U64Vec4::new(u64::MAX, 2, 3, 4)).is_err()); |
| 1933 |
assert!(U16Vec4::try_from(U64Vec4::new(1, u64::MAX, 3, 4)).is_err()); |
| 1934 |
assert!(U16Vec4::try_from(U64Vec4::new(1, 2, u64::MAX, 4)).is_err()); |
| 1935 |
assert!(U16Vec4::try_from(U64Vec4::new(1, 2, 3, u64::MAX)).is_err()); |
| 1936 |
}); |
| 1937 |
|
| 1938 |
glam_test!(test_wrapping_add, { |
| 1939 |
assert_eq!( |
| 1940 |
U16Vec4::new(u16::MAX, 5, u16::MAX, 0).wrapping_add(U16Vec4::new(1, 3, u16::MAX, 0)), |
| 1941 |
U16Vec4::new(0, 8, 65534, 0), |
| 1942 |
); |
| 1943 |
}); |
| 1944 |
|
| 1945 |
glam_test!(test_wrapping_sub, { |
| 1946 |
assert_eq!( |
| 1947 |
U16Vec4::new(u16::MAX, 5, u16::MAX - 1, 0).wrapping_sub(U16Vec4::new( |
| 1948 |
1, |
| 1949 |
3, |
| 1950 |
u16::MAX, |
| 1951 |
0 |
| 1952 |
)), |
| 1953 |
U16Vec4::new(65534, 2, 65535, 0) |
| 1954 |
); |
| 1955 |
}); |
| 1956 |
|
| 1957 |
glam_test!(test_wrapping_mul, { |
| 1958 |
assert_eq!( |
| 1959 |
U16Vec4::new(u16::MAX, 5, u16::MAX, 0).wrapping_mul(U16Vec4::new(3, 3, 5, 1)), |
| 1960 |
U16Vec4::new(65533, 15, 65531, 0) |
| 1961 |
); |
| 1962 |
}); |
| 1963 |
|
| 1964 |
glam_test!(test_wrapping_div, { |
| 1965 |
assert_eq!( |
| 1966 |
U16Vec4::new(u16::MAX, 5, u16::MAX, 0).wrapping_div(U16Vec4::new(3, 3, 5, 1)), |
| 1967 |
U16Vec4::new(21845, 1, 13107, 0) |
| 1968 |
); |
| 1969 |
}); |
| 1970 |
|
| 1971 |
glam_test!(test_saturating_add, { |
| 1972 |
assert_eq!( |
| 1973 |
U16Vec4::new(u16::MAX, u16::MAX, 0, 0).saturating_add(U16Vec4::new(1, u16::MAX, 2, 3)), |
| 1974 |
U16Vec4::new(u16::MAX, u16::MAX, 2, 3) |
| 1975 |
); |
| 1976 |
}); |
| 1977 |
|
| 1978 |
glam_test!(test_saturating_sub, { |
| 1979 |
assert_eq!( |
| 1980 |
U16Vec4::new(0, u16::MAX, 0, 0).saturating_sub(U16Vec4::new(1, 1, 2, 3)), |
| 1981 |
U16Vec4::new(0, 65534, 0, 0) |
| 1982 |
); |
| 1983 |
}); |
| 1984 |
|
| 1985 |
glam_test!(test_saturating_mul, { |
| 1986 |
assert_eq!( |
| 1987 |
U16Vec4::new(u16::MAX, u16::MAX, 0, 0).saturating_mul(U16Vec4::new(2, u16::MAX, 0, 0)), |
| 1988 |
U16Vec4::new(u16::MAX, u16::MAX, 0, 0) |
| 1989 |
); |
| 1990 |
}); |
| 1991 |
|
| 1992 |
glam_test!(test_saturating_div, { |
| 1993 |
assert_eq!( |
| 1994 |
U16Vec4::new(u16::MAX, u16::MAX, 0, 0).saturating_div(U16Vec4::new(2, u16::MAX, 3, 4)), |
| 1995 |
U16Vec4::new(32767, 1, 0, 0) |
| 1996 |
); |
| 1997 |
}); |
| 1998 |
|
| 1999 |
glam_test!(test_wrapping_add_signed, { |
| 2000 |
assert_eq!( |
| 2001 |
U16Vec4::new(u16::MAX, u16::MAX, u16::MAX, u16::MAX) |
| 2002 |
.wrapping_add_signed(I16Vec4::new(1, 1, 1, 1)), |
| 2003 |
U16Vec4::new(u16::MIN, u16::MIN, u16::MIN, u16::MIN) |
| 2004 |
); |
| 2005 |
}); |
| 2006 |
|
| 2007 |
glam_test!(test_saturating_add_signed, { |
| 2008 |
assert_eq!( |
| 2009 |
U16Vec4::new(u16::MAX, u16::MAX, u16::MAX, u16::MAX) |
| 2010 |
.saturating_add_signed(I16Vec4::new(1, 1, 1, 1)), |
| 2011 |
U16Vec4::new(u16::MAX, u16::MAX, u16::MAX, u16::MAX) |
| 2012 |
); |
| 2013 |
}); |
| 2014 |
|
| 2015 |
impl_vec4_tests!(u16, u16vec4, U16Vec4, U16Vec3, U16Vec2, BVec4); |
| 2016 |
impl_vec4_eq_hash_tests!(u16, u16vec4); |
| 2017 |
|
| 2018 |
impl_vec4_scalar_shift_op_tests!(U16Vec4, 0, 2); |
| 2019 |
impl_vec4_shift_op_tests!(U16Vec4); |
| 2020 |
|
| 2021 |
impl_vec4_scalar_bit_op_tests!(U16Vec4, 0, 2); |
| 2022 |
impl_vec4_bit_op_tests!(U16Vec4, 0, 2); |
| 2023 |
} |
| 2024 |
|
| 2025 |
mod ivec4 { |
| 2026 |
use glam::{ivec4, BVec4, I16Vec4, I64Vec4, IVec2, IVec3, IVec4, U16Vec4, U64Vec4, UVec4}; |
| 2027 |
|
| 2028 |
glam_test!(test_align, { |
| 2029 |
use std::mem; |
| 2030 |
assert_eq!(16, mem::size_of::<IVec4>()); |
| 2031 |
#[cfg(not(feature = "cuda"))] |
| 2032 |
assert_eq!(4, mem::align_of::<IVec4>()); |
| 2033 |
#[cfg(feature = "cuda")] |
| 2034 |
assert_eq!(16, mem::align_of::<IVec4>()); |
| 2035 |
assert_eq!(4, mem::size_of::<BVec4>()); |
| 2036 |
assert_eq!(1, mem::align_of::<BVec4>()); |
| 2037 |
}); |
| 2038 |
|
| 2039 |
glam_test!(test_try_from, { |
| 2040 |
assert_eq!( |
| 2041 |
IVec4::new(1, 2, 3, 4), |
| 2042 |
IVec4::from(U16Vec4::new(1, 2, 3, 4)) |
| 2043 |
); |
| 2044 |
assert_eq!( |
| 2045 |
IVec4::new(1, 2, 3, 4), |
| 2046 |
IVec4::from(I16Vec4::new(1, 2, 3, 4)) |
| 2047 |
); |
| 2048 |
|
| 2049 |
assert_eq!( |
| 2050 |
IVec4::new(1, 2, 3, 4), |
| 2051 |
IVec4::try_from(UVec4::new(1, 2, 3, 4)).unwrap() |
| 2052 |
); |
| 2053 |
assert!(IVec4::try_from(UVec4::new(u32::MAX, 2, 3, 4)).is_err()); |
| 2054 |
assert!(IVec4::try_from(UVec4::new(1, u32::MAX, 3, 4)).is_err()); |
| 2055 |
assert!(IVec4::try_from(UVec4::new(1, 2, u32::MAX, 4)).is_err()); |
| 2056 |
assert!(IVec4::try_from(UVec4::new(1, 2, 3, u32::MAX)).is_err()); |
| 2057 |
|
| 2058 |
assert_eq!( |
| 2059 |
IVec4::new(1, 2, 3, 4), |
| 2060 |
IVec4::try_from(I64Vec4::new(1, 2, 3, 4)).unwrap() |
| 2061 |
); |
| 2062 |
assert!(IVec4::try_from(I64Vec4::new(i64::MAX, 2, 3, 4)).is_err()); |
| 2063 |
assert!(IVec4::try_from(I64Vec4::new(1, i64::MAX, 3, 4)).is_err()); |
| 2064 |
assert!(IVec4::try_from(I64Vec4::new(1, 2, i64::MAX, 4)).is_err()); |
| 2065 |
assert!(IVec4::try_from(I64Vec4::new(1, 2, 3, i64::MAX)).is_err()); |
| 2066 |
|
| 2067 |
assert_eq!( |
| 2068 |
IVec4::new(1, 2, 3, 4), |
| 2069 |
IVec4::try_from(U64Vec4::new(1, 2, 3, 4)).unwrap() |
| 2070 |
); |
| 2071 |
assert!(IVec4::try_from(U64Vec4::new(u64::MAX, 2, 3, 4)).is_err()); |
| 2072 |
assert!(IVec4::try_from(U64Vec4::new(1, u64::MAX, 3, 4)).is_err()); |
| 2073 |
assert!(IVec4::try_from(U64Vec4::new(1, 2, u64::MAX, 4)).is_err()); |
| 2074 |
assert!(IVec4::try_from(U64Vec4::new(1, 2, 3, u64::MAX)).is_err()); |
| 2075 |
}); |
| 2076 |
|
| 2077 |
glam_test!(test_wrapping_add, { |
| 2078 |
assert_eq!( |
| 2079 |
IVec4::new(i32::MAX, 5, i32::MIN, 0).wrapping_add(IVec4::new(1, 3, i32::MAX, 0)), |
| 2080 |
IVec4::new(i32::MIN, 8, -1, 0), |
| 2081 |
); |
| 2082 |
}); |
| 2083 |
|
| 2084 |
glam_test!(test_wrapping_sub, { |
| 2085 |
assert_eq!( |
| 2086 |
IVec4::new(i32::MAX, 5, i32::MIN, 0).wrapping_sub(IVec4::new(1, 3, i32::MAX, 0)), |
| 2087 |
IVec4::new(2147483646, 2, 1, 0) |
| 2088 |
); |
| 2089 |
}); |
| 2090 |
|
| 2091 |
glam_test!(test_wrapping_mul, { |
| 2092 |
assert_eq!( |
| 2093 |
IVec4::new(i32::MAX, 5, i32::MIN, 0).wrapping_mul(IVec4::new(3, 3, 5, 1)), |
| 2094 |
IVec4::new(2147483645, 15, -2147483648, 0) |
| 2095 |
); |
| 2096 |
}); |
| 2097 |
|
| 2098 |
glam_test!(test_wrapping_div, { |
| 2099 |
assert_eq!( |
| 2100 |
IVec4::new(i32::MAX, 5, i32::MIN, 0).wrapping_div(IVec4::new(3, 3, 5, 1)), |
| 2101 |
IVec4::new(715827882, 1, -429496729, 0) |
| 2102 |
); |
| 2103 |
}); |
| 2104 |
|
| 2105 |
glam_test!(test_saturating_add, { |
| 2106 |
assert_eq!( |
| 2107 |
IVec4::new(i32::MAX, i32::MIN, 0, 0).saturating_add(IVec4::new(1, -1, 2, 3)), |
| 2108 |
IVec4::new(i32::MAX, i32::MIN, 2, 3) |
| 2109 |
); |
| 2110 |
}); |
| 2111 |
|
| 2112 |
glam_test!(test_saturating_sub, { |
| 2113 |
assert_eq!( |
| 2114 |
IVec4::new(i32::MIN, i32::MAX, 0, 0).saturating_sub(IVec4::new(1, -1, 2, 3)), |
| 2115 |
IVec4::new(i32::MIN, i32::MAX, -2, -3) |
| 2116 |
); |
| 2117 |
}); |
| 2118 |
|
| 2119 |
glam_test!(test_saturating_mul, { |
| 2120 |
assert_eq!( |
| 2121 |
IVec4::new(i32::MAX, i32::MIN, 0, 0).saturating_mul(IVec4::new(2, 2, 0, 0)), |
| 2122 |
IVec4::new(i32::MAX, i32::MIN, 0, 0) |
| 2123 |
); |
| 2124 |
}); |
| 2125 |
|
| 2126 |
glam_test!(test_saturating_div, { |
| 2127 |
assert_eq!( |
| 2128 |
IVec4::new(i32::MAX, i32::MIN, 0, 0).saturating_div(IVec4::new(2, 2, 3, 4)), |
| 2129 |
IVec4::new(1073741823, -1073741824, 0, 0) |
| 2130 |
); |
| 2131 |
}); |
| 2132 |
|
| 2133 |
glam_test!(test_wrapping_add_unsigned, { |
| 2134 |
assert_eq!( |
| 2135 |
IVec4::new(i32::MAX, i32::MAX, i32::MAX, i32::MAX) |
| 2136 |
.wrapping_add_unsigned(UVec4::new(1, 1, 1, 1)), |
| 2137 |
IVec4::new(i32::MIN, i32::MIN, i32::MIN, i32::MIN) |
| 2138 |
); |
| 2139 |
}); |
| 2140 |
|
| 2141 |
glam_test!(test_wrapping_sub_unsigned, { |
| 2142 |
assert_eq!( |
| 2143 |
IVec4::new(i32::MIN, i32::MIN, i32::MIN, i32::MIN) |
| 2144 |
.wrapping_sub_unsigned(UVec4::new(1, 1, 1, 1)), |
| 2145 |
IVec4::new(i32::MAX, i32::MAX, i32::MAX, i32::MAX) |
| 2146 |
); |
| 2147 |
}); |
| 2148 |
|
| 2149 |
glam_test!(test_saturating_add_unsigned, { |
| 2150 |
assert_eq!( |
| 2151 |
IVec4::new(i32::MAX, i32::MAX, i32::MAX, i32::MAX) |
| 2152 |
.saturating_add_unsigned(UVec4::new(1, 1, 1, 1)), |
| 2153 |
IVec4::new(i32::MAX, i32::MAX, i32::MAX, i32::MAX) |
| 2154 |
); |
| 2155 |
}); |
| 2156 |
|
| 2157 |
glam_test!(test_saturating_sub_unsigned, { |
| 2158 |
assert_eq!( |
| 2159 |
IVec4::new(i32::MIN, i32::MIN, i32::MIN, i32::MIN) |
| 2160 |
.saturating_sub_unsigned(UVec4::new(1, 1, 1, 1)), |
| 2161 |
IVec4::new(i32::MIN, i32::MIN, i32::MIN, i32::MIN) |
| 2162 |
); |
| 2163 |
}); |
| 2164 |
|
| 2165 |
impl_vec4_signed_integer_tests!(i32, ivec4, IVec4, IVec3, IVec2, BVec4); |
| 2166 |
impl_vec4_eq_hash_tests!(i32, ivec4); |
| 2167 |
|
| 2168 |
impl_vec4_scalar_shift_op_tests!(IVec4, -2, 2); |
| 2169 |
impl_vec4_shift_op_tests!(IVec4); |
| 2170 |
|
| 2171 |
impl_vec4_scalar_bit_op_tests!(IVec4, -2, 2); |
| 2172 |
impl_vec4_bit_op_tests!(IVec4, -2, 2); |
| 2173 |
} |
| 2174 |
|
| 2175 |
mod uvec4 { |
| 2176 |
use glam::{uvec4, BVec4, I16Vec4, I64Vec4, IVec4, U16Vec4, U64Vec4, UVec2, UVec3, UVec4}; |
| 2177 |
|
| 2178 |
glam_test!(test_align, { |
| 2179 |
use std::mem; |
| 2180 |
assert_eq!(16, mem::size_of::<UVec4>()); |
| 2181 |
#[cfg(not(feature = "cuda"))] |
| 2182 |
assert_eq!(4, mem::align_of::<UVec4>()); |
| 2183 |
#[cfg(feature = "cuda")] |
| 2184 |
assert_eq!(16, mem::align_of::<UVec4>()); |
| 2185 |
assert_eq!(4, mem::size_of::<BVec4>()); |
| 2186 |
assert_eq!(1, mem::align_of::<BVec4>()); |
| 2187 |
}); |
| 2188 |
|
| 2189 |
glam_test!(test_try_from, { |
| 2190 |
assert_eq!( |
| 2191 |
UVec4::new(1, 2, 3, 4), |
| 2192 |
UVec4::try_from(I16Vec4::new(1, 2, 3, 4)).unwrap() |
| 2193 |
); |
| 2194 |
assert!(UVec4::try_from(I16Vec4::new(-1, 2, 3, 4)).is_err()); |
| 2195 |
assert!(UVec4::try_from(I16Vec4::new(1, -2, 3, 4)).is_err()); |
| 2196 |
assert!(UVec4::try_from(I16Vec4::new(1, 2, -3, 4)).is_err()); |
| 2197 |
assert!(UVec4::try_from(I16Vec4::new(1, 2, 3, -4)).is_err()); |
| 2198 |
|
| 2199 |
assert_eq!( |
| 2200 |
UVec4::new(1, 2, 3, 4), |
| 2201 |
UVec4::from(U16Vec4::new(1, 2, 3, 4)) |
| 2202 |
); |
| 2203 |
|
| 2204 |
assert_eq!( |
| 2205 |
UVec4::new(1, 2, 3, 4), |
| 2206 |
UVec4::try_from(IVec4::new(1, 2, 3, 4)).unwrap() |
| 2207 |
); |
| 2208 |
assert!(UVec4::try_from(IVec4::new(-1, 2, 3, 4)).is_err()); |
| 2209 |
assert!(UVec4::try_from(IVec4::new(1, -2, 3, 4)).is_err()); |
| 2210 |
assert!(UVec4::try_from(IVec4::new(1, 2, -3, 4)).is_err()); |
| 2211 |
assert!(UVec4::try_from(IVec4::new(1, 2, 3, -4)).is_err()); |
| 2212 |
|
| 2213 |
assert_eq!( |
| 2214 |
UVec4::new(1, 2, 3, 4), |
| 2215 |
UVec4::try_from(I64Vec4::new(1, 2, 3, 4)).unwrap() |
| 2216 |
); |
| 2217 |
assert!(UVec4::try_from(I64Vec4::new(-1, 2, 3, 4)).is_err()); |
| 2218 |
assert!(UVec4::try_from(I64Vec4::new(1, -2, 3, 4)).is_err()); |
| 2219 |
assert!(UVec4::try_from(I64Vec4::new(1, 2, -3, 4)).is_err()); |
| 2220 |
assert!(UVec4::try_from(I64Vec4::new(1, 2, 3, -4)).is_err()); |
| 2221 |
|
| 2222 |
assert!(UVec4::try_from(I64Vec4::new(i64::MAX, 2, 3, 4)).is_err()); |
| 2223 |
assert!(UVec4::try_from(I64Vec4::new(1, i64::MAX, 3, 4)).is_err()); |
| 2224 |
assert!(UVec4::try_from(I64Vec4::new(1, 2, i64::MAX, 4)).is_err()); |
| 2225 |
assert!(UVec4::try_from(I64Vec4::new(1, 2, 3, i64::MAX)).is_err()); |
| 2226 |
|
| 2227 |
assert_eq!( |
| 2228 |
UVec4::new(1, 2, 3, 4), |
| 2229 |
UVec4::try_from(U64Vec4::new(1, 2, 3, 4)).unwrap() |
| 2230 |
); |
| 2231 |
assert!(UVec4::try_from(U64Vec4::new(u64::MAX, 2, 3, 4)).is_err()); |
| 2232 |
assert!(UVec4::try_from(U64Vec4::new(1, u64::MAX, 3, 4)).is_err()); |
| 2233 |
assert!(UVec4::try_from(U64Vec4::new(1, 2, u64::MAX, 4)).is_err()); |
| 2234 |
assert!(UVec4::try_from(U64Vec4::new(1, 2, 3, u64::MAX)).is_err()); |
| 2235 |
}); |
| 2236 |
|
| 2237 |
glam_test!(test_wrapping_add, { |
| 2238 |
assert_eq!( |
| 2239 |
UVec4::new(u32::MAX, 5, u32::MAX, 0).wrapping_add(UVec4::new(1, 3, u32::MAX, 0)), |
| 2240 |
UVec4::new(0, 8, 4294967294, 0), |
| 2241 |
); |
| 2242 |
}); |
| 2243 |
|
| 2244 |
glam_test!(test_wrapping_sub, { |
| 2245 |
assert_eq!( |
| 2246 |
UVec4::new(u32::MAX, 5, u32::MAX - 1, 0).wrapping_sub(UVec4::new(1, 3, u32::MAX, 0)), |
| 2247 |
UVec4::new(4294967294, 2, 4294967295, 0) |
| 2248 |
); |
| 2249 |
}); |
| 2250 |
|
| 2251 |
glam_test!(test_wrapping_mul, { |
| 2252 |
assert_eq!( |
| 2253 |
UVec4::new(u32::MAX, 5, u32::MAX, 0).wrapping_mul(UVec4::new(3, 3, 5, 1)), |
| 2254 |
UVec4::new(4294967293, 15, 4294967291, 0) |
| 2255 |
); |
| 2256 |
}); |
| 2257 |
|
| 2258 |
glam_test!(test_wrapping_div, { |
| 2259 |
assert_eq!( |
| 2260 |
UVec4::new(u32::MAX, 5, u32::MAX, 0).wrapping_div(UVec4::new(3, 3, 5, 1)), |
| 2261 |
UVec4::new(1431655765, 1, 858993459, 0) |
| 2262 |
); |
| 2263 |
}); |
| 2264 |
|
| 2265 |
glam_test!(test_saturating_add, { |
| 2266 |
assert_eq!( |
| 2267 |
UVec4::new(u32::MAX, u32::MAX, 0, 0).saturating_add(UVec4::new(1, u32::MAX, 2, 3)), |
| 2268 |
UVec4::new(u32::MAX, u32::MAX, 2, 3) |
| 2269 |
); |
| 2270 |
}); |
| 2271 |
|
| 2272 |
glam_test!(test_saturating_sub, { |
| 2273 |
assert_eq!( |
| 2274 |
UVec4::new(0, u32::MAX, 0, 0).saturating_sub(UVec4::new(1, 1, 2, 3)), |
| 2275 |
UVec4::new(0, 4294967294, 0, 0) |
| 2276 |
); |
| 2277 |
}); |
| 2278 |
|
| 2279 |
glam_test!(test_saturating_mul, { |
| 2280 |
assert_eq!( |
| 2281 |
UVec4::new(u32::MAX, u32::MAX, 0, 0).saturating_mul(UVec4::new(2, u32::MAX, 0, 0)), |
| 2282 |
UVec4::new(u32::MAX, u32::MAX, 0, 0) |
| 2283 |
); |
| 2284 |
}); |
| 2285 |
|
| 2286 |
glam_test!(test_saturating_div, { |
| 2287 |
assert_eq!( |
| 2288 |
UVec4::new(u32::MAX, u32::MAX, 0, 0).saturating_div(UVec4::new(2, u32::MAX, 3, 4)), |
| 2289 |
UVec4::new(2147483647, 1, 0, 0) |
| 2290 |
); |
| 2291 |
}); |
| 2292 |
|
| 2293 |
glam_test!(test_wrapping_add_signed, { |
| 2294 |
assert_eq!( |
| 2295 |
UVec4::new(u32::MAX, u32::MAX, u32::MAX, u32::MAX) |
| 2296 |
.wrapping_add_signed(IVec4::new(1, 1, 1, 1)), |
| 2297 |
UVec4::new(u32::MIN, u32::MIN, u32::MIN, u32::MIN) |
| 2298 |
); |
| 2299 |
}); |
| 2300 |
|
| 2301 |
glam_test!(test_saturating_add_signed, { |
| 2302 |
assert_eq!( |
| 2303 |
UVec4::new(u32::MAX, u32::MAX, u32::MAX, u32::MAX) |
| 2304 |
.saturating_add_signed(IVec4::new(1, 1, 1, 1)), |
| 2305 |
UVec4::new(u32::MAX, u32::MAX, u32::MAX, u32::MAX) |
| 2306 |
); |
| 2307 |
}); |
| 2308 |
|
| 2309 |
impl_vec4_tests!(u32, uvec4, UVec4, UVec3, UVec2, BVec4); |
| 2310 |
impl_vec4_eq_hash_tests!(u32, uvec4); |
| 2311 |
|
| 2312 |
impl_vec4_scalar_shift_op_tests!(UVec4, 0, 2); |
| 2313 |
impl_vec4_shift_op_tests!(UVec4); |
| 2314 |
|
| 2315 |
impl_vec4_scalar_bit_op_tests!(UVec4, 0, 2); |
| 2316 |
impl_vec4_bit_op_tests!(UVec4, 0, 2); |
| 2317 |
} |
| 2318 |
|
| 2319 |
mod i64vec4 { |
| 2320 |
use glam::{ |
| 2321 |
i64vec4, BVec4, I16Vec4, I64Vec2, I64Vec3, I64Vec4, IVec4, U16Vec4, U64Vec4, UVec4, |
| 2322 |
}; |
| 2323 |
|
| 2324 |
glam_test!(test_align, { |
| 2325 |
use std::mem; |
| 2326 |
assert_eq!(32, mem::size_of::<I64Vec4>()); |
| 2327 |
#[cfg(not(feature = "cuda"))] |
| 2328 |
assert_eq!(8, mem::align_of::<I64Vec4>()); |
| 2329 |
#[cfg(feature = "cuda")] |
| 2330 |
assert_eq!(16, mem::align_of::<I64Vec4>()); |
| 2331 |
assert_eq!(4, mem::size_of::<BVec4>()); |
| 2332 |
assert_eq!(1, mem::align_of::<BVec4>()); |
| 2333 |
}); |
| 2334 |
|
| 2335 |
glam_test!(test_try_from, { |
| 2336 |
assert_eq!( |
| 2337 |
I64Vec4::new(1, 2, 3, 4), |
| 2338 |
I64Vec4::from(I16Vec4::new(1, 2, 3, 4)) |
| 2339 |
); |
| 2340 |
assert_eq!( |
| 2341 |
I64Vec4::new(1, 2, 3, 4), |
| 2342 |
I64Vec4::from(U16Vec4::new(1, 2, 3, 4)) |
| 2343 |
); |
| 2344 |
assert_eq!( |
| 2345 |
I64Vec4::new(1, 2, 3, 4), |
| 2346 |
I64Vec4::from(IVec4::new(1, 2, 3, 4)) |
| 2347 |
); |
| 2348 |
assert_eq!( |
| 2349 |
I64Vec4::new(1, 2, 3, 4), |
| 2350 |
I64Vec4::from(UVec4::new(1, 2, 3, 4)) |
| 2351 |
); |
| 2352 |
|
| 2353 |
assert_eq!( |
| 2354 |
I64Vec4::new(1, 2, 3, 4), |
| 2355 |
I64Vec4::try_from(U64Vec4::new(1, 2, 3, 4)).unwrap() |
| 2356 |
); |
| 2357 |
assert!(I64Vec4::try_from(U64Vec4::new(u64::MAX, 2, 3, 4)).is_err()); |
| 2358 |
assert!(I64Vec4::try_from(U64Vec4::new(1, u64::MAX, 3, 4)).is_err()); |
| 2359 |
assert!(I64Vec4::try_from(U64Vec4::new(1, 2, u64::MAX, 4)).is_err()); |
| 2360 |
assert!(I64Vec4::try_from(U64Vec4::new(1, 2, 3, u64::MAX)).is_err()); |
| 2361 |
}); |
| 2362 |
|
| 2363 |
glam_test!(test_wrapping_add_unsigned, { |
| 2364 |
assert_eq!( |
| 2365 |
I64Vec4::new(i64::MAX, i64::MAX, i64::MAX, i64::MAX) |
| 2366 |
.wrapping_add_unsigned(U64Vec4::new(1, 1, 1, 1)), |
| 2367 |
I64Vec4::new(i64::MIN, i64::MIN, i64::MIN, i64::MIN) |
| 2368 |
); |
| 2369 |
}); |
| 2370 |
|
| 2371 |
glam_test!(test_wrapping_sub_unsigned, { |
| 2372 |
assert_eq!( |
| 2373 |
I64Vec4::new(i64::MIN, i64::MIN, i64::MIN, i64::MIN) |
| 2374 |
.wrapping_sub_unsigned(U64Vec4::new(1, 1, 1, 1)), |
| 2375 |
I64Vec4::new(i64::MAX, i64::MAX, i64::MAX, i64::MAX) |
| 2376 |
); |
| 2377 |
}); |
| 2378 |
|
| 2379 |
glam_test!(test_saturating_add_unsigned, { |
| 2380 |
assert_eq!( |
| 2381 |
I64Vec4::new(i64::MAX, i64::MAX, i64::MAX, i64::MAX) |
| 2382 |
.saturating_add_unsigned(U64Vec4::new(1, 1, 1, 1)), |
| 2383 |
I64Vec4::new(i64::MAX, i64::MAX, i64::MAX, i64::MAX) |
| 2384 |
); |
| 2385 |
}); |
| 2386 |
|
| 2387 |
glam_test!(test_saturating_sub_unsigned, { |
| 2388 |
assert_eq!( |
| 2389 |
I64Vec4::new(i64::MIN, i64::MIN, i64::MIN, i64::MIN) |
| 2390 |
.saturating_sub_unsigned(U64Vec4::new(1, 1, 1, 1)), |
| 2391 |
I64Vec4::new(i64::MIN, i64::MIN, i64::MIN, i64::MIN) |
| 2392 |
); |
| 2393 |
}); |
| 2394 |
|
| 2395 |
impl_vec4_signed_integer_tests!(i64, i64vec4, I64Vec4, I64Vec3, I64Vec2, BVec4); |
| 2396 |
impl_vec4_eq_hash_tests!(i64, i64vec4); |
| 2397 |
|
| 2398 |
impl_vec4_scalar_shift_op_tests!(I64Vec4, -2, 2); |
| 2399 |
impl_vec4_shift_op_tests!(I64Vec4); |
| 2400 |
|
| 2401 |
impl_vec4_scalar_bit_op_tests!(I64Vec4, -2, 2); |
| 2402 |
impl_vec4_bit_op_tests!(I64Vec4, -2, 2); |
| 2403 |
} |
| 2404 |
|
| 2405 |
mod u64vec4 { |
| 2406 |
use glam::{ |
| 2407 |
u64vec4, BVec4, I16Vec4, I64Vec4, IVec4, U16Vec4, U64Vec2, U64Vec3, U64Vec4, UVec4, |
| 2408 |
}; |
| 2409 |
|
| 2410 |
glam_test!(test_align, { |
| 2411 |
use std::mem; |
| 2412 |
assert_eq!(32, mem::size_of::<U64Vec4>()); |
| 2413 |
#[cfg(not(feature = "cuda"))] |
| 2414 |
assert_eq!(8, mem::align_of::<U64Vec4>()); |
| 2415 |
#[cfg(feature = "cuda")] |
| 2416 |
assert_eq!(16, mem::align_of::<U64Vec4>()); |
| 2417 |
assert_eq!(4, mem::size_of::<BVec4>()); |
| 2418 |
assert_eq!(1, mem::align_of::<BVec4>()); |
| 2419 |
}); |
| 2420 |
|
| 2421 |
glam_test!(test_try_from, { |
| 2422 |
assert_eq!( |
| 2423 |
U64Vec4::new(1, 2, 3, 4), |
| 2424 |
U64Vec4::try_from(I16Vec4::new(1, 2, 3, 4)).unwrap() |
| 2425 |
); |
| 2426 |
assert!(U64Vec4::try_from(I16Vec4::new(-1, 2, 3, 4)).is_err()); |
| 2427 |
assert!(U64Vec4::try_from(I16Vec4::new(1, -2, 3, 4)).is_err()); |
| 2428 |
assert!(U64Vec4::try_from(I16Vec4::new(1, 2, -3, 4)).is_err()); |
| 2429 |
assert!(U64Vec4::try_from(I16Vec4::new(1, 2, 3, -4)).is_err()); |
| 2430 |
|
| 2431 |
assert_eq!( |
| 2432 |
U64Vec4::new(1, 2, 3, 4), |
| 2433 |
U64Vec4::from(U16Vec4::new(1, 2, 3, 4)) |
| 2434 |
); |
| 2435 |
|
| 2436 |
assert_eq!( |
| 2437 |
U64Vec4::new(1, 2, 3, 4), |
| 2438 |
U64Vec4::try_from(IVec4::new(1, 2, 3, 4)).unwrap() |
| 2439 |
); |
| 2440 |
assert!(U64Vec4::try_from(IVec4::new(-1, 2, 3, 4)).is_err()); |
| 2441 |
assert!(U64Vec4::try_from(IVec4::new(1, -2, 3, 4)).is_err()); |
| 2442 |
assert!(U64Vec4::try_from(IVec4::new(1, 2, -3, 4)).is_err()); |
| 2443 |
assert!(U64Vec4::try_from(IVec4::new(1, 2, 3, -4)).is_err()); |
| 2444 |
|
| 2445 |
assert_eq!( |
| 2446 |
U64Vec4::new(1, 2, 3, 4), |
| 2447 |
U64Vec4::from(UVec4::new(1, 2, 3, 4)) |
| 2448 |
); |
| 2449 |
|
| 2450 |
assert_eq!( |
| 2451 |
U64Vec4::new(1, 2, 3, 4), |
| 2452 |
U64Vec4::try_from(I64Vec4::new(1, 2, 3, 4)).unwrap() |
| 2453 |
); |
| 2454 |
assert!(U64Vec4::try_from(I64Vec4::new(-1, 2, 3, 4)).is_err()); |
| 2455 |
assert!(U64Vec4::try_from(I64Vec4::new(1, -2, 3, 4)).is_err()); |
| 2456 |
assert!(U64Vec4::try_from(I64Vec4::new(1, 2, -3, 4)).is_err()); |
| 2457 |
assert!(U64Vec4::try_from(I64Vec4::new(1, 2, 3, -4)).is_err()); |
| 2458 |
}); |
| 2459 |
|
| 2460 |
glam_test!(test_wrapping_add_signed, { |
| 2461 |
assert_eq!( |
| 2462 |
U64Vec4::new(u64::MAX, u64::MAX, u64::MAX, u64::MAX) |
| 2463 |
.wrapping_add_signed(I64Vec4::new(1, 1, 1, 1)), |
| 2464 |
U64Vec4::new(u64::MIN, u64::MIN, u64::MIN, u64::MIN) |
| 2465 |
); |
| 2466 |
}); |
| 2467 |
|
| 2468 |
glam_test!(test_saturating_add_signed, { |
| 2469 |
assert_eq!( |
| 2470 |
U64Vec4::new(u64::MAX, u64::MAX, u64::MAX, u64::MAX) |
| 2471 |
.saturating_add_signed(I64Vec4::new(1, 1, 1, 1)), |
| 2472 |
U64Vec4::new(u64::MAX, u64::MAX, u64::MAX, u64::MAX) |
| 2473 |
); |
| 2474 |
}); |
| 2475 |
|
| 2476 |
impl_vec4_tests!(u64, u64vec4, U64Vec4, U64Vec3, U64Vec2, BVec4); |
| 2477 |
impl_vec4_eq_hash_tests!(u64, u64vec4); |
| 2478 |
|
| 2479 |
impl_vec4_scalar_shift_op_tests!(U64Vec4, 0, 2); |
| 2480 |
impl_vec4_shift_op_tests!(U64Vec4); |
| 2481 |
|
| 2482 |
impl_vec4_scalar_bit_op_tests!(U64Vec4, 0, 2); |
| 2483 |
impl_vec4_bit_op_tests!(U64Vec4, 0, 2); |
| 2484 |
} |