Array-Tour

 view release on metacpan or  search on metacpan

lib/Array/Tour.pm  view on Meta::CPAN


=head3 _set()

$self->_set(%attributes);

Take the parameters provided to new() and use them to set the
attributes of the touring object.

=cut

sub _set()
{
	my $self = shift;
	my(%params) = @_;

	warn "Unknown paramter $_" foreach (grep{$_ !~ /reverse/} (keys %params));
	return $self;
}

=head3 _uses_array()

lib/Array/Tour/RandomWalk.pm  view on Meta::CPAN

our $VERSION = '0.06';

=head3 direction()

Returns the current direction as found in the :directions EXPORT tag.

Overrides Array::Tour's direction() method.

=cut

sub direction()
{
	my $self = shift;
	return ($self->{tourstatus} == STOP)? NoDirection: $self->{direction};
}

=head2 Tour Object Methods

=head3 next()

Returns an array reference to the next coordinates to use.  Returns undef if

lib/Array/Tour/Serpentine.pm  view on Meta::CPAN


=head3 direction()

  $dir = $tour->direction()

  Return the direction we just walked.

  Overrides Array::Tour's direction() method.
=cut

sub direction()
{
	my $self = shift;
	return ($self->{status} == STOP)? undef: ${$self->{direction}}[0];
}

=head3 next()

Returns a reference to an array of coordinates.  Returns undef
if there is no next cell to visit.

lib/Array/Tour/Serpentine.pm  view on Meta::CPAN

=head3 opposite()

  $ruot = $tour->opposite();

Return a new object that follows the same path as the original object,
reversing the inward/outward direction.


=cut

sub opposite()
{
	my $self = shift;
	my %anti_self;
	my @dimensions = @{ $self->{dimensions} };

	$anti_self{dimensions} = $self->{dimensions};

	$anti_self{corner_right} ^=  1;
	$anti_self{corner_bottom} ^= 1;

lib/Array/Tour/Serpentine.pm  view on Meta::CPAN

}

=head3 _set()

  $self->_set(%parameters);

  Override Array::Tour's _set() method for one that can handle
  our parameters.
=cut

sub _set()
{
	my $self = shift;
	my(%params) = @_;
	my($pace_x, $pace_y) = (1, 1);
	my($start_x, $start_y) = (0, 0);
	my @dirlist = (East, South, West, North);
	my @dimensions = @{$self->{dimensions}};
	my @direction;

	warn "Unknown paramter $_" foreach (grep{$_ !~ /vertical|corner_right|corner_bottom/} (keys %params));

lib/Array/Tour/Spiral.pm  view on Meta::CPAN

=head3 direction

$dir = $tour->direction()

Return the direction we just walked.

Overrides Array::Tour's direction() method.

=cut

sub direction()
{
	my $self = shift;
	return ($self->{status} == STOP)? undef: ${$self->{direction}}[0];
}

=head3 next()

Returns an array reference to the next coordinates to use. Returns
undef if there is no next cell to visit.

lib/Array/Tour/Spiral.pm  view on Meta::CPAN

        $grid[$y_coord, $x_coord] = isprime($ctr++);
    }

The above example generates Ulam's Spiral
L<http://en.wikipedia.org/wiki/Ulam_spiral> in the array @grid.

Overrides Array::Tour's next() method.

=cut

sub next()
{
	my $self = shift;

	return undef unless ($self->has_next());

	#
	# Set up the conditions for the pacing.
	# The first pacing value is incremented by one for inward
	# spirals because by the time it is used for the second time
	# it won't be shortened by a perpendicular branch of the walk.

lib/Array/Tour/Spiral.pm  view on Meta::CPAN


=head3 anti_spiral()

  $larips = $spiral->anti_spiral();

Return a new object that follows the same path as the original object,
reversing the inward/outward direction.

=cut

sub anti_spiral()
{
	my $self = shift;
	my %anti_self;
	my @dimensions = @{ $self->{dimensions} };

	$anti_self{dimensions} = $self->{dimensions};
	$anti_self{counterclock} = $self->{counterclock} ^ 1;
	$anti_self{inward} = $self->{inward} ^ 1;

	my $width = $dimensions[0];

lib/Array/Tour/Spiral.pm  view on Meta::CPAN

}

=head3 _set()

  $self->_set(%parameters);

  Override Array::Tour's _set() method for one that can handle
  our parameters.
=cut

sub _set()
{
	my $self = shift;
	my(%params) = @_;

	warn "Unknown paramter $_" foreach (grep{$_ !~ /inward|counterclock|corner_right|corner_bottom/} (keys %params));

	#
	# Set counterclock, corner_right, corner_bottom, and inward
	# to 0/1 values.
	#

lib/Array/Tour/Spiral.pm  view on Meta::CPAN

	return $self->_set_outward();
}

=head3 _set_inward()

  $self->_set_inward();

  Set the attributes knowing that the spiral path goes inward.
=cut

sub _set_inward()
{
	my $self = shift;
	my @dimensions = @{ $self->{dimensions} };
	my $width = $dimensions[0];
	my $height = $dimensions[1];
	my $counterclock = $self->{counterclock};
	my $corner_bottom = $self->{corner_bottom};
	my $corner_right = $self->{corner_right};
	my $pace_x = $width - 1;
	my $pace_y = $height - 1;

lib/Array/Tour/Spiral.pm  view on Meta::CPAN

	return $self;
}

=head3 _set_outward()

  $self->_set_outward();

  Set the attributes knowing that the spiral path goes outward.
=cut

sub _set_outward()
{
	my $self = shift;
	my @dimensions = @{ $self->{dimensions} };
	my $width = $dimensions[0];
	my $height = $dimensions[1];
	my $counterclock = $self->{counterclock};
	my $corner_bottom = $self->{corner_bottom};
	my $corner_right = $self->{corner_right};
	my($pace_x, $pace_y) = (1, 1);
	my @direction = (East, South, West, North);



( run in 0.859 second using v1.01-cache-2.11-cpan-55f5a4728d2 )