line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
694
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
2
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
60
|
|
3
|
|
|
|
|
|
|
package Math::HexGrid; |
4
|
|
|
|
|
|
|
$Math::HexGrid::VERSION = '0.02'; |
5
|
|
|
|
|
|
|
# ABSTRACT: Math::HexGrid - create hex coordinate grids |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
476
|
use Math::HexGrid::Hex; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
8
|
1
|
|
|
1
|
|
7
|
use List::Util qw/min max/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
521
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new_hexagon |
14
|
|
|
|
|
|
|
{ |
15
|
1
|
|
|
1
|
1
|
467
|
my ($class, $radius) = @_; |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
|
|
2
|
my %map; |
18
|
1
|
|
|
|
|
5
|
for (my $q = - $radius; $q <= $radius; $q++) |
19
|
|
|
|
|
|
|
{ |
20
|
5
|
|
|
|
|
20
|
my $r1 = max(-$radius, -$q - $radius); |
21
|
5
|
|
|
|
|
12
|
my $r2 = min($radius, -$q + $radius); |
22
|
|
|
|
|
|
|
|
23
|
5
|
|
|
|
|
13
|
for (my $r = $r1; $r <= $r2; $r++) |
24
|
|
|
|
|
|
|
{ |
25
|
19
|
|
|
|
|
40
|
$map{"$q$r"} = Math::HexGrid::Hex->new($q, $r); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
|
|
8
|
bless { |
30
|
|
|
|
|
|
|
map => \%map, |
31
|
|
|
|
|
|
|
type => 'hexagon', |
32
|
|
|
|
|
|
|
}, $class; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub new_triangle |
37
|
|
|
|
|
|
|
{ |
38
|
1
|
|
|
1
|
1
|
3
|
my ($class, $rows) = @_; |
39
|
|
|
|
|
|
|
|
40
|
1
|
|
|
|
|
3
|
my %map; |
41
|
1
|
|
|
|
|
5
|
for (my $q = 0; $q <= $rows; $q++) |
42
|
|
|
|
|
|
|
{ |
43
|
3
|
|
|
|
|
10
|
for (my $r = 0; $r <= $rows - $q; $r++) |
44
|
|
|
|
|
|
|
{ |
45
|
6
|
|
|
|
|
18
|
$map{"$q$r"} = Math::HexGrid::Hex->new($q, $r); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
1
|
|
|
|
|
6
|
bless { |
49
|
|
|
|
|
|
|
map => \%map, |
50
|
|
|
|
|
|
|
type => 'triangle', |
51
|
|
|
|
|
|
|
}, $class; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
2
|
|
|
2
|
1
|
7
|
sub hexgrid { $_[0]->{map} } |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub hex |
59
|
|
|
|
|
|
|
{ |
60
|
2
|
|
|
2
|
1
|
5
|
my ($self, $q, $r) = @_; |
61
|
2
|
|
|
|
|
11
|
$self->{map}{"$q$r"}; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub count_sides |
66
|
|
|
|
|
|
|
{ |
67
|
2
|
|
|
2
|
1
|
4
|
my ($self) = @_; |
68
|
2
|
|
|
|
|
3
|
my $n = keys %{$self->{map}}; |
|
2
|
|
|
|
|
4
|
|
69
|
|
|
|
|
|
|
|
70
|
2
|
100
|
|
|
|
10
|
if ($self->{type} eq 'hexagon') |
|
|
50
|
|
|
|
|
|
71
|
|
|
|
|
|
|
{ |
72
|
1
|
|
|
|
|
7
|
($n-1) * 3 + $n-1 + 6; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
elsif ($self->{type} eq 'triangle') |
75
|
|
|
|
|
|
|
{ |
76
|
1
|
|
|
|
|
20
|
$n * 4 + 3; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
else |
79
|
|
|
|
|
|
|
{ |
80
|
0
|
|
|
|
|
|
die "Unknown map type!"; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
__END__ |