viva_aion/position

Position - Discrete coordinates in the labyrinth

Space is quantized. Consciousness moves in discrete steps. Between positions lies the Void.

Types

Cardinal directions for movement

pub type Direction {
  Up
  Down
  Left
  Right
}

Constructors

  • Up
  • Down
  • Left
  • Right

A position in 2D space

pub type Position {
  Position(x: Int, y: Int)
}

Constructors

  • Position(x: Int, y: Int)

Values

pub fn all_directions() -> List(Direction)

All cardinal directions

pub fn direction_to_string(dir: Direction) -> String

Direction to string

pub fn distance_squared(a: Position, b: Position) -> Int

Euclidean distance squared (avoids sqrt)

pub fn equals(a: Position, b: Position) -> Bool

Check if two positions are equal

pub fn from_key(key: Int, width: Int) -> Position

Convert key back to position

pub fn in_bounds(pos: Position, width: Int, height: Int) -> Bool

Check if position is within bounds

pub fn in_interior(
  pos: Position,
  width: Int,
  height: Int,
) -> Bool

Check if position is within interior (not on border)

pub fn manhattan_distance(a: Position, b: Position) -> Int

Manhattan distance between two positions

pub fn midpoint(a: Position, b: Position) -> Position

Get midpoint between two adjacent positions

pub fn move(pos: Position, direction: Direction) -> Position

Move position in a direction

pub fn move_double(
  pos: Position,
  direction: Direction,
) -> Position

Move position by 2 steps (for maze generation)

pub fn neighbors(pos: Position) -> List(Position)

Get all neighbors (4-directional)

pub fn neighbors_in_bounds(
  pos: Position,
  width: Int,
  height: Int,
) -> List(Position)

Get neighbors within bounds

pub fn new(x: Int, y: Int) -> Position

Create a new position

pub fn opposite(dir: Direction) -> Direction

Opposite direction

pub fn origin() -> Position

Origin point

pub fn to_key(pos: Position, width: Int) -> Int

Convert position to unique integer key (for dict)

pub fn to_string(pos: Position) -> String

Convert position to string

Search Document