Add utils for hexagonal grild #50

Merged
tipragot merged 23 commits from hex-utils into main 2024-02-14 17:49:08 +00:00
Showing only changes of commit b6f7a202b4 - Show all commits

View file

@ -21,7 +21,8 @@ impl HexPosition {
///
/// Hexagonal grid using the [cube](https://www.redblobgames.com/grids/hexagons/#coordinates) coordinate system,
/// 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:
///
@ -47,11 +48,13 @@ impl HexPosition {
(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
/// and inserts HexPositions into a HashSet, ensuring that each generated position
/// is within the given range from the current position.
/// This function iterates over the possible q and r values within the
/// specified range and inserts HexPositions into a HashSet, ensuring
/// that each generated position is within the given range from the
/// current position.
///
/// for more details: https://www.redblobgames.com/grids/hexagons/#range
///
@ -75,7 +78,6 @@ impl HexPosition {
}
result_positions
}
}
impl ops::Add<HexPosition> for HexPosition {