view release on metacpan or search on metacpan
lib/Array/Tour.pm view on Meta::CPAN
541542543544545546547548549550551552553554555556557558559560=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
717273747576777879808182838485868788899091our
$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
5556575859606162636465666768697071727374=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
123124125126127128129130131132133134135136137138139140141142=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
145146147148149150151152153154155156157158159160161162163164165}
=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
6364656667686970717273747576777879808182=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
90919293949596979899100101102103104105106107108109110
$grid
[
$y_coord
,
$x_coord
] = isprime(
$ctr
++);
}
The above example generates Ulam's Spiral
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
147148149150151152153154155156157158159160161162163164165166167=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
190191192193194195196197198199200201202203204205206207208209210}
=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
217218219220221222223224225226227228229230231232233234235236237
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
257258259260261262263264265266267268269270271272273274275276277
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);