Acme-TextLayout
view release on metacpan or search on metacpan
lib/Acme/TextLayout.pm view on Meta::CPAN
}
} @keys;
$.Below{$char} = \@d;
return @d;
}
=head2 B<left>
@r = $tl->left($char);
Return a list (possibly empty) of each of the characters to
the left (and adjacent) to the specified character.
=cut
sub left {
my ($self, $char) = @_;
my @r = @{$.Ranges{$char}};
return () if $r[2] == 0;
return @{$.Left{$char}} if defined $.Left{$char};
my @keys = keys(%.Ranges);
my @d;
map {
if ($_ ne $char) {
my @other = @{$.Ranges{$_}};
push(@d, $_) if ./_in_y(\@r, \@other) &&
($other[3] == ($r[2]-1));
}
} @keys;
$.Left{$char} = \@d;
return @d;
}
=head2 B<right>
@r = $tl->right($char);
Return a list (possibly empty) of each of the characters to
the right (and adjacent) to the specified character.
=cut
sub right {
my ($self, $char) = @_;
my @r = @{$.Ranges{$char}};
return () if $r[2] == ./width();
return @{$.Right{$char}} if defined $.Right{$char};
my @keys = keys(%.Ranges);
my @d;
map {
if ($_ ne $char) {
my @other = @{$.Ranges{$_}};
push(@d, $_) if ./_in_y(\@r, \@other) &&
($other[2] == ($r[3]+1));
}
} @keys;
$.Right{$char} = \@d;
return @d;
}
=head2 B<range_as_percent>
($xpercent, $ypercent) = $tl->range_as_percent($char);
Returns the percentage of x and y that this character consumes
in the I<pattern>. Number returned for each is <= 1.0.
=cut
sub range_as_percent {
my ($self, $char) = @_;
my ($ymin, $ymax, $xmin, $xmax) = ./range($char);
my $width = ./width();
my $height = ./height();
return (($xmax-$xmin+1)/$width, ($ymax-$ymin+1)/$height);
}
=head2 B<order>
@chars = $tl->order([$line]);
Return the order of the characters encountered on line $line
(zero-based). $line defaults to zero if not specified.
=cut
sub order {
my ($self, $line) = @_;
$line = 0 unless defined $line;
die "$.Class - in order, line $line is too big!\n"
unless $line < ./height();
my $text = $.textRef[$line];
return unless defined $text;
my %Chars;
my @Chars;
my @chars = split('', $text);
map {
unless (defined $Chars{$_}) {
push(@Chars, $_);
$Chars{$_} = 1;
}
} @chars;
return @Chars;
}
=head2 B<only_one>
$stat = $tl->only_one();
Returns 1 if there is only a single character in your pattern,
0 if there are more.
=cut
sub only_one {
my ($self) = @_;
return ./order() == 1;
}
=head1 AUTHOR
X Cramps, C<< <cramps.the at gmail.com> >>
=head1 BUGS
There shouldn't be any. But I am a human, and do mess up sometimes.
Please report any bugs or feature requests to C<bug-acme-textlayout
at rt.cpan.org>, or through
the web interface at
( run in 2.129 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )