generated from tipragot/rust
Remake utils for hexagon grids #55
|
@ -1,11 +1,11 @@
|
||||||
//! All functions related to calculations in a hexagonal grid.
|
//! All functions related to calculations in a hexagonal grid.
|
||||||
|
|
||||||
|
|
||||||
use std::ops::{
|
use std::ops::{
|
||||||
Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Rem, RemAssign, Sub, SubAssign,
|
Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Rem, RemAssign, Sub, SubAssign,
|
||||||
};
|
};
|
||||||
|
|
||||||
use num::{cast::AsPrimitive, FromPrimitive};
|
use num::cast::AsPrimitive;
|
||||||
|
use num::FromPrimitive;
|
||||||
use paste::paste;
|
use paste::paste;
|
||||||
|
|
||||||
/// Represents a number that can be used in calculations for hexagonal grids.
|
/// Represents a number that can be used in calculations for hexagonal grids.
|
||||||
|
@ -164,7 +164,7 @@ pub struct HexSpiral<T: Number> {
|
||||||
index: usize,
|
index: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Number + AsPrimitive<usize>+ FromPrimitive> Iterator for HexSpiral<T> {
|
impl<T: Number + AsPrimitive<usize> + FromPrimitive> Iterator for HexSpiral<T> {
|
||||||
type Item = HexPosition<T>;
|
type Item = HexPosition<T>;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
@ -183,11 +183,9 @@ impl<T: Number + AsPrimitive<usize>+ FromPrimitive> Iterator for HexSpiral<T> {
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: Number + AsPrimitive<usize> + FromPrimitive> HexPosition<T> {
|
||||||
impl<T: Number + AsPrimitive<usize>+ FromPrimitive> HexPosition<T> {
|
|
||||||
/// Creates a new hexagonal position.
|
/// Creates a new hexagonal position.
|
||||||
pub fn new(x: T, y: T) -> Self {
|
pub fn new(x: T, y: T) -> Self {
|
||||||
Self(x, y)
|
Self(x, y)
|
||||||
|
@ -256,7 +254,6 @@ macro_rules! impl_ops {
|
||||||
)*}};
|
)*}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl_ops! {
|
impl_ops! {
|
||||||
(Add, add),
|
(Add, add),
|
||||||
(Sub, sub),
|
(Sub, sub),
|
||||||
|
|
Loading…
Reference in a new issue