5 use std::ops::AddAssign;
9 #[derive(Default, PartialEq, Debug, Clone, Copy)]
10 pub struct Vec3 (pub f32, pub f32, pub f32);
14 fn add(self, other: Vec3) -> Vec3 {
15 Vec3(self.0 + other.0, self.1 + other.1, self.2 + other.2)
19 impl AddAssign for Vec3 {
20 fn add_assign(&mut self, other: Vec3) {
21 *self = Vec3(self.0 + other.0, self.1 + other.1, self.2 + other.2)
27 fn sub(self, other: Vec3) -> Vec3 {
28 Vec3(self.0 - other.0, self.1 - other.1, self.2 - other.2)
32 impl Mul<f32> for Vec3 {
34 fn mul(self, f: f32) -> Vec3 {
35 Vec3(self.0 * f, self.1 * f, self.2 * f)
39 pub fn norm(v: &Vec3) -> Vec3 {
40 let len = (v.0 * v.0 + v.1 * v.1 + v.2 * v.2).sqrt();
41 Vec3(v.0 / len, v.1 / len, v.2 / len)