README

NAME

Grid - Role for Arrays.

SYNOPSIS

use Grid;

my @grid = < a b c d e f g h i j k l m n o p q r s t u v w x >;

@grid does Grid[:4columns];

DESCRIPTION

Grid is a Role that transforms an Array to Array+{Grid}, And provides additional methods (e.g flip, rotate, transpose).

To flip a Grid horizontaly or vertically:

@grid.flip: :horizontal
@grid.flip: :vertical

It is also possible to apply methods to a subgrid of Grid, provided a valid subgrid indices:

my @indices  = 9, 10, 13, 14; @grid.flip: :vertical(@indices); # or
my @vertical = 9, 10, 13, 14; @grid.flip: :@vertical;`

Grid preserves the overall shape, So some operations require is-square to be True for Grid (or Subgrid), otherwise fails and returns self.

EXAMPLES

grid

flip

rotate

transpose

append

prepend

pop

shift

METHODS

grid

method grid ( Bool:D :$formatted = False ) { ... }

Returns list of strings or a formatted string of Grid.

columns

method columns { ... }

Returns Grid's columns count.

rows

method columns { ... }

Returns Grid's rows count.

check

multi method check ( :@rows! --> Bool:D ) { ... }

Check if Rows can fit in Grid.

multi method check ( :@columns! --> Bool:D ) { ... }

Check if Columns can fit in Grid.

reshape

method reshape ( Grid:D:  Int :$columns! where * > 0 --> Grid:D ) { ... }

flip

multi method flip ( Grid:D: Int:D :$horizontal! --> Grid:D ) { ... }

Horizontal Flip.

multi method flip ( Grid:D: Int:D :$vertical! --> Grid:D ) { ... }

Verical Flip.

multi method flip ( Grid:D: Int:D :$diagonal! --> Grid:D ) { ... }

Diagonal Flip.

multi method flip ( Grid:D: Int:D :$antidiagonal! --> Grid:D ) { ... }

Anti-Diagonal Flip.

multi method flip ( Grid:D: :@horizontal! --> Grid:D ) { ... }

Horizontal Flip (Subgrid).

multi method flip ( Grid:D: :@vertical! --> Grid:D ) { ... }

Vertical Flip (Subgrid).

multi method flip ( Grid:D: :@diagonal! --> Grid:D ) { ... }

Diagonal Flip (Subgrid).

multi method flip ( Grid:D: :@antidiagonal! --> Grid:D ) { ... }

Anti-Diagonal Flip (Subgrid).

rotate

multi method rotate ( Grid:D:  Int:D :$left! --> Grid:D ) { ... }

Left Rotate. (Columns)

multi method rotate ( Grid:D:  Int:D :$right! --> Grid:D ) { ... }

Right Rotate. (Columns)

multi method rotate ( Grid:D:  Int:D :$up! --> Grid:D ) { ... }

Up Rotate. (Rows)

multi method rotate ( Grid:D:  Int:D :$down! --> Grid:D ) { ... }

Up Rotate. (Rows)

multi method rotate ( Grid:D: Int:D :$clockwise! --> Grid:D ) { ... }

Clockwise Rotate.

multi method rotate ( Grid:D: Int:D :$anticlockwise! --> Grid:D ) { ... }

Anti-Clockwise Rotate.

multi method rotate ( Grid:D: :@clockwise! --> Grid:D ) { ... }

Clockwise Rotate (Subgrid)

multi method rotate ( Grid:D: :@anticlockwise! --> Grid:D ) { ... }

Clockwise Rotate (Subgrid)

transpose

multi method transpose ( Grid:D: --> Grid:D ) { ... }

Transpose.

multi method transpose ( Grid:D: :@indices! --> Grid:D ) { ... }

Transpose (Subgrid)

append

multi method append ( Grid:D: :@rows! --> Grid:D ) { ... }

Append Rows.

multi method append ( Grid:D: :@columns! --> Grid:D ) { ... }

Append Columns.

Prepend

multi method prepend ( Grid:D: :@rows! --> Grid:D ) {

Prepend Rows.

multi method prepend ( Grid:D: :@columns! --> Grid:D ) { ... }

Prepend Columns.

push

multi method push ( Grid:D: :@rows! --> Grid:D ) { ... }

Push Rows.

multi method push ( Grid:D: :@columns! --> Grid:D ) {

Push Columns.

pop

multi method pop ( Grid:D:  Int :$rows! --> Grid:D ) { ... }

Pop Rows.

multi method pop ( Grid:D:  Int :$columns! --> Grid:D ) { ... }

Pop Columns.

shift

multi method shift ( Grid:D:  Int :$rows! --> Grid:D ) { ... }

Shift Rows.

multi method shift ( Grid:D:  Int :$columns! --> Grid:D ) { ... }

Shift Columns.

unshift

multi method unshift ( Grid:D: :@rows! --> Grid:D ) { ... }

Unshift Rows.

multi method unshift ( Grid:D: :@columns! --> Grid:D ) {

Unshift Columns.

has-subgrid

method has-subgrid( :@indices!, :$square = False --> Int:D ) { ... }
Returns `columns` if `:@indices` is a subgrid of `Grid`, `False` otherwise.

is-square

method is-square ( --> Bool:D ) { ... }

Returns True if Grid is a square, False otherwise.

AUTHOR

Haytham Elganiny [email protected]

COPYRIGHT AND LICENSE

Copyright 2019 Haytham Elganiny

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.

Grid v0.0.5

Grid Role for Arrays.

Authors

  • Haytham Elganiny

License

Artistic-2.0

Dependencies

Test Dependencies

Provides

  • Grid

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.