From 7ccc82fc0992fc23aee354d687ce009ae0523bea Mon Sep 17 00:00:00 2001 From: Julian T Date: Mon, 8 Feb 2021 18:26:27 +0100 Subject: Finish depth of field --- src/core/vector2.rs | 18 +++++++++++++++++- src/core/vector3.rs | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'src/core') diff --git a/src/core/vector2.rs b/src/core/vector2.rs index b3fa443..7e40394 100644 --- a/src/core/vector2.rs +++ b/src/core/vector2.rs @@ -2,7 +2,7 @@ //! //! This is implemented generictly with types that fit in the Number trait use crate::{Float, Number}; -use std::ops::{Sub, Add}; +use std::ops::{Sub, Add, Mul}; use std::fmt; use std::cmp::min; @@ -45,6 +45,16 @@ impl Add for Vector2 { } } +impl Mul for Vector2 { + type Output = Self; + fn mul(self, op: T) -> Self::Output { + Self::new_xy( + self.x * op, + self.y * op, + ) + } +} + impl fmt::Display for Vector2 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.write_fmt(format_args!("[{}, {}]", self.x, self.y)) @@ -94,6 +104,12 @@ impl Vector2i { } } +impl Vector2f { + pub fn len(&self) -> Float { + (self.x*self.x + self.y*self.y).sqrt() + } +} + #[cfg(test)] mod tests { diff --git a/src/core/vector3.rs b/src/core/vector3.rs index 1ae4db2..24b84e9 100644 --- a/src/core/vector3.rs +++ b/src/core/vector3.rs @@ -108,6 +108,8 @@ impl fmt::Display for Vector3 { } impl Vector3f { + pub const ZERO: Self = Vector3f {x: 0.0, y: 0.0, z: 0.0}; + /// Calculates the length times itself /// /// This is faster than using len * len as the square is ommited -- cgit v1.2.3