GamesEngine.Grid.Coordinate (games_engine v0.3.2)

Coordinate Component - represents a square within a grid

Currently also provides functions for handling coordinate transformations.

Summary

Functions

Converts a coordinate's linear index to row/col subscript

Creates a new %Coordinate{} struct

Converts a coordinate's row/col subscript into a linear index

Types

@type t() :: %GamesEngine.Grid.Coordinate{col: term(), row: term()}

Functions

Link to this function

ind2sub(ind, rows, cols)

Converts a coordinate's linear index to row/col subscript

0360,00,10,2
147-->1,01,11,2
2582,02,12,2
@spec new({non_neg_integer(), non_neg_integer()}) :: t() | {:error | String.t()}

Creates a new %Coordinate{} struct

Link to this function

sub2ind(arg, rows, cols)

@spec sub2ind(
  {non_neg_integer(), non_neg_integer()},
  non_neg_integer(),
  non_neg_integer()
) ::
  non_neg_integer() | {:error, String.t()}

Converts a coordinate's row/col subscript into a linear index

0,00,10,2036
1,01,11,2-->147
2,02,12,2258