Acme-TextLayout
view release on metacpan or search on metacpan
lib/Acme/TextLayout.pm view on Meta::CPAN
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]);
t/01-test.t view on Meta::CPAN
EOF
ok($tl->instantiate(text => $pattern));
ok($tl->only_one() == 1);
$tl = Acme::TextLayout->new;
$pattern = <<'EOF';
AAAABBBBBB
AAAABBBBBB
EOF
ok($tl->instantiate(text => $pattern));
ok(check([qw(0.4 1)], $tl->range_as_percent('A')));
ok(check([qw(0.6 1)], $tl->range_as_percent('B')));
ok(check([qw(0 0 39 99)], $tl->map_range(100, 100, 'A')));
ok(check([qw(40 0 99 99)], $tl->map_range(100, 100, 'B')));
$pattern = <<'EOF';
AAAABBBBBB
AAAABBBBBB
CCCCDDDDDD
CCCCDDDDDD
EOF
ok($tl->instantiate(text => $pattern));
ok(check([qw(0.4 0.5)], $tl->range_as_percent('A')));
ok(check([qw(0.4 0.5)], $tl->range_as_percent('C')));
ok(check([qw(0.6 0.5)], $tl->range_as_percent('B')));
ok(check([qw(0.6 0.5)], $tl->range_as_percent('D')));
ok(check([qw(0 0 39 49)], $tl->map_range(100, 100, 'A')));
ok(check([qw(0 50 39 99)], $tl->map_range(100, 100, 'C')));
ok(check([qw(40 0 99 49)], $tl->map_range(100, 100, 'B')));
ok(check([qw(40 50 99 99)], $tl->map_range(100, 100, 'D')));
ok($tl->height()==4 && $tl->width()==10);
ok(check([qw(0 1 0 3)], $tl->range('A')));
ok(check([qw(2 3 0 3)], $tl->range('C')));
ok(check([qw(0 1 4 9)], $tl->range('B')));
ok(check([qw(2 3 4 9)], $tl->range('D')));
( run in 0.331 second using v1.01-cache-2.11-cpan-05162d3a2b1 )