generated from tipragot/rust
Add num calcules
This commit is contained in:
parent
5d0fedac8c
commit
9af2d354e7
|
@ -1,6 +1,7 @@
|
|||
//! This file contains utilities for working with hex coordinates.
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::ops;
|
||||
|
||||
/// Contains all ``HexPosition`` neighbors of a ``HexPosition``
|
||||
pub struct GroupHexPosition(HashSet<HexPosition>);
|
||||
|
@ -97,3 +98,71 @@ impl HexPosition {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue