Array-Tour

 view release on metacpan or  search on metacpan

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

541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
=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

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
=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

123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
=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

145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
}
 
=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

63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
=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

90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
        $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

147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
=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

190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
}
 
=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

217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
        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

257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
        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 1.571 second using v1.01-cache-2.11-cpan-55f5a4728d2 )