aboutsummaryrefslogtreecommitdiff
path: root/src/core/vector2.rs
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2021-02-08 18:26:27 +0100
committerJulian T <julian@jtle.dk>2021-02-08 18:27:00 +0100
commit7ccc82fc0992fc23aee354d687ce009ae0523bea (patch)
tree635f7ffe386c638ef8d5ca0db81a3da8ef0f7cc0 /src/core/vector2.rs
parentdbe5f54957ddc13549a6ce822da95170aa09a0c6 (diff)
Finish depth of field
Diffstat (limited to 'src/core/vector2.rs')
-rw-r--r--src/core/vector2.rs18
1 files changed, 17 insertions, 1 deletions
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<T: Number> Add for Vector2<T> {
}
}
+impl<T: Number> Mul<T> for Vector2<T> {
+ type Output = Self;
+ fn mul(self, op: T) -> Self::Output {
+ Self::new_xy(
+ self.x * op,
+ self.y * op,
+ )
+ }
+}
+
impl<T: Number> fmt::Display for Vector2<T> {
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 {