line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright (C) 2009-2021 Alex Schroeder |
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 . |
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 |
31
|
|
|
|
|
|
|
L |
32
|
|
|
|
|
|
|
L |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
package Game::TextMapper::Line::Square; |
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
1
|
|
8
|
use Game::TextMapper::Constants qw($dx $dy); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
122
|
|
39
|
1
|
|
|
1
|
|
7
|
use Game::TextMapper::Point; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
1
|
|
25
|
use Modern::Perl '2018'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
42
|
1
|
|
|
1
|
|
174
|
use Mojo::Base 'Game::TextMapper::Line'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub pixels { |
45
|
2120
|
|
|
2120
|
0
|
2684
|
my ($self, $point) = @_; |
46
|
2120
|
|
|
|
|
3124
|
my ($x, $y) = ($point->x * $dy, ($point->y + $self->offset->[$point->z]) * $dy); |
47
|
2120
|
50
|
|
|
|
18859
|
return ($x, $y) if wantarray; |
48
|
0
|
|
|
|
|
0
|
return sprintf("%d,%d", $x, $y); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub one_step { |
52
|
483
|
|
|
483
|
0
|
1485
|
my ($self, $from, $to) = @_; |
53
|
483
|
|
|
|
|
549
|
my ($min, $best); |
54
|
483
|
|
|
|
|
708
|
my $dx = $to->x - $from->x; |
55
|
483
|
|
|
|
|
2446
|
my $dy = $to->y - $from->y; |
56
|
483
|
100
|
|
|
|
2300
|
if (abs($dx) >= abs($dy)) { |
57
|
265
|
100
|
|
|
|
382
|
my $x = $from->x + ($dx > 0 ? 1 : -1); |
58
|
265
|
|
|
|
|
1029
|
return Game::TextMapper::Point->new(x => $x, y => $from->y, z => $from->z); |
59
|
|
|
|
|
|
|
} else { |
60
|
218
|
100
|
|
|
|
340
|
my $y = $from->y + ($dy > 0 ? 1 : -1); |
61
|
218
|
|
|
|
|
763
|
return Game::TextMapper::Point->new(x => $from->x, y => $y, z => $from->z); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |