NAME
Math::Grid::Coordinates - create geometric grids
SYNOPSYS
use Math::Grid::Coordinates;
my $grid = Math::Grid::Coordinates->new($grid_width, $grid_height, $item_width, $item_height, $gutter, $border, $arrangement);
DESCRIPTION
Math::Grid::Coordinates creates an array of x-y positions for items of a given height and width arranged in a grid. This is used to create grid layouts on a page, or repeate items on a number of pages of the same size.
REQUIRES
INITIALIZING THE GRID
The grid can be initialized by setting page size, the number of the items and the gutters and borders, like so:
my $grid = Math::Grid::Coordinates->new({ page_width => 210, page_height => 297, grid_width => 2, grid_height => 3, gutter => 6, border => 12 });
in which case the item size is calculated.
It can also be initialized by setting item size, the number of the items and the gutters and borders, like so:
my $grid = Math::Grid::Coordinates->new({ item_width => 210, item_height => 297, grid_width => 2, grid_height => 3, gutter => 6, border => 12 });
Gutters and borders can be percentages of page width or height like so:
my $grid = Math::Grid::Coordinates->new({ item_width => 210, item_height => 297, grid_width => 2, grid_height => 3, gutter => 2pw, border => 4pw });
METHODS
bbox
$grid->bbox();
Returns the total bounding box of the grid
numbers
$grid->numbers();
Returns the sequence item numbers, with the top left item as item 1.
+---------+---------+---------+---------+
| | | | |
| 1 | 2 | 3 | 4 |
| | | | |
+---------+---------+---------+---------+
| | | | |
| 5 | 6 | 7 | 8 |
| | | | |
+---------+---------+---------+---------+
| | | | |
| 9 | 10 | 11 | 12 |
| | | | |
+---------+---------+---------+---------+
sequence
$grid->sequence();
Returns the sequence of x-y grid item coordinates, with the top left item as item [0, 0]
, the next one (assuming a horizontal arrangement) being [1, 0]
etc.
+---------+---------+---------+---------+
| | | | |
| [0, 0] | [0, 1] | [0, 2] | [0, 3] |
| | | | |
+---------+---------+---------+---------+
| | | | |
| [1, 0] | [1, 1] | [1, 2] | [1, 3] |
| | | | |
+---------+---------+---------+---------+
| | | | |
| [2, 0] | [2, 1] | [2, 2] | [2, 3] |
| | | | |
+---------+---------+---------+---------+
position
$grid->position(0, 0);
Returns the position of item as an array of x and y coordinates.
block
$grid->block($x, $y, $width, $height);
Returns the position and size of item as an array of x and y coordinates, and width and height.
positions
$grid->positions();
Returns the sequence of x-y grid coordinates.
total_height
$grid->total_height();
The total height of the grid
total_width
$grid->total_width();
The total width of the grid
calculate
$grid->calculate();
Calculates item width and height based on page size, borders, gutters and item count
guides
$grid->guides();
Returns start and end coordinates of layout guides
marks
$grid->marks($length);
Returns start and end coordinates of layout marks (short lines outside page)
To do
Allow for bottom or top start of grid