3 use std::ops::AddAssign;
5 use std::ops::SubAssign;
8 #[derive(Default, PartialEq, Debug, Clone, Copy)]
9 pub struct Vec3(pub f32, pub f32, pub f32);
13 fn add(self, other: Vec3) -> Vec3 {
14 Vec3(self.0 + other.0, self.1 + other.1, self.2 + other.2)
18 impl AddAssign for Vec3 {
19 fn add_assign(&mut self, other: Vec3) {
20 *self = Vec3(self.0 + other.0, self.1 + other.1, self.2 + other.2)
26 fn sub(self, other: Vec3) -> Vec3 {
27 Vec3(self.0 - other.0, self.1 - other.1, self.2 - other.2)
31 impl SubAssign for Vec3 {
32 fn sub_assign(&mut self, other: Vec3) {
33 *self = Vec3(self.0 - other.0, self.1 - other.1, self.2 - other.2)
37 impl Mul<f32> for Vec3 {
39 fn mul(self, f: f32) -> Vec3 {
40 Vec3(self.0 * f, self.1 * f, self.2 * f)
44 pub fn norm(v: &Vec3) -> Vec3 {
45 let len = (v.0 * v.0 + v.1 * v.1 + v.2 * v.2).sqrt();
46 Vec3(v.0 / len, v.1 / len, v.2 / len)