diff options
author | Julian T <julian@jtle.dk> | 2021-02-21 18:01:56 +0100 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2021-02-21 18:01:56 +0100 |
commit | da1c3949a449f3fafe579c62ff6b14ffd993a197 (patch) | |
tree | 754df5c9b5e9f0fa0a8bb7a8cd3dd4b12fe5ad89 /src/core/vector3.rs | |
parent | c695da871a75bb6786c08c3546ef71ed032bd61d (diff) |
Add 3d bounding box and merged SceneIntersection and Intersection
Diffstat (limited to 'src/core/vector3.rs')
-rw-r--r-- | src/core/vector3.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/core/vector3.rs b/src/core/vector3.rs index e26c07c..1cc6f60 100644 --- a/src/core/vector3.rs +++ b/src/core/vector3.rs @@ -2,7 +2,7 @@ //! //! Also add more 3d math things needed for shading and 3d calculations. use crate::{Float, Number, NEAR_ZERO}; -use std::ops::{Mul, Sub, Add, DivAssign, Neg, AddAssign}; +use std::ops::{Mul, Sub, Add, DivAssign, Neg, AddAssign, Index}; use std::fmt; #[derive(Clone, Copy)] @@ -107,6 +107,20 @@ impl<T: Number> fmt::Display for Vector3<T> { } } +// Ohh god +impl<T: Number> Index<u32> for Vector3<T> { + type Output = T; + + fn index(&self, i: u32) -> &Self::Output { + match i { + 0 => &self.x, + 1 => &self.y, + 2 => &self.z, + _ => panic!("index out of bounds: index {} is not possible with 3d vector", i) + } + } +} + impl Vector3f { pub const ZERO: Self = Vector3f {x: 0.0, y: 0.0, z: 0.0}; |