mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Move Vec2 to common utilities
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
//! Common helper utilities to all days
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use std::ops::Add;
|
||||
use std::ops::Index;
|
||||
use std::ops::IndexMut;
|
||||
use std::ops::Sub;
|
||||
|
||||
use anyhow::Result;
|
||||
use nom::combinator::map;
|
||||
@@ -172,3 +176,38 @@ impl IndexSet {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct Vec2(pub [i32; 2]);
|
||||
|
||||
impl Add<Self> for Vec2 {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
Self([self[0] + rhs[0], self[1] + rhs[1]])
|
||||
}
|
||||
}
|
||||
|
||||
impl Sub<Self> for Vec2 {
|
||||
type Output = Self;
|
||||
|
||||
fn sub(self, rhs: Self) -> Self::Output {
|
||||
Self([self[0] - rhs[0], self[1] - rhs[1]])
|
||||
}
|
||||
}
|
||||
|
||||
impl Index<usize> for Vec2 {
|
||||
type Output = i32;
|
||||
|
||||
#[inline]
|
||||
fn index(&self, index: usize) -> &Self::Output {
|
||||
&self.0[index]
|
||||
}
|
||||
}
|
||||
|
||||
impl IndexMut<usize> for Vec2 {
|
||||
#[inline]
|
||||
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
|
||||
&mut self.0[index]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user