Game-TextMapper

 view release on metacpan or  search on metacpan

lib/Game/TextMapper/Point.pm  view on Meta::CPAN

# Copyright (C) 2009-2021  Alex Schroeder <alex@gnu.org>
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.

=encoding utf8

=head1 NAME

Game::TextMapper::Point - a point on the map

=head1 DESCRIPTION

This is a simple class to hold points. Points have coordinates and know how to
print them.

=cut

package Game::TextMapper::Point;
use Modern::Perl '2018';
use Mojo::Base -base;

=head2 Attributes

C<x>, C<y>, C<z> are coordinates.

C<type>, C<label>, C<size> are used to draw the SVG. These are used by the
actual implementations, L<Game::TextMapper::Point::Hex> and
L<Game::TextMapper::Point::Square>.

C<map> is a reference to L<Game::TextMapper::Mapper> from which to get
C<text_attributes> (for the coordinates), and both C<label_attributes> and
C<glow_attributes> (for the label).

=cut

has 'x';
has 'y';
has 'z';
has 'type';
has 'label';
has 'size';
has 'map';

=head2 Methods

=head3 str

Returns "(1,2,3)" or "(1,2)" depending on whether the z coordinate is defined or
not; use this for log output.

=cut

sub str {
  my $self = shift;
  if (defined $self->z) {
    return '(' . $self->x . ',' . $self->y . ',' . $self->z . ')';
  } else {
    return '(' . $self->x . ',' . $self->y . ')';
  }
}

=head3 equal($other)

True if all three coordinates match.

=cut

sub equal {
  my ($self, $other) = @_;
  return $self->x == $other->x && $self->y == $other->y && $self->z == $other->z;
}

=head3 cmp($other)

Return -1, 0, or 1 depending on the three coordinates.

=cut

sub cmp {



( run in 0.666 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )