line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
135970
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
2
|
1
|
|
|
1
|
|
11
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
3
|
|
|
|
|
|
|
package Math::Shape::Grid; |
4
|
|
|
|
|
|
|
$Math::Shape::Grid::VERSION = '0.03'; |
5
|
1
|
|
|
1
|
|
14
|
use 5.008; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
33
|
|
6
|
1
|
|
|
1
|
|
5
|
use List::Util qw/max min/; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
471
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: a 2d grid for visualizing Math::Shape::Point objects on the terminal |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub print { |
12
|
1
|
|
|
1
|
1
|
119
|
my $points = shift; |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
|
|
3
|
my ($min_x, $max_x, $min_y, $max_y) = qw/0 0 0 0/; |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
|
|
2
|
for my $name (sort { $a cmp $b } keys %{$points}) { |
|
5
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
11
|
|
17
|
4
|
|
|
|
|
5
|
my $point = $points->{$name}; |
18
|
|
|
|
|
|
|
|
19
|
4
|
|
|
|
|
654
|
printf "%s x:%3s, y:%3s, r:%6s\n", $name, $point->{x}, $point->{y}, $point->{r}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# get grid range |
22
|
4
|
100
|
|
|
|
17
|
$min_x = $point->{x} if $point->{x} < $min_x; |
23
|
4
|
100
|
|
|
|
11
|
$max_x = $point->{x} if $point->{x} > $max_x; |
24
|
4
|
100
|
|
|
|
10
|
$min_y = $point->{y} if $point->{y} < $min_y; |
25
|
4
|
100
|
|
|
|
12
|
$max_y = $point->{y} if $point->{y} > $max_y; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
|
|
11
|
my $max = max ( $max_x, $max_y ) + 5; |
29
|
1
|
|
|
|
|
11
|
my $min = min ( $min_x, $min_y ) + -5; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# print grid |
32
|
1
|
|
|
|
|
37
|
print "\n "; |
33
|
1
|
|
|
|
|
5
|
for ($min..$max) { printf "%3s", $_ } |
|
18
|
|
|
|
|
367
|
|
34
|
1
|
|
|
|
|
79
|
printf "%3s", "x\n"; |
35
|
1
|
|
|
|
|
6
|
for my $y (reverse $min..$max) |
36
|
|
|
|
|
|
|
{ |
37
|
18
|
|
|
|
|
1158
|
printf "%3s", $y; |
38
|
18
|
|
|
|
|
55
|
for my $x ($min..$max) |
39
|
|
|
|
|
|
|
{ |
40
|
324
|
|
|
|
|
490
|
my $intercept = sprintf "%3s", '.'; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# loop through points to see if we have a match |
43
|
324
|
|
|
|
|
482
|
for (keys %{ $points } ) { |
|
324
|
|
|
|
|
1047
|
|
44
|
1296
|
|
|
|
|
1642
|
my $p = $points->{$_}; |
45
|
1296
|
100
|
100
|
|
|
3679
|
if ($p->{x} == $x && $p->{y} == $y) { |
46
|
4
|
|
|
|
|
18
|
$intercept = sprintf "%3s", $_; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
324
|
|
|
|
|
13475
|
print $intercept; |
50
|
|
|
|
|
|
|
} |
51
|
18
|
|
|
|
|
2644
|
print "\n"; |
52
|
|
|
|
|
|
|
} |
53
|
1
|
|
|
|
|
193
|
printf "%3s", "y\n"; |
54
|
1
|
|
|
|
|
9
|
1; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |