1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
//! Vector2 generic.
/// Generic Vector2.
///
/// Requires for the Type to derive `Debug, Clone, PartialEq` and implement `Default` trait
///
/// Doesn't overload operators like the other Vector2s
#[derive(Debug, Clone, PartialEq)]
pub struct Vec2generic<T>{
/// X value.
pub x: T,
/// Y value.
pub y: T
}
impl<T: Clone> Vec2generic<T>{
/// Creates a new [`Vec2generic`] with x and y defined.
///
/// use `default()` for a default initialized.
pub fn new(x: T, y: T) -> Self {
Self{
x,
y
}
}
/// Puts x into y and y into x
pub fn flip(&mut self){
let tmp = self.x.clone();
self.x = self.y.clone();
self.y = tmp;
}
}
impl<T: Default> Default for Vec2generic<T> {
/// Creates a new [`Vec2generic`] with x and y initialized with the Type default.
fn default() -> Self {
Self{
x: T::default(),
y: T::default()
}
}
}