generated from tipragot/rust
Add utils for hexagonal grild #50
|
@ -21,7 +21,8 @@ impl HexPosition {
|
||||||
///
|
///
|
||||||
/// Hexagonal grid using the [cube](https://www.redblobgames.com/grids/hexagons/#coordinates) coordinate system,
|
/// Hexagonal grid using the [cube](https://www.redblobgames.com/grids/hexagons/#coordinates) coordinate system,
|
||||||
/// is like a cube in 2D space.
|
/// is like a cube in 2D space.
|
||||||
/// The Manhattan distance between two positions is equal to: the half of the sum of abs(dx) + abs(dy) + abs(dz)
|
/// The Manhattan distance between two positions is equal to: the half of
|
||||||
|
/// the sum of abs(dx) + abs(dy) + abs(dz)
|
||||||
///
|
///
|
||||||
/// # Example:
|
/// # Example:
|
||||||
///
|
///
|
||||||
|
@ -47,11 +48,13 @@ impl HexPosition {
|
||||||
(dq.abs() + dr.abs() + ds.abs()) as f32 / 2.
|
(dq.abs() + dr.abs() + ds.abs()) as f32 / 2.
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns all positions within a given `range` from the current HexPosition.
|
/// Returns all positions within a given `range` from the current
|
||||||
|
/// HexPosition.
|
||||||
///
|
///
|
||||||
/// This function iterates over the possible q and r values within the specified range
|
/// This function iterates over the possible q and r values within the
|
||||||
/// and inserts HexPositions into a HashSet, ensuring that each generated position
|
/// specified range and inserts HexPositions into a HashSet, ensuring
|
||||||
/// is within the given range from the current position.
|
/// that each generated position is within the given range from the
|
||||||
|
/// current position.
|
||||||
///
|
///
|
||||||
/// for more details: https://www.redblobgames.com/grids/hexagons/#range
|
/// for more details: https://www.redblobgames.com/grids/hexagons/#range
|
||||||
///
|
///
|
||||||
|
@ -75,7 +78,6 @@ impl HexPosition {
|
||||||
}
|
}
|
||||||
result_positions
|
result_positions
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ops::Add<HexPosition> for HexPosition {
|
impl ops::Add<HexPosition> for HexPosition {
|
||||||
|
|
Loading…
Reference in a new issue