blib/lib/Game/TextMapper/Line/Square.pm

filter: Statementstmt 96.1% 25 / 26 Branchbran 87.5% 7 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 2 totaltotal 90.4% 38 / 42 CC 5 SCAR 8.9
CC
5
Cov
94%
one_step
4.0
pixels
2.1
BEGIN
1.0
CRAP 2.4
« blib/lib/Game/TextMapper/Schroeder/Hex.pm ↑ Summary blib/lib/Game/TextMapper/Line/Hex.pm »
1 # Copyright (C) 2009-2021 Alex Schroeder <alex@gnu.org>
2 #
3 # This program is free software: you can redistribute it and/or modify it under
4 # the terms of the GNU Affero General Public License as published by the Free
5 # Software Foundation, either version 3 of the License, or (at your option) any
6 # later version.
7 #
8 # This program is distributed in the hope that it will be useful, but WITHOUT
9 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
11 # details.
12 #
13 # You should have received a copy of the GNU Affero General Public License along
14 # with this program. If not, see <http://www.gnu.org/licenses/>.
15  
16 =encoding utf8
17  
18 =head1 NAME
19  
20 Game::TextMapper::Line::Square - a line implementation for square maps
21  
22 =head1 DESCRIPTION
23  
24 The line connects two points on a square map. This class knows how to compute
25 all the regions between these two points, how to compute the next region along
26 the line, and how to output SVG.
27  
28 =head1 SEE ALSO
29  
30 L<Game::TextMapper::Point>
31 L<Game::TextMapper::Line::Line>
32 L<Game::TextMapper::Line::Hex>
33  
34 =cut
35  
36 package Game::TextMapper::Line::Square;
37  
38 11 ▶use Game::TextMapper::Constants qw($dx $dy);
Subroutine BEGIN: called CC=1 SCAR=0.0
39 11 ▶use Game::TextMapper::Point;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 11 ▶use Modern::Perl '2018';
Subroutine BEGIN: called CC=1 SCAR=0.0
42 11 ▶use Mojo::Base 'Game::TextMapper::Line';
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 sub pixels {
45 1674 ▶ my ($self, $point) = @_;
Subroutine pixels: called CC=2 SCAR=7.6
Pod undocumented
46 1674 my ($x, $y) = ($point->x * $dy, ($point->y + $self->offset->[$point->z]) * $dy);
47 1674 ▶ return ($x, $y) if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 1674 0 1674
48 0 return sprintf("%d,%d", $x, $y);
49 }
50  
51 sub one_step {
52 373 ▶ my ($self, $from, $to) = @_;
Subroutine one_step: called CC=4 SCAR=13.9
Pod undocumented
53 373 my ($min, $best);
54 373 my $dx = $to->x - $from->x;
55 373 my $dy = $to->y - $from->y;
56 373 ▶ if (abs($dx) >= abs($dy)) {
Branch: 1 branch
BranchTrueFalseTotal
if (abs $dx >= abs $dy) { } 138 235 373
57 138 ▶ my $x = $from->x + ($dx > 0 ? 1 : -1);
Branch: 1 branch
BranchTrueFalseTotal
$dx > 0 ? : 89 49 138
58 138 return Game::TextMapper::Point->new(x => $x, y => $from->y, z => $from->z);
59 } else {
60 235 ▶ my $y = $from->y + ($dy > 0 ? 1 : -1);
Branch: 1 branch
BranchTrueFalseTotal
$dy > 0 ? : 149 86 235
61 235 return Game::TextMapper::Point->new(x => $from->x, y => $y, z => $from->z);
62 }
63 }
64  
65 11 1;
« blib/lib/Game/TextMapper/Schroeder/Hex.pm ↑ Summary blib/lib/Game/TextMapper/Line/Hex.pm »