Created
November 28, 2015 03:37
-
-
Save vadixidav/ef9068feb66fc297cb1d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate num; | |
use num::Float; | |
use std::ops::{Add, Sub, Neg, Mul, Div}; | |
//Trait that implements all the functions necessary for any n-dimensional particle | |
pub trait Vector<'a, 'b, D>: Sized + Clone | |
where D: Float, &'a Self: Add<&'b Self, Output=Self> + Sub<&'b Self, Output=Self> + Neg<Output=Self> + | |
Mul<D, Output=Self> + Div<D, Output=Self> | |
{ | |
fn displacement(&self) -> D; | |
fn normalized(&self) -> Self { | |
self / self.displacement() | |
} | |
fn normalize(&mut self) { | |
let c = self.clone(); | |
*self = c.normalized(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment