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
#![allow(dead_code)] use num_traits::NumOps; /** Creates a mathematical vector in up to 4 dimensions. # Arguments * `x` - The x dimensional value. * `y` - The y dimensional value. * `z` - The z dimensional value. * `w` - The w dimensional value. # Examples ``` ``` */ struct Vector<T: NumOps + Copy> { x: T, y: T, z: T, w: T, } impl<T: NumOps + Copy> Vector<T> { /** Gets the length of the vector. # Returns The length of the vector. # Examples ``` ``` */ fn get_length(&self) -> T { self.x * self.x + self.y * self.y + self.z * self.z + self.w * self.w } }