1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
use core::ops::Neg; use num_traits::{One, Zero}; #[inline(always)] pub fn new<T>(x: T, y: T, z: T) -> [T; 3] { [x, y, z] } #[inline(always)] pub fn from_vec2<T>(v: &[T; 2]) -> [T; 3] where T: Zero + Clone, { new(v[0].clone(), v[1].clone(), T::zero()) } #[inline(always)] pub fn from_vec4<T>(v: &[T; 4]) -> [T; 3] where T: Clone, { new(v[0].clone(), v[1].clone(), v[2].clone()) } #[inline(always)] pub fn new_one<T>() -> [T; 3] where T: One, { new(T::one(), T::one(), T::one()) } #[inline(always)] pub fn new_zero<T>() -> [T; 3] where T: Zero, { new(T::zero(), T::zero(), T::zero()) } #[inline(always)] pub fn new_up<T>() -> [T; 3] where T: One + Zero, { new(T::zero(), T::zero(), T::one()) } #[inline(always)] pub fn new_down<T>() -> [T; 3] where T: Neg<Output = T> + One + Zero, { new(T::zero(), T::zero(), -T::one()) } #[inline(always)] pub fn new_left<T>() -> [T; 3] where T: Neg<Output = T> + One + Zero, { new(-T::one(), T::zero(), T::zero()) } #[inline(always)] pub fn new_right<T>() -> [T; 3] where T: One + Zero, { new(T::one(), T::zero(), T::zero()) } #[inline(always)] pub fn new_forward<T>() -> [T; 3] where T: One + Zero, { new(T::zero(), T::one(), T::zero()) } #[inline(always)] pub fn new_backward<T>() -> [T; 3] where T: Neg<Output = T> + One + Zero, { new(T::zero(), -T::one(), T::zero()) }