Skip to content

Instantly share code, notes, and snippets.

@vadixidav
Created November 28, 2015 03:37
Show Gist options
  • Save vadixidav/ef9068feb66fc297cb1d to your computer and use it in GitHub Desktop.
Save vadixidav/ef9068feb66fc297cb1d to your computer and use it in GitHub Desktop.
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