GamesEngine.Validations.GridValidations (games_engine v0.3.2)
Functions with perform validations of a game grid
Summary
Functions
Ensures a linear index is within the bounds of the supplied grid
Determines whether a %Point{}
is within the bounds of a %Grid{}
.
If the %Point{}
's coordinates are outside the %Grid{}
, will return an error tuple
along with the direction(s) which the %Point{}
is outside the %Grid{}
Ensures a row/col subscript is within the bounds of the supplied grid
Types
Link to this type
point_within_bounds_errors()
Functions
Link to this function
ind_within_bounds(ind, grid)
@spec ind_within_bounds(non_neg_integer(), GamesEngine.Grid.t()) :: :ok
Ensures a linear index is within the bounds of the supplied grid
Link to this function
ind_within_bounds(ind, rows, cols)
@spec ind_within_bounds(non_neg_integer(), non_neg_integer(), non_neg_integer()) :: :ok
Link to this function
point_within_bounds(point, grid)
@spec point_within_bounds(GamesEngine.Grid.Point.t(), GamesEngine.Grid.t()) :: :ok
Determines whether a %Point{}
is within the bounds of a %Grid{}
.
If the %Point{}
's coordinates are outside the %Grid{}
, will return an error tuple
along with the direction(s) which the %Point{}
is outside the %Grid{}
Examples
iex> grid = %GamesEngine.Grid{rows: 10, cols: 10}
iex> point = %GamesEngine.Grid.Point{x: 3, y: 5.4}
iex> GamesEngine.Validations.GridValidations.point_within_bounds(point, grid)
:ok
iex> grid = %GamesEngine.Grid{rows: 10, cols: 10}
iex> point = %GamesEngine.Grid.Point{x: 12, y: -7.3}
iex> GamesEngine.Validations.GridValidations.point_within_bounds(point, grid)
{:error, %{top: true, bottom: false, right: true, left: false}}
Link to this function
sub_within_bounds(arg, grid)
@spec sub_within_bounds( {non_neg_integer(), non_neg_integer()}, GamesEngine.Grid.t() ) :: :ok | {:error, String.t()}
Ensures a row/col subscript is within the bounds of the supplied grid
Link to this function
sub_within_bounds(arg, rows, cols)
@spec sub_within_bounds( {non_neg_integer(), non_neg_integer()}, non_neg_integer(), non_neg_integer() ) :: :ok | {:error, String.t()}