HexGrid.pm

filter: Statementstmt 91.6% 22 / 24 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod 100% 2 / 2 totaltotal 91.6% 33 / 36 SCAR 11.0
CC
3
Cov
93%
new_hexagon
3.0
get_hex
2.0
BEGIN
1.0
CRAP 3.0
« HexGrid/Hex.pm ↑ Summary
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
BranchTrueFalseTotal
if ($q <= $radius) 5 1 6
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
BranchTrueFalseTotal
if ($r <= $r2) 19 5 24
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__
« HexGrid/Hex.pm ↑ Summary