Change num methode
All checks were successful
Rust Checks / checks (push) Successful in 1m32s
Rust Checks / checks (pull_request) Successful in 1m54s

This commit is contained in:
CoCo_Sol 2024-02-14 18:41:14 +01:00
parent 4c08cd83c4
commit b04ed1acf4

View file

@ -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<T: HexNumber + Eq + Hash + std::cmp::PartialOrd + num::ToPrimitive> HexPosi
}
}
impl<T: HexNumber> ops::Add<Self> for HexPosition<T> {
impl<T: HexNumber> Add<Self> for HexPosition<T> {
type Output = Self;
fn add(self, other: Self) -> Self::Output {
@ -99,13 +99,14 @@ impl<T: HexNumber> ops::Add<Self> for HexPosition<T> {
}
}
impl<T: HexNumber> ops::AddAssign<Self> for HexPosition<T> {
impl<T: HexNumber + AddAssign> AddAssign<Self> for HexPosition<T> {
fn add_assign(&mut self, other: Self) {
*self = *self + other;
self.q += other.q;
self.r += other.r;
}
}
impl<T: HexNumber> ops::Sub<Self> for HexPosition<T> {
impl<T: HexNumber> Sub<Self> for HexPosition<T> {
type Output = Self;
fn sub(self, other: Self) -> Self {
@ -116,8 +117,9 @@ impl<T: HexNumber> ops::Sub<Self> for HexPosition<T> {
}
}
impl<T: HexNumber> ops::SubAssign<Self> for HexPosition<T> {
impl<T: HexNumber + SubAssign> SubAssign<Self> for HexPosition<T> {
fn sub_assign(&mut self, other: Self) {
*self = *self - other;
self.q -= other.q;
self.r -= other.r;
}
}