/// A 2D vector. #[derive(Debug, Clone, Copy, PartialEq)] pub struct Vector { /// The X component of the [`Vector`] /// /// [`Vector`]: struct.Vector.html pub x: T, /// The Y component of the [`Vector`] /// /// [`Vector`]: struct.Vector.html pub y: T, } impl Vector { /// Creates a new [`Vector`] with the given components. /// /// [`Vector`]: struct.Vector.html pub const fn new(x: T, y: T) -> Self { Self { x, y } } } impl std::ops::Add for Vector where T: std::ops::Add, { type Output = Self; fn add(self, b: Self) -> Self { Self::new(self.x + b.x, self.y + b.y) } } impl std::ops::Sub for Vector where T: std::ops::Sub, { type Output = Self; fn sub(self, b: Self) -> Self { Self::new(self.x - b.x, self.y - b.y) } } impl Default for Vector where T: Default, { fn default() -> Self { Self { x: T::default(), y: T::default(), } } }