use std::ops::{Add, Sub, Mul, Div};
#[repr(C)]
#[derive(Clone, PartialOrd, PartialEq, Debug, Copy)]
pub struct Vector3<T> {
pub x: T,
pub y: T,
pub z: T
}
impl<T> Vector3<T> {
pub fn new(x: T, y: T, z: T) -> Vector3<T> {
Vector3 {
x: x,
y: y,
z: z
}
}
}
pub type Vector3f = Vector3<f32>;
pub type Vector3i = Vector3<i32>;
pub type Vector3u = Vector3<u32>;
impl<T: Add + Copy> Add<T> for Vector3<T> {
type Output = Vector3<T::Output>;
fn add(self, rhs: T) -> Vector3<T::Output> {
Vector3 {
x: self.x + rhs,
y: self.y + rhs,
z: self.z + rhs
}
}
}
impl<T: Sub + Copy> Sub<T> for Vector3<T> {
type Output = Vector3<T::Output>;
fn sub(self, rhs: T) -> Vector3<T::Output> {
Vector3 {
x: self.x - rhs,
y: self.y - rhs,
z: self.z - rhs
}
}
}
impl<T: Mul + Copy> Mul<T> for Vector3<T> {
type Output = Vector3<T::Output>;
fn mul(self, rhs: T) -> Vector3<T::Output> {
Vector3 {
x: self.x * rhs,
y: self.y * rhs,
z: self.z * rhs
}
}
}
impl<T: Div + Copy> Div<T> for Vector3<T> {
type Output = Vector3<T::Output>;
fn div(self, rhs: T) -> Vector3<T::Output> {
Vector3 {
x: self.x / rhs,
y: self.y / rhs,
z: self.z / rhs
}
}
}
impl<T: Add> Add for Vector3<T> {
type Output = Vector3<T::Output>;
fn add(self, rhs: Vector3<T>) -> Vector3<T::Output> {
Vector3 {
x: self.x + rhs.x,
y: self.y + rhs.y,
z: self.z + rhs.z
}
}
}
impl<T: Sub> Sub for Vector3<T> {
type Output = Vector3<T::Output>;
fn sub(self, rhs: Vector3<T>) -> Vector3<T::Output> {
Vector3 {
x: self.x - rhs.x,
y: self.y - rhs.y,
z: self.z - rhs.z
}
}
}
impl<T: Mul> Mul for Vector3<T> {
type Output = Vector3<T::Output>;
fn mul(self, rhs: Vector3<T>) -> Vector3<T::Output> {
Vector3 {
x: self.x * rhs.x,
y: self.y * rhs.y,
z: self.z * rhs.z
}
}
}
impl<T: Div> Div for Vector3<T> {
type Output = Vector3<T::Output>;
fn div(self, rhs: Vector3<T>) -> Vector3<T::Output> {
Vector3 {
x: self.x / rhs.x,
y: self.y / rhs.y,
z: self.z / rhs.z
}
}
}