Add num calcules
Some checks failed
Rust Checks / checks (push) Failing after 1m49s
Rust Checks / checks (pull_request) Failing after 1m11s

This commit is contained in:
CoCo_Sol 2024-02-13 20:41:48 +01:00
parent 5d0fedac8c
commit 9af2d354e7

View file

@ -1,6 +1,7 @@
//! This file contains utilities for working with hex coordinates. //! This file contains utilities for working with hex coordinates.
use std::collections::HashSet; use std::collections::HashSet;
use std::ops;
/// Contains all ``HexPosition`` neighbors of a ``HexPosition`` /// Contains all ``HexPosition`` neighbors of a ``HexPosition``
pub struct GroupHexPosition(HashSet<HexPosition>); pub struct GroupHexPosition(HashSet<HexPosition>);
@ -97,3 +98,71 @@ impl HexPosition {
GroupHexPosition(positions) GroupHexPosition(positions)
} }
} }
impl ops::Add<HexPosition> for HexPosition {
type Output = HexPosition;
fn add(self, other: HexPosition) -> HexPosition {
HexPosition {
q: self.q + other.q,
r: self.r + other.r,
}
}
}
impl ops::AddAssign<HexPosition> for HexPosition {
fn add_assign(&mut self, other: HexPosition) {
*self = *self + other;
}
}
impl ops::Sub<HexPosition> for HexPosition {
type Output = HexPosition;
fn sub(self, other: HexPosition) -> HexPosition {
HexPosition {
q: self.q - other.q,
r: self.r - other.r,
}
}
}
impl ops::SubAssign<HexPosition> for HexPosition {
fn sub_assign(&mut self, other: HexPosition) {
*self = *self - other;
}
}
impl ops::Mul<i32> for HexPosition {
type Output = HexPosition;
fn mul(self, other: i32) -> HexPosition {
HexPosition {
q: self.q * other,
r: self.r * other,
}
}
}
impl ops::MulAssign<i32> for HexPosition {
fn mul_assign(&mut self, other: i32) {
*self = *self * other;
}
}
impl ops::Div<i32> for HexPosition {
type Output = HexPosition;
fn div(self, other: i32) -> HexPosition {
HexPosition {
q: self.q / other,
r: self.r / other,
}
}
}
impl ops::DivAssign<i32> for HexPosition {
fn div_assign(&mut self, other: i32) {
*self = *self / other;
}
}