Grid::Coord - abstract representation and manipulation of points and rectangles


NAME

Grid::Coord - abstract representation and manipulation of points and rectangles

Back to Top


SYNOPSIS

  use Grid::Coord
        my $point1 = Grid::Coord->new(5,4);        # point(y=>5, x=>4)
        my $rect1  = Grid::Coord->new(2,3 => 6,5); # rectangle
        print "TRUE" if $rect1->contains($point1);
        my $rect2  = Grid::Coord->new(3,4 => 5,5); # another rectangle
        my $rect3  = $rect1->overlap($rect2)       # (3,4 => 5,5)
        print $rect3->stringify;                   # "(3,4 => 5,5)"
        print $rect3;                              # "(3,4 => 5,5)"
        print "TRUE" if $rect3->equals(Grid::Coord->new(3,4 => 5,5));
        print "TRUE" if $rect3 == Grid::Coord->new(3,4 => 5,5);

Back to Top


DESCRIPTION

Manage points or rectangles on a grid. This is generic, and could be used for spreadsheets, ascii art, or other nefarious purposes.

Back to Top


USAGE

Constructor

 Grid->Coord->new($y, $x);
 Grid->Coord->new($min_y, $min_x,  $max_y, $max_x);

Accessing coordinates

The min_y, min_x, max_y, max_x functions:

 print $coord->max_x; # get value
 $coord->min_x(4);    # set value to 4

Relationships with other Coords

 $c3 = $c1->overlap($c2);
 print "TRUE" if $rect1->contains($rect2);
 print "TRUE" if $rect1->equals($rect2);

Overloaded operators

Four operators are overloaded:

Iterating

The iterator returns a Grid::Coord object for each cell in the current Grid::Coord range.

  my $it = $grid->cell_iterator; # or ->cell_iterator_rowwise
  # my $it = $grid->cell_iterator_colwise; # top to bottom
  while (my $cell = $it3->()) {
    # do something to $cell
  }

You can also iterate columns/rows with $grid->cells_iterator $grid->rows_iterator

Back to Top


BUGS

None reported yet.

Back to Top


SUPPORT

From the author.

Back to Top


AUTHOR

        osfameron@cpan.org
        http://osfameron.perlmonk.org/

Back to Top


COPYRIGHT

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.

Back to Top


SEE ALSO

perl(1).

Back to Top

 Grid::Coord - abstract representation and manipulation of points and rectangles