5 use std::ops::AddAssign;
7 use std::ops::SubAssign;
10 #[derive(Default, PartialEq, Debug, Clone, Copy)]
11 pub struct Vec3(pub f32, pub f32, pub f32);
15 fn add(self, other: Vec3) -> Vec3 {
16 Vec3(self.0 + other.0, self.1 + other.1, self.2 + other.2)
20 impl AddAssign for Vec3 {
21 fn add_assign(&mut self, other: Vec3) {
22 *self = Vec3(self.0 + other.0, self.1 + other.1, self.2 + other.2)
28 fn sub(self, other: Vec3) -> Vec3 {
29 Vec3(self.0 - other.0, self.1 - other.1, self.2 - other.2)
33 impl SubAssign for Vec3 {
34 fn sub_assign(&mut self, other: Vec3) {
35 *self = Vec3(self.0 - other.0, self.1 - other.1, self.2 - other.2)
39 impl Mul<f32> for Vec3 {
41 fn mul(self, f: f32) -> Vec3 {
42 Vec3(self.0 * f, self.1 * f, self.2 * f)
46 pub fn norm(v: &Vec3) -> Vec3 {
47 let len = (v.0 * v.0 + v.1 * v.1 + v.2 * v.2).sqrt();
48 Vec3(v.0 / len, v.1 / len, v.2 / len)