Add Vec4::xyz()
This commit is contained in:
parent
80b2d87d22
commit
908da3d995
|
|
@ -1,4 +1,4 @@
|
|||
use super::Float;
|
||||
use super::{Float, Vec3};
|
||||
|
||||
use itertools::izip;
|
||||
|
||||
|
|
@ -32,6 +32,12 @@ impl<T: Float> Vec4<T> {
|
|||
self.coords[3]
|
||||
}
|
||||
|
||||
pub fn xyz(&self) -> Vec3<T> {
|
||||
let mut coords = [T::zero(); 3];
|
||||
coords.copy_from_slice(&self.coords[0..3]);
|
||||
Vec3 { coords }
|
||||
}
|
||||
|
||||
pub fn dot(&self, rhs: &Vec4<T>) -> T {
|
||||
self.coords
|
||||
.iter()
|
||||
|
|
@ -138,6 +144,14 @@ mod tests {
|
|||
assert!(target.w() == 4.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn xyz_returns_expected_value() {
|
||||
let target = Vec4::new(1.0, 2.0, 3.0, 4.0).xyz();
|
||||
assert!(target.x() == 1.0);
|
||||
assert!(target.y() == 2.0);
|
||||
assert!(target.z() == 3.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dot_product_returns_correct_result() {
|
||||
let a = Vec4::new(1.0, 2.0, 3.0, 4.0);
|
||||
|
|
|
|||
Loading…
Reference in New Issue