adventofcode/src/coordinate_systems/euclidian.rs

63 Zeilen
1,2 KiB
Rust

use num::*;
use std::ops::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct Euclidian<T>
where
T: Integer,
{
pub x: T,
pub y: T,
pub z: T,
}
impl<T: Integer> Add for Euclidian<T> {
fn add(self, rhs: Self) -> Self::Output {
Euclidian {
x: self.x + rhs.x,
y: self.y + rhs.y,
z: self.z + rhs.z,
}
}
type Output = Euclidian<T>;
}
impl<T: Integer + AddAssign> AddAssign for Euclidian<T> {
fn add_assign(&mut self, rhs: Self) {
self.x += rhs.x;
self.y += rhs.y;
self.z += rhs.z;
}
}
impl<T: Integer> Sub for Euclidian<T> {
fn sub(self, rhs: Self) -> Self::Output {
Euclidian {
x: self.x - rhs.x,
y: self.y - rhs.y,
z: self.z - rhs.z,
}
}
type Output = Euclidian<T>;
}
impl<T: Integer + SubAssign> SubAssign for Euclidian<T> {
fn sub_assign(&mut self, rhs: Self) {
self.x -= rhs.x;
self.y -= rhs.y;
self.z -= rhs.z;
}
}
impl<T: Integer> Euclidian<T> {
pub const fn new(x: T, y: T, z: T) -> Self {
Self { x: x, y: y, z: z }
}
}
#[cfg(test)]
mod test {
use super::*;
}