| 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, $masknew: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_map, { |
| 156 |
let v = $vec4::new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 157 |
assert_eq!(v.map(|n| n + 3 as $t), v + $vec4::splat(3 as $t)); |
| 158 |
assert_eq!(v.map(|_| 0 as $t), $vec4::ZERO); |
| 159 |
}); |
| 160 |
|
| 161 |
glam_test!(test_with, { |
| 162 |
assert_eq!($vec4::X, $vec4::ZERO.with_x(1 as $t)); |
| 163 |
assert_eq!($vec4::Y, $vec4::ZERO.with_y(1 as $t)); |
| 164 |
assert_eq!($vec4::Z, $vec4::ZERO.with_z(1 as $t)); |
| 165 |
assert_eq!($vec4::W, $vec4::ZERO.with_w(1 as $t)); |
| 166 |
}); |
| 167 |
|
| 168 |
glam_test!(test_accessors, { |
| 169 |
let mut a = $vec4::ZERO; |
| 170 |
a.x = 1 as $t; |
| 171 |
a.y = 2 as $t; |
| 172 |
a.z = 3 as $t; |
| 173 |
a.w = 4 as $t; |
| 174 |
assert_eq!(1 as $t, a.x); |
| 175 |
assert_eq!(2 as $t, a.y); |
| 176 |
assert_eq!(3 as $t, a.z); |
| 177 |
assert_eq!(4 as $t, a.w); |
| 178 |
assert_eq!((1 as $t, 2 as $t, 3 as $t, 4 as $t), a.into()); |
| 179 |
|
| 180 |
let mut a = $vec4::ZERO; |
| 181 |
a[0] = 1 as $t; |
| 182 |
a[1] = 2 as $t; |
| 183 |
a[2] = 3 as $t; |
| 184 |
a[3] = 4 as $t; |
| 185 |
assert_eq!(1 as $t, a[0]); |
| 186 |
assert_eq!(2 as $t, a[1]); |
| 187 |
assert_eq!(3 as $t, a[2]); |
| 188 |
assert_eq!(4 as $t, a[3]); |
| 189 |
assert_eq!((1 as $t, 2 as $t, 3 as $t, 4 as $t), a.into()); |
| 190 |
}); |
| 191 |
|
| 192 |
glam_test!(test_dot_unsigned, { |
| 193 |
let x = $new(1 as $t, 0 as $t, 0 as $t, 0 as $t); |
| 194 |
let y = $new(0 as $t, 1 as $t, 0 as $t, 0 as $t); |
| 195 |
let z = $new(0 as $t, 0 as $t, 1 as $t, 0 as $t); |
| 196 |
let w = $new(0 as $t, 0 as $t, 0 as $t, 1 as $t); |
| 197 |
assert_eq!(1 as $t, x.dot(x)); |
| 198 |
assert_eq!(0 as $t, x.dot(y)); |
| 199 |
assert_eq!(0 as $t, y.dot(z)); |
| 200 |
assert_eq!(0 as $t, z.dot(w)); |
| 201 |
|
| 202 |
assert_eq!( |
| 203 |
$new(28 as $t, 28 as $t, 28 as $t, 28 as $t), |
| 204 |
$new(0 as $t, 5 as $t, 3 as $t, 6 as $t) |
| 205 |
.dot_into_vec($new(7 as $t, 2 as $t, 4 as $t, 1 as $t)) |
| 206 |
); |
| 207 |
}); |
| 208 |
|
| 209 |
glam_test!(test_length_squared_unsigned, { |
| 210 |
let x = $new(1 as $t, 0 as $t, 0 as $t, 0 as $t); |
| 211 |
let z = $new(0 as $t, 0 as $t, 1 as $t, 0 as $t); |
| 212 |
let w = $new(0 as $t, 0 as $t, 0 as $t, 1 as $t); |
| 213 |
assert_eq!(4 as $t, (2 as $t * x).length_squared()); |
| 214 |
assert_eq!(16 as $t, (4 as $t * z).length_squared()); |
| 215 |
assert_eq!(64 as $t, (8 as $t * w).length_squared()); |
| 216 |
assert_eq!( |
| 217 |
2 as $t * 2 as $t + 3 as $t * 3 as $t + 4 as $t * 4 as $t + 5 as $t * 5 as $t, |
| 218 |
$new(2 as $t, 3 as $t, 4 as $t, 5 as $t).length_squared() |
| 219 |
); |
| 220 |
}); |
| 221 |
|
| 222 |
glam_test!(test_ops, { |
| 223 |
let a = $new(2 as $t, 4 as $t, 8 as $t, 10 as $t); |
| 224 |
assert_eq!($new(4 as $t, 8 as $t, 16 as $t, 20 as $t), a + a); |
| 225 |
assert_eq!($new(2 as $t, 4 as $t, 8 as $t, 10 as $t), 0 as $t + a); |
| 226 |
assert_eq!($new(0 as $t, 0 as $t, 0 as $t, 0 as $t), a - a); |
| 227 |
assert_eq!($new(8 as $t, 6 as $t, 2 as $t, 0 as $t), 10 as $t - a); |
| 228 |
assert_eq!($new(4 as $t, 16 as $t, 64 as $t, 100 as $t), a * a); |
| 229 |
assert_eq!($new(4 as $t, 8 as $t, 16 as $t, 20 as $t), a * 2 as $t); |
| 230 |
assert_eq!($new(4 as $t, 8 as $t, 16 as $t, 20 as $t), 2 as $t * a); |
| 231 |
assert_eq!($new(1 as $t, 1 as $t, 1 as $t, 1 as $t), a / a); |
| 232 |
assert_eq!($new(1 as $t, 2 as $t, 4 as $t, 5 as $t), a / 2 as $t); |
| 233 |
assert_eq!($new(8 as $t, 4 as $t, 2 as $t, 1.6 as $t), 16 as $t / a); |
| 234 |
assert_eq!($new(0 as $t, 0 as $t, 0 as $t, 0 as $t), a % a); |
| 235 |
assert_eq!($new(0 as $t, 1 as $t, 1 as $t, 1 as $t), a % (a - 1 as $t)); |
| 236 |
assert_eq!($new(0 as $t, 0 as $t, 0 as $t, 0 as $t), a % 1 as $t); |
| 237 |
assert_eq!($new(2 as $t, 1 as $t, 2 as $t, 1 as $t), a % 3 as $t); |
| 238 |
assert_eq!($new(1 as $t, 1 as $t, 1 as $t, 7 as $t), 17 as $t % a); |
| 239 |
assert_eq!($new(2 as $t, 4 as $t, 0 as $t, 2 as $t), a % 8 as $t); |
| 240 |
}); |
| 241 |
|
| 242 |
glam_test!(test_ops_propagated, { |
| 243 |
let vec = $new(2 as $t, 4 as $t, 8 as $t, 10 as $t); |
| 244 |
let scalar = 2 as $t; |
| 245 |
let g_scalar = 10 as $t; |
| 246 |
|
| 247 |
assert_eq!((vec + vec), (vec + &vec)); |
| 248 |
assert_eq!((vec + vec), (&vec + vec)); |
| 249 |
assert_eq!((vec + vec), (&vec + &vec)); |
| 250 |
assert_eq!((vec + scalar), (vec + &scalar)); |
| 251 |
assert_eq!((vec + scalar), (&vec + &scalar)); |
| 252 |
assert_eq!((vec + scalar), (&vec + scalar)); |
| 253 |
assert_eq!((scalar + vec), (&scalar + vec)); |
| 254 |
assert_eq!((scalar + vec), (&scalar + &vec)); |
| 255 |
assert_eq!((scalar + vec), (scalar + &vec)); |
| 256 |
|
| 257 |
assert_eq!((vec - vec), (vec - &vec)); |
| 258 |
assert_eq!((vec - vec), (&vec - vec)); |
| 259 |
assert_eq!((vec - vec), (&vec - &vec)); |
| 260 |
assert_eq!((vec - scalar), (vec - &scalar)); |
| 261 |
assert_eq!((vec - scalar), (&vec - &scalar)); |
| 262 |
assert_eq!((vec - scalar), (&vec - scalar)); |
| 263 |
assert_eq!((g_scalar - vec), (&g_scalar - vec)); |
| 264 |
assert_eq!((g_scalar - vec), (&g_scalar - &vec)); |
| 265 |
assert_eq!((g_scalar - vec), (g_scalar - &vec)); |
| 266 |
|
| 267 |
assert_eq!((vec * vec), (vec * &vec)); |
| 268 |
assert_eq!((vec * vec), (&vec * vec)); |
| 269 |
assert_eq!((vec * vec), (&vec * &vec)); |
| 270 |
assert_eq!((vec * scalar), (vec * &scalar)); |
| 271 |
assert_eq!((vec * scalar), (&vec * &scalar)); |
| 272 |
assert_eq!((vec * scalar), (&vec * scalar)); |
| 273 |
assert_eq!((scalar * vec), (&scalar * vec)); |
| 274 |
assert_eq!((scalar * vec), (&scalar * &vec)); |
| 275 |
assert_eq!((scalar * vec), (scalar * &vec)); |
| 276 |
|
| 277 |
assert_eq!((vec / vec), (vec / &vec)); |
| 278 |
assert_eq!((vec / vec), (&vec / vec)); |
| 279 |
assert_eq!((vec / vec), (&vec / &vec)); |
| 280 |
assert_eq!((vec / scalar), (vec / &scalar)); |
| 281 |
assert_eq!((vec / scalar), (&vec / &scalar)); |
| 282 |
assert_eq!((vec / scalar), (&vec / scalar)); |
| 283 |
assert_eq!((scalar / vec), (&scalar / vec)); |
| 284 |
assert_eq!((scalar / vec), (&scalar / &vec)); |
| 285 |
assert_eq!((scalar / vec), (scalar / &vec)); |
| 286 |
|
| 287 |
assert_eq!((vec % vec), (vec % &vec)); |
| 288 |
assert_eq!((vec % vec), (&vec % vec)); |
| 289 |
assert_eq!((vec % vec), (&vec % &vec)); |
| 290 |
assert_eq!((vec % scalar), (vec % &scalar)); |
| 291 |
assert_eq!((vec % scalar), (&vec % &scalar)); |
| 292 |
assert_eq!((vec % scalar), (&vec % scalar)); |
| 293 |
assert_eq!((scalar % vec), (&scalar % vec)); |
| 294 |
assert_eq!((scalar % vec), (&scalar % &vec)); |
| 295 |
assert_eq!((scalar % vec), (scalar % &vec)); |
| 296 |
}); |
| 297 |
|
| 298 |
glam_test!(test_assign_ops, { |
| 299 |
let a = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 300 |
let mut b = a; |
| 301 |
|
| 302 |
b += 2 as $t; |
| 303 |
assert_eq!($new(3 as $t, 4 as $t, 5 as $t, 6 as $t), b); |
| 304 |
b -= 2 as $t; |
| 305 |
assert_eq!($new(1 as $t, 2 as $t, 3 as $t, 4 as $t), b); |
| 306 |
b *= 2 as $t; |
| 307 |
assert_eq!($new(2 as $t, 4 as $t, 6 as $t, 8 as $t), b); |
| 308 |
b /= 2 as $t; |
| 309 |
assert_eq!($new(1 as $t, 2 as $t, 3 as $t, 4 as $t), b); |
| 310 |
b %= 2 as $t; |
| 311 |
assert_eq!($new(1 as $t, 0 as $t, 1 as $t, 0 as $t), b); |
| 312 |
|
| 313 |
b = a; |
| 314 |
b += a; |
| 315 |
assert_eq!($new(2 as $t, 4 as $t, 6 as $t, 8 as $t), b); |
| 316 |
b -= a; |
| 317 |
assert_eq!($new(1 as $t, 2 as $t, 3 as $t, 4 as $t), b); |
| 318 |
b *= a; |
| 319 |
assert_eq!($new(1 as $t, 4 as $t, 9 as $t, 16 as $t), b); |
| 320 |
b /= a; |
| 321 |
assert_eq!($new(1 as $t, 2 as $t, 3 as $t, 4 as $t), b); |
| 322 |
b *= 2 as $t; |
| 323 |
assert_eq!($new(2 as $t, 4 as $t, 6 as $t, 8 as $t), b); |
| 324 |
b /= 2 as $t; |
| 325 |
assert_eq!($new(1 as $t, 2 as $t, 3 as $t, 4 as $t), b); |
| 326 |
b %= (b + 1 as $t); |
| 327 |
assert_eq!($new(1 as $t, 2 as $t, 3 as $t, 4 as $t), b); |
| 328 |
b %= b; |
| 329 |
assert_eq!($new(0 as $t, 0 as $t, 0 as $t, 0 as $t), b); |
| 330 |
}); |
| 331 |
|
| 332 |
glam_test!(test_assign_ops_propagation, { |
| 333 |
let vec = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 334 |
let mut a = vec; |
| 335 |
let mut b = vec; |
| 336 |
let scalar = 2 as $t; |
| 337 |
|
| 338 |
a += &scalar; |
| 339 |
b += scalar; |
| 340 |
assert_eq!(b, a, "AddAssign<Scalar>"); |
| 341 |
a -= &scalar; |
| 342 |
b -= scalar; |
| 343 |
assert_eq!(b, a, "SubAssign<Scalar>"); |
| 344 |
a *= &scalar; |
| 345 |
b *= scalar; |
| 346 |
assert_eq!(b, a, "MulAssign<Scalar>"); |
| 347 |
a /= &scalar; |
| 348 |
b /= scalar; |
| 349 |
assert_eq!(b, a, "DivAssign<Scalar>"); |
| 350 |
a %= &scalar; |
| 351 |
b %= scalar; |
| 352 |
assert_eq!(b, a, "MulAssign<Scalar>"); |
| 353 |
|
| 354 |
a = vec; |
| 355 |
b = vec; |
| 356 |
a += &vec; |
| 357 |
b += vec; |
| 358 |
assert_eq!(b, a, "AddAssign<Vec>"); |
| 359 |
a -= &vec; |
| 360 |
b -= vec; |
| 361 |
assert_eq!(b, a, "SubAssign<Vec>"); |
| 362 |
a *= &vec; |
| 363 |
b *= vec; |
| 364 |
assert_eq!(b, a, "MulAssign<Vec>"); |
| 365 |
a /= &vec; |
| 366 |
b /= vec; |
| 367 |
assert_eq!(b, a, "DivAssign<Vec>"); |
| 368 |
a %= &vec; |
| 369 |
b %= vec; |
| 370 |
assert_eq!(b, a, "RemAssign<Vec>"); |
| 371 |
}); |
| 372 |
|
| 373 |
glam_test!(test_min_max, { |
| 374 |
let a = $new(4 as $t, 6 as $t, 2 as $t, 8 as $t); |
| 375 |
let b = $new(5 as $t, 3 as $t, 7 as $t, 1 as $t); |
| 376 |
assert_eq!((4 as $t, 3 as $t, 2 as $t, 1 as $t), a.min(b).into()); |
| 377 |
assert_eq!((4 as $t, 3 as $t, 2 as $t, 1 as $t), b.min(a).into()); |
| 378 |
assert_eq!((5 as $t, 6 as $t, 7 as $t, 8 as $t), a.max(b).into()); |
| 379 |
assert_eq!((5 as $t, 6 as $t, 7 as $t, 8 as $t), b.max(a).into()); |
| 380 |
}); |
| 381 |
|
| 382 |
glam_test!(test_clamp, { |
| 383 |
fn vec(x: i32, y: i32, z: i32, w: i32) -> $vec4 { |
| 384 |
$vec4::new(x as $t, y as $t, z as $t, w as $t) |
| 385 |
} |
| 386 |
let min = vec(1, 1, 3, 3); |
| 387 |
let max = vec(6, 6, 8, 8); |
| 388 |
assert_eq!(vec(0, 0, 0, 0).clamp(min, max), vec(1, 1, 3, 3)); |
| 389 |
assert_eq!(vec(2, 2, 2, 2).clamp(min, max), vec(2, 2, 3, 3)); |
| 390 |
assert_eq!(vec(4, 4, 5, 5).clamp(min, max), vec(4, 4, 5, 5)); |
| 391 |
assert_eq!(vec(6, 6, 6, 6).clamp(min, max), vec(6, 6, 6, 6)); |
| 392 |
assert_eq!(vec(7, 7, 7, 7).clamp(min, max), vec(6, 6, 7, 7)); |
| 393 |
assert_eq!(vec(9, 9, 9, 9).clamp(min, max), vec(6, 6, 8, 8)); |
| 394 |
|
| 395 |
should_glam_assert!({ $vec4::clamp($vec4::ZERO, $vec4::ONE, $vec4::ZERO) }); |
| 396 |
}); |
| 397 |
|
| 398 |
glam_test!(test_hmin_hmax, { |
| 399 |
assert_eq!( |
| 400 |
1 as $t, |
| 401 |
$new(1 as $t, 2 as $t, 3 as $t, 4 as $t).min_element() |
| 402 |
); |
| 403 |
assert_eq!( |
| 404 |
1 as $t, |
| 405 |
$new(4 as $t, 1 as $t, 2 as $t, 3 as $t).min_element() |
| 406 |
); |
| 407 |
assert_eq!( |
| 408 |
1 as $t, |
| 409 |
$new(3 as $t, 4 as $t, 1 as $t, 2 as $t).min_element() |
| 410 |
); |
| 411 |
assert_eq!( |
| 412 |
1 as $t, |
| 413 |
$new(2 as $t, 3 as $t, 4 as $t, 1 as $t).min_element() |
| 414 |
); |
| 415 |
assert_eq!( |
| 416 |
4 as $t, |
| 417 |
$new(1 as $t, 2 as $t, 3 as $t, 4 as $t).max_element() |
| 418 |
); |
| 419 |
assert_eq!( |
| 420 |
4 as $t, |
| 421 |
$new(4 as $t, 1 as $t, 2 as $t, 3 as $t).max_element() |
| 422 |
); |
| 423 |
assert_eq!( |
| 424 |
4 as $t, |
| 425 |
$new(3 as $t, 4 as $t, 1 as $t, 2 as $t).max_element() |
| 426 |
); |
| 427 |
assert_eq!( |
| 428 |
4 as $t, |
| 429 |
$new(2 as $t, 3 as $t, 4 as $t, 1 as $t).max_element() |
| 430 |
); |
| 431 |
assert_eq!( |
| 432 |
3 as $t, |
| 433 |
$new(1 as $t, 2 as $t, 3 as $t, 4 as $t) |
| 434 |
.truncate() |
| 435 |
.max_element() |
| 436 |
); |
| 437 |
assert_eq!( |
| 438 |
2 as $t, |
| 439 |
$new(4 as $t, 3 as $t, 2 as $t, 1 as $t) |
| 440 |
.truncate() |
| 441 |
.min_element() |
| 442 |
); |
| 443 |
}); |
| 444 |
|
| 445 |
glam_test!(test_sum_product, { |
| 446 |
let a = $new(2 as $t, 3 as $t, 4 as $t, 5 as $t); |
| 447 |
assert_eq!(a.element_sum(), 14 as $t); |
| 448 |
assert_eq!(a.element_product(), 120 as $t); |
| 449 |
}); |
| 450 |
|
| 451 |
glam_test!(test_eq, { |
| 452 |
let a = $new(1 as $t, 1 as $t, 1 as $t, 1 as $t); |
| 453 |
let b = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 454 |
assert!(a.cmpeq(a).all()); |
| 455 |
assert!(b.cmpeq(b).all()); |
| 456 |
assert!(a.cmpne(b).any()); |
| 457 |
assert!(b.cmpne(a).any()); |
| 458 |
assert!(b.cmpeq(a).any()); |
| 459 |
}); |
| 460 |
|
| 461 |
glam_test!(test_cmp, { |
| 462 |
assert!(!$mask::default().any()); |
| 463 |
assert!(!$mask::default().all()); |
| 464 |
assert_eq!($mask::default().bitmask(), 0x0); |
| 465 |
let a = $new(1 as $t, 1 as $t, 1 as $t, 1 as $t); |
| 466 |
let b = $new(2 as $t, 2 as $t, 2 as $t, 2 as $t); |
| 467 |
let c = $new(1 as $t, 1 as $t, 2 as $t, 2 as $t); |
| 468 |
let d = $new(2 as $t, 1 as $t, 1 as $t, 2 as $t); |
| 469 |
assert_eq!(a.cmplt(a).bitmask(), 0x0); |
| 470 |
assert_eq!(a.cmplt(b).bitmask(), 0xf); |
| 471 |
assert_eq!(a.cmplt(c).bitmask(), 0xc); |
| 472 |
assert_eq!(c.cmple(a).bitmask(), 0x3); |
| 473 |
assert_eq!(a.cmplt(d).bitmask(), 0x9); |
| 474 |
assert!(a.cmplt(b).all()); |
| 475 |
assert!(a.cmplt(c).any()); |
| 476 |
assert!(a.cmple(b).all()); |
| 477 |
assert!(a.cmple(a).all()); |
| 478 |
assert!(b.cmpgt(a).all()); |
| 479 |
assert!(b.cmpge(a).all()); |
| 480 |
assert!(b.cmpge(b).all()); |
| 481 |
assert!(!(a.cmpge(c).all())); |
| 482 |
assert!(c.cmple(c).all()); |
| 483 |
assert!(c.cmpge(c).all()); |
| 484 |
assert!(a.cmpeq(a).all()); |
| 485 |
assert!(!a.cmpeq(b).all()); |
| 486 |
assert!(a.cmpeq(c).any()); |
| 487 |
assert!(!a.cmpne(a).all()); |
| 488 |
assert!(a.cmpne(b).all()); |
| 489 |
assert!(a.cmpne(c).any()); |
| 490 |
assert!(a == a); |
| 491 |
}); |
| 492 |
|
| 493 |
glam_test!(test_slice, { |
| 494 |
let a = [1 as $t, 2 as $t, 3 as $t, 4 as $t]; |
| 495 |
let b = $vec4::from_slice(&a); |
| 496 |
let c: [$t; 4] = b.into(); |
| 497 |
assert_eq!(a, c); |
| 498 |
let mut d = [0 as $t, 0 as $t, 0 as $t, 0 as $t]; |
| 499 |
b.write_to_slice(&mut d[..]); |
| 500 |
assert_eq!(a, d); |
| 501 |
|
| 502 |
should_panic!({ $vec4::ONE.write_to_slice(&mut [0 as $t; 3]) }); |
| 503 |
should_panic!({ $vec4::from_slice(&[0 as $t; 3]) }); |
| 504 |
}); |
| 505 |
|
| 506 |
glam_test!(test_mask_new, { |
| 507 |
assert_eq!( |
| 508 |
$mask::new(false, false, false, false), |
| 509 |
$masknew(false, false, false, false) |
| 510 |
); |
| 511 |
assert_eq!( |
| 512 |
$mask::new(false, false, true, true), |
| 513 |
$masknew(false, false, true, true) |
| 514 |
); |
| 515 |
assert_eq!( |
| 516 |
$mask::new(true, true, false, false), |
| 517 |
$masknew(true, true, false, false) |
| 518 |
); |
| 519 |
assert_eq!( |
| 520 |
$mask::new(false, true, false, true), |
| 521 |
$masknew(false, true, false, true) |
| 522 |
); |
| 523 |
assert_eq!( |
| 524 |
$mask::new(true, false, true, false), |
| 525 |
$masknew(true, false, true, false) |
| 526 |
); |
| 527 |
assert_eq!( |
| 528 |
$mask::new(true, true, true, true), |
| 529 |
$masknew(true, true, true, true) |
| 530 |
); |
| 531 |
}); |
| 532 |
|
| 533 |
glam_test!(test_mask_from_array_bool, { |
| 534 |
assert_eq!( |
| 535 |
$mask::new(false, false, false, false), |
| 536 |
$mask::from([false, false, false, false]) |
| 537 |
); |
| 538 |
assert_eq!( |
| 539 |
$mask::new(false, false, true, true), |
| 540 |
$mask::from([false, false, true, true]) |
| 541 |
); |
| 542 |
assert_eq!( |
| 543 |
$mask::new(true, true, false, false), |
| 544 |
$mask::from([true, true, false, false]) |
| 545 |
); |
| 546 |
assert_eq!( |
| 547 |
$mask::new(false, true, false, true), |
| 548 |
$mask::from([false, true, false, true]) |
| 549 |
); |
| 550 |
assert_eq!( |
| 551 |
$mask::new(true, false, true, false), |
| 552 |
$mask::from([true, false, true, false]) |
| 553 |
); |
| 554 |
assert_eq!( |
| 555 |
$mask::new(true, true, true, true), |
| 556 |
$mask::from([true, true, true, true]) |
| 557 |
); |
| 558 |
}); |
| 559 |
|
| 560 |
glam_test!(test_mask_into_array_u32, { |
| 561 |
assert_eq!( |
| 562 |
Into::<[u32; 4]>::into($mask::new(false, false, false, false)), |
| 563 |
[0, 0, 0, 0] |
| 564 |
); |
| 565 |
assert_eq!( |
| 566 |
Into::<[u32; 4]>::into($mask::new(false, false, true, true)), |
| 567 |
[0, 0, !0, !0] |
| 568 |
); |
| 569 |
assert_eq!( |
| 570 |
Into::<[u32; 4]>::into($mask::new(true, true, false, false)), |
| 571 |
[!0, !0, 0, 0] |
| 572 |
); |
| 573 |
assert_eq!( |
| 574 |
Into::<[u32; 4]>::into($mask::new(false, true, false, true)), |
| 575 |
[0, !0, 0, !0] |
| 576 |
); |
| 577 |
assert_eq!( |
| 578 |
Into::<[u32; 4]>::into($mask::new(true, false, true, false)), |
| 579 |
[!0, 0, !0, 0] |
| 580 |
); |
| 581 |
assert_eq!( |
| 582 |
Into::<[u32; 4]>::into($mask::new(true, true, true, true)), |
| 583 |
[!0, !0, !0, !0] |
| 584 |
); |
| 585 |
}); |
| 586 |
|
| 587 |
glam_test!(test_mask_into_array_bool, { |
| 588 |
assert_eq!( |
| 589 |
Into::<[bool; 4]>::into($mask::new(false, false, false, false)), |
| 590 |
[false, false, false, false] |
| 591 |
); |
| 592 |
assert_eq!( |
| 593 |
Into::<[bool; 4]>::into($mask::new(false, false, true, true)), |
| 594 |
[false, false, true, true] |
| 595 |
); |
| 596 |
assert_eq!( |
| 597 |
Into::<[bool; 4]>::into($mask::new(true, true, false, false)), |
| 598 |
[true, true, false, false] |
| 599 |
); |
| 600 |
assert_eq!( |
| 601 |
Into::<[bool; 4]>::into($mask::new(false, true, false, true)), |
| 602 |
[false, true, false, true] |
| 603 |
); |
| 604 |
assert_eq!( |
| 605 |
Into::<[bool; 4]>::into($mask::new(true, false, true, false)), |
| 606 |
[true, false, true, false] |
| 607 |
); |
| 608 |
assert_eq!( |
| 609 |
Into::<[bool; 4]>::into($mask::new(true, true, true, true)), |
| 610 |
[true, true, true, true] |
| 611 |
); |
| 612 |
}); |
| 613 |
|
| 614 |
glam_test!(test_mask_splat, { |
| 615 |
assert_eq!($mask::splat(false), $mask::new(false, false, false, false)); |
| 616 |
assert_eq!($mask::splat(true), $mask::new(true, true, true, true)); |
| 617 |
}); |
| 618 |
|
| 619 |
glam_test!(test_mask_bitmask, { |
| 620 |
assert_eq!($mask::new(false, false, false, false).bitmask(), 0b0000); |
| 621 |
assert_eq!($mask::new(false, false, true, true).bitmask(), 0b1100); |
| 622 |
assert_eq!($mask::new(true, true, false, false).bitmask(), 0b0011); |
| 623 |
assert_eq!($mask::new(false, true, false, true).bitmask(), 0b1010); |
| 624 |
assert_eq!($mask::new(true, false, true, false).bitmask(), 0b0101); |
| 625 |
assert_eq!($mask::new(true, true, true, true).bitmask(), 0b1111); |
| 626 |
}); |
| 627 |
|
| 628 |
glam_test!(test_mask_any, { |
| 629 |
assert_eq!($mask::new(false, false, false, false).any(), false); |
| 630 |
assert_eq!($mask::new(true, false, false, false).any(), true); |
| 631 |
assert_eq!($mask::new(false, true, false, false).any(), true); |
| 632 |
assert_eq!($mask::new(false, false, true, false).any(), true); |
| 633 |
assert_eq!($mask::new(false, false, false, true).any(), true); |
| 634 |
}); |
| 635 |
|
| 636 |
glam_test!(test_mask_all, { |
| 637 |
assert_eq!($mask::new(true, true, true, true).all(), true); |
| 638 |
assert_eq!($mask::new(false, true, true, true).all(), false); |
| 639 |
assert_eq!($mask::new(true, false, true, true).all(), false); |
| 640 |
assert_eq!($mask::new(true, true, false, true).all(), false); |
| 641 |
assert_eq!($mask::new(true, true, true, false).all(), false); |
| 642 |
}); |
| 643 |
|
| 644 |
glam_test!(test_mask_select, { |
| 645 |
let a = $vec4::new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 646 |
let b = $vec4::new(5 as $t, 6 as $t, 7 as $t, 8 as $t); |
| 647 |
assert_eq!( |
| 648 |
$vec4::select($mask::new(true, true, true, true), a, b), |
| 649 |
$vec4::new(1 as $t, 2 as $t, 3 as $t, 4 as $t), |
| 650 |
); |
| 651 |
assert_eq!( |
| 652 |
$vec4::select($mask::new(true, false, true, false), a, b), |
| 653 |
$vec4::new(1 as $t, 6 as $t, 3 as $t, 8 as $t), |
| 654 |
); |
| 655 |
assert_eq!( |
| 656 |
$vec4::select($mask::new(false, true, false, true), a, b), |
| 657 |
$vec4::new(5 as $t, 2 as $t, 7 as $t, 4 as $t), |
| 658 |
); |
| 659 |
assert_eq!( |
| 660 |
$vec4::select($mask::new(false, false, false, false), a, b), |
| 661 |
$vec4::new(5 as $t, 6 as $t, 7 as $t, 8 as $t), |
| 662 |
); |
| 663 |
}); |
| 664 |
|
| 665 |
glam_test!(test_mask_and, { |
| 666 |
assert_eq!( |
| 667 |
($mask::new(false, false, false, false) & $mask::new(false, false, false, false)) |
| 668 |
.bitmask(), |
| 669 |
0b0000, |
| 670 |
); |
| 671 |
assert_eq!( |
| 672 |
($mask::new(true, true, true, true) & $mask::new(true, true, true, true)).bitmask(), |
| 673 |
0b1111, |
| 674 |
); |
| 675 |
assert_eq!( |
| 676 |
($mask::new(true, false, true, false) & $mask::new(false, true, false, true)) |
| 677 |
.bitmask(), |
| 678 |
0b0000, |
| 679 |
); |
| 680 |
assert_eq!( |
| 681 |
($mask::new(true, false, true, true) & $mask::new(true, true, true, false)) |
| 682 |
.bitmask(), |
| 683 |
0b0101, |
| 684 |
); |
| 685 |
|
| 686 |
let mut mask = $mask::new(true, true, false, false); |
| 687 |
mask &= $mask::new(true, false, true, false); |
| 688 |
assert_eq!(mask.bitmask(), 0b0001); |
| 689 |
}); |
| 690 |
|
| 691 |
glam_test!(test_mask_or, { |
| 692 |
assert_eq!( |
| 693 |
($mask::new(false, false, false, false) | $mask::new(false, false, false, false)) |
| 694 |
.bitmask(), |
| 695 |
0b0000, |
| 696 |
); |
| 697 |
assert_eq!( |
| 698 |
($mask::new(true, true, true, true) | $mask::new(true, true, true, true)).bitmask(), |
| 699 |
0b1111, |
| 700 |
); |
| 701 |
assert_eq!( |
| 702 |
($mask::new(true, false, true, false) | $mask::new(false, true, false, true)) |
| 703 |
.bitmask(), |
| 704 |
0b1111, |
| 705 |
); |
| 706 |
assert_eq!( |
| 707 |
($mask::new(true, false, true, false) | $mask::new(true, false, true, false)) |
| 708 |
.bitmask(), |
| 709 |
0b0101, |
| 710 |
); |
| 711 |
|
| 712 |
let mut mask = $mask::new(true, true, false, false); |
| 713 |
mask |= $mask::new(true, false, true, false); |
| 714 |
assert_eq!(mask.bitmask(), 0b0111); |
| 715 |
}); |
| 716 |
|
| 717 |
glam_test!(test_mask_xor, { |
| 718 |
assert_eq!( |
| 719 |
($mask::new(false, false, false, false) ^ $mask::new(false, false, false, false)) |
| 720 |
.bitmask(), |
| 721 |
0b0000, |
| 722 |
); |
| 723 |
assert_eq!( |
| 724 |
($mask::new(true, true, true, true) ^ $mask::new(true, true, true, true)).bitmask(), |
| 725 |
0b0000, |
| 726 |
); |
| 727 |
assert_eq!( |
| 728 |
($mask::new(true, false, true, false) ^ $mask::new(false, true, false, true)) |
| 729 |
.bitmask(), |
| 730 |
0b1111, |
| 731 |
); |
| 732 |
assert_eq!( |
| 733 |
($mask::new(true, false, true, false) ^ $mask::new(true, false, true, false)) |
| 734 |
.bitmask(), |
| 735 |
0b0000, |
| 736 |
); |
| 737 |
|
| 738 |
let mut mask = $mask::new(true, true, false, false); |
| 739 |
mask ^= $mask::new(true, false, true, false); |
| 740 |
assert_eq!(mask.bitmask(), 0b0110); |
| 741 |
}); |
| 742 |
|
| 743 |
glam_test!(test_mask_not, { |
| 744 |
assert_eq!((!$mask::new(false, false, false, false)).bitmask(), 0b1111); |
| 745 |
assert_eq!((!$mask::new(true, true, true, true)).bitmask(), 0b0000); |
| 746 |
assert_eq!((!$mask::new(true, false, true, false)).bitmask(), 0b1010); |
| 747 |
assert_eq!((!$mask::new(false, true, false, true)).bitmask(), 0b0101); |
| 748 |
}); |
| 749 |
|
| 750 |
glam_test!(test_mask_fmt, { |
| 751 |
let a = $mask::new(true, false, true, false); |
| 752 |
|
| 753 |
assert_eq!(format!("{}", a), "[true, false, true, false]"); |
| 754 |
assert_eq!( |
| 755 |
format!("{:?}", a), |
| 756 |
format!("{}(0xffffffff, 0x0, 0xffffffff, 0x0)", stringify!($mask)) |
| 757 |
); |
| 758 |
}); |
| 759 |
|
| 760 |
glam_test!(test_mask_eq, { |
| 761 |
let a = $mask::new(true, false, true, false); |
| 762 |
let b = $mask::new(true, false, true, false); |
| 763 |
let c = $mask::new(false, true, true, false); |
| 764 |
|
| 765 |
assert_eq!(a, b); |
| 766 |
assert_eq!(b, a); |
| 767 |
assert_ne!(a, c); |
| 768 |
assert_ne!(b, c); |
| 769 |
}); |
| 770 |
|
| 771 |
glam_test!(test_mask_test, { |
| 772 |
let a = $mask::new(true, false, true, false); |
| 773 |
assert_eq!(a.test(0), true); |
| 774 |
assert_eq!(a.test(1), false); |
| 775 |
assert_eq!(a.test(2), true); |
| 776 |
assert_eq!(a.test(3), false); |
| 777 |
|
| 778 |
let b = $mask::new(false, true, false, true); |
| 779 |
assert_eq!(b.test(0), false); |
| 780 |
assert_eq!(b.test(1), true); |
| 781 |
assert_eq!(b.test(2), false); |
| 782 |
assert_eq!(b.test(3), true); |
| 783 |
}); |
| 784 |
|
| 785 |
glam_test!(test_mask_set, { |
| 786 |
let mut a = $mask::new(false, true, false, true); |
| 787 |
a.set(0, true); |
| 788 |
assert_eq!(a.test(0), true); |
| 789 |
a.set(1, false); |
| 790 |
assert_eq!(a.test(1), false); |
| 791 |
a.set(2, true); |
| 792 |
assert_eq!(a.test(2), true); |
| 793 |
a.set(3, false); |
| 794 |
assert_eq!(a.test(3), false); |
| 795 |
|
| 796 |
let mut b = $mask::new(true, false, true, false); |
| 797 |
b.set(0, false); |
| 798 |
assert_eq!(b.test(0), false); |
| 799 |
b.set(1, true); |
| 800 |
assert_eq!(b.test(1), true); |
| 801 |
b.set(2, false); |
| 802 |
assert_eq!(b.test(2), false); |
| 803 |
b.set(3, true); |
| 804 |
assert_eq!(b.test(3), true); |
| 805 |
}); |
| 806 |
|
| 807 |
glam_test!(test_mask_hash, { |
| 808 |
use std::collections::hash_map::DefaultHasher; |
| 809 |
use std::hash::Hash; |
| 810 |
use std::hash::Hasher; |
| 811 |
|
| 812 |
let a = $mask::new(true, false, true, false); |
| 813 |
let b = $mask::new(true, false, true, false); |
| 814 |
let c = $mask::new(false, true, true, false); |
| 815 |
|
| 816 |
let mut hasher = DefaultHasher::new(); |
| 817 |
a.hash(&mut hasher); |
| 818 |
let a_hashed = hasher.finish(); |
| 819 |
|
| 820 |
let mut hasher = DefaultHasher::new(); |
| 821 |
b.hash(&mut hasher); |
| 822 |
let b_hashed = hasher.finish(); |
| 823 |
|
| 824 |
let mut hasher = DefaultHasher::new(); |
| 825 |
c.hash(&mut hasher); |
| 826 |
let c_hashed = hasher.finish(); |
| 827 |
|
| 828 |
assert_eq!(a, b); |
| 829 |
assert_eq!(a_hashed, b_hashed); |
| 830 |
assert_ne!(a, c); |
| 831 |
assert_ne!(a_hashed, c_hashed); |
| 832 |
}); |
| 833 |
|
| 834 |
glam_test!(test_to_from_slice, { |
| 835 |
let v = $vec4::new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 836 |
let mut a = [0 as $t, 0 as $t, 0 as $t, 0 as $t]; |
| 837 |
v.write_to_slice(&mut a); |
| 838 |
assert_eq!(v, $vec4::from_slice(&a)); |
| 839 |
|
| 840 |
let mut a = [0 as $t; 17]; |
| 841 |
v.write_to_slice(&mut a); |
| 842 |
assert_eq!(v, $vec4::from_slice(&a[..4])); |
| 843 |
assert_eq!([0 as $t; 13], a[4..]); |
| 844 |
}); |
| 845 |
|
| 846 |
glam_test!(test_sum, { |
| 847 |
let one = $vec4::ONE; |
| 848 |
assert_eq!([one, one].iter().sum::<$vec4>(), one + one); |
| 849 |
assert_eq!([one, one].into_iter().sum::<$vec4>(), one + one); |
| 850 |
}); |
| 851 |
|
| 852 |
glam_test!(test_product, { |
| 853 |
let two = $vec4::new(2 as $t, 2 as $t, 2 as $t, 2 as $t); |
| 854 |
assert_eq!([two, two].iter().product::<$vec4>(), two * two); |
| 855 |
assert_eq!([two, two].into_iter().product::<$vec4>(), two * two); |
| 856 |
}); |
| 857 |
}; |
| 858 |
} |
| 859 |
|
| 860 |
macro_rules! impl_vec4_signed_tests { |
| 861 |
($t:ident, $new:ident, $vec4:ident, $vec3:ident, $vec2:ident, $mask:ident, $masknew:ident) => { |
| 862 |
impl_vec4_tests!($t, $new, $vec4, $vec3, $vec2, $mask, $masknew); |
| 863 |
|
| 864 |
glam_test!(test_neg, { |
| 865 |
let a = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 866 |
assert_eq!((-1 as $t, -2 as $t, -3 as $t, -4 as $t), (-a).into()); |
| 867 |
assert_eq!( |
| 868 |
$new(-0 as $t, -0 as $t, -0 as $t, -0 as $t), |
| 869 |
-$new(0 as $t, 0 as $t, 0 as $t, 0 as $t) |
| 870 |
); |
| 871 |
assert_eq!( |
| 872 |
$new(0 as $t, -0 as $t, -0 as $t, -0 as $t), |
| 873 |
-$new(-0 as $t, 0 as $t, 0 as $t, 0 as $t) |
| 874 |
); |
| 875 |
}); |
| 876 |
|
| 877 |
glam_test!(test_neg_propagation, { |
| 878 |
let a = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 879 |
assert_eq!(-a, -(&a)); |
| 880 |
}); |
| 881 |
|
| 882 |
glam_test!(test_is_negative_bitmask, { |
| 883 |
assert_eq!($vec4::ZERO.is_negative_bitmask(), 0b0000); |
| 884 |
assert_eq!($vec4::ONE.is_negative_bitmask(), 0b0000); |
| 885 |
assert_eq!((-$vec4::ONE).is_negative_bitmask(), 0b1111); |
| 886 |
assert_eq!( |
| 887 |
$vec4::new(-1 as $t, 2 as $t, 3 as $t, -4 as $t).is_negative_bitmask(), |
| 888 |
0b1001 |
| 889 |
); |
| 890 |
assert_eq!( |
| 891 |
$vec4::new(1 as $t, 5 as $t, -3 as $t, 7 as $t).is_negative_bitmask(), |
| 892 |
0b0100 |
| 893 |
); |
| 894 |
assert_eq!( |
| 895 |
$vec4::new(3 as $t, -4 as $t, 1 as $t, 6 as $t).is_negative_bitmask(), |
| 896 |
0b0010 |
| 897 |
); |
| 898 |
assert_eq!( |
| 899 |
$vec4::new(2 as $t, -6 as $t, 5 as $t, -3 as $t).is_negative_bitmask(), |
| 900 |
0b1010 |
| 901 |
); |
| 902 |
}); |
| 903 |
|
| 904 |
glam_test!(test_abs, { |
| 905 |
assert_eq!($vec4::ZERO.abs(), $vec4::ZERO); |
| 906 |
assert_eq!($vec4::ONE.abs(), $vec4::ONE); |
| 907 |
assert_eq!((-$vec4::ONE).abs(), $vec4::ONE); |
| 908 |
}); |
| 909 |
|
| 910 |
glam_test!(test_dot_signed, { |
| 911 |
let x = $new(1 as $t, 0 as $t, 0 as $t, 0 as $t); |
| 912 |
let y = $new(0 as $t, 1 as $t, 0 as $t, 0 as $t); |
| 913 |
let z = $new(0 as $t, 0 as $t, 1 as $t, 0 as $t); |
| 914 |
let w = $new(0 as $t, 0 as $t, 0 as $t, 1 as $t); |
| 915 |
assert_eq!(1 as $t, x.dot(x)); |
| 916 |
assert_eq!(0 as $t, x.dot(y)); |
| 917 |
assert_eq!(0 as $t, x.dot(-z)); |
| 918 |
assert_eq!(-1 as $t, w.dot(-w)); |
| 919 |
}); |
| 920 |
|
| 921 |
glam_test!(test_length_squared_signed, { |
| 922 |
let x = $new(1 as $t, 0 as $t, 0 as $t, 0 as $t); |
| 923 |
let y = $new(0 as $t, 1 as $t, 0 as $t, 0 as $t); |
| 924 |
let z = $new(0 as $t, 0 as $t, 1 as $t, 0 as $t); |
| 925 |
let w = $new(0 as $t, 0 as $t, 0 as $t, 1 as $t); |
| 926 |
assert_eq!(4 as $t, (2 as $t * x).length_squared()); |
| 927 |
assert_eq!(9 as $t, (-3 as $t * y).length_squared()); |
| 928 |
assert_eq!(16 as $t, (4 as $t * z).length_squared()); |
| 929 |
assert_eq!(64 as $t, (8 as $t * w).length_squared()); |
| 930 |
assert_eq!( |
| 931 |
2 as $t * 2 as $t + 3 as $t * 3 as $t + 4 as $t * 4 as $t + 5 as $t * 5 as $t, |
| 932 |
$new(2 as $t, 3 as $t, 4 as $t, 5 as $t).length_squared() |
| 933 |
); |
| 934 |
assert_eq!(2 as $t, x.distance_squared(y)); |
| 935 |
assert_eq!(13 as $t, (2 as $t * x).distance_squared(-3 as $t * z)); |
| 936 |
}); |
| 937 |
|
| 938 |
glam_test!(test_div_euclid, { |
| 939 |
let one = $vec4::ONE; |
| 940 |
let two = one + one; |
| 941 |
let three = two + one; |
| 942 |
assert_eq!(three.div_euclid(two), one); |
| 943 |
assert_eq!((-three).div_euclid(two), -two); |
| 944 |
assert_eq!(three.div_euclid(-two), -one); |
| 945 |
assert_eq!((-three).div_euclid(-two), two); |
| 946 |
}); |
| 947 |
|
| 948 |
glam_test!(test_rem_euclid, { |
| 949 |
let one = $vec4::ONE; |
| 950 |
let two = one + one; |
| 951 |
let three = two + one; |
| 952 |
let four = three + one; |
| 953 |
assert_eq!(four.rem_euclid(three), one); |
| 954 |
assert_eq!((-four).rem_euclid(three), two); |
| 955 |
assert_eq!(four.rem_euclid(-three), one); |
| 956 |
assert_eq!((-four).rem_euclid(-three), two); |
| 957 |
}); |
| 958 |
}; |
| 959 |
} |
| 960 |
|
| 961 |
macro_rules! impl_vec4_signed_integer_tests { |
| 962 |
($t:ident, $new:ident, $vec4:ident, $vec3:ident, $vec2:ident, $mask:ident, $masknew:ident) => { |
| 963 |
impl_vec4_signed_tests!($t, $new, $vec4, $vec3, $vec2, $mask, $masknew); |
| 964 |
|
| 965 |
glam_test!(test_signum, { |
| 966 |
assert_eq!($vec4::ZERO.signum(), $vec4::ZERO); |
| 967 |
assert_eq!($vec4::ONE.signum(), $vec4::ONE); |
| 968 |
assert_eq!((-$vec4::ONE).signum(), -$vec4::ONE); |
| 969 |
}); |
| 970 |
}; |
| 971 |
} |
| 972 |
|
| 973 |
macro_rules! impl_vec4_eq_hash_tests { |
| 974 |
($t:ident, $new:ident) => { |
| 975 |
glam_test!(test_ve2_hash, { |
| 976 |
use std::collections::hash_map::DefaultHasher; |
| 977 |
use std::hash::Hash; |
| 978 |
use std::hash::Hasher; |
| 979 |
|
| 980 |
let a = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 981 |
let b = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t); |
| 982 |
let c = $new(3 as $t, 2 as $t, 1 as $t, 4 as $t); |
| 983 |
|
| 984 |
let mut hasher = DefaultHasher::new(); |
| 985 |
a.hash(&mut hasher); |
| 986 |
let a_hashed = hasher.finish(); |
| 987 |
|
| 988 |
let mut hasher = DefaultHasher::new(); |
| 989 |
b.hash(&mut hasher); |
| 990 |
let b_hashed = hasher.finish(); |
| 991 |
|
| 992 |
let mut hasher = DefaultHasher::new(); |
| 993 |
c.hash(&mut hasher); |
| 994 |
let c_hashed = hasher.finish(); |
| 995 |
|
| 996 |
assert_eq!(a, b); |
| 997 |
assert_eq!(a_hashed, b_hashed); |
| 998 |
assert_ne!(a, c); |
| 999 |
assert_ne!(a_hashed, c_hashed); |
| 1000 |
}); |
| 1001 |
}; |
| 1002 |
} |
| 1003 |
|
| 1004 |
macro_rules! impl_vec4_float_tests { |
| 1005 |
($t:ident, $new:ident, $vec4:ident, $vec3:ident, $vec2:ident, $mask:ident, $masknew:ident) => { |
| 1006 |
impl_vec4_signed_tests!($t, $new, $vec4, $vec3, $vec2, $mask, $masknew); |
| 1007 |
impl_vec_float_normalize_tests!($t, $vec4); |
| 1008 |
|
| 1009 |
glam_test!(test_vec4_nan, { |
| 1010 |
assert!($vec4::NAN.is_nan()); |
| 1011 |
assert!(!$vec4::NAN.is_finite()); |
| 1012 |
}); |
| 1013 |
|
| 1014 |
glam_test!(test_funcs, { |
| 1015 |
let x = $new(1.0, 0.0, 0.0, 0.0); |
| 1016 |
let y = $new(0.0, 1.0, 0.0, 0.0); |
| 1017 |
let z = $new(0.0, 0.0, 1.0, 0.0); |
| 1018 |
let w = $new(0.0, 0.0, 0.0, 1.0); |
| 1019 |
assert_eq!(2.0, (-2.0 * x).length()); |
| 1020 |
assert_eq!(3.0, (3.0 * y).length()); |
| 1021 |
assert_eq!(4.0, (-4.0 * z).length()); |
| 1022 |
assert_eq!(5.0, (-5.0 * w).length()); |
| 1023 |
assert_eq!((2.0 as $t).sqrt(), w.distance(y)); |
| 1024 |
assert_eq!(5.0, (3.0 * x).distance(-4.0 * y)); |
| 1025 |
assert_eq!(13.0, (-5.0 * w).distance(12.0 * y)); |
| 1026 |
assert_eq!(x, (2.0 * x).normalize()); |
| 1027 |
assert_eq!( |
| 1028 |
1.0 * 5.0 + 2.0 * 6.0 + 3.0 * 7.0 + 4.0 * 8.0, |
| 1029 |
$new(1.0, 2.0, 3.0, 4.0).dot($new(5.0, 6.0, 7.0, 8.0)) |
| 1030 |
); |
| 1031 |
assert_eq!( |
| 1032 |
(2.0 as $t * 2.0 + 3.0 * 3.0 + 4.0 * 4.0 + 5.0 * 5.0).sqrt(), |
| 1033 |
$new(2.0, 3.0, 4.0, 5.0).length() |
| 1034 |
); |
| 1035 |
assert_eq!( |
| 1036 |
1.0 / (2.0 as $t * 2.0 + 3.0 * 3.0 + 4.0 * 4.0 + 5.0 * 5.0).sqrt(), |
| 1037 |
$new(2.0, 3.0, 4.0, 5.0).length_recip() |
| 1038 |
); |
| 1039 |
assert!($new(2.0, 3.0, 4.0, 5.0).normalize().is_normalized()); |
| 1040 |
assert_approx_eq!( |
| 1041 |
$new(2.0, 3.0, 4.0, 5.0) |
| 1042 |
/ (2.0 as $t * 2.0 + 3.0 * 3.0 + 4.0 * 4.0 + 5.0 * 5.0).sqrt(), |
| 1043 |
$new(2.0, 3.0, 4.0, 5.0).normalize() |
| 1044 |
); |
| 1045 |
assert_eq!( |
| 1046 |
$new(0.5, 0.25, 0.125, 0.0625), |
| 1047 |
$new(2.0, 4.0, 8.0, 16.0).recip() |
| 1048 |
); |
| 1049 |
}); |
| 1050 |
|
| 1051 |
glam_test!(test_project_reject, { |
| 1052 |
assert_eq!( |
| 1053 |
$new(0.0, 0.0, 0.0, 1.0), |
| 1054 |
$new(0.0, 1.0, 0.0, 1.0).project_onto($new(0.0, 0.0, 0.0, 2.0)) |
| 1055 |
); |
| 1056 |
assert_eq!( |
| 1057 |
$new(0.0, 1.0, 0.0, 0.0), |
| 1058 |
$new(0.0, 1.0, 0.0, 1.0).reject_from($new(0.0, 0.0, 0.0, 2.0)) |
| 1059 |
); |
| 1060 |
assert_eq!( |
| 1061 |
$new(0.0, 0.0, 0.0, 1.0), |
| 1062 |
$new(0.0, 1.0, 0.0, 1.0).project_onto_normalized($new(0.0, 0.0, 0.0, 1.0)) |
| 1063 |
); |
| 1064 |
assert_eq!( |
| 1065 |
$new(0.0, 1.0, 0.0, 0.0), |
| 1066 |
$new(0.0, 1.0, 0.0, 1.0).reject_from_normalized($new(0.0, 0.0, 0.0, 1.0)) |
| 1067 |
); |
| 1068 |
should_glam_assert!({ $vec4::ONE.project_onto($vec4::ZERO) }); |
| 1069 |
should_glam_assert!({ $vec4::ONE.reject_from($vec4::ZERO) }); |
| 1070 |
should_glam_assert!({ $vec4::ONE.project_onto_normalized($vec4::ONE) }); |
| 1071 |
should_glam_assert!({ $vec4::ONE.reject_from_normalized($vec4::ONE) }); |
| 1072 |
}); |
| 1073 |
|
| 1074 |
glam_test!(test_signum, { |
| 1075 |
assert_eq!($vec4::ZERO.signum(), $vec4::ONE); |
| 1076 |
assert_eq!((-$vec4::ZERO).signum(), -$vec4::ONE); |
| 1077 |
assert_eq!($vec4::ONE.signum(), $vec4::ONE); |
| 1078 |
assert_eq!((-$vec4::ONE).signum(), -$vec4::ONE); |
| 1079 |
assert_eq!($vec4::INFINITY.signum(), $vec4::ONE); |
| 1080 |
assert_eq!($vec4::NEG_INFINITY.signum(), -$vec4::ONE); |
| 1081 |
assert!($vec4::NAN.signum().is_nan_mask().all()); |
| 1082 |
}); |
| 1083 |
|
| 1084 |
glam_test!(test_copysign, { |
| 1085 |
assert_eq!($vec4::ZERO.copysign(-$vec4::ZERO), -$vec4::ZERO); |
| 1086 |
assert_eq!((-$vec4::ZERO).copysign(-$vec4::ZERO), -$vec4::ZERO); |
| 1087 |
assert_eq!($vec4::ZERO.copysign($vec4::ZERO), $vec4::ZERO); |
| 1088 |
assert_eq!((-$vec4::ZERO).copysign($vec4::ZERO), $vec4::ZERO); |
| 1089 |
assert_eq!($vec4::ONE.copysign(-$vec4::ZERO), -$vec4::ONE); |
| 1090 |
assert_eq!((-$vec4::ONE).copysign(-$vec4::ZERO), -$vec4::ONE); |
| 1091 |
assert_eq!($vec4::ONE.copysign($vec4::ZERO), $vec4::ONE); |
| 1092 |
assert_eq!((-$vec4::ONE).copysign($vec4::ZERO), $vec4::ONE); |
| 1093 |
assert_eq!($vec4::ZERO.copysign(-$vec4::ONE), -$vec4::ZERO); |
| 1094 |
assert_eq!((-$vec4::ZERO).copysign(-$vec4::ONE), -$vec4::ZERO); |
| 1095 |
assert_eq!($vec4::ZERO.copysign($vec4::ONE), $vec4::ZERO); |
| 1096 |
assert_eq!((-$vec4::ZERO).copysign($vec4::ONE), $vec4::ZERO); |
| 1097 |
assert_eq!($vec4::ONE.copysign(-$vec4::ONE), -$vec4::ONE); |
| 1098 |
assert_eq!((-$vec4::ONE).copysign(-$vec4::ONE), -$vec4::ONE); |
| 1099 |
assert_eq!($vec4::ONE.copysign($vec4::ONE), $vec4::ONE); |
| 1100 |
assert_eq!((-$vec4::ONE).copysign($vec4::ONE), $vec4::ONE); |
| 1101 |
assert_eq!($vec4::INFINITY.copysign($vec4::ONE), $vec4::INFINITY); |
| 1102 |
assert_eq!($vec4::INFINITY.copysign(-$vec4::ONE), $vec4::NEG_INFINITY); |
| 1103 |
assert_eq!($vec4::NEG_INFINITY.copysign($vec4::ONE), $vec4::INFINITY); |
| 1104 |
assert_eq!( |
| 1105 |
$vec4::NEG_INFINITY.copysign(-$vec4::ONE), |
| 1106 |
$vec4::NEG_INFINITY |
| 1107 |
); |
| 1108 |
assert!($vec4::NAN.copysign($vec4::ONE).is_nan_mask().all()); |
| 1109 |
assert!($vec4::NAN.copysign(-$vec4::ONE).is_nan_mask().all()); |
| 1110 |
}); |
| 1111 |
|
| 1112 |
glam_test!(test_float_is_negative_bitmask, { |
| 1113 |
assert_eq!($vec4::ZERO.is_negative_bitmask(), 0b0000); |
| 1114 |
assert_eq!((-$vec4::ZERO).is_negative_bitmask(), 0b1111); |
| 1115 |
assert_eq!($vec4::ONE.is_negative_bitmask(), 0b0000); |
| 1116 |
assert_eq!((-$vec4::ONE).is_negative_bitmask(), 0b1111); |
| 1117 |
assert_eq!( |
| 1118 |
$vec4::new(-1.0, 2.0, 3.0, -4.0).is_negative_bitmask(), |
| 1119 |
0b1001 |
| 1120 |
); |
| 1121 |
assert_eq!( |
| 1122 |
$vec4::new(8.0, 3.0, 1.0, -0.0).is_negative_bitmask(), |
| 1123 |
0b1000 |
| 1124 |
); |
| 1125 |
assert_eq!( |
| 1126 |
$vec4::new(1.0, 5.0, -3.0, 7.0).is_negative_bitmask(), |
| 1127 |
0b0100 |
| 1128 |
); |
| 1129 |
assert_eq!( |
| 1130 |
$vec4::new(3.0, -4.0, 1.0, 6.0).is_negative_bitmask(), |
| 1131 |
0b0010 |
| 1132 |
); |
| 1133 |
assert_eq!( |
| 1134 |
$vec4::new(2.0, -6.0, 5.0, -3.0).is_negative_bitmask(), |
| 1135 |
0b1010 |
| 1136 |
); |
| 1137 |
}); |
| 1138 |
|
| 1139 |
glam_test!(test_round, { |
| 1140 |
assert_eq!($vec4::new(1.35, 0.0, 0.0, 0.0).round().x, 1.0); |
| 1141 |
assert_eq!($vec4::new(0.0, 1.5, 0.0, 0.0).round().y, 2.0); |
| 1142 |
assert_eq!($vec4::new(0.0, 0.0, -15.5, 0.0).round().z, -16.0); |
| 1143 |
assert_eq!($vec4::new(0.0, 0.0, 0.0, 0.0).round().z, 0.0); |
| 1144 |
assert_eq!($vec4::new(0.0, 21.1, 0.0, 0.0).round().y, 21.0); |
| 1145 |
assert_eq!($vec4::new(0.0, 0.0, 0.0, 11.123).round().w, 11.0); |
| 1146 |
assert_eq!($vec4::new(0.0, 0.0, 11.501, 0.0).round().z, 12.0); |
| 1147 |
assert_eq!( |
| 1148 |
$vec4::new($t::NEG_INFINITY, $t::INFINITY, 1.0, -1.0).round(), |
| 1149 |
$vec4::new($t::NEG_INFINITY, $t::INFINITY, 1.0, -1.0) |
| 1150 |
); |
| 1151 |
assert!($vec4::new($t::NAN, 0.0, 0.0, 1.0).round().x.is_nan()); |
| 1152 |
}); |
| 1153 |
|
| 1154 |
glam_test!(test_floor, { |
| 1155 |
assert_eq!( |
| 1156 |
$vec4::new(1.35, 1.5, -1.5, 1.999).floor(), |
| 1157 |
$vec4::new(1.0, 1.0, -2.0, 1.0) |
| 1158 |
); |
| 1159 |
assert_eq!( |
| 1160 |
$vec4::new($t::INFINITY, $t::NEG_INFINITY, 0.0, 0.0).floor(), |
| 1161 |
$vec4::new($t::INFINITY, $t::NEG_INFINITY, 0.0, 0.0) |
| 1162 |
); |
| 1163 |
assert!($vec4::new(0.0, $t::NAN, 0.0, 0.0).floor().y.is_nan()); |
| 1164 |
assert_eq!( |
| 1165 |
$vec4::new(-0.0, -2000000.123, 10000000.123, 1000.9).floor(), |
| 1166 |
$vec4::new(-0.0, -2000001.0, 10000000.0, 1000.0) |
| 1167 |
); |
| 1168 |
}); |
| 1169 |
|
| 1170 |
glam_test!(test_fract_gl, { |
| 1171 |
assert_approx_eq!( |
| 1172 |
$vec4::new(1.35, 1.5, -1.5, 1.999).fract_gl(), |
| 1173 |
$vec4::new(0.35, 0.5, 0.5, 0.999) |
| 1174 |
); |
| 1175 |
assert_approx_eq!( |
| 1176 |
$vec4::new(-0.0, -200000.123, 1000000.123, 1000.9).fract_gl(), |
| 1177 |
$vec4::new(0.0, 0.877, 0.123, 0.9), |
| 1178 |
0.002 |
| 1179 |
); |
| 1180 |
}); |
| 1181 |
|
| 1182 |
glam_test!(test_fract, { |
| 1183 |
assert_approx_eq!( |
| 1184 |
$vec4::new(1.35, 1.5, -1.5, 1.999).fract(), |
| 1185 |
$vec4::new(0.35, 0.5, -0.5, 0.999) |
| 1186 |
); |
| 1187 |
assert_approx_eq!( |
| 1188 |
$vec4::new(-0.0, -200000.123, 1000000.123, 1000.9).fract(), |
| 1189 |
$vec4::new(0.0, -0.123, 0.123, 0.9), |
| 1190 |
0.002 |
| 1191 |
); |
| 1192 |
}); |
| 1193 |
|
| 1194 |
glam_test!(test_ceil, { |
| 1195 |
assert_eq!( |
| 1196 |
$vec4::new(1.35, 1.5, -1.5, 1234.1234).ceil(), |
| 1197 |
$vec4::new(2.0, 2.0, -1.0, 1235.0) |
| 1198 |
); |
| 1199 |
assert_eq!( |
| 1200 |
$vec4::new($t::INFINITY, $t::NEG_INFINITY, 0.0, 0.0).ceil(), |
| 1201 |
$vec4::new($t::INFINITY, $t::NEG_INFINITY, 0.0, 0.0) |
| 1202 |
); |
| 1203 |
assert!($vec4::new(0.0, 0.0, $t::NAN, 0.0).ceil().z.is_nan()); |
| 1204 |
assert_eq!( |
| 1205 |
$vec4::new(-1234.1234, -2000000.123, 1000000.123, 1000.9).ceil(), |
| 1206 |
$vec4::new(-1234.0, -2000000.0, 1000001.0, 1001.0) |
| 1207 |
); |
| 1208 |
}); |
| 1209 |
|
| 1210 |
glam_test!(test_trunc, { |
| 1211 |
assert_eq!( |
| 1212 |
$vec4::new(1.35, 1.5, -1.5, 1.999).trunc(), |
| 1213 |
$vec4::new(1.0, 1.0, -1.0, 1.0) |
| 1214 |
); |
| 1215 |
assert_eq!( |
| 1216 |
$vec4::new($t::INFINITY, $t::NEG_INFINITY, 0.0, 0.0).trunc(), |
| 1217 |
$vec4::new($t::INFINITY, $t::NEG_INFINITY, 0.0, 0.0) |
| 1218 |
); |
| 1219 |
assert!($vec4::new(0.0, $t::NAN, 0.0, 0.0).trunc().y.is_nan()); |
| 1220 |
assert_eq!( |
| 1221 |
$vec4::new(-0.0, -2000000.123, 10000000.123, 1000.9).trunc(), |
| 1222 |
$vec4::new(-0.0, -2000000.0, 10000000.0, 1000.0) |
| 1223 |
); |
| 1224 |
}); |
| 1225 |
|
| 1226 |
glam_test!(test_lerp, { |
| 1227 |
let v0 = $vec4::new(-1.0, -1.0, -1.0, -1.0); |
| 1228 |
let v1 = $vec4::new(1.0, 1.0, 1.0, 1.0); |
| 1229 |
assert_approx_eq!(v0, v0.lerp(v1, 0.0)); |
| 1230 |
assert_approx_eq!(v1, v0.lerp(v1, 1.0)); |
| 1231 |
assert_approx_eq!($vec4::ZERO, v0.lerp(v1, 0.5)); |
| 1232 |
}); |
| 1233 |
|
| 1234 |
glam_test!(test_lerp_big_difference, { |
| 1235 |
let v0 = $vec4::new(-1e30, -1e30, -1e30, -1e30); |
| 1236 |
let v1 = $vec4::new(16.0, 16.0, 16.0, 16.0); |
| 1237 |
assert_approx_eq!(v0, v0.lerp(v1, 0.0)); |
| 1238 |
assert_approx_eq!(v1, v0.lerp(v1, 1.0)); |
| 1239 |
}); |
| 1240 |
|
| 1241 |
glam_test!(test_move_towards, { |
| 1242 |
let v0 = $vec4::new(-1.0, -1.0, -1.0, -1.0); |
| 1243 |
let v1 = $vec4::new(1.0, 1.0, 1.0, 1.0); |
| 1244 |
assert_approx_eq!(v0, v0.move_towards(v1, 0.0)); |
| 1245 |
assert_approx_eq!(v1, v0.move_towards(v1, v0.distance(v1))); |
| 1246 |
assert_approx_eq!(v1, v0.move_towards(v1, v0.distance(v1) + 1.0)); |
| 1247 |
}); |
| 1248 |
|
| 1249 |
glam_test!(test_midpoint, { |
| 1250 |
let v0 = $vec4::new(-1.0, -1.0, -1.0, -1.0); |
| 1251 |
let v1 = $vec4::new(1.0, 1.0, 1.0, 1.0); |
| 1252 |
let v2 = $vec4::new(-1.5, 0.0, 1.0, 0.5); |
| 1253 |
assert_approx_eq!($vec4::ZERO, v0.midpoint(v1)); |
| 1254 |
assert_approx_eq!($vec4::new(-0.25, 0.5, 1.0, 0.75), v1.midpoint(v2)); |
| 1255 |
}); |
| 1256 |
|
| 1257 |
glam_test!(test_is_finite, { |
| 1258 |
assert!($vec4::new(0.0, 0.0, 0.0, 0.0).is_finite()); |
| 1259 |
assert!($vec4::new(-1e-10, 1.0, 1e10, 42.0).is_finite()); |
| 1260 |
assert!(!$vec4::new($t::INFINITY, 0.0, 0.0, 0.0).is_finite()); |
| 1261 |
assert!(!$vec4::new(0.0, $t::NAN, 0.0, 0.0).is_finite()); |
| 1262 |
assert!(!$vec4::new(0.0, 0.0, $t::NEG_INFINITY, 0.0).is_finite()); |
| 1263 |
assert!(!$vec4::new(0.0, 0.0, 0.0, $t::NAN).is_finite()); |
| 1264 |
assert!(!$vec4::INFINITY.is_finite()); |
| 1265 |
assert!(!$vec4::NEG_INFINITY.is_finite()); |
| 1266 |
}); |
| 1267 |
|
| 1268 |
glam_test!(test_powf, { |
| 1269 |
assert_eq!( |
| 1270 |
$vec4::new(2.0, 4.0, 8.0, 16.0).powf(2.0), |
| 1271 |
$vec4::new(4.0, 16.0, 64.0, 256.0) |
| 1272 |
); |
| 1273 |
}); |
| 1274 |
|
| 1275 |
glam_test!(test_exp, { |
| 1276 |
assert_approx_eq!( |
| 1277 |
$vec4::new(1.0, 2.0, 3.0, 4.0).exp(), |
| 1278 |
$vec4::new( |
| 1279 |
(1.0 as $t).exp(), |
| 1280 |
(2.0 as $t).exp(), |
| 1281 |
(3.0 as $t).exp(), |
| 1282 |
(4.0 as $t).exp() |
| 1283 |
), |
| 1284 |
1e-5 |
| 1285 |
); |
| 1286 |
}); |
| 1287 |
|
| 1288 |
glam_test!(test_clamp_length, { |
| 1289 |
// Too long gets shortened |
| 1290 |
assert_eq!( |
| 1291 |
$vec4::new(12.0, 16.0, 0.0, 0.0).clamp_length(7.0, 10.0), |
| 1292 |
$vec4::new(6.0, 8.0, 0.0, 0.0) // shortened to length 10.0 |
| 1293 |
); |
| 1294 |
// In the middle is unchanged |
| 1295 |
assert_eq!( |
| 1296 |
$vec4::new(2.0, 1.0, 0.0, 0.0).clamp_length(0.5, 5.0), |
| 1297 |
$vec4::new(2.0, 1.0, 0.0, 0.0) // unchanged |
| 1298 |
); |
| 1299 |
// Too short gets lengthened |
| 1300 |
assert_eq!( |
| 1301 |
$vec4::new(0.6, 0.8, 0.0, 0.0).clamp_length(10.0, 20.0), |
| 1302 |
$vec4::new(6.0, 8.0, 0.0, 0.0) // lengthened to length 10.0 |
| 1303 |
); |
| 1304 |
should_glam_assert!({ $vec4::ONE.clamp_length(1.0, 0.0) }); |
| 1305 |
}); |
| 1306 |
|
| 1307 |
glam_test!(test_clamp_length_max, { |
| 1308 |
// Too long gets shortened |
| 1309 |
assert_eq!( |
| 1310 |
$vec4::new(12.0, 16.0, 0.0, 0.0).clamp_length_max(10.0), |
| 1311 |
$vec4::new(6.0, 8.0, 0.0, 0.0) // shortened to length 10.0 |
| 1312 |
); |
| 1313 |
// Not too long is unchanged |
| 1314 |
assert_eq!( |
| 1315 |
$vec4::new(2.0, 1.0, 0.0, 0.0).clamp_length_max(5.0), |
| 1316 |
$vec4::new(2.0, 1.0, 0.0, 0.0) // unchanged |
| 1317 |
); |
| 1318 |
}); |
| 1319 |
|
| 1320 |
glam_test!(test_clamp_length_min, { |
| 1321 |
// Not too short is unchanged |
| 1322 |
assert_eq!( |
| 1323 |
$vec4::new(2.0, 1.0, 0.0, 0.0).clamp_length_min(0.5), |
| 1324 |
$vec4::new(2.0, 1.0, 0.0, 0.0) // unchanged |
| 1325 |
); |
| 1326 |
// Too short gets lengthened |
| 1327 |
assert_eq!( |
| 1328 |
$vec4::new(0.6, 0.8, 0.0, 0.0).clamp_length_min(10.0), |
| 1329 |
$vec4::new(6.0, 8.0, 0.0, 0.0) // lengthened to length 10.0 |
| 1330 |
); |
| 1331 |
}); |
| 1332 |
|
| 1333 |
glam_test!(test_mul_add, { |
| 1334 |
assert_eq!( |
| 1335 |
$vec4::new(1.0, 1.0, 1.0, 1.0).mul_add( |
| 1336 |
$vec4::new(0.5, 2.0, -4.0, 0.0), |
| 1337 |
$vec4::new(-1.0, -1.0, -1.0, -1.0) |
| 1338 |
), |
| 1339 |
$vec4::new(-0.5, 1.0, -5.0, -1.0) |
| 1340 |
); |
| 1341 |
}); |
| 1342 |
|
| 1343 |
glam_test!(test_fmt_float, { |
| 1344 |
let a = $vec4::new(1.0, 2.0, 3.0, 4.0); |
| 1345 |
assert_eq!(format!("{:.2}", a), "[1.00, 2.00, 3.00, 4.00]"); |
| 1346 |
}); |
| 1347 |
|
| 1348 |
glam_test!(test_reflect, { |
| 1349 |
let incident = $vec4::new(1.0, -1.0, 1.0, 1.0); |
| 1350 |
let normal = $vec4::Y; |
| 1351 |
assert_approx_eq!(incident.reflect(normal), $vec4::ONE); |
| 1352 |
}); |
| 1353 |
|
| 1354 |
glam_test!(test_refract, { |
| 1355 |
let incident = $vec4::NEG_ONE.normalize(); |
| 1356 |
let normal = $vec4::ONE.normalize(); |
| 1357 |
assert_approx_eq!(incident.refract(normal, 0.5), incident); |
| 1358 |
|
| 1359 |
let incident = $vec4::new(1.0, -1.0, 0.0, 0.0).normalize(); |
| 1360 |
let normal = $vec4::Y; |
| 1361 |
assert_approx_eq!(incident.refract(normal, 1.5), $vec4::ZERO); |
| 1362 |
}); |
| 1363 |
}; |
| 1364 |
} |
| 1365 |
|
| 1366 |
macro_rules! impl_vec4_scalar_shift_op_test { |
| 1367 |
($vec4:ident, $t_min:literal, $t_max:literal, $rhs_min:literal, $rhs_max:literal) => { |
| 1368 |
glam_test!(test_vec4_scalar_shift_ops, { |
| 1369 |
for x in $t_min..$t_max { |
| 1370 |
for y in $t_min..$t_max { |
| 1371 |
for z in $t_min..$t_max { |
| 1372 |
for w in $t_min..$t_max { |
| 1373 |
for rhs in $rhs_min..$rhs_max { |
| 1374 |
assert_eq!( |
| 1375 |
$vec4::new(x, y, z, w) << rhs, |
| 1376 |
$vec4::new(x << rhs, y << rhs, z << rhs, w << rhs) |
| 1377 |
); |
| 1378 |
assert_eq!( |
| 1379 |
$vec4::new(x, y, z, w) >> rhs, |
| 1380 |
$vec4::new(x >> rhs, y >> rhs, z >> rhs, w >> rhs) |
| 1381 |
); |
| 1382 |
} |
| 1383 |
} |
| 1384 |
} |
| 1385 |
} |
| 1386 |
} |
| 1387 |
}); |
| 1388 |
}; |
| 1389 |
} |
| 1390 |
|
| 1391 |
macro_rules! impl_vec4_scalar_shift_op_tests { |
| 1392 |
($vec4:ident, $t_min:literal, $t_max:literal) => { |
| 1393 |
mod shift_by_i8 { |
| 1394 |
use glam::$vec4; |
| 1395 |
impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0i8, 2); |
| 1396 |
} |
| 1397 |
mod shift_by_i16 { |
| 1398 |
use glam::$vec4; |
| 1399 |
impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0i16, 2); |
| 1400 |
} |
| 1401 |
mod shift_by_i32 { |
| 1402 |
use glam::$vec4; |
| 1403 |
impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0i32, 2); |
| 1404 |
} |
| 1405 |
mod shift_by_i64 { |
| 1406 |
use glam::$vec4; |
| 1407 |
impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0i64, 2); |
| 1408 |
} |
| 1409 |
mod shift_by_u8 { |
| 1410 |
use glam::$vec4; |
| 1411 |
impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0u8, 2); |
| 1412 |
} |
| 1413 |
mod shift_by_u16 { |
| 1414 |
use glam::$vec4; |
| 1415 |
impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0u16, 2); |
| 1416 |
} |
| 1417 |
mod shift_by_u32 { |
| 1418 |
use glam::$vec4; |
| 1419 |
impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0u32, 2); |
| 1420 |
} |
| 1421 |
mod shift_by_u64 { |
| 1422 |
use glam::$vec4; |
| 1423 |
impl_vec4_scalar_shift_op_test!($vec4, $t_min, $t_max, 0u64, 2); |
| 1424 |
} |
| 1425 |
}; |
| 1426 |
} |
| 1427 |
|
| 1428 |
macro_rules! impl_vec4_shift_op_test { |
| 1429 |
($vec4:ident, $rhs:ident, $t_min:literal, $t_max:literal) => { |
| 1430 |
glam_test!(test_vec4_shift_ops, { |
| 1431 |
for x1 in $t_min..$t_max { |
| 1432 |
for y1 in $t_min..$t_max { |
| 1433 |
for z1 in $t_min..$t_max { |
| 1434 |
for w1 in $t_min..$t_max { |
| 1435 |
for x2 in $t_min..$t_max { |
| 1436 |
for y2 in $t_min..$t_max { |
| 1437 |
for z2 in $t_min..$t_max { |
| 1438 |
for w2 in $t_min..$t_max { |
| 1439 |
assert_eq!( |
| 1440 |
$vec4::new(x1, y1, z1, w1) |
| 1441 |
<< $rhs::new(x2, y2, z2, w2), |
| 1442 |
$vec4::new(x1 << x2, y1 << y2, z1 << z2, w1 << w2) |
| 1443 |
); |
| 1444 |
assert_eq!( |
| 1445 |
$vec4::new(x1, y1, z1, w1) |
| 1446 |
>> $rhs::new(x2, y2, z2, w2), |
| 1447 |
$vec4::new(x1 >> x2, y1 >> y2, z1 >> z2, w1 >> w2) |
| 1448 |
); |
| 1449 |
} |
| 1450 |
} |
| 1451 |
} |
| 1452 |
} |
| 1453 |
} |
| 1454 |
} |
| 1455 |
} |
| 1456 |
} |
| 1457 |
}); |
| 1458 |
}; |
| 1459 |
} |
| 1460 |
|
| 1461 |
macro_rules! impl_vec4_shift_op_tests { |
| 1462 |
($vec4:ident) => { |
| 1463 |
mod shift_ivec4_by_ivec4 { |
| 1464 |
use super::*; |
| 1465 |
impl_vec4_shift_op_test!($vec4, IVec4, 0, 2); |
| 1466 |
} |
| 1467 |
mod shift_ivec4_by_uvec4 { |
| 1468 |
use super::*; |
| 1469 |
impl_vec4_shift_op_test!($vec4, UVec4, 0, 2); |
| 1470 |
} |
| 1471 |
}; |
| 1472 |
} |
| 1473 |
|
| 1474 |
macro_rules! impl_vec4_scalar_bit_op_tests { |
| 1475 |
($vec4:ident, $t_min:literal, $t_max:literal) => { |
| 1476 |
glam_test!(test_vec4_scalar_bit_ops, { |
| 1477 |
for x in $t_min..$t_max { |
| 1478 |
for y in $t_min..$t_max { |
| 1479 |
for z in $t_min..$t_max { |
| 1480 |
for w in $t_min..$t_max { |
| 1481 |
for rhs in $t_min..$t_max { |
| 1482 |
assert_eq!( |
| 1483 |
$vec4::new(x, y, z, w) & rhs, |
| 1484 |
$vec4::new(x & rhs, y & rhs, z & rhs, w & rhs) |
| 1485 |
); |
| 1486 |
assert_eq!( |
| 1487 |
$vec4::new(x, y, z, w) | rhs, |
| 1488 |
$vec4::new(x | rhs, y | rhs, z | rhs, w | rhs) |
| 1489 |
); |
| 1490 |
assert_eq!( |
| 1491 |
$vec4::new(x, y, z, w) ^ rhs, |
| 1492 |
$vec4::new(x ^ rhs, y ^ rhs, z ^ rhs, w ^ rhs) |
| 1493 |
); |
| 1494 |
} |
| 1495 |
} |
| 1496 |
} |
| 1497 |
} |
| 1498 |
} |
| 1499 |
}); |
| 1500 |
}; |
| 1501 |
} |
| 1502 |
|
| 1503 |
macro_rules! impl_vec4_bit_op_tests { |
| 1504 |
($vec4:ident, $t_min:literal, $t_max:literal) => { |
| 1505 |
glam_test!(test_vec4_bit_ops, { |
| 1506 |
for x1 in $t_min..$t_max { |
| 1507 |
for y1 in $t_min..$t_max { |
| 1508 |
for z1 in $t_min..$t_max { |
| 1509 |
for w1 in $t_min..$t_max { |
| 1510 |
assert_eq!(!$vec4::new(x1, y1, z1, w1), $vec4::new(!x1, !y1, !z1, !w1)); |
| 1511 |
|
| 1512 |
for x2 in $t_min..$t_max { |
| 1513 |
for y2 in $t_min..$t_max { |
| 1514 |
for z2 in $t_min..$t_max { |
| 1515 |
for w2 in $t_min..$t_max { |
| 1516 |
assert_eq!( |
| 1517 |
$vec4::new(x1, y1, z1, w1) |
| 1518 |
& $vec4::new(x2, y2, z2, w2), |
| 1519 |
$vec4::new(x1 & x2, y1 & y2, z1 & z2, w1 & w2) |
| 1520 |
); |
| 1521 |
assert_eq!( |
| 1522 |
$vec4::new(x1, y1, z1, w1) |
| 1523 |
| $vec4::new(x2, y2, z2, w2), |
| 1524 |
$vec4::new(x1 | x2, y1 | y2, z1 | z2, w1 | w2) |
| 1525 |
); |
| 1526 |
assert_eq!( |
| 1527 |
$vec4::new(x1, y1, z1, w1) |
| 1528 |
^ $vec4::new(x2, y2, z2, w2), |
| 1529 |
$vec4::new(x1 ^ x2, y1 ^ y2, z1 ^ z2, w1 ^ w2) |
| 1530 |
); |
| 1531 |
} |
| 1532 |
} |
| 1533 |
} |
| 1534 |
} |
| 1535 |
} |
| 1536 |
} |
| 1537 |
} |
| 1538 |
} |
| 1539 |
}); |
| 1540 |
}; |
| 1541 |
} |
| 1542 |
|
| 1543 |
mod vec4 { |
| 1544 |
#[cfg(feature = "scalar-math")] |
| 1545 |
use glam::{bvec4, BVec4}; |
| 1546 |
#[cfg(not(feature = "scalar-math"))] |
| 1547 |
use glam::{bvec4a, BVec4A}; |
| 1548 |
use glam::{vec4, Vec2, Vec3, Vec4}; |
| 1549 |
|
| 1550 |
glam_test!(test_align, { |
| 1551 |
use std::mem; |
| 1552 |
assert_eq!(16, mem::size_of::<Vec4>()); |
| 1553 |
if cfg!(any(not(feature = "scalar-math"), feature = "cuda")) { |
| 1554 |
assert_eq!(16, mem::align_of::<Vec4>()); |
| 1555 |
} else { |
| 1556 |
assert_eq!(4, mem::align_of::<Vec4>()); |
| 1557 |
} |
| 1558 |
#[cfg(not(feature = "scalar-math"))] |
| 1559 |
{ |
| 1560 |
assert_eq!(16, mem::size_of::<BVec4A>()); |
| 1561 |
assert_eq!(16, mem::align_of::<BVec4A>()); |
| 1562 |
} |
| 1563 |
#[cfg(feature = "scalar-math")] |
| 1564 |
{ |
| 1565 |
assert_eq!(4, mem::size_of::<BVec4>()); |
| 1566 |
assert_eq!(1, mem::align_of::<BVec4>()); |
| 1567 |
} |
| 1568 |
}); |
| 1569 |
|
| 1570 |
#[cfg(all( |
| 1571 |
target_feature = "sse2", |
| 1572 |
not(any(feature = "core-simd", feature = "scalar-math")) |
| 1573 |
))] |
| 1574 |
#[test] |
| 1575 |
fn test_m128() { |
| 1576 |
#[cfg(target_arch = "x86")] |
| 1577 |
use core::arch::x86::*; |
| 1578 |
#[cfg(target_arch = "x86_64")] |
| 1579 |
use core::arch::x86_64::*; |
| 1580 |
|
| 1581 |
#[repr(C, align(16))] |
| 1582 |
struct F32x4_A16([f32; 4]); |
| 1583 |
|
| 1584 |
let v0 = Vec4::new(1.0, 2.0, 3.0, 4.0); |
| 1585 |
let m0: __m128 = v0.into(); |
| 1586 |
let mut a0 = F32x4_A16([0.0, 0.0, 0.0, 0.0]); |
| 1587 |
unsafe { |
| 1588 |
_mm_store_ps(a0.0.as_mut_ptr(), m0); |
| 1589 |
} |
| 1590 |
assert_eq!([1.0, 2.0, 3.0, 4.0], a0.0); |
| 1591 |
let v1 = Vec4::from(m0); |
| 1592 |
assert_eq!(v0, v1); |
| 1593 |
|
| 1594 |
#[repr(C, align(16))] |
| 1595 |
struct U32x4_A16([u32; 4]); |
| 1596 |
|
| 1597 |
let v0 = BVec4A::new(true, false, true, false); |
| 1598 |
let m0: __m128 = v0.into(); |
| 1599 |
let mut a0 = U32x4_A16([1, 2, 3, 4]); |
| 1600 |
unsafe { |
| 1601 |
_mm_store_ps(a0.0.as_mut_ptr() as *mut f32, m0); |
| 1602 |
} |
| 1603 |
assert_eq!([0xffffffff, 0, 0xffffffff, 0], a0.0); |
| 1604 |
} |
| 1605 |
|
| 1606 |
glam_test!(test_as, { |
| 1607 |
use glam::{DVec4, I16Vec4, I64Vec4, I8Vec4, IVec4, U16Vec4, U64Vec4, U8Vec4, UVec4, Vec4}; |
| 1608 |
assert_eq!( |
| 1609 |
DVec4::new(-1.0, -2.0, -3.0, -4.0), |
| 1610 |
Vec4::new(-1.0, -2.0, -3.0, -4.0).as_dvec4() |
| 1611 |
); |
| 1612 |
assert_eq!( |
| 1613 |
I8Vec4::new(-1, -2, -3, -4), |
| 1614 |
Vec4::new(-1.0, -2.0, -3.0, -4.0).as_i8vec4() |
| 1615 |
); |
| 1616 |
assert_eq!( |
| 1617 |
U8Vec4::new(1, 2, 3, 4), |
| 1618 |
Vec4::new(1.0, 2.0, 3.0, 4.0).as_u8vec4() |
| 1619 |
); |
| 1620 |
assert_eq!( |
| 1621 |
I16Vec4::new(-1, -2, -3, -4), |
| 1622 |
Vec4::new(-1.0, -2.0, -3.0, -4.0).as_i16vec4() |
| 1623 |
); |
| 1624 |
assert_eq!( |
| 1625 |
U16Vec4::new(1, 2, 3, 4), |
| 1626 |
Vec4::new(1.0, 2.0, 3.0, 4.0).as_u16vec4() |
| 1627 |
); |
| 1628 |
assert_eq!( |
| 1629 |
IVec4::new(-1, -2, -3, -4), |
| 1630 |
Vec4::new(-1.0, -2.0, -3.0, -4.0).as_ivec4() |
| 1631 |
); |
| 1632 |
assert_eq!( |
| 1633 |
UVec4::new(1, 2, 3, 4), |
| 1634 |
Vec4::new(1.0, 2.0, 3.0, 4.0).as_uvec4() |
| 1635 |
); |
| 1636 |
assert_eq!( |
| 1637 |
I64Vec4::new(-1, -2, -3, -4), |
| 1638 |
Vec4::new(-1.0, -2.0, -3.0, -4.0).as_i64vec4() |
| 1639 |
); |
| 1640 |
assert_eq!( |
| 1641 |
U64Vec4::new(1, 2, 3, 4), |
| 1642 |
Vec4::new(1.0, 2.0, 3.0, 4.0).as_u64vec4() |
| 1643 |
); |
| 1644 |
|
| 1645 |
assert_eq!( |
| 1646 |
Vec4::new(-1.0, -2.0, -3.0, -4.0), |
| 1647 |
DVec4::new(-1.0, -2.0, -3.0, -4.0).as_vec4() |
| 1648 |
); |
| 1649 |
assert_eq!( |
| 1650 |
I8Vec4::new(-1, -2, -3, -4), |
| 1651 |
DVec4::new(-1.0, -2.0, -3.0, -4.0).as_i8vec4() |
| 1652 |
); |
| 1653 |
assert_eq!( |
| 1654 |
U8Vec4::new(1, 2, 3, 4), |
| 1655 |
DVec4::new(1.0, 2.0, 3.0, 4.0).as_u8vec4() |
| 1656 |
); |
| 1657 |
assert_eq!( |
| 1658 |
I16Vec4::new(-1, -2, -3, -4), |
| 1659 |
DVec4::new(-1.0, -2.0, -3.0, -4.0).as_i16vec4() |
| 1660 |
); |
| 1661 |
assert_eq!( |
| 1662 |
U16Vec4::new(1, 2, 3, 4), |
| 1663 |
DVec4::new(1.0, 2.0, 3.0, 4.0).as_u16vec4() |
| 1664 |
); |
| 1665 |
assert_eq!( |
| 1666 |
IVec4::new(-1, -2, -3, -4), |
| 1667 |
DVec4::new(-1.0, -2.0, -3.0, -4.0).as_ivec4() |
| 1668 |
); |
| 1669 |
assert_eq!( |
| 1670 |
UVec4::new(1, 2, 3, 4), |
| 1671 |
DVec4::new(1.0, 2.0, 3.0, 4.0).as_uvec4() |
| 1672 |
); |
| 1673 |
assert_eq!( |
| 1674 |
I64Vec4::new(-1, -2, -3, -4), |
| 1675 |
DVec4::new(-1.0, -2.0, -3.0, -4.0).as_i64vec4() |
| 1676 |
); |
| 1677 |
assert_eq!( |
| 1678 |
U64Vec4::new(1, 2, 3, 4), |
| 1679 |
DVec4::new(1.0, 2.0, 3.0, 4.0).as_u64vec4() |
| 1680 |
); |
| 1681 |
|
| 1682 |
assert_eq!( |
| 1683 |
Vec4::new(-1.0, -2.0, -3.0, -4.0), |
| 1684 |
I8Vec4::new(-1, -2, -3, -4).as_vec4() |
| 1685 |
); |
| 1686 |
assert_eq!( |
| 1687 |
DVec4::new(-1.0, -2.0, -3.0, -4.0), |
| 1688 |
I8Vec4::new(-1, -2, -3, -4).as_dvec4() |
| 1689 |
); |
| 1690 |
assert_eq!(U8Vec4::new(1, 2, 3, 4), I8Vec4::new(1, 2, 3, 4).as_u8vec4()); |
| 1691 |
assert_eq!( |
| 1692 |
I16Vec4::new(-1, -2, -3, -4), |
| 1693 |
I8Vec4::new(-1, -2, -3, -4).as_i16vec4() |
| 1694 |
); |
| 1695 |
assert_eq!( |
| 1696 |
U16Vec4::new(1, 2, 3, 4), |
| 1697 |
I8Vec4::new(1, 2, 3, 4).as_u16vec4() |
| 1698 |
); |
| 1699 |
assert_eq!( |
| 1700 |
IVec4::new(-1, -2, -3, -4), |
| 1701 |
I8Vec4::new(-1, -2, -3, -4).as_ivec4() |
| 1702 |
); |
| 1703 |
assert_eq!(UVec4::new(1, 2, 3, 4), I8Vec4::new(1, 2, 3, 4).as_uvec4()); |
| 1704 |
assert_eq!( |
| 1705 |
I64Vec4::new(-1, -2, -3, -4), |
| 1706 |
I8Vec4::new(-1, -2, -3, -4).as_i64vec4() |
| 1707 |
); |
| 1708 |
assert_eq!( |
| 1709 |
U64Vec4::new(1, 2, 3, 4), |
| 1710 |
I8Vec4::new(1, 2, 3, 4).as_u64vec4() |
| 1711 |
); |
| 1712 |
|
| 1713 |
assert_eq!( |
| 1714 |
Vec4::new(1.0, 2.0, 3.0, 4.0), |
| 1715 |
U8Vec4::new(1, 2, 3, 4).as_vec4() |
| 1716 |
); |
| 1717 |
assert_eq!( |
| 1718 |
DVec4::new(1.0, 2.0, 3.0, 4.0), |
| 1719 |
U8Vec4::new(1, 2, 3, 4).as_dvec4() |
| 1720 |
); |
| 1721 |
assert_eq!(I8Vec4::new(1, 2, 3, 4), U8Vec4::new(1, 2, 3, 4).as_i8vec4()); |
| 1722 |
assert_eq!( |
| 1723 |
I16Vec4::new(1, 2, 3, 4), |
| 1724 |
U8Vec4::new(1, 2, 3, 4).as_i16vec4() |
| 1725 |
); |
| 1726 |
assert_eq!( |
| 1727 |
U16Vec4::new(1, 2, 3, 4), |
| 1728 |
U8Vec4::new(1, 2, 3, 4).as_u16vec4() |
| 1729 |
); |
| 1730 |
assert_eq!(IVec4::new(1, 2, 3, 4), U8Vec4::new(1, 2, 3, 4).as_ivec4()); |
| 1731 |
assert_eq!(UVec4::new(1, 2, 3, 4), U8Vec4::new(1, 2, 3, 4).as_uvec4()); |
| 1732 |
assert_eq!( |
| 1733 |
I64Vec4::new(1, 2, 3, 4), |
| 1734 |
U8Vec4::new(1, 2, 3, 4).as_i64vec4() |
| 1735 |
); |
| 1736 |
assert_eq!( |
| 1737 |
U64Vec4::new(1, 2, 3, 4), |
| 1738 |
U8Vec4::new(1, 2, 3, 4).as_u64vec4() |
| 1739 |
); |
| 1740 |
|
| 1741 |
assert_eq!( |
| 1742 |
Vec4::new(-1.0, -2.0, -3.0, -4.0), |
| 1743 |
I16Vec4::new(-1, -2, -3, -4).as_vec4() |
| 1744 |
); |
| 1745 |
assert_eq!( |
| 1746 |
DVec4::new(-1.0, -2.0, -3.0, -4.0), |
| 1747 |
I16Vec4::new(-1, -2, -3, -4).as_dvec4() |
| 1748 |
); |
| 1749 |
assert_eq!( |
| 1750 |
I8Vec4::new(-1, -2, -3, -4), |
| 1751 |
I16Vec4::new(-1, -2, -3, -4).as_i8vec4() |
| 1752 |
); |
| 1753 |
assert_eq!( |
| 1754 |
U8Vec4::new(1, 2, 3, 4), |
| 1755 |
I16Vec4::new(1, 2, 3, 4).as_u8vec4() |
| 1756 |
); |
| 1757 |
assert_eq!( |
| 1758 |
U16Vec4::new(1, 2, 3, 4), |
| 1759 |
I16Vec4::new(1, 2, 3, 4).as_u16vec4() |
| 1760 |
); |
| 1761 |
assert_eq!( |
| 1762 |
IVec4::new(-1, -2, -3, -4), |
| 1763 |
I16Vec4::new(-1, -2, -3, -4).as_ivec4() |
| 1764 |
); |
| 1765 |
assert_eq!(UVec4::new(1, 2, 3, 4), I16Vec4::new(1, 2, 3, 4).as_uvec4()); |
| 1766 |
assert_eq!( |
| 1767 |
I64Vec4::new(-1, -2, -3, -4), |
| 1768 |
I16Vec4::new(-1, -2, -3, -4).as_i64vec4() |
| 1769 |
); |
| 1770 |
assert_eq!( |
| 1771 |
U64Vec4::new(1, 2, 3, 4), |
| 1772 |
I16Vec4::new(1, 2, 3, 4).as_u64vec4() |
| 1773 |
); |
| 1774 |
|
| 1775 |
assert_eq!( |
| 1776 |
Vec4::new(1.0, 2.0, 3.0, 4.0), |
| 1777 |
U16Vec4::new(1, 2, 3, 4).as_vec4() |
| 1778 |
); |
| 1779 |
assert_eq!( |
| 1780 |
DVec4::new(1.0, 2.0, 3.0, 4.0), |
| 1781 |
U16Vec4::new(1, 2, 3, 4).as_dvec4() |
| 1782 |
); |
| 1783 |
assert_eq!( |
| 1784 |
I8Vec4::new(1, 2, 3, 4), |
| 1785 |
U16Vec4::new(1, 2, 3, 4).as_i8vec4() |
| 1786 |
); |
| 1787 |
assert_eq!( |
| 1788 |
U8Vec4::new(1, 2, 3, 4), |
| 1789 |
U16Vec4::new(1, 2, 3, 4).as_u8vec4() |
| 1790 |
); |
| 1791 |
assert_eq!( |
| 1792 |
I16Vec4::new(1, 2, 3, 4), |
| 1793 |
U16Vec4::new(1, 2, 3, 4).as_i16vec4() |
| 1794 |
); |
| 1795 |
assert_eq!(IVec4::new(1, 2, 3, 4), U16Vec4::new(1, 2, 3, 4).as_ivec4()); |
| 1796 |
assert_eq!(UVec4::new(1, 2, 3, 4), U16Vec4::new(1, 2, 3, 4).as_uvec4()); |
| 1797 |
assert_eq!( |
| 1798 |
I64Vec4::new(1, 2, 3, 4), |
| 1799 |
U16Vec4::new(1, 2, 3, 4).as_i64vec4() |
| 1800 |
); |
| 1801 |
assert_eq!( |
| 1802 |
U64Vec4::new(1, 2, 3, 4), |
| 1803 |
U16Vec4::new(1, 2, 3, 4).as_u64vec4() |
| 1804 |
); |
| 1805 |
|
| 1806 |
assert_eq!( |
| 1807 |
Vec4::new(-1.0, -2.0, -3.0, -4.0), |
| 1808 |
IVec4::new(-1, -2, -3, -4).as_vec4() |
| 1809 |
); |
| 1810 |
assert_eq!( |
| 1811 |
DVec4::new(-1.0, -2.0, -3.0, -4.0), |
| 1812 |
IVec4::new(-1, -2, -3, -4).as_dvec4() |
| 1813 |
); |
| 1814 |
assert_eq!( |
| 1815 |
I8Vec4::new(-1, -2, -3, -4), |
| 1816 |
IVec4::new(-1, -2, -3, -4).as_i8vec4() |
| 1817 |
); |
| 1818 |
assert_eq!(U8Vec4::new(1, 2, 3, 4), IVec4::new(1, 2, 3, 4).as_u8vec4()); |
| 1819 |
assert_eq!(UVec4::new(1, 2, 3, 4), IVec4::new(1, 2, 3, 4).as_uvec4()); |
| 1820 |
assert_eq!( |
| 1821 |
I16Vec4::new(-1, -2, -3, -4), |
| 1822 |
IVec4::new(-1, -2, -3, -4).as_i16vec4() |
| 1823 |
); |
| 1824 |
assert_eq!( |
| 1825 |
U16Vec4::new(1, 2, 3, 4), |
| 1826 |
IVec4::new(1, 2, 3, 4).as_u16vec4() |
| 1827 |
); |
| 1828 |
assert_eq!( |
| 1829 |
I64Vec4::new(-1, -2, -3, -4), |
| 1830 |
IVec4::new(-1, -2, -3, -4).as_i64vec4() |
| 1831 |
); |
| 1832 |
assert_eq!( |
| 1833 |
U64Vec4::new(1, 2, 3, 4), |
| 1834 |
IVec4::new(1, 2, 3, 4).as_u64vec4() |
| 1835 |
); |
| 1836 |
|
| 1837 |
assert_eq!( |
| 1838 |
Vec4::new(1.0, 2.0, 3.0, 4.0), |
| 1839 |
UVec4::new(1, 2, 3, 4).as_vec4() |
| 1840 |
); |
| 1841 |
assert_eq!( |
| 1842 |
DVec4::new(1.0, 2.0, 3.0, 4.0), |
| 1843 |
UVec4::new(1, 2, 3, 4).as_dvec4() |
| 1844 |
); |
| 1845 |
assert_eq!(I8Vec4::new(1, 2, 3, 4), UVec4::new(1, 2, 3, 4).as_i8vec4()); |
| 1846 |
assert_eq!(U8Vec4::new(1, 2, 3, 4), UVec4::new(1, 2, 3, 4).as_u8vec4()); |
| 1847 |
assert_eq!( |
| 1848 |
I16Vec4::new(1, 2, 3, 4), |
| 1849 |
UVec4::new(1, 2, 3, 4).as_i16vec4() |
| 1850 |
); |
| 1851 |
assert_eq!( |
| 1852 |
U16Vec4::new(1, 2, 3, 4), |
| 1853 |
UVec4::new(1, 2, 3, 4).as_u16vec4() |
| 1854 |
); |
| 1855 |
assert_eq!(IVec4::new(1, 2, 3, 4), UVec4::new(1, 2, 3, 4).as_ivec4()); |
| 1856 |
assert_eq!( |
| 1857 |
I64Vec4::new(1, 2, 3, 4), |
| 1858 |
UVec4::new(1, 2, 3, 4).as_i64vec4() |
| 1859 |
); |
| 1860 |
assert_eq!( |
| 1861 |
U64Vec4::new(1, 2, 3, 4), |
| 1862 |
UVec4::new(1, 2, 3, 4).as_u64vec4() |
| 1863 |
); |
| 1864 |
|
| 1865 |
assert_eq!( |
| 1866 |
Vec4::new(-1.0, -2.0, -3.0, -4.0), |
| 1867 |
I64Vec4::new(-1, -2, -3, -4).as_vec4() |
| 1868 |
); |
| 1869 |
assert_eq!( |
| 1870 |
DVec4::new(-1.0, -2.0, -3.0, -4.0), |
| 1871 |
I64Vec4::new(-1, -2, -3, -4).as_dvec4() |
| 1872 |
); |
| 1873 |
assert_eq!( |
| 1874 |
U8Vec4::new(1, 2, 3, 4), |
| 1875 |
I64Vec4::new(1, 2, 3, 4).as_u8vec4() |
| 1876 |
); |
| 1877 |
assert_eq!( |
| 1878 |
I8Vec4::new(-1, -2, -3, -4), |
| 1879 |
I64Vec4::new(-1, -2, -3, -4).as_i8vec4() |
| 1880 |
); |
| 1881 |
assert_eq!( |
| 1882 |
U16Vec4::new(1, 2, 3, 4), |
| 1883 |
I64Vec4::new(1, 2, 3, 4).as_u16vec4() |
| 1884 |
); |
| 1885 |
assert_eq!( |
| 1886 |
I16Vec4::new(-1, -2, -3, -4), |
| 1887 |
I64Vec4::new(-1, -2, -3, -4).as_i16vec4() |
| 1888 |
); |
| 1889 |
assert_eq!(UVec4::new(1, 2, 3, 4), I64Vec4::new(1, 2, 3, 4).as_uvec4()); |
| 1890 |
assert_eq!( |
| 1891 |
IVec4::new(-1, -2, -3, -4), |
| 1892 |
I64Vec4::new(-1, -2, -3, -4).as_ivec4() |
| 1893 |
); |
| 1894 |
assert_eq!( |
| 1895 |
U64Vec4::new(1, 2, 3, 4), |
| 1896 |
I64Vec4::new(1, 2, 3, 4).as_u64vec4() |
| 1897 |
); |
| 1898 |
|
| 1899 |
assert_eq!( |
| 1900 |
Vec4::new(1.0, 2.0, 3.0, 4.0), |
| 1901 |
U64Vec4::new(1, 2, 3, 4).as_vec4() |
| 1902 |
); |
| 1903 |
assert_eq!( |
| 1904 |
DVec4::new(1.0, 2.0, 3.0, 4.0), |
| 1905 |
U64Vec4::new(1, 2, 3, 4).as_dvec4() |
| 1906 |
); |
| 1907 |
assert_eq!( |
| 1908 |
I8Vec4::new(1, 2, 3, 4), |
| 1909 |
U64Vec4::new(1, 2, 3, 4).as_i8vec4() |
| 1910 |
); |
| 1911 |
assert_eq!( |
| 1912 |
U8Vec4::new(1, 2, 3, 4), |
| 1913 |
U64Vec4::new(1, 2, 3, 4).as_u8vec4() |
| 1914 |
); |
| 1915 |
assert_eq!( |
| 1916 |
I16Vec4::new(1, 2, 3, 4), |
| 1917 |
U64Vec4::new(1, 2, 3, 4).as_i16vec4() |
| 1918 |
); |
| 1919 |
assert_eq!( |
| 1920 |
U16Vec4::new(1, 2, 3, 4), |
| 1921 |
U64Vec4::new(1, 2, 3, 4).as_u16vec4() |
| 1922 |
); |
| 1923 |
assert_eq!(IVec4::new(1, 2, 3, 4), U64Vec4::new(1, 2, 3, 4).as_ivec4()); |
| 1924 |
assert_eq!(UVec4::new(1, 2, 3, 4), U64Vec4::new(1, 2, 3, 4).as_uvec4()); |
| 1925 |
assert_eq!( |
| 1926 |
I64Vec4::new(1, 2, 3, 4), |
| 1927 |
U64Vec4::new(1, 2, 3, 4).as_i64vec4() |
| 1928 |
); |
| 1929 |
}); |
| 1930 |
|
| 1931 |
glam_test!(test_vec3a, { |
| 1932 |
use glam::Vec3A; |
| 1933 |
assert_eq!( |
| 1934 |
Vec4::new(1.0, 2.0, 3.0, 4.0), |
| 1935 |
Vec4::from((Vec3A::new(1.0, 2.0, 3.0), 4.0)) |
| 1936 |
); |
| 1937 |
assert_eq!( |
| 1938 |
Vec4::new(1.0, 2.0, 3.0, 4.0), |
| 1939 |
Vec4::from((1.0, Vec3A::new(2.0, 3.0, 4.0))) |
| 1940 |
); |
| 1941 |
}); |
| 1942 |
|
| 1943 |
#[cfg(not(feature = "scalar-math"))] |
| 1944 |
impl_vec4_float_tests!(f32, vec4, Vec4, Vec3, Vec2, BVec4A, bvec4a); |
| 1945 |
|
| 1946 |
#[cfg(feature = "scalar-math")] |
| 1947 |
impl_vec4_float_tests!(f32, vec4, Vec4, Vec3, Vec2, BVec4, bvec4); |
| 1948 |
} |
| 1949 |
|
| 1950 |
mod dvec4 { |
| 1951 |
use glam::{bvec4, dvec4, BVec4, DVec2, DVec3, DVec4, IVec4, UVec4, Vec4}; |
| 1952 |
|
| 1953 |
glam_test!(test_align, { |
| 1954 |
use std::mem; |
| 1955 |
assert_eq!(32, mem::size_of::<DVec4>()); |
| 1956 |
#[cfg(not(feature = "cuda"))] |
| 1957 |
assert_eq!(mem::align_of::<f64>(), mem::align_of::<DVec4>()); |
| 1958 |
#[cfg(feature = "cuda")] |
| 1959 |
assert_eq!(16, mem::align_of::<DVec4>()); |
| 1960 |
assert_eq!(4, mem::size_of::<BVec4>()); |
| 1961 |
assert_eq!(1, mem::align_of::<BVec4>()); |
| 1962 |
}); |
| 1963 |
|
| 1964 |
glam_test!(test_try_from, { |
| 1965 |
assert_eq!( |
| 1966 |
DVec4::new(1.0, 2.0, 3.0, 4.0), |
| 1967 |
DVec4::from(Vec4::new(1.0, 2.0, 3.0, 4.0)) |
| 1968 |
); |
| 1969 |
assert_eq!( |
| 1970 |
DVec4::new(1.0, 2.0, 3.0, 4.0), |
| 1971 |
DVec4::from(IVec4::new(1, 2, 3, 4)) |
| 1972 |
); |
| 1973 |
assert_eq!( |
| 1974 |
DVec4::new(1.0, 2.0, 3.0, 4.0), |
| 1975 |
DVec4::from(UVec4::new(1, 2, 3, 4)) |
| 1976 |
); |
| 1977 |
}); |
| 1978 |
|
| 1979 |
impl_vec4_float_tests!(f64, dvec4, DVec4, DVec3, DVec2, BVec4, bvec4); |
| 1980 |
} |
| 1981 |
|
| 1982 |
mod i8vec4 { |
| 1983 |
use glam::{ |
| 1984 |
bvec4, i8vec4, BVec4, I16Vec4, I64Vec4, I8Vec2, I8Vec3, I8Vec4, IVec4, U16Vec4, U64Vec4, |
| 1985 |
U8Vec4, UVec4, |
| 1986 |
}; |
| 1987 |
|
| 1988 |
glam_test!(test_align, { |
| 1989 |
use std::mem; |
| 1990 |
assert_eq!(4, mem::size_of::<I8Vec4>()); |
| 1991 |
#[cfg(not(feature = "cuda"))] |
| 1992 |
assert_eq!(1, mem::align_of::<I8Vec4>()); |
| 1993 |
#[cfg(feature = "cuda")] |
| 1994 |
assert_eq!(4, mem::align_of::<I8Vec4>()); |
| 1995 |
}); |
| 1996 |
|
| 1997 |
glam_test!(test_try_from, { |
| 1998 |
assert_eq!( |
| 1999 |
I8Vec4::new(1, 2, 3, 4), |
| 2000 |
I8Vec4::try_from(U8Vec4::new(1, 2, 3, 4)).unwrap() |
| 2001 |
); |
| 2002 |
assert!(I8Vec4::try_from(U8Vec4::new(u8::MAX, 2, 3, 4)).is_err()); |
| 2003 |
assert!(I8Vec4::try_from(U8Vec4::new(1, u8::MAX, 3, 4)).is_err()); |
| 2004 |
assert!(I8Vec4::try_from(U8Vec4::new(1, 2, u8::MAX, 4)).is_err()); |
| 2005 |
assert!(I8Vec4::try_from(U8Vec4::new(1, 2, 3, u8::MAX)).is_err()); |
| 2006 |
|
| 2007 |
assert_eq!( |
| 2008 |
I8Vec4::new(1, 2, 3, 4), |
| 2009 |
I8Vec4::try_from(I16Vec4::new(1, 2, 3, 4)).unwrap() |
| 2010 |
); |
| 2011 |
assert!(I8Vec4::try_from(I16Vec4::new(i16::MAX, 2, 3, 4)).is_err()); |
| 2012 |
assert!(I8Vec4::try_from(I16Vec4::new(1, i16::MAX, 3, 4)).is_err()); |
| 2013 |
assert!(I8Vec4::try_from(I16Vec4::new(1, 2, i16::MAX, 4)).is_err()); |
| 2014 |
assert!(I8Vec4::try_from(I16Vec4::new(1, 2, 3, i16::MAX)).is_err()); |
| 2015 |
|
| 2016 |
assert_eq!( |
| 2017 |
I8Vec4::new(1, 2, 3, 4), |
| 2018 |
I8Vec4::try_from(U16Vec4::new(1, 2, 3, 4)).unwrap() |
| 2019 |
); |
| 2020 |
assert!(I8Vec4::try_from(U16Vec4::new(u16::MAX, 2, 3, 4)).is_err()); |
| 2021 |
assert!(I8Vec4::try_from(U16Vec4::new(1, u16::MAX, 3, 4)).is_err()); |
| 2022 |
assert!(I8Vec4::try_from(U16Vec4::new(1, 2, u16::MAX, 4)).is_err()); |
| 2023 |
assert!(I8Vec4::try_from(U16Vec4::new(1, 2, 3, u16::MAX)).is_err()); |
| 2024 |
|
| 2025 |
assert_eq!( |
| 2026 |
I8Vec4::new(1, 2, 3, 4), |
| 2027 |
I8Vec4::try_from(IVec4::new(1, 2, 3, 4)).unwrap() |
| 2028 |
); |
| 2029 |
assert!(I8Vec4::try_from(IVec4::new(i32::MAX, 2, 3, 4)).is_err()); |
| 2030 |
assert!(I8Vec4::try_from(IVec4::new(1, i32::MAX, 3, 4)).is_err()); |
| 2031 |
assert!(I8Vec4::try_from(IVec4::new(1, 2, i32::MAX, 4)).is_err()); |
| 2032 |
assert!(I8Vec4::try_from(IVec4::new(1, 2, 3, i32::MAX)).is_err()); |
| 2033 |
|
| 2034 |
assert_eq!( |
| 2035 |
I8Vec4::new(1, 2, 3, 4), |
| 2036 |
I8Vec4::try_from(UVec4::new(1, 2, 3, 4)).unwrap() |
| 2037 |
); |
| 2038 |
assert!(I8Vec4::try_from(UVec4::new(u32::MAX, 2, 3, 4)).is_err()); |
| 2039 |
assert!(I8Vec4::try_from(UVec4::new(1, u32::MAX, 3, 4)).is_err()); |
| 2040 |
assert!(I8Vec4::try_from(UVec4::new(1, 2, u32::MAX, 4)).is_err()); |
| 2041 |
assert!(I8Vec4::try_from(UVec4::new(1, 2, 3, u32::MAX)).is_err()); |
| 2042 |
|
| 2043 |
assert_eq!( |
| 2044 |
I8Vec4::new(1, 2, 3, 4), |
| 2045 |
I8Vec4::try_from(I64Vec4::new(1, 2, 3, 4)).unwrap() |
| 2046 |
); |
| 2047 |
assert!(I8Vec4::try_from(I64Vec4::new(i64::MAX, 2, 3, 4)).is_err()); |
| 2048 |
assert!(I8Vec4::try_from(I64Vec4::new(1, i64::MAX, 3, 4)).is_err()); |
| 2049 |
assert!(I8Vec4::try_from(I64Vec4::new(1, 2, i64::MAX, 4)).is_err()); |
| 2050 |
assert!(I8Vec4::try_from(I64Vec4::new(1, 2, 3, i64::MAX)).is_err()); |
| 2051 |
|
| 2052 |
assert_eq!( |
| 2053 |
I8Vec4::new(1, 2, 3, 4), |
| 2054 |
I8Vec4::try_from(U64Vec4::new(1, 2, 3, 4)).unwrap() |
| 2055 |
); |
| 2056 |
assert!(I8Vec4::try_from(U64Vec4::new(u64::MAX, 2, 3, 4)).is_err()); |
| 2057 |
assert!(I8Vec4::try_from(U64Vec4::new(1, u64::MAX, 3, 4)).is_err()); |
| 2058 |
assert!(I8Vec4::try_from(U64Vec4::new(1, 2, u64::MAX, 4)).is_err()); |
| 2059 |
assert!(I8Vec4::try_from(U64Vec4::new(1, 2, 3, u64::MAX)).is_err()); |
| 2060 |
}); |
| 2061 |
|
| 2062 |
glam_test!(test_wrapping_add, { |
| 2063 |
assert_eq!( |
| 2064 |
I8Vec4::new(i8::MAX, 5, i8::MIN, 0).wrapping_add(I8Vec4::new(1, 3, i8::MAX, 0)), |
| 2065 |
I8Vec4::new(i8::MIN, 8, -1, 0), |
| 2066 |
); |
| 2067 |
}); |
| 2068 |
|
| 2069 |
glam_test!(test_wrapping_sub, { |
| 2070 |
assert_eq!( |
| 2071 |
I8Vec4::new(i8::MAX, 5, i8::MIN, 0).wrapping_sub(I8Vec4::new(1, 3, i8::MAX, 0)), |
| 2072 |
I8Vec4::new(126, 2, 1, 0) |
| 2073 |
); |
| 2074 |
}); |
| 2075 |
|
| 2076 |
glam_test!(test_wrapping_mul, { |
| 2077 |
assert_eq!( |
| 2078 |
I8Vec4::new(i8::MAX, 5, i8::MIN, 0).wrapping_mul(I8Vec4::new(3, 3, 5, 1)), |
| 2079 |
I8Vec4::new(125, 15, -128, 0) |
| 2080 |
); |
| 2081 |
}); |
| 2082 |
|
| 2083 |
glam_test!(test_wrapping_div, { |
| 2084 |
assert_eq!( |
| 2085 |
I8Vec4::new(i8::MAX, 5, i8::MIN, 0).wrapping_div(I8Vec4::new(3, 3, 5, 1)), |
| 2086 |
I8Vec4::new(42, 1, -25, 0) |
| 2087 |
); |
| 2088 |
}); |
| 2089 |
|
| 2090 |
glam_test!(test_saturating_add, { |
| 2091 |
assert_eq!( |
| 2092 |
I8Vec4::new(i8::MAX, i8::MIN, 0, 0).saturating_add(I8Vec4::new(1, -1, 2, 3)), |
| 2093 |
I8Vec4::new(i8::MAX, i8::MIN, 2, 3) |
| 2094 |
); |
| 2095 |
}); |
| 2096 |
|
| 2097 |
glam_test!(test_saturating_sub, { |
| 2098 |
assert_eq!( |
| 2099 |
I8Vec4::new(i8::MIN, i8::MAX, 0, 0).saturating_sub(I8Vec4::new(1, -1, 2, 3)), |
| 2100 |
I8Vec4::new(i8::MIN, i8::MAX, -2, -3) |
| 2101 |
); |
| 2102 |
}); |
| 2103 |
|
| 2104 |
glam_test!(test_saturating_mul, { |
| 2105 |
assert_eq!( |
| 2106 |
I8Vec4::new(i8::MAX, i8::MIN, 0, 0).saturating_mul(I8Vec4::new(2, 2, 0, 0)), |
| 2107 |
I8Vec4::new(i8::MAX, i8::MIN, 0, 0) |
| 2108 |
); |
| 2109 |
}); |
| 2110 |
|
| 2111 |
glam_test!(test_saturating_div, { |
| 2112 |
assert_eq!( |
| 2113 |
I8Vec4::new(i8::MAX, i8::MIN, 0, 0).saturating_div(I8Vec4::new(2, 2, 3, 4)), |
| 2114 |
I8Vec4::new(63, -64, 0, 0) |
| 2115 |
); |
| 2116 |
}); |
| 2117 |
|
| 2118 |
glam_test!(test_wrapping_add_unsigned, { |
| 2119 |
assert_eq!( |
| 2120 |
I8Vec4::new(i8::MAX, i8::MAX, i8::MAX, i8::MAX) |
| 2121 |
.wrapping_add_unsigned(U8Vec4::new(1, 1, 1, 1)), |
| 2122 |
I8Vec4::new(i8::MIN, i8::MIN, i8::MIN, i8::MIN) |
| 2123 |
); |
| 2124 |
}); |
| 2125 |
|
| 2126 |
glam_test!(test_wrapping_sub_unsigned, { |
| 2127 |
assert_eq!( |
| 2128 |
I8Vec4::new(i8::MIN, i8::MIN, i8::MIN, i8::MIN) |
| 2129 |
.wrapping_sub_unsigned(U8Vec4::new(1, 1, 1, 1)), |
| 2130 |
I8Vec4::new(i8::MAX, i8::MAX, i8::MAX, i8::MAX) |
| 2131 |
); |
| 2132 |
}); |
| 2133 |
|
| 2134 |
glam_test!(test_saturating_add_unsigned, { |
| 2135 |
assert_eq!( |
| 2136 |
I8Vec4::new(i8::MAX, i8::MAX, i8::MAX, i8::MAX) |
| 2137 |
.saturating_add_unsigned(U8Vec4::new(1, 1, 1, 1)), |
| 2138 |
I8Vec4::new(i8::MAX, i8::MAX, i8::MAX, i8::MAX) |
| 2139 |
); |
| 2140 |
}); |
| 2141 |
|
| 2142 |
glam_test!(test_saturating_sub_unsigned, { |
| 2143 |
assert_eq!( |
| 2144 |
I8Vec4::new(i8::MIN, i8::MIN, i8::MIN, i8::MIN) |
| 2145 |
.saturating_sub_unsigned(U8Vec4::new(1, 1, 1, 1)), |
| 2146 |
I8Vec4::new(i8::MIN, i8::MIN, i8::MIN, i8::MIN) |
| 2147 |
); |
| 2148 |
}); |
| 2149 |
|
| 2150 |
impl_vec4_signed_integer_tests!(i8, i8vec4, I8Vec4, I8Vec3, I8Vec2, BVec4, bvec4); |
| 2151 |
impl_vec4_eq_hash_tests!(i8, i8vec4); |
| 2152 |
|
| 2153 |
impl_vec4_scalar_shift_op_tests!(I8Vec4, -2, 2); |
| 2154 |
impl_vec4_shift_op_tests!(I8Vec4); |
| 2155 |
|
| 2156 |
impl_vec4_scalar_bit_op_tests!(I8Vec4, -2, 2); |
| 2157 |
impl_vec4_bit_op_tests!(I8Vec4, -2, 2); |
| 2158 |
} |
| 2159 |
|
| 2160 |
mod u8vec4 { |
| 2161 |
use glam::{ |
| 2162 |
bvec4, u8vec4, BVec4, I16Vec4, I64Vec4, I8Vec4, IVec4, U16Vec4, U64Vec4, U8Vec2, U8Vec3, |
| 2163 |
U8Vec4, UVec4, |
| 2164 |
}; |
| 2165 |
|
| 2166 |
glam_test!(test_align, { |
| 2167 |
use std::mem; |
| 2168 |
assert_eq!(4, mem::size_of::<U8Vec4>()); |
| 2169 |
#[cfg(not(feature = "cuda"))] |
| 2170 |
assert_eq!(1, mem::align_of::<U8Vec4>()); |
| 2171 |
#[cfg(feature = "cuda")] |
| 2172 |
assert_eq!(4, mem::align_of::<U8Vec4>()); |
| 2173 |
}); |
| 2174 |
|
| 2175 |
glam_test!(test_try_from, { |
| 2176 |
assert_eq!( |
| 2177 |
U8Vec4::new(1, 2, 3, 4), |
| 2178 |
U8Vec4::try_from(I8Vec4::new(1, 2, 3, 4)).unwrap() |
| 2179 |
); |
| 2180 |
assert!(U8Vec4::try_from(I8Vec4::new(-1, 2, 3, 4)).is_err()); |
| 2181 |
assert!(U8Vec4::try_from(I8Vec4::new(1, -2, 3, 4)).is_err()); |
| 2182 |
assert!(U8Vec4::try_from(I8Vec4::new(1, 2, -3, 4)).is_err()); |
| 2183 |
assert!(U8Vec4::try_from(I8Vec4::new(1, 2, 3, -4)).is_err()); |
| 2184 |
|
| 2185 |
assert_eq!( |
| 2186 |
U8Vec4::new(1, 2, 3, 4), |
| 2187 |
U8Vec4::try_from(I16Vec4::new(1, 2, 3, 4)).unwrap() |
| 2188 |
); |
| 2189 |
assert!(U8Vec4::try_from(I16Vec4::new(-1, 2, 3, 4)).is_err()); |
| 2190 |
assert!(U8Vec4::try_from(I16Vec4::new(1, -2, 3, 4)).is_err()); |
| 2191 |
assert!(U8Vec4::try_from(I16Vec4::new(1, 2, -3, 4)).is_err()); |
| 2192 |
assert!(U8Vec4::try_from(I16Vec4::new(1, 2, 3, -4)).is_err()); |
| 2193 |
|
| 2194 |
assert!(U8Vec4::try_from(I16Vec4::new(i16::MAX, 2, 3, 4)).is_err()); |
| 2195 |
assert!(U8Vec4::try_from(I16Vec4::new(1, i16::MAX, 3, 4)).is_err()); |
| 2196 |
assert!(U8Vec4::try_from(I16Vec4::new(1, 2, i16::MAX, 4)).is_err()); |
| 2197 |
assert!(U8Vec4::try_from(I16Vec4::new(1, 2, 3, i16::MAX)).is_err()); |
| 2198 |
|
| 2199 |
assert_eq!( |
| 2200 |
U8Vec4::new(1, 2, 3, 4), |
| 2201 |
U8Vec4::try_from(U16Vec4::new(1, 2, 3, 4)).unwrap() |
| 2202 |
); |
| 2203 |
assert!(U8Vec4::try_from(U16Vec4::new(u16::MAX, 2, 3, 4)).is_err()); |
| 2204 |
assert!(U8Vec4::try_from(U16Vec4::new(1, u16::MAX, 3, 4)).is_err()); |
| 2205 |
assert!(U8Vec4::try_from(U16Vec4::new(1, 2, u16::MAX, 4)).is_err()); |
| 2206 |
assert!(U8Vec4::try_from(U16Vec4::new(1, 2, 3, u16::MAX)).is_err()); |
| 2207 |
|
| 2208 |
assert_eq!( |
| 2209 |
U8Vec4::new(1, 2, 3, 4), |
| 2210 |
U8Vec4::try_from(IVec4::new(1, 2, 3, 4)).unwrap() |
| 2211 |
); |
| 2212 |
assert!(U8Vec4::try_from(IVec4::new(-1, 2, 3, 4)).is_err()); |
| 2213 |
assert!(U8Vec4::try_from(IVec4::new(1, -2, 3, 4)).is_err()); |
| 2214 |
assert!(U8Vec4::try_from(IVec4::new(1, 2, -3, 4)).is_err()); |
| 2215 |
assert!(U8Vec4::try_from(IVec4::new(1, 2, 3, -4)).is_err()); |
| 2216 |
|
| 2217 |
assert!(U8Vec4::try_from(IVec4::new(i32::MAX, 2, 3, 4)).is_err()); |
| 2218 |
assert!(U8Vec4::try_from(IVec4::new(1, i32::MAX, 3, 4)).is_err()); |
| 2219 |
assert!(U8Vec4::try_from(IVec4::new(1, 2, i32::MAX, 4)).is_err()); |
| 2220 |
assert!(U8Vec4::try_from(IVec4::new(1, 2, 3, i32::MAX)).is_err()); |
| 2221 |
|
| 2222 |
assert_eq!( |
| 2223 |
U8Vec4::new(1, 2, 3, 4), |
| 2224 |
U8Vec4::try_from(UVec4::new(1, 2, 3, 4)).unwrap() |
| 2225 |
); |
| 2226 |
assert!(U8Vec4::try_from(UVec4::new(u32::MAX, 2, 3, 4)).is_err()); |
| 2227 |
assert!(U8Vec4::try_from(UVec4::new(1, u32::MAX, 3, 4)).is_err()); |
| 2228 |
assert!(U8Vec4::try_from(UVec4::new(1, 2, u32::MAX, 4)).is_err()); |
| 2229 |
assert!(U8Vec4::try_from(UVec4::new(1, 2, 3, u32::MAX)).is_err()); |
| 2230 |
|
| 2231 |
assert_eq!( |
| 2232 |
U8Vec4::new(1, 2, 3, 4), |
| 2233 |
U8Vec4::try_from(I64Vec4::new(1, 2, 3, 4)).unwrap() |
| 2234 |
); |
| 2235 |
assert!(U8Vec4::try_from(I64Vec4::new(-1, 2, 3, 4)).is_err()); |
| 2236 |
assert!(U8Vec4::try_from(I64Vec4::new(1, -2, 3, 4)).is_err()); |
| 2237 |
assert!(U8Vec4::try_from(I64Vec4::new(1, 2, -3, 4)).is_err()); |
| 2238 |
assert!(U8Vec4::try_from(I64Vec4::new(1, 2, 3, -4)).is_err()); |
| 2239 |
|
| 2240 |
assert!(U8Vec4::try_from(I64Vec4::new(i64::MAX, 2, 3, 4)).is_err()); |
| 2241 |
assert!(U8Vec4::try_from(I64Vec4::new(1, i64::MAX, 3, 4)).is_err()); |
| 2242 |
assert!(U8Vec4::try_from(I64Vec4::new(1, 2, i64::MAX, 4)).is_err()); |
| 2243 |
assert!(U8Vec4::try_from(I64Vec4::new(1, 2, 3, i64::MAX)).is_err()); |
| 2244 |
|
| 2245 |
assert_eq!( |
| 2246 |
U8Vec4::new(1, 2, 3, 4), |
| 2247 |
U8Vec4::try_from(U64Vec4::new(1, 2, 3, 4)).unwrap() |
| 2248 |
); |
| 2249 |
assert!(U8Vec4::try_from(U64Vec4::new(u64::MAX, 2, 3, 4)).is_err()); |
| 2250 |
assert!(U8Vec4::try_from(U64Vec4::new(1, u64::MAX, 3, 4)).is_err()); |
| 2251 |
assert!(U8Vec4::try_from(U64Vec4::new(1, 2, u64::MAX, 4)).is_err()); |
| 2252 |
assert!(U8Vec4::try_from(U64Vec4::new(1, 2, 3, u64::MAX)).is_err()); |
| 2253 |
}); |
| 2254 |
|
| 2255 |
glam_test!(test_wrapping_add, { |
| 2256 |
assert_eq!( |
| 2257 |
U8Vec4::new(u8::MAX, 5, u8::MAX, 0).wrapping_add(U8Vec4::new(1, 3, u8::MAX, 0)), |
| 2258 |
U8Vec4::new(0, 8, 254, 0), |
| 2259 |
); |
| 2260 |
}); |
| 2261 |
|
| 2262 |
glam_test!(test_wrapping_sub, { |
| 2263 |
assert_eq!( |
| 2264 |
U8Vec4::new(u8::MAX, 5, u8::MAX - 1, 0).wrapping_sub(U8Vec4::new(1, 3, u8::MAX, 0)), |
| 2265 |
U8Vec4::new(254, 2, 255, 0) |
| 2266 |
); |
| 2267 |
}); |
| 2268 |
|
| 2269 |
glam_test!(test_wrapping_mul, { |
| 2270 |
assert_eq!( |
| 2271 |
U8Vec4::new(u8::MAX, 5, u8::MAX, 0).wrapping_mul(U8Vec4::new(3, 3, 5, 1)), |
| 2272 |
U8Vec4::new(253, 15, 251, 0) |
| 2273 |
); |
| 2274 |
}); |
| 2275 |
|
| 2276 |
glam_test!(test_wrapping_div, { |
| 2277 |
assert_eq!( |
| 2278 |
U8Vec4::new(u8::MAX, 5, u8::MAX, 0).wrapping_div(U8Vec4::new(3, 3, 5, 1)), |
| 2279 |
U8Vec4::new(85, 1, 51, 0) |
| 2280 |
); |
| 2281 |
}); |
| 2282 |
|
| 2283 |
glam_test!(test_saturating_add, { |
| 2284 |
assert_eq!( |
| 2285 |
U8Vec4::new(u8::MAX, u8::MAX, 0, 0).saturating_add(U8Vec4::new(1, u8::MAX, 2, 3)), |
| 2286 |
U8Vec4::new(u8::MAX, u8::MAX, 2, 3) |
| 2287 |
); |
| 2288 |
}); |
| 2289 |
|
| 2290 |
glam_test!(test_saturating_sub, { |
| 2291 |
assert_eq!( |
| 2292 |
U8Vec4::new(0, u8::MAX, 0, 0).saturating_sub(U8Vec4::new(1, 1, 2, 3)), |
| 2293 |
U8Vec4::new(0, 254, 0, 0) |
| 2294 |
); |
| 2295 |
}); |
| 2296 |
|
| 2297 |
glam_test!(test_saturating_mul, { |
| 2298 |
assert_eq!( |
| 2299 |
U8Vec4::new(u8::MAX, u8::MAX, 0, 0).saturating_mul(U8Vec4::new(2, u8::MAX, 0, 0)), |
| 2300 |
U8Vec4::new(u8::MAX, u8::MAX, 0, 0) |
| 2301 |
); |
| 2302 |
}); |
| 2303 |
|
| 2304 |
glam_test!(test_saturating_div, { |
| 2305 |
assert_eq!( |
| 2306 |
U8Vec4::new(u8::MAX, u8::MAX, 0, 0).saturating_div(U8Vec4::new(2, u8::MAX, 3, 4)), |
| 2307 |
U8Vec4::new(127, 1, 0, 0) |
| 2308 |
); |
| 2309 |
}); |
| 2310 |
|
| 2311 |
glam_test!(test_wrapping_add_signed, { |
| 2312 |
assert_eq!( |
| 2313 |
U8Vec4::new(u8::MAX, u8::MAX, u8::MAX, u8::MAX) |
| 2314 |
.wrapping_add_signed(I8Vec4::new(1, 1, 1, 1)), |
| 2315 |
U8Vec4::new(u8::MIN, u8::MIN, u8::MIN, u8::MIN) |
| 2316 |
); |
| 2317 |
}); |
| 2318 |
|
| 2319 |
glam_test!(test_saturating_add_signed, { |
| 2320 |
assert_eq!( |
| 2321 |
U8Vec4::new(u8::MAX, u8::MAX, u8::MAX, u8::MAX) |
| 2322 |
.saturating_add_signed(I8Vec4::new(1, 1, 1, 1)), |
| 2323 |
U8Vec4::new(u8::MAX, u8::MAX, u8::MAX, u8::MAX) |
| 2324 |
); |
| 2325 |
}); |
| 2326 |
|
| 2327 |
impl_vec4_tests!(u8, u8vec4, U8Vec4, U8Vec3, U8Vec2, BVec4, bvec4); |
| 2328 |
impl_vec4_eq_hash_tests!(u8, u8vec4); |
| 2329 |
|
| 2330 |
impl_vec4_scalar_shift_op_tests!(U8Vec4, 0, 2); |
| 2331 |
impl_vec4_shift_op_tests!(U8Vec4); |
| 2332 |
|
| 2333 |
impl_vec4_scalar_bit_op_tests!(U8Vec4, 0, 2); |
| 2334 |
impl_vec4_bit_op_tests!(U8Vec4, 0, 2); |
| 2335 |
} |
| 2336 |
|
| 2337 |
mod i16vec4 { |
| 2338 |
use glam::{ |
| 2339 |
bvec4, i16vec4, BVec4, I16Vec2, I16Vec3, I16Vec4, I64Vec4, I8Vec4, IVec4, U16Vec4, U64Vec4, |
| 2340 |
U8Vec4, UVec4, |
| 2341 |
}; |
| 2342 |
|
| 2343 |
glam_test!(test_align, { |
| 2344 |
use std::mem; |
| 2345 |
assert_eq!(8, mem::size_of::<I16Vec4>()); |
| 2346 |
#[cfg(not(feature = "cuda"))] |
| 2347 |
assert_eq!(2, mem::align_of::<I16Vec4>()); |
| 2348 |
#[cfg(feature = "cuda")] |
| 2349 |
assert_eq!(8, mem::align_of::<I16Vec4>()); |
| 2350 |
}); |
| 2351 |
|
| 2352 |
glam_test!(test_try_from, { |
| 2353 |
assert_eq!( |
| 2354 |
I16Vec4::new(1, 2, 3, 4), |
| 2355 |
I16Vec4::from(U8Vec4::new(1, 2, 3, 4)) |
| 2356 |
); |
| 2357 |
assert_eq!( |
| 2358 |
I16Vec4::new(1, 2, 3, 4), |
| 2359 |
I16Vec4::from(I8Vec4::new(1, 2, 3, 4)) |
| 2360 |
); |
| 2361 |
|
| 2362 |
assert_eq!( |
| 2363 |
I16Vec4::new(1, 2, 3, 4), |
| 2364 |
I16Vec4::try_from(U16Vec4::new(1, 2, 3, 4)).unwrap() |
| 2365 |
); |
| 2366 |
assert!(I16Vec4::try_from(U16Vec4::new(u16::MAX, 2, 3, 4)).is_err()); |
| 2367 |
assert!(I16Vec4::try_from(U16Vec4::new(1, u16::MAX, 3, 4)).is_err()); |
| 2368 |
assert!(I16Vec4::try_from(U16Vec4::new(1, 2, u16::MAX, 4)).is_err()); |
| 2369 |
assert!(I16Vec4::try_from(U16Vec4::new(1, 2, 3, u16::MAX)).is_err()); |
| 2370 |
|
| 2371 |
assert_eq!( |
| 2372 |
I16Vec4::new(1, 2, 3, 4), |
| 2373 |
I16Vec4::try_from(IVec4::new(1, 2, 3, 4)).unwrap() |
| 2374 |
); |
| 2375 |
assert!(I16Vec4::try_from(IVec4::new(i32::MAX, 2, 3, 4)).is_err()); |
| 2376 |
assert!(I16Vec4::try_from(IVec4::new(1, i32::MAX, 3, 4)).is_err()); |
| 2377 |
assert!(I16Vec4::try_from(IVec4::new(1, 2, i32::MAX, 4)).is_err()); |
| 2378 |
assert!(I16Vec4::try_from(IVec4::new(1, 2, 3, i32::MAX)).is_err()); |
| 2379 |
|
| 2380 |
assert_eq!( |
| 2381 |
I16Vec4::new(1, 2, 3, 4), |
| 2382 |
I16Vec4::try_from(UVec4::new(1, 2, 3, 4)).unwrap() |
| 2383 |
); |
| 2384 |
assert!(I16Vec4::try_from(UVec4::new(u32::MAX, 2, 3, 4)).is_err()); |
| 2385 |
assert!(I16Vec4::try_from(UVec4::new(1, u32::MAX, 3, 4)).is_err()); |
| 2386 |
assert!(I16Vec4::try_from(UVec4::new(1, 2, u32::MAX, 4)).is_err()); |
| 2387 |
assert!(I16Vec4::try_from(UVec4::new(1, 2, 3, u32::MAX)).is_err()); |
| 2388 |
|
| 2389 |
assert_eq!( |
| 2390 |
I16Vec4::new(1, 2, 3, 4), |
| 2391 |
I16Vec4::try_from(I64Vec4::new(1, 2, 3, 4)).unwrap() |
| 2392 |
); |
| 2393 |
assert!(I16Vec4::try_from(I64Vec4::new(i64::MAX, 2, 3, 4)).is_err()); |
| 2394 |
assert!(I16Vec4::try_from(I64Vec4::new(1, i64::MAX, 3, 4)).is_err()); |
| 2395 |
assert!(I16Vec4::try_from(I64Vec4::new(1, 2, i64::MAX, 4)).is_err()); |
| 2396 |
assert!(I16Vec4::try_from(I64Vec4::new(1, 2, 3, i64::MAX)).is_err()); |
| 2397 |
|
| 2398 |
assert_eq!( |
| 2399 |
I16Vec4::new(1, 2, 3, 4), |
| 2400 |
I16Vec4::try_from(U64Vec4::new(1, 2, 3, 4)).unwrap() |
| 2401 |
); |
| 2402 |
assert!(I16Vec4::try_from(U64Vec4::new(u64::MAX, 2, 3, 4)).is_err()); |
| 2403 |
assert!(I16Vec4::try_from(U64Vec4::new(1, u64::MAX, 3, 4)).is_err()); |
| 2404 |
assert!(I16Vec4::try_from(U64Vec4::new(1, 2, u64::MAX, 4)).is_err()); |
| 2405 |
assert!(I16Vec4::try_from(U64Vec4::new(1, 2, 3, u64::MAX)).is_err()); |
| 2406 |
}); |
| 2407 |
|
| 2408 |
glam_test!(test_wrapping_add, { |
| 2409 |
assert_eq!( |
| 2410 |
I16Vec4::new(i16::MAX, 5, i16::MIN, 0).wrapping_add(I16Vec4::new(1, 3, i16::MAX, 0)), |
| 2411 |
I16Vec4::new(i16::MIN, 8, -1, 0), |
| 2412 |
); |
| 2413 |
}); |
| 2414 |
|
| 2415 |
glam_test!(test_wrapping_sub, { |
| 2416 |
assert_eq!( |
| 2417 |
I16Vec4::new(i16::MAX, 5, i16::MIN, 0).wrapping_sub(I16Vec4::new(1, 3, i16::MAX, 0)), |
| 2418 |
I16Vec4::new(32766, 2, 1, 0) |
| 2419 |
); |
| 2420 |
}); |
| 2421 |
|
| 2422 |
glam_test!(test_wrapping_mul, { |
| 2423 |
assert_eq!( |
| 2424 |
I16Vec4::new(i16::MAX, 5, i16::MIN, 0).wrapping_mul(I16Vec4::new(3, 3, 5, 1)), |
| 2425 |
I16Vec4::new(32765, 15, -32768, 0) |
| 2426 |
); |
| 2427 |
}); |
| 2428 |
|
| 2429 |
glam_test!(test_wrapping_div, { |
| 2430 |
assert_eq!( |
| 2431 |
I16Vec4::new(i16::MAX, 5, i16::MIN, 0).wrapping_div(I16Vec4::new(3, 3, 5, 1)), |
| 2432 |
I16Vec4::new(10922, 1, -6553, 0) |
| 2433 |
); |
| 2434 |
}); |
| 2435 |
|
| 2436 |
glam_test!(test_saturating_add, { |
| 2437 |
assert_eq!( |
| 2438 |
I16Vec4::new(i16::MAX, i16::MIN, 0, 0).saturating_add(I16Vec4::new(1, -1, 2, 3)), |
| 2439 |
I16Vec4::new(i16::MAX, i16::MIN, 2, 3) |
| 2440 |
); |
| 2441 |
}); |
| 2442 |
|
| 2443 |
glam_test!(test_saturating_sub, { |
| 2444 |
assert_eq!( |
| 2445 |
I16Vec4::new(i16::MIN, i16::MAX, 0, 0).saturating_sub(I16Vec4::new(1, -1, 2, 3)), |
| 2446 |
I16Vec4::new(i16::MIN, i16::MAX, -2, -3) |
| 2447 |
); |
| 2448 |
}); |
| 2449 |
|
| 2450 |
glam_test!(test_saturating_mul, { |
| 2451 |
assert_eq!( |
| 2452 |
I16Vec4::new(i16::MAX, i16::MIN, 0, 0).saturating_mul(I16Vec4::new(2, 2, 0, 0)), |
| 2453 |
I16Vec4::new(i16::MAX, i16::MIN, 0, 0) |
| 2454 |
); |
| 2455 |
}); |
| 2456 |
|
| 2457 |
glam_test!(test_saturating_div, { |
| 2458 |
assert_eq!( |
| 2459 |
I16Vec4::new(i16::MAX, i16::MIN, 0, 0).saturating_div(I16Vec4::new(2, 2, 3, 4)), |
| 2460 |
I16Vec4::new(16383, -16384, 0, 0) |
| 2461 |
); |
| 2462 |
}); |
| 2463 |
|
| 2464 |
glam_test!(test_wrapping_add_unsigned, { |
| 2465 |
assert_eq!( |
| 2466 |
I16Vec4::new(i16::MAX, i16::MAX, i16::MAX, i16::MAX) |
| 2467 |
.wrapping_add_unsigned(U16Vec4::new(1, 1, 1, 1)), |
| 2468 |
I16Vec4::new(i16::MIN, i16::MIN, i16::MIN, i16::MIN) |
| 2469 |
); |
| 2470 |
}); |
| 2471 |
|
| 2472 |
glam_test!(test_wrapping_sub_unsigned, { |
| 2473 |
assert_eq!( |
| 2474 |
I16Vec4::new(i16::MIN, i16::MIN, i16::MIN, i16::MIN) |
| 2475 |
.wrapping_sub_unsigned(U16Vec4::new(1, 1, 1, 1)), |
| 2476 |
I16Vec4::new(i16::MAX, i16::MAX, i16::MAX, i16::MAX) |
| 2477 |
); |
| 2478 |
}); |
| 2479 |
|
| 2480 |
glam_test!(test_saturating_add_unsigned, { |
| 2481 |
assert_eq!( |
| 2482 |
I16Vec4::new(i16::MAX, i16::MAX, i16::MAX, i16::MAX) |
| 2483 |
.saturating_add_unsigned(U16Vec4::new(1, 1, 1, 1)), |
| 2484 |
I16Vec4::new(i16::MAX, i16::MAX, i16::MAX, i16::MAX) |
| 2485 |
); |
| 2486 |
}); |
| 2487 |
|
| 2488 |
glam_test!(test_saturating_sub_unsigned, { |
| 2489 |
assert_eq!( |
| 2490 |
I16Vec4::new(i16::MIN, i16::MIN, i16::MIN, i16::MIN) |
| 2491 |
.saturating_sub_unsigned(U16Vec4::new(1, 1, 1, 1)), |
| 2492 |
I16Vec4::new(i16::MIN, i16::MIN, i16::MIN, i16::MIN) |
| 2493 |
); |
| 2494 |
}); |
| 2495 |
|
| 2496 |
impl_vec4_signed_integer_tests!(i16, i16vec4, I16Vec4, I16Vec3, I16Vec2, BVec4, bvec4); |
| 2497 |
impl_vec4_eq_hash_tests!(i16, i16vec4); |
| 2498 |
|
| 2499 |
impl_vec4_scalar_shift_op_tests!(I16Vec4, -2, 2); |
| 2500 |
impl_vec4_shift_op_tests!(I16Vec4); |
| 2501 |
|
| 2502 |
impl_vec4_scalar_bit_op_tests!(I16Vec4, -2, 2); |
| 2503 |
impl_vec4_bit_op_tests!(I16Vec4, -2, 2); |
| 2504 |
} |
| 2505 |
|
| 2506 |
mod u16vec4 { |
| 2507 |
use glam::{ |
| 2508 |
bvec4, u16vec4, BVec4, I16Vec4, I64Vec4, I8Vec4, IVec4, U16Vec2, U16Vec3, U16Vec4, U64Vec4, |
| 2509 |
U8Vec4, UVec4, |
| 2510 |
}; |
| 2511 |
|
| 2512 |
glam_test!(test_align, { |
| 2513 |
use std::mem; |
| 2514 |
assert_eq!(8, mem::size_of::<U16Vec4>()); |
| 2515 |
#[cfg(not(feature = "cuda"))] |
| 2516 |
assert_eq!(2, mem::align_of::<U16Vec4>()); |
| 2517 |
#[cfg(feature = "cuda")] |
| 2518 |
assert_eq!(8, mem::align_of::<U16Vec4>()); |
| 2519 |
}); |
| 2520 |
|
| 2521 |
glam_test!(test_try_from, { |
| 2522 |
assert_eq!( |
| 2523 |
U16Vec4::new(1, 2, 3, 4), |
| 2524 |
U16Vec4::try_from(I8Vec4::new(1, 2, 3, 4)).unwrap() |
| 2525 |
); |
| 2526 |
assert!(U16Vec4::try_from(I8Vec4::new(-1, 2, 3, 4)).is_err()); |
| 2527 |
assert!(U16Vec4::try_from(I8Vec4::new(1, -2, 3, 4)).is_err()); |
| 2528 |
assert!(U16Vec4::try_from(I8Vec4::new(1, 2, -3, 4)).is_err()); |
| 2529 |
assert!(U16Vec4::try_from(I8Vec4::new(1, 2, 3, -4)).is_err()); |
| 2530 |
|
| 2531 |
assert_eq!( |
| 2532 |
U16Vec4::new(1, 2, 3, 4), |
| 2533 |
U16Vec4::from(U8Vec4::new(1, 2, 3, 4)) |
| 2534 |
); |
| 2535 |
|
| 2536 |
assert_eq!( |
| 2537 |
U16Vec4::new(1, 2, 3, 4), |
| 2538 |
U16Vec4::try_from(I16Vec4::new(1, 2, 3, 4)).unwrap() |
| 2539 |
); |
| 2540 |
assert!(U16Vec4::try_from(I16Vec4::new(-1, 2, 3, 4)).is_err()); |
| 2541 |
assert!(U16Vec4::try_from(I16Vec4::new(1, -2, 3, 4)).is_err()); |
| 2542 |
assert!(U16Vec4::try_from(I16Vec4::new(1, 2, -3, 4)).is_err()); |
| 2543 |
assert!(U16Vec4::try_from(I16Vec4::new(1, 2, 3, -4)).is_err()); |
| 2544 |
|
| 2545 |
assert_eq!( |
| 2546 |
U16Vec4::new(1, 2, 3, 4), |
| 2547 |
U16Vec4::try_from(IVec4::new(1, 2, 3, 4)).unwrap() |
| 2548 |
); |
| 2549 |
assert!(U16Vec4::try_from(IVec4::new(-1, 2, 3, 4)).is_err()); |
| 2550 |
assert!(U16Vec4::try_from(IVec4::new(1, -2, 3, 4)).is_err()); |
| 2551 |
assert!(U16Vec4::try_from(IVec4::new(1, 2, -3, 4)).is_err()); |
| 2552 |
assert!(U16Vec4::try_from(IVec4::new(1, 2, 3, -4)).is_err()); |
| 2553 |
|
| 2554 |
assert!(U16Vec4::try_from(IVec4::new(i32::MAX, 2, 3, 4)).is_err()); |
| 2555 |
assert!(U16Vec4::try_from(IVec4::new(1, i32::MAX, 3, 4)).is_err()); |
| 2556 |
assert!(U16Vec4::try_from(IVec4::new(1, 2, i32::MAX, 4)).is_err()); |
| 2557 |
assert!(U16Vec4::try_from(IVec4::new(1, 2, 3, i32::MAX)).is_err()); |
| 2558 |
|
| 2559 |
assert_eq!( |
| 2560 |
U16Vec4::new(1, 2, 3, 4), |
| 2561 |
U16Vec4::try_from(UVec4::new(1, 2, 3, 4)).unwrap() |
| 2562 |
); |
| 2563 |
assert!(U16Vec4::try_from(UVec4::new(u32::MAX, 2, 3, 4)).is_err()); |
| 2564 |
assert!(U16Vec4::try_from(UVec4::new(1, u32::MAX, 3, 4)).is_err()); |
| 2565 |
assert!(U16Vec4::try_from(UVec4::new(1, 2, u32::MAX, 4)).is_err()); |
| 2566 |
assert!(U16Vec4::try_from(UVec4::new(1, 2, 3, u32::MAX)).is_err()); |
| 2567 |
|
| 2568 |
assert_eq!( |
| 2569 |
U16Vec4::new(1, 2, 3, 4), |
| 2570 |
U16Vec4::try_from(I64Vec4::new(1, 2, 3, 4)).unwrap() |
| 2571 |
); |
| 2572 |
assert!(U16Vec4::try_from(I64Vec4::new(-1, 2, 3, 4)).is_err()); |
| 2573 |
assert!(U16Vec4::try_from(I64Vec4::new(1, -2, 3, 4)).is_err()); |
| 2574 |
assert!(U16Vec4::try_from(I64Vec4::new(1, 2, -3, 4)).is_err()); |
| 2575 |
assert!(U16Vec4::try_from(I64Vec4::new(1, 2, 3, -4)).is_err()); |
| 2576 |
|
| 2577 |
assert!(U16Vec4::try_from(I64Vec4::new(i64::MAX, 2, 3, 4)).is_err()); |
| 2578 |
assert!(U16Vec4::try_from(I64Vec4::new(1, i64::MAX, 3, 4)).is_err()); |
| 2579 |
assert!(U16Vec4::try_from(I64Vec4::new(1, 2, i64::MAX, 4)).is_err()); |
| 2580 |
assert!(U16Vec4::try_from(I64Vec4::new(1, 2, 3, i64::MAX)).is_err()); |
| 2581 |
|
| 2582 |
assert_eq!( |
| 2583 |
U16Vec4::new(1, 2, 3, 4), |
| 2584 |
U16Vec4::try_from(U64Vec4::new(1, 2, 3, 4)).unwrap() |
| 2585 |
); |
| 2586 |
assert!(U16Vec4::try_from(U64Vec4::new(u64::MAX, 2, 3, 4)).is_err()); |
| 2587 |
assert!(U16Vec4::try_from(U64Vec4::new(1, u64::MAX, 3, 4)).is_err()); |
| 2588 |
assert!(U16Vec4::try_from(U64Vec4::new(1, 2, u64::MAX, 4)).is_err()); |
| 2589 |
assert!(U16Vec4::try_from(U64Vec4::new(1, 2, 3, u64::MAX)).is_err()); |
| 2590 |
}); |
| 2591 |
|
| 2592 |
glam_test!(test_wrapping_add, { |
| 2593 |
assert_eq!( |
| 2594 |
U16Vec4::new(u16::MAX, 5, u16::MAX, 0).wrapping_add(U16Vec4::new(1, 3, u16::MAX, 0)), |
| 2595 |
U16Vec4::new(0, 8, 65534, 0), |
| 2596 |
); |
| 2597 |
}); |
| 2598 |
|
| 2599 |
glam_test!(test_wrapping_sub, { |
| 2600 |
assert_eq!( |
| 2601 |
U16Vec4::new(u16::MAX, 5, u16::MAX - 1, 0).wrapping_sub(U16Vec4::new( |
| 2602 |
1, |
| 2603 |
3, |
| 2604 |
u16::MAX, |
| 2605 |
0 |
| 2606 |
)), |
| 2607 |
U16Vec4::new(65534, 2, 65535, 0) |
| 2608 |
); |
| 2609 |
}); |
| 2610 |
|
| 2611 |
glam_test!(test_wrapping_mul, { |
| 2612 |
assert_eq!( |
| 2613 |
U16Vec4::new(u16::MAX, 5, u16::MAX, 0).wrapping_mul(U16Vec4::new(3, 3, 5, 1)), |
| 2614 |
U16Vec4::new(65533, 15, 65531, 0) |
| 2615 |
); |
| 2616 |
}); |
| 2617 |
|
| 2618 |
glam_test!(test_wrapping_div, { |
| 2619 |
assert_eq!( |
| 2620 |
U16Vec4::new(u16::MAX, 5, u16::MAX, 0).wrapping_div(U16Vec4::new(3, 3, 5, 1)), |
| 2621 |
U16Vec4::new(21845, 1, 13107, 0) |
| 2622 |
); |
| 2623 |
}); |
| 2624 |
|
| 2625 |
glam_test!(test_saturating_add, { |
| 2626 |
assert_eq!( |
| 2627 |
U16Vec4::new(u16::MAX, u16::MAX, 0, 0).saturating_add(U16Vec4::new(1, u16::MAX, 2, 3)), |
| 2628 |
U16Vec4::new(u16::MAX, u16::MAX, 2, 3) |
| 2629 |
); |
| 2630 |
}); |
| 2631 |
|
| 2632 |
glam_test!(test_saturating_sub, { |
| 2633 |
assert_eq!( |
| 2634 |
U16Vec4::new(0, u16::MAX, 0, 0).saturating_sub(U16Vec4::new(1, 1, 2, 3)), |
| 2635 |
U16Vec4::new(0, 65534, 0, 0) |
| 2636 |
); |
| 2637 |
}); |
| 2638 |
|
| 2639 |
glam_test!(test_saturating_mul, { |
| 2640 |
assert_eq!( |
| 2641 |
U16Vec4::new(u16::MAX, u16::MAX, 0, 0).saturating_mul(U16Vec4::new(2, u16::MAX, 0, 0)), |
| 2642 |
U16Vec4::new(u16::MAX, u16::MAX, 0, 0) |
| 2643 |
); |
| 2644 |
}); |
| 2645 |
|
| 2646 |
glam_test!(test_saturating_div, { |
| 2647 |
assert_eq!( |
| 2648 |
U16Vec4::new(u16::MAX, u16::MAX, 0, 0).saturating_div(U16Vec4::new(2, u16::MAX, 3, 4)), |
| 2649 |
U16Vec4::new(32767, 1, 0, 0) |
| 2650 |
); |
| 2651 |
}); |
| 2652 |
|
| 2653 |
glam_test!(test_wrapping_add_signed, { |
| 2654 |
assert_eq!( |
| 2655 |
U16Vec4::new(u16::MAX, u16::MAX, u16::MAX, u16::MAX) |
| 2656 |
.wrapping_add_signed(I16Vec4::new(1, 1, 1, 1)), |
| 2657 |
U16Vec4::new(u16::MIN, u16::MIN, u16::MIN, u16::MIN) |
| 2658 |
); |
| 2659 |
}); |
| 2660 |
|
| 2661 |
glam_test!(test_saturating_add_signed, { |
| 2662 |
assert_eq!( |
| 2663 |
U16Vec4::new(u16::MAX, u16::MAX, u16::MAX, u16::MAX) |
| 2664 |
.saturating_add_signed(I16Vec4::new(1, 1, 1, 1)), |
| 2665 |
U16Vec4::new(u16::MAX, u16::MAX, u16::MAX, u16::MAX) |
| 2666 |
); |
| 2667 |
}); |
| 2668 |
|
| 2669 |
impl_vec4_tests!(u16, u16vec4, U16Vec4, U16Vec3, U16Vec2, BVec4, bvec4); |
| 2670 |
impl_vec4_eq_hash_tests!(u16, u16vec4); |
| 2671 |
|
| 2672 |
impl_vec4_scalar_shift_op_tests!(U16Vec4, 0, 2); |
| 2673 |
impl_vec4_shift_op_tests!(U16Vec4); |
| 2674 |
|
| 2675 |
impl_vec4_scalar_bit_op_tests!(U16Vec4, 0, 2); |
| 2676 |
impl_vec4_bit_op_tests!(U16Vec4, 0, 2); |
| 2677 |
} |
| 2678 |
|
| 2679 |
mod ivec4 { |
| 2680 |
use glam::{ |
| 2681 |
bvec4, ivec4, BVec4, I16Vec4, I64Vec4, I8Vec4, IVec2, IVec3, IVec4, U16Vec4, U64Vec4, |
| 2682 |
U8Vec4, UVec4, |
| 2683 |
}; |
| 2684 |
|
| 2685 |
glam_test!(test_align, { |
| 2686 |
use std::mem; |
| 2687 |
assert_eq!(16, mem::size_of::<IVec4>()); |
| 2688 |
#[cfg(not(feature = "cuda"))] |
| 2689 |
assert_eq!(4, mem::align_of::<IVec4>()); |
| 2690 |
#[cfg(feature = "cuda")] |
| 2691 |
assert_eq!(16, mem::align_of::<IVec4>()); |
| 2692 |
assert_eq!(4, mem::size_of::<BVec4>()); |
| 2693 |
assert_eq!(1, mem::align_of::<BVec4>()); |
| 2694 |
}); |
| 2695 |
|
| 2696 |
glam_test!(test_try_from, { |
| 2697 |
assert_eq!(IVec4::new(1, 2, 3, 4), IVec4::from(U8Vec4::new(1, 2, 3, 4))); |
| 2698 |
assert_eq!(IVec4::new(1, 2, 3, 4), IVec4::from(I8Vec4::new(1, 2, 3, 4))); |
| 2699 |
|
| 2700 |
assert_eq!( |
| 2701 |
IVec4::new(1, 2, 3, 4), |
| 2702 |
IVec4::from(U16Vec4::new(1, 2, 3, 4)) |
| 2703 |
); |
| 2704 |
assert_eq!( |
| 2705 |
IVec4::new(1, 2, 3, 4), |
| 2706 |
IVec4::from(I16Vec4::new(1, 2, 3, 4)) |
| 2707 |
); |
| 2708 |
|
| 2709 |
assert_eq!( |
| 2710 |
IVec4::new(1, 2, 3, 4), |
| 2711 |
IVec4::try_from(UVec4::new(1, 2, 3, 4)).unwrap() |
| 2712 |
); |
| 2713 |
assert!(IVec4::try_from(UVec4::new(u32::MAX, 2, 3, 4)).is_err()); |
| 2714 |
assert!(IVec4::try_from(UVec4::new(1, u32::MAX, 3, 4)).is_err()); |
| 2715 |
assert!(IVec4::try_from(UVec4::new(1, 2, u32::MAX, 4)).is_err()); |
| 2716 |
assert!(IVec4::try_from(UVec4::new(1, 2, 3, u32::MAX)).is_err()); |
| 2717 |
|
| 2718 |
assert_eq!( |
| 2719 |
IVec4::new(1, 2, 3, 4), |
| 2720 |
IVec4::try_from(I64Vec4::new(1, 2, 3, 4)).unwrap() |
| 2721 |
); |
| 2722 |
assert!(IVec4::try_from(I64Vec4::new(i64::MAX, 2, 3, 4)).is_err()); |
| 2723 |
assert!(IVec4::try_from(I64Vec4::new(1, i64::MAX, 3, 4)).is_err()); |
| 2724 |
assert!(IVec4::try_from(I64Vec4::new(1, 2, i64::MAX, 4)).is_err()); |
| 2725 |
assert!(IVec4::try_from(I64Vec4::new(1, 2, 3, i64::MAX)).is_err()); |
| 2726 |
|
| 2727 |
assert_eq!( |
| 2728 |
IVec4::new(1, 2, 3, 4), |
| 2729 |
IVec4::try_from(U64Vec4::new(1, 2, 3, 4)).unwrap() |
| 2730 |
); |
| 2731 |
assert!(IVec4::try_from(U64Vec4::new(u64::MAX, 2, 3, 4)).is_err()); |
| 2732 |
assert!(IVec4::try_from(U64Vec4::new(1, u64::MAX, 3, 4)).is_err()); |
| 2733 |
assert!(IVec4::try_from(U64Vec4::new(1, 2, u64::MAX, 4)).is_err()); |
| 2734 |
assert!(IVec4::try_from(U64Vec4::new(1, 2, 3, u64::MAX)).is_err()); |
| 2735 |
}); |
| 2736 |
|
| 2737 |
glam_test!(test_wrapping_add, { |
| 2738 |
assert_eq!( |
| 2739 |
IVec4::new(i32::MAX, 5, i32::MIN, 0).wrapping_add(IVec4::new(1, 3, i32::MAX, 0)), |
| 2740 |
IVec4::new(i32::MIN, 8, -1, 0), |
| 2741 |
); |
| 2742 |
}); |
| 2743 |
|
| 2744 |
glam_test!(test_wrapping_sub, { |
| 2745 |
assert_eq!( |
| 2746 |
IVec4::new(i32::MAX, 5, i32::MIN, 0).wrapping_sub(IVec4::new(1, 3, i32::MAX, 0)), |
| 2747 |
IVec4::new(2147483646, 2, 1, 0) |
| 2748 |
); |
| 2749 |
}); |
| 2750 |
|
| 2751 |
glam_test!(test_wrapping_mul, { |
| 2752 |
assert_eq!( |
| 2753 |
IVec4::new(i32::MAX, 5, i32::MIN, 0).wrapping_mul(IVec4::new(3, 3, 5, 1)), |
| 2754 |
IVec4::new(2147483645, 15, -2147483648, 0) |
| 2755 |
); |
| 2756 |
}); |
| 2757 |
|
| 2758 |
glam_test!(test_wrapping_div, { |
| 2759 |
assert_eq!( |
| 2760 |
IVec4::new(i32::MAX, 5, i32::MIN, 0).wrapping_div(IVec4::new(3, 3, 5, 1)), |
| 2761 |
IVec4::new(715827882, 1, -429496729, 0) |
| 2762 |
); |
| 2763 |
}); |
| 2764 |
|
| 2765 |
glam_test!(test_saturating_add, { |
| 2766 |
assert_eq!( |
| 2767 |
IVec4::new(i32::MAX, i32::MIN, 0, 0).saturating_add(IVec4::new(1, -1, 2, 3)), |
| 2768 |
IVec4::new(i32::MAX, i32::MIN, 2, 3) |
| 2769 |
); |
| 2770 |
}); |
| 2771 |
|
| 2772 |
glam_test!(test_saturating_sub, { |
| 2773 |
assert_eq!( |
| 2774 |
IVec4::new(i32::MIN, i32::MAX, 0, 0).saturating_sub(IVec4::new(1, -1, 2, 3)), |
| 2775 |
IVec4::new(i32::MIN, i32::MAX, -2, -3) |
| 2776 |
); |
| 2777 |
}); |
| 2778 |
|
| 2779 |
glam_test!(test_saturating_mul, { |
| 2780 |
assert_eq!( |
| 2781 |
IVec4::new(i32::MAX, i32::MIN, 0, 0).saturating_mul(IVec4::new(2, 2, 0, 0)), |
| 2782 |
IVec4::new(i32::MAX, i32::MIN, 0, 0) |
| 2783 |
); |
| 2784 |
}); |
| 2785 |
|
| 2786 |
glam_test!(test_saturating_div, { |
| 2787 |
assert_eq!( |
| 2788 |
IVec4::new(i32::MAX, i32::MIN, 0, 0).saturating_div(IVec4::new(2, 2, 3, 4)), |
| 2789 |
IVec4::new(1073741823, -1073741824, 0, 0) |
| 2790 |
); |
| 2791 |
}); |
| 2792 |
|
| 2793 |
glam_test!(test_wrapping_add_unsigned, { |
| 2794 |
assert_eq!( |
| 2795 |
IVec4::new(i32::MAX, i32::MAX, i32::MAX, i32::MAX) |
| 2796 |
.wrapping_add_unsigned(UVec4::new(1, 1, 1, 1)), |
| 2797 |
IVec4::new(i32::MIN, i32::MIN, i32::MIN, i32::MIN) |
| 2798 |
); |
| 2799 |
}); |
| 2800 |
|
| 2801 |
glam_test!(test_wrapping_sub_unsigned, { |
| 2802 |
assert_eq!( |
| 2803 |
IVec4::new(i32::MIN, i32::MIN, i32::MIN, i32::MIN) |
| 2804 |
.wrapping_sub_unsigned(UVec4::new(1, 1, 1, 1)), |
| 2805 |
IVec4::new(i32::MAX, i32::MAX, i32::MAX, i32::MAX) |
| 2806 |
); |
| 2807 |
}); |
| 2808 |
|
| 2809 |
glam_test!(test_saturating_add_unsigned, { |
| 2810 |
assert_eq!( |
| 2811 |
IVec4::new(i32::MAX, i32::MAX, i32::MAX, i32::MAX) |
| 2812 |
.saturating_add_unsigned(UVec4::new(1, 1, 1, 1)), |
| 2813 |
IVec4::new(i32::MAX, i32::MAX, i32::MAX, i32::MAX) |
| 2814 |
); |
| 2815 |
}); |
| 2816 |
|
| 2817 |
glam_test!(test_saturating_sub_unsigned, { |
| 2818 |
assert_eq!( |
| 2819 |
IVec4::new(i32::MIN, i32::MIN, i32::MIN, i32::MIN) |
| 2820 |
.saturating_sub_unsigned(UVec4::new(1, 1, 1, 1)), |
| 2821 |
IVec4::new(i32::MIN, i32::MIN, i32::MIN, i32::MIN) |
| 2822 |
); |
| 2823 |
}); |
| 2824 |
|
| 2825 |
impl_vec4_signed_integer_tests!(i32, ivec4, IVec4, IVec3, IVec2, BVec4, bvec4); |
| 2826 |
impl_vec4_eq_hash_tests!(i32, ivec4); |
| 2827 |
|
| 2828 |
impl_vec4_scalar_shift_op_tests!(IVec4, -2, 2); |
| 2829 |
impl_vec4_shift_op_tests!(IVec4); |
| 2830 |
|
| 2831 |
impl_vec4_scalar_bit_op_tests!(IVec4, -2, 2); |
| 2832 |
impl_vec4_bit_op_tests!(IVec4, -2, 2); |
| 2833 |
} |
| 2834 |
|
| 2835 |
mod uvec4 { |
| 2836 |
use glam::{ |
| 2837 |
bvec4, uvec4, BVec4, I16Vec4, I64Vec4, I8Vec4, IVec4, U16Vec4, U64Vec4, U8Vec4, UVec2, |
| 2838 |
UVec3, UVec4, |
| 2839 |
}; |
| 2840 |
|
| 2841 |
glam_test!(test_align, { |
| 2842 |
use std::mem; |
| 2843 |
assert_eq!(16, mem::size_of::<UVec4>()); |
| 2844 |
#[cfg(not(feature = "cuda"))] |
| 2845 |
assert_eq!(4, mem::align_of::<UVec4>()); |
| 2846 |
#[cfg(feature = "cuda")] |
| 2847 |
assert_eq!(16, mem::align_of::<UVec4>()); |
| 2848 |
assert_eq!(4, mem::size_of::<BVec4>()); |
| 2849 |
assert_eq!(1, mem::align_of::<BVec4>()); |
| 2850 |
}); |
| 2851 |
|
| 2852 |
glam_test!(test_try_from, { |
| 2853 |
assert_eq!( |
| 2854 |
UVec4::new(1, 2, 3, 4), |
| 2855 |
UVec4::try_from(I8Vec4::new(1, 2, 3, 4)).unwrap() |
| 2856 |
); |
| 2857 |
assert!(UVec4::try_from(I8Vec4::new(-1, 2, 3, 4)).is_err()); |
| 2858 |
assert!(UVec4::try_from(I8Vec4::new(1, -2, 3, 4)).is_err()); |
| 2859 |
assert!(UVec4::try_from(I8Vec4::new(1, 2, -3, 4)).is_err()); |
| 2860 |
assert!(UVec4::try_from(I8Vec4::new(1, 2, 3, -4)).is_err()); |
| 2861 |
|
| 2862 |
assert_eq!(UVec4::new(1, 2, 3, 4), UVec4::from(U8Vec4::new(1, 2, 3, 4))); |
| 2863 |
|
| 2864 |
assert_eq!( |
| 2865 |
UVec4::new(1, 2, 3, 4), |
| 2866 |
UVec4::try_from(I16Vec4::new(1, 2, 3, 4)).unwrap() |
| 2867 |
); |
| 2868 |
assert!(UVec4::try_from(I16Vec4::new(-1, 2, 3, 4)).is_err()); |
| 2869 |
assert!(UVec4::try_from(I16Vec4::new(1, -2, 3, 4)).is_err()); |
| 2870 |
assert!(UVec4::try_from(I16Vec4::new(1, 2, -3, 4)).is_err()); |
| 2871 |
assert!(UVec4::try_from(I16Vec4::new(1, 2, 3, -4)).is_err()); |
| 2872 |
|
| 2873 |
assert_eq!( |
| 2874 |
UVec4::new(1, 2, 3, 4), |
| 2875 |
UVec4::from(U16Vec4::new(1, 2, 3, 4)) |
| 2876 |
); |
| 2877 |
|
| 2878 |
assert_eq!( |
| 2879 |
UVec4::new(1, 2, 3, 4), |
| 2880 |
UVec4::try_from(IVec4::new(1, 2, 3, 4)).unwrap() |
| 2881 |
); |
| 2882 |
assert!(UVec4::try_from(IVec4::new(-1, 2, 3, 4)).is_err()); |
| 2883 |
assert!(UVec4::try_from(IVec4::new(1, -2, 3, 4)).is_err()); |
| 2884 |
assert!(UVec4::try_from(IVec4::new(1, 2, -3, 4)).is_err()); |
| 2885 |
assert!(UVec4::try_from(IVec4::new(1, 2, 3, -4)).is_err()); |
| 2886 |
|
| 2887 |
assert_eq!( |
| 2888 |
UVec4::new(1, 2, 3, 4), |
| 2889 |
UVec4::try_from(I64Vec4::new(1, 2, 3, 4)).unwrap() |
| 2890 |
); |
| 2891 |
assert!(UVec4::try_from(I64Vec4::new(-1, 2, 3, 4)).is_err()); |
| 2892 |
assert!(UVec4::try_from(I64Vec4::new(1, -2, 3, 4)).is_err()); |
| 2893 |
assert!(UVec4::try_from(I64Vec4::new(1, 2, -3, 4)).is_err()); |
| 2894 |
assert!(UVec4::try_from(I64Vec4::new(1, 2, 3, -4)).is_err()); |
| 2895 |
|
| 2896 |
assert!(UVec4::try_from(I64Vec4::new(i64::MAX, 2, 3, 4)).is_err()); |
| 2897 |
assert!(UVec4::try_from(I64Vec4::new(1, i64::MAX, 3, 4)).is_err()); |
| 2898 |
assert!(UVec4::try_from(I64Vec4::new(1, 2, i64::MAX, 4)).is_err()); |
| 2899 |
assert!(UVec4::try_from(I64Vec4::new(1, 2, 3, i64::MAX)).is_err()); |
| 2900 |
|
| 2901 |
assert_eq!( |
| 2902 |
UVec4::new(1, 2, 3, 4), |
| 2903 |
UVec4::try_from(U64Vec4::new(1, 2, 3, 4)).unwrap() |
| 2904 |
); |
| 2905 |
assert!(UVec4::try_from(U64Vec4::new(u64::MAX, 2, 3, 4)).is_err()); |
| 2906 |
assert!(UVec4::try_from(U64Vec4::new(1, u64::MAX, 3, 4)).is_err()); |
| 2907 |
assert!(UVec4::try_from(U64Vec4::new(1, 2, u64::MAX, 4)).is_err()); |
| 2908 |
assert!(UVec4::try_from(U64Vec4::new(1, 2, 3, u64::MAX)).is_err()); |
| 2909 |
}); |
| 2910 |
|
| 2911 |
glam_test!(test_wrapping_add, { |
| 2912 |
assert_eq!( |
| 2913 |
UVec4::new(u32::MAX, 5, u32::MAX, 0).wrapping_add(UVec4::new(1, 3, u32::MAX, 0)), |
| 2914 |
UVec4::new(0, 8, 4294967294, 0), |
| 2915 |
); |
| 2916 |
}); |
| 2917 |
|
| 2918 |
glam_test!(test_wrapping_sub, { |
| 2919 |
assert_eq!( |
| 2920 |
UVec4::new(u32::MAX, 5, u32::MAX - 1, 0).wrapping_sub(UVec4::new(1, 3, u32::MAX, 0)), |
| 2921 |
UVec4::new(4294967294, 2, 4294967295, 0) |
| 2922 |
); |
| 2923 |
}); |
| 2924 |
|
| 2925 |
glam_test!(test_wrapping_mul, { |
| 2926 |
assert_eq!( |
| 2927 |
UVec4::new(u32::MAX, 5, u32::MAX, 0).wrapping_mul(UVec4::new(3, 3, 5, 1)), |
| 2928 |
UVec4::new(4294967293, 15, 4294967291, 0) |
| 2929 |
); |
| 2930 |
}); |
| 2931 |
|
| 2932 |
glam_test!(test_wrapping_div, { |
| 2933 |
assert_eq!( |
| 2934 |
UVec4::new(u32::MAX, 5, u32::MAX, 0).wrapping_div(UVec4::new(3, 3, 5, 1)), |
| 2935 |
UVec4::new(1431655765, 1, 858993459, 0) |
| 2936 |
); |
| 2937 |
}); |
| 2938 |
|
| 2939 |
glam_test!(test_saturating_add, { |
| 2940 |
assert_eq!( |
| 2941 |
UVec4::new(u32::MAX, u32::MAX, 0, 0).saturating_add(UVec4::new(1, u32::MAX, 2, 3)), |
| 2942 |
UVec4::new(u32::MAX, u32::MAX, 2, 3) |
| 2943 |
); |
| 2944 |
}); |
| 2945 |
|
| 2946 |
glam_test!(test_saturating_sub, { |
| 2947 |
assert_eq!( |
| 2948 |
UVec4::new(0, u32::MAX, 0, 0).saturating_sub(UVec4::new(1, 1, 2, 3)), |
| 2949 |
UVec4::new(0, 4294967294, 0, 0) |
| 2950 |
); |
| 2951 |
}); |
| 2952 |
|
| 2953 |
glam_test!(test_saturating_mul, { |
| 2954 |
assert_eq!( |
| 2955 |
UVec4::new(u32::MAX, u32::MAX, 0, 0).saturating_mul(UVec4::new(2, u32::MAX, 0, 0)), |
| 2956 |
UVec4::new(u32::MAX, u32::MAX, 0, 0) |
| 2957 |
); |
| 2958 |
}); |
| 2959 |
|
| 2960 |
glam_test!(test_saturating_div, { |
| 2961 |
assert_eq!( |
| 2962 |
UVec4::new(u32::MAX, u32::MAX, 0, 0).saturating_div(UVec4::new(2, u32::MAX, 3, 4)), |
| 2963 |
UVec4::new(2147483647, 1, 0, 0) |
| 2964 |
); |
| 2965 |
}); |
| 2966 |
|
| 2967 |
glam_test!(test_wrapping_add_signed, { |
| 2968 |
assert_eq!( |
| 2969 |
UVec4::new(u32::MAX, u32::MAX, u32::MAX, u32::MAX) |
| 2970 |
.wrapping_add_signed(IVec4::new(1, 1, 1, 1)), |
| 2971 |
UVec4::new(u32::MIN, u32::MIN, u32::MIN, u32::MIN) |
| 2972 |
); |
| 2973 |
}); |
| 2974 |
|
| 2975 |
glam_test!(test_saturating_add_signed, { |
| 2976 |
assert_eq!( |
| 2977 |
UVec4::new(u32::MAX, u32::MAX, u32::MAX, u32::MAX) |
| 2978 |
.saturating_add_signed(IVec4::new(1, 1, 1, 1)), |
| 2979 |
UVec4::new(u32::MAX, u32::MAX, u32::MAX, u32::MAX) |
| 2980 |
); |
| 2981 |
}); |
| 2982 |
|
| 2983 |
impl_vec4_tests!(u32, uvec4, UVec4, UVec3, UVec2, BVec4, bvec4); |
| 2984 |
impl_vec4_eq_hash_tests!(u32, uvec4); |
| 2985 |
|
| 2986 |
impl_vec4_scalar_shift_op_tests!(UVec4, 0, 2); |
| 2987 |
impl_vec4_shift_op_tests!(UVec4); |
| 2988 |
|
| 2989 |
impl_vec4_scalar_bit_op_tests!(UVec4, 0, 2); |
| 2990 |
impl_vec4_bit_op_tests!(UVec4, 0, 2); |
| 2991 |
} |
| 2992 |
|
| 2993 |
mod i64vec4 { |
| 2994 |
use glam::{ |
| 2995 |
bvec4, i64vec4, BVec4, I16Vec4, I64Vec2, I64Vec3, I64Vec4, I8Vec4, IVec4, U16Vec4, U64Vec4, |
| 2996 |
U8Vec4, UVec4, |
| 2997 |
}; |
| 2998 |
|
| 2999 |
glam_test!(test_align, { |
| 3000 |
use std::mem; |
| 3001 |
assert_eq!(32, mem::size_of::<I64Vec4>()); |
| 3002 |
#[cfg(not(feature = "cuda"))] |
| 3003 |
assert_eq!(8, mem::align_of::<I64Vec4>()); |
| 3004 |
#[cfg(feature = "cuda")] |
| 3005 |
assert_eq!(16, mem::align_of::<I64Vec4>()); |
| 3006 |
assert_eq!(4, mem::size_of::<BVec4>()); |
| 3007 |
assert_eq!(1, mem::align_of::<BVec4>()); |
| 3008 |
}); |
| 3009 |
|
| 3010 |
glam_test!(test_try_from, { |
| 3011 |
assert_eq!( |
| 3012 |
I64Vec4::new(1, 2, 3, 4), |
| 3013 |
I64Vec4::from(I8Vec4::new(1, 2, 3, 4)) |
| 3014 |
); |
| 3015 |
assert_eq!( |
| 3016 |
I64Vec4::new(1, 2, 3, 4), |
| 3017 |
I64Vec4::from(U8Vec4::new(1, 2, 3, 4)) |
| 3018 |
); |
| 3019 |
assert_eq!( |
| 3020 |
I64Vec4::new(1, 2, 3, 4), |
| 3021 |
I64Vec4::from(I16Vec4::new(1, 2, 3, 4)) |
| 3022 |
); |
| 3023 |
assert_eq!( |
| 3024 |
I64Vec4::new(1, 2, 3, 4), |
| 3025 |
I64Vec4::from(U16Vec4::new(1, 2, 3, 4)) |
| 3026 |
); |
| 3027 |
assert_eq!( |
| 3028 |
I64Vec4::new(1, 2, 3, 4), |
| 3029 |
I64Vec4::from(IVec4::new(1, 2, 3, 4)) |
| 3030 |
); |
| 3031 |
assert_eq!( |
| 3032 |
I64Vec4::new(1, 2, 3, 4), |
| 3033 |
I64Vec4::from(UVec4::new(1, 2, 3, 4)) |
| 3034 |
); |
| 3035 |
|
| 3036 |
assert_eq!( |
| 3037 |
I64Vec4::new(1, 2, 3, 4), |
| 3038 |
I64Vec4::try_from(U64Vec4::new(1, 2, 3, 4)).unwrap() |
| 3039 |
); |
| 3040 |
assert!(I64Vec4::try_from(U64Vec4::new(u64::MAX, 2, 3, 4)).is_err()); |
| 3041 |
assert!(I64Vec4::try_from(U64Vec4::new(1, u64::MAX, 3, 4)).is_err()); |
| 3042 |
assert!(I64Vec4::try_from(U64Vec4::new(1, 2, u64::MAX, 4)).is_err()); |
| 3043 |
assert!(I64Vec4::try_from(U64Vec4::new(1, 2, 3, u64::MAX)).is_err()); |
| 3044 |
}); |
| 3045 |
|
| 3046 |
glam_test!(test_wrapping_add_unsigned, { |
| 3047 |
assert_eq!( |
| 3048 |
I64Vec4::new(i64::MAX, i64::MAX, i64::MAX, i64::MAX) |
| 3049 |
.wrapping_add_unsigned(U64Vec4::new(1, 1, 1, 1)), |
| 3050 |
I64Vec4::new(i64::MIN, i64::MIN, i64::MIN, i64::MIN) |
| 3051 |
); |
| 3052 |
}); |
| 3053 |
|
| 3054 |
glam_test!(test_wrapping_sub_unsigned, { |
| 3055 |
assert_eq!( |
| 3056 |
I64Vec4::new(i64::MIN, i64::MIN, i64::MIN, i64::MIN) |
| 3057 |
.wrapping_sub_unsigned(U64Vec4::new(1, 1, 1, 1)), |
| 3058 |
I64Vec4::new(i64::MAX, i64::MAX, i64::MAX, i64::MAX) |
| 3059 |
); |
| 3060 |
}); |
| 3061 |
|
| 3062 |
glam_test!(test_saturating_add_unsigned, { |
| 3063 |
assert_eq!( |
| 3064 |
I64Vec4::new(i64::MAX, i64::MAX, i64::MAX, i64::MAX) |
| 3065 |
.saturating_add_unsigned(U64Vec4::new(1, 1, 1, 1)), |
| 3066 |
I64Vec4::new(i64::MAX, i64::MAX, i64::MAX, i64::MAX) |
| 3067 |
); |
| 3068 |
}); |
| 3069 |
|
| 3070 |
glam_test!(test_saturating_sub_unsigned, { |
| 3071 |
assert_eq!( |
| 3072 |
I64Vec4::new(i64::MIN, i64::MIN, i64::MIN, i64::MIN) |
| 3073 |
.saturating_sub_unsigned(U64Vec4::new(1, 1, 1, 1)), |
| 3074 |
I64Vec4::new(i64::MIN, i64::MIN, i64::MIN, i64::MIN) |
| 3075 |
); |
| 3076 |
}); |
| 3077 |
|
| 3078 |
impl_vec4_signed_integer_tests!(i64, i64vec4, I64Vec4, I64Vec3, I64Vec2, BVec4, bvec4); |
| 3079 |
impl_vec4_eq_hash_tests!(i64, i64vec4); |
| 3080 |
|
| 3081 |
impl_vec4_scalar_shift_op_tests!(I64Vec4, -2, 2); |
| 3082 |
impl_vec4_shift_op_tests!(I64Vec4); |
| 3083 |
|
| 3084 |
impl_vec4_scalar_bit_op_tests!(I64Vec4, -2, 2); |
| 3085 |
impl_vec4_bit_op_tests!(I64Vec4, -2, 2); |
| 3086 |
} |
| 3087 |
|
| 3088 |
mod u64vec4 { |
| 3089 |
use glam::{ |
| 3090 |
bvec4, u64vec4, BVec4, I16Vec4, I64Vec4, I8Vec4, IVec4, U16Vec4, U64Vec2, U64Vec3, U64Vec4, |
| 3091 |
U8Vec4, UVec4, |
| 3092 |
}; |
| 3093 |
|
| 3094 |
glam_test!(test_align, { |
| 3095 |
use std::mem; |
| 3096 |
assert_eq!(32, mem::size_of::<U64Vec4>()); |
| 3097 |
#[cfg(not(feature = "cuda"))] |
| 3098 |
assert_eq!(8, mem::align_of::<U64Vec4>()); |
| 3099 |
#[cfg(feature = "cuda")] |
| 3100 |
assert_eq!(16, mem::align_of::<U64Vec4>()); |
| 3101 |
assert_eq!(4, mem::size_of::<BVec4>()); |
| 3102 |
assert_eq!(1, mem::align_of::<BVec4>()); |
| 3103 |
}); |
| 3104 |
|
| 3105 |
glam_test!(test_try_from, { |
| 3106 |
assert_eq!( |
| 3107 |
U64Vec4::new(1, 2, 3, 4), |
| 3108 |
U64Vec4::try_from(I8Vec4::new(1, 2, 3, 4)).unwrap() |
| 3109 |
); |
| 3110 |
assert!(U64Vec4::try_from(I8Vec4::new(-1, 2, 3, 4)).is_err()); |
| 3111 |
assert!(U64Vec4::try_from(I8Vec4::new(1, -2, 3, 4)).is_err()); |
| 3112 |
assert!(U64Vec4::try_from(I8Vec4::new(1, 2, -3, 4)).is_err()); |
| 3113 |
assert!(U64Vec4::try_from(I8Vec4::new(1, 2, 3, -4)).is_err()); |
| 3114 |
|
| 3115 |
assert_eq!( |
| 3116 |
U64Vec4::new(1, 2, 3, 4), |
| 3117 |
U64Vec4::from(U8Vec4::new(1, 2, 3, 4)) |
| 3118 |
); |
| 3119 |
|
| 3120 |
assert_eq!( |
| 3121 |
U64Vec4::new(1, 2, 3, 4), |
| 3122 |
U64Vec4::try_from(I16Vec4::new(1, 2, 3, 4)).unwrap() |
| 3123 |
); |
| 3124 |
assert!(U64Vec4::try_from(I16Vec4::new(-1, 2, 3, 4)).is_err()); |
| 3125 |
assert!(U64Vec4::try_from(I16Vec4::new(1, -2, 3, 4)).is_err()); |
| 3126 |
assert!(U64Vec4::try_from(I16Vec4::new(1, 2, -3, 4)).is_err()); |
| 3127 |
assert!(U64Vec4::try_from(I16Vec4::new(1, 2, 3, -4)).is_err()); |
| 3128 |
|
| 3129 |
assert_eq!( |
| 3130 |
U64Vec4::new(1, 2, 3, 4), |
| 3131 |
U64Vec4::from(U16Vec4::new(1, 2, 3, 4)) |
| 3132 |
); |
| 3133 |
|
| 3134 |
assert_eq!( |
| 3135 |
U64Vec4::new(1, 2, 3, 4), |
| 3136 |
U64Vec4::try_from(IVec4::new(1, 2, 3, 4)).unwrap() |
| 3137 |
); |
| 3138 |
assert!(U64Vec4::try_from(IVec4::new(-1, 2, 3, 4)).is_err()); |
| 3139 |
assert!(U64Vec4::try_from(IVec4::new(1, -2, 3, 4)).is_err()); |
| 3140 |
assert!(U64Vec4::try_from(IVec4::new(1, 2, -3, 4)).is_err()); |
| 3141 |
assert!(U64Vec4::try_from(IVec4::new(1, 2, 3, -4)).is_err()); |
| 3142 |
|
| 3143 |
assert_eq!( |
| 3144 |
U64Vec4::new(1, 2, 3, 4), |
| 3145 |
U64Vec4::from(UVec4::new(1, 2, 3, 4)) |
| 3146 |
); |
| 3147 |
|
| 3148 |
assert_eq!( |
| 3149 |
U64Vec4::new(1, 2, 3, 4), |
| 3150 |
U64Vec4::try_from(I64Vec4::new(1, 2, 3, 4)).unwrap() |
| 3151 |
); |
| 3152 |
assert!(U64Vec4::try_from(I64Vec4::new(-1, 2, 3, 4)).is_err()); |
| 3153 |
assert!(U64Vec4::try_from(I64Vec4::new(1, -2, 3, 4)).is_err()); |
| 3154 |
assert!(U64Vec4::try_from(I64Vec4::new(1, 2, -3, 4)).is_err()); |
| 3155 |
assert!(U64Vec4::try_from(I64Vec4::new(1, 2, 3, -4)).is_err()); |
| 3156 |
}); |
| 3157 |
|
| 3158 |
glam_test!(test_wrapping_add_signed, { |
| 3159 |
assert_eq!( |
| 3160 |
U64Vec4::new(u64::MAX, u64::MAX, u64::MAX, u64::MAX) |
| 3161 |
.wrapping_add_signed(I64Vec4::new(1, 1, 1, 1)), |
| 3162 |
U64Vec4::new(u64::MIN, u64::MIN, u64::MIN, u64::MIN) |
| 3163 |
); |
| 3164 |
}); |
| 3165 |
|
| 3166 |
glam_test!(test_saturating_add_signed, { |
| 3167 |
assert_eq!( |
| 3168 |
U64Vec4::new(u64::MAX, u64::MAX, u64::MAX, u64::MAX) |
| 3169 |
.saturating_add_signed(I64Vec4::new(1, 1, 1, 1)), |
| 3170 |
U64Vec4::new(u64::MAX, u64::MAX, u64::MAX, u64::MAX) |
| 3171 |
); |
| 3172 |
}); |
| 3173 |
|
| 3174 |
impl_vec4_tests!(u64, u64vec4, U64Vec4, U64Vec3, U64Vec2, BVec4, bvec4); |
| 3175 |
impl_vec4_eq_hash_tests!(u64, u64vec4); |
| 3176 |
|
| 3177 |
impl_vec4_scalar_shift_op_tests!(U64Vec4, 0, 2); |
| 3178 |
impl_vec4_shift_op_tests!(U64Vec4); |
| 3179 |
|
| 3180 |
impl_vec4_scalar_bit_op_tests!(U64Vec4, 0, 2); |
| 3181 |
impl_vec4_bit_op_tests!(U64Vec4, 0, 2); |
| 3182 |
} |