Skip to content

Commit

Permalink
Restructure 'util' folder
Browse files Browse the repository at this point in the history
  • Loading branch information
CcydtN committed Dec 16, 2024
1 parent c6e50e6 commit c0d1dc9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 46 deletions.
48 changes: 2 additions & 46 deletions src/bin/util/mod.rs
Original file line number Diff line number Diff line change
@@ -1,47 +1,3 @@
use std::ops::Sub;
mod vector;

use std::ops::Add;

#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub(crate) struct Vector {
pub(crate) x: usize,
pub(crate) y: usize,
}

impl Vector {
pub(crate) fn new(x: usize, y: usize) -> Self {
Self { x, y }
}
}

impl Add for Vector {
type Output = Self;

fn add(self, rhs: Self) -> Self::Output {
Self::new(self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y))
}
}

impl Add for &Vector {
type Output = Vector;

fn add(self, rhs: Self) -> Self::Output {
Vector::new(self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y))
}
}

impl Sub for Vector {
type Output = Self;

fn sub(self, rhs: Self) -> Self::Output {
Self::new(self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y))
}
}

impl Sub for &Vector {
type Output = Vector;

fn sub(self, rhs: Self) -> Self::Output {
Vector::new(self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y))
}
}
pub(crate) use vector::Vector;
46 changes: 46 additions & 0 deletions src/bin/util/vector.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use std::ops::Add;
use std::ops::Sub;

#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub(crate) struct Vector {
pub(crate) x: usize,
pub(crate) y: usize,
}

impl Vector {
pub(crate) fn new(x: usize, y: usize) -> Self {
Self { x, y }
}
}

impl Add for Vector {
type Output = Self;

fn add(self, rhs: Self) -> Self::Output {
Self::new(self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y))
}
}

impl Add for &Vector {
type Output = Vector;

fn add(self, rhs: Self) -> Self::Output {
Vector::new(self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y))
}
}

impl Sub for Vector {
type Output = Self;

fn sub(self, rhs: Self) -> Self::Output {
Self::new(self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y))
}
}

impl Sub for &Vector {
type Output = Vector;

fn sub(self, rhs: Self) -> Self::Output {
Vector::new(self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y))
}
}

0 comments on commit c0d1dc9

Please sign in to comment.