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