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