Expand description
This module provides an enum Balance that models a position within a 3x3 grid,
along with several utility methods to manipulate these positions.
The Balance enum is intended for scenarios where balanced ternary logic or
grid-based movement is required. It represents nine possible positions in a
3x3 grid, with the central point being (0, 0) and other points positioned
as offsets relative to this center.
§Main Features
Balanceenum variants represent specific positions in the grid, such asTopLeft,Center, orBottomRight.- Methods to convert between
Balancevariants and their 2D vector representations. - Utility methods to move a position in the grid (e.g.,
up,down,left,right).
§Usage Examples
Basic usage of Balance to convert between variants and vectors:
use balanced_direction::Balance;
let position = Balance::TopLeft;
assert_eq!(position.to_vector(), (-1, -1));
let center = Balance::Center;
assert_eq!(center.to_vector(), (0, 0));
let balance = Balance::from_vector(-1, -1);
assert_eq!(balance, Balance::TopLeft);Moving positions in the grid:
use balanced_direction::Balance;
let balance = Balance::Center;
assert_eq!(balance.up(), Balance::Top);
assert_eq!(balance.down(), Balance::Bottom);
assert_eq!(balance.left(), Balance::Left);
assert_eq!(balance.right(), Balance::Right);Structs§
- Path
- Represents a sequence of movements in a grid, where each movement
is represented by a
Balancevalue indicating the direction of one step.
Enums§
- Balance
- Represents a position within a 3x3 grid, with each variant corresponding to a specific point.