Remove deprecatd emscripten option ERROR_ON_MISSING_LIBRARIES
[mandelwow.git] / support / vec3.rs
1 use std::f32;
2 use std::ops::Add;
3 use std::ops::AddAssign;
4 use std::ops::Sub;
5 use std::ops::SubAssign;
6 use std::ops::Mul;
7
8 #[derive(Default, PartialEq, Debug, Clone, Copy)]
9 pub struct Vec3(pub f32, pub f32, pub f32);
10
11 impl Add for Vec3 {
12     type Output = Vec3;
13     fn add(self, other: Vec3) -> Vec3 {
14         Vec3(self.0 + other.0, self.1 + other.1, self.2 + other.2)
15     }
16 }
17
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)
21     }
22 }
23
24 impl Sub for Vec3 {
25     type Output = Vec3;
26     fn sub(self, other: Vec3) -> Vec3 {
27         Vec3(self.0 - other.0, self.1 - other.1, self.2 - other.2)
28     }
29 }
30
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)
34     }
35 }
36
37 impl Mul<f32> for Vec3 {
38     type Output = Vec3;
39     fn mul(self, f: f32) -> Vec3 {
40         Vec3(self.0 * f, self.1 * f, self.2 * f)
41     }
42 }
43
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)
47 }