| 1 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | package Math::HexGrid; | ||||||||||
| 4 | 1 | $Math::HexGrid::VERSION = '0.01'; | |||||||||
| 5 | # ABSTRACT: Math::HexGrid - create hex coordinate grids | ||||||||||
| 6 | |||||||||||
| 7 | 1 | ▶ | use Math::HexGrid::Hex; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use List::Util qw/min max/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | |||||||||||
| 11 | |||||||||||
| 12 | |||||||||||
| 13 | sub new_hexagon | ||||||||||
| 14 | { | ||||||||||
| 15 | 1 | ▶ | my ($class, $radius) = @_; | ||||||||
|
Subroutine
new_hexagon: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 16 | |||||||||||
| 17 | 1 | my %map; | |||||||||
| 18 | 1 | ▶ | for (my $q = - $radius; $q <= $radius; $q++) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | { | ||||||||||
| 20 | 5 | my $r1 = max(-$radius, -$q - $radius); | |||||||||
| 21 | 5 | my $r2 = min($radius, -$q + $radius); | |||||||||
| 22 | |||||||||||
| 23 | 5 | ▶ | for (my $r = $r1; $r <= $r2; $r++) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | { | ||||||||||
| 25 | 19 | $map{"$q$r"} = Math::HexGrid::Hex->new($q, $r); | |||||||||
| 26 | } | ||||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 1 | bless { | |||||||||
| 30 | map => \%map, | ||||||||||
| 31 | }, $class; | ||||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | |||||||||||
| 35 | sub get_hex | ||||||||||
| 36 | { | ||||||||||
| 37 | 0 | ▶ | my ($self, $q, $r) = @_; | ||||||||
|
Subroutine
get_hex: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 38 | 0 | $self->{map}{"$q$r"}; | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | |||||||||||
| 42 | 1 | 1; | |||||||||
| 43 | |||||||||||
| 44 | __END__ | ||||||||||