Kit/Shape.pm

filter: Statementstmt 100% 71 / 71 Branchbran 95.8% 23 / 24 Conditioncond 83.3% 5 / 6 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 8 / 8 Podpod 100% 5 / 5 totaltotal 97.4% 115 / 118 CC 19 SCAR 15.8
CC
19
Cov
98%
line
7.0
outline
6.0
ring
5.0
CRAP 4.8
« Kit/Zones.pm ↑ Summary Kit/History.pm »
1 package Game::Terminal::Kit::Shape;
2  
3 3 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 our $VERSION = '0.06';
8  
9 10 ▶sub line {
Subroutine line: called CC=7 SCAR=19.5
Pod documented
10 10 my ($x, $y, $to_x, $to_y) = map { int $_ } @_;
11 10 my ($across, $down) = (abs($to_x - $x), abs($to_y - $y));
12 10 ▶ my ($step_x, $step_y) = ($x < $to_x ? 1 : -1, $y < $to_y ? 1 : -1);
Branch: 2 branches
BranchTrueFalseTotal
$x < $to_x ? : 6 4 10
$y < $to_y ? : 4 6 10
13 10 my $error = $across - $down;
14 10 my @points;
15 10 while (1) {
16 65 push @points, [ $x, $y ];
17 65 ▶ last if $x == $to_x && $y == $to_y;
Branch: 1 branch
BranchTrueFalseTotal
if $x == $to_x and $y == $to_y 10 55 65
Condition100%3/3
$x == $to_x and $y == $to_y
!ll&&!rl&&r
53210
MC/DC100%2/2
$x == $to_x and $y == $to_y
$x == $to_x $y == $to_y
Truth table100%3/3
A and B
A= $x == $to_xB= $y == $to_y
ABresult
0X0
100
111
18 55 my $twice = 2 * $error;
19 55 ▶ if ($twice > -$down) {
Branch: 1 branch
BranchTrueFalseTotal
if ($twice > -$down) 51 4 55
20 51 $error -= $down;
21 51 $x += $step_x;
22 }
23 55 ▶ if ($twice < $across) {
Branch: 1 branch
BranchTrueFalseTotal
if ($twice < $across) 29 26 55
24 29 $error += $across;
25 29 $y += $step_y;
26 }
27 }
28 10 return @points;
29 }
30  
31 3 ▶sub rect {
Subroutine rect: called CC=2 SCAR=6.9
Pod documented
32 3 my ($x, $y, $width, $height) = map { int $_ } @_;
33 3 my @points;
34 3 for my $row ($y .. $y + $height - 1) {
35 4 push @points, map { [ $_, $row ] } $x .. $x + $width - 1;
36 }
37 3 return @points;
38 }
39  
40 7 ▶sub outline {
Subroutine outline: called CC=6 SCAR=17.9
Pod documented
41 7 my ($x, $y, $width, $height) = map { int $_ } @_;
42 7 ▶ return () if $width < 1 || $height < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $width < 1 or $height < 1 1 6 7
Condition66%2/3
$width < 1 or $height < 1
l!l&&r!l&&!r
106
MC/DC50%1/2
$width < 1 or $height < 1
$width < 1 $height < 1
Truth table66%2/3
A or B
A= $width < 1B= $height < 1
ABresult
1X1
011
000
43 6 my ($right, $bottom) = ($x + $width - 1, $y + $height - 1);
44 6 my @points = map { [ $_, $y ] } $x .. $right;
45 6 for my $row ($y + 1 .. $bottom - 1) {
46 5 push @points, [ $x, $row ];
47 5 ▶ push @points, [ $right, $row ] if $right > $x;
Branch: 1 branch
BranchTrueFalseTotal
if $right > $x 4 1 5
48 }
49 6 ▶ push @points, map { [ $_, $bottom ] } $x .. $right if $bottom > $y;
Branch: 1 branch
BranchTrueFalseTotal
if $bottom > $y 4 2 6
50 6 return @points;
51 }
52  
53 15 ▶sub disc {
Subroutine disc: called CC=3 SCAR=11.0
Pod documented
54 15 my ($x, $y, $radius) = map { int $_ } @_;
55 15 ▶ return () if $radius < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $radius < 0 1 14 15
56 14 my $reach = $radius * $radius + $radius;
57 14 my @points;
58 14 for my $down (-$radius .. $radius) {
59 118 my $half = int sqrt($reach - $down * $down);
60 118 push @points, map { [ $_, $y + $down ] } $x - $half .. $x + $half;
61 }
62 14 return @points;
63 }
64  
65 12 ▶sub ring {
Subroutine ring: called CC=5 SCAR=16.1
Pod documented
66 12 my ($x, $y, $radius) = map { int $_ } @_;
67 12 ▶ return () if $radius < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $radius < 0 0 12 12
68 12 my $reach = $radius * $radius + $radius;
69 12 my @points;
70 12 for my $down (-$radius .. $radius) {
71 110 my $half = int sqrt($reach - $down * $down);
72 110 ▶ my $after = abs($down) == $radius ? -1 : int sqrt($reach - (abs($down) + 1) ** 2);
Branch: 1 branch
BranchTrueFalseTotal
abs $down == $radius ? : 23 87 110
73 110 ▶ my $inner = $after + 1 < $half ? $after + 1 : $half;
Branch: 1 branch
BranchTrueFalseTotal
$after + 1 < $half ? : 32 78 110
74 110 push @points, map { [ $x - $_, $y + $down ] } reverse $inner .. $half;
75 110 push @points, map { [ $x + $_, $y + $down ] } grep { $_ > 0 } $inner .. $half;
76 }
77 12 return @points;
78 }
79  
80 3 1;
81  
82 __END__
« Kit/Zones.pm ↑ Summary Kit/History.pm »