diff --git a/crates/border-wars/src/hex.rs b/crates/border-wars/src/hex.rs index b02c530..03ae69e 100644 --- a/crates/border-wars/src/hex.rs +++ b/crates/border-wars/src/hex.rs @@ -2,9 +2,9 @@ use std::collections::HashSet; use std::hash::Hash; -use std::ops; +use std::ops::{Add, AddAssign, Sub, SubAssign}; -use num::Signed; +use num::{FromPrimitive, Signed}; use partial_min_max::{max, min}; /// Represents a number that can be used in a hexagonal grid. @@ -88,7 +88,7 @@ impl HexPosi } } -impl ops::Add for HexPosition { +impl Add for HexPosition { type Output = Self; fn add(self, other: Self) -> Self::Output { @@ -99,13 +99,14 @@ impl ops::Add for HexPosition { } } -impl ops::AddAssign for HexPosition { +impl AddAssign for HexPosition { fn add_assign(&mut self, other: Self) { - *self = *self + other; + self.q += other.q; + self.r += other.r; } } -impl ops::Sub for HexPosition { +impl Sub for HexPosition { type Output = Self; fn sub(self, other: Self) -> Self { @@ -116,8 +117,9 @@ impl ops::Sub for HexPosition { } } -impl ops::SubAssign for HexPosition { +impl SubAssign for HexPosition { fn sub_assign(&mut self, other: Self) { - *self = *self - other; + self.q -= other.q; + self.r -= other.r; } }