line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#_{ Encoding and name |
2
|
|
|
|
|
|
|
=encoding utf8 |
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
Grid::Layout::Track |
5
|
|
|
|
|
|
|
=cut |
6
|
|
|
|
|
|
|
#_} |
7
|
|
|
|
|
|
|
package Grid::Layout::Track; |
8
|
|
|
|
|
|
|
#_{ use … |
9
|
5
|
|
|
5
|
|
25
|
use warnings; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
126
|
|
10
|
5
|
|
|
5
|
|
20
|
use strict; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
69
|
|
11
|
5
|
|
|
5
|
|
28
|
use utf8; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
21
|
|
12
|
|
|
|
|
|
|
|
13
|
5
|
|
|
5
|
|
92
|
use Carp; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
2874
|
|
14
|
|
|
|
|
|
|
#_} |
15
|
|
|
|
|
|
|
our $VERSION = $Grid::Layout::VERSION; |
16
|
|
|
|
|
|
|
#_{ Synopsis |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
#_} |
21
|
|
|
|
|
|
|
#_{ Description |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 DESCRIPTION |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
a C<< Grid::Layout::Track >> is the space between to adjacent L<< Grid::Layout::Line >>s. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Usually, a horizontal track is referred to as a row, a vertical track as a column. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
#_} |
31
|
|
|
|
|
|
|
#_{ Methods |
32
|
|
|
|
|
|
|
#_{ POD |
33
|
|
|
|
|
|
|
=head1 METHODS |
34
|
|
|
|
|
|
|
=cut |
35
|
|
|
|
|
|
|
#_} |
36
|
|
|
|
|
|
|
sub new { #_{ |
37
|
|
|
|
|
|
|
#_{ POD |
38
|
|
|
|
|
|
|
=head2 new |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Creates a C<< Grid::Layout::Track >>. Should not be called by the user. |
41
|
|
|
|
|
|
|
The constructor is called by L<< Grid::Layout/add_track >> instead. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
#_} |
45
|
|
|
|
|
|
|
|
46
|
44
|
|
|
44
|
0
|
55
|
my $class = shift; |
47
|
44
|
|
|
|
|
48
|
my $grid_layout = shift; |
48
|
44
|
|
|
|
|
50
|
my $V_or_H = shift; |
49
|
44
|
|
|
|
|
56
|
my $position = shift; |
50
|
|
|
|
|
|
|
|
51
|
44
|
50
|
|
|
|
117
|
croak 'Grid::Layout expected' unless $grid_layout->isa('Grid::Layout'); |
52
|
44
|
50
|
66
|
|
|
110
|
croak 'V or H expected' unless $V_or_H eq 'V' or $V_or_H eq 'H'; |
53
|
44
|
50
|
|
|
|
140
|
croak 'position not a number' unless $position =~ /^\d+$/; |
54
|
|
|
|
|
|
|
|
55
|
44
|
|
|
|
|
79
|
my $self = {}; |
56
|
|
|
|
|
|
|
|
57
|
44
|
|
|
|
|
72
|
$self -> {grid_layout} = $grid_layout; |
58
|
44
|
|
|
|
|
68
|
$self -> {V_or_H } = $V_or_H; |
59
|
44
|
|
|
|
|
64
|
$self -> {position } = $position; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
44
|
|
|
|
|
57
|
bless $self, $class; |
63
|
44
|
|
|
|
|
77
|
return $self; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
} #_} |
66
|
|
|
|
|
|
|
#_{ line_left/right/above/beneath |
67
|
|
|
|
|
|
|
sub line_left { #_{ |
68
|
|
|
|
|
|
|
#_{ POD |
69
|
|
|
|
|
|
|
=head2 line_left |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Returns the line to the left of the track. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Only applicable if the track is vertical (C<< $self->{V_or_H} eq 'V' >>). |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
#_} |
77
|
|
|
|
|
|
|
|
78
|
2
|
|
|
2
|
0
|
6
|
my $self = shift; |
79
|
|
|
|
|
|
|
|
80
|
2
|
50
|
|
|
|
5
|
croak 'Type of track is not vertical' unless $self->{V_or_H} eq 'V'; |
81
|
|
|
|
|
|
|
|
82
|
2
|
|
|
|
|
4
|
return $self->{grid_layout}->line_x($self->{position}); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
} #_} |
85
|
|
|
|
|
|
|
sub line_right { #_{ |
86
|
|
|
|
|
|
|
#_{ POD |
87
|
|
|
|
|
|
|
=head2 line_right |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Returns the line to the right of the track. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Only applicable if the track is vertical (C<< $self->{V_or_H} eq 'V' >>). |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
#_} |
95
|
|
|
|
|
|
|
|
96
|
1
|
|
|
1
|
0
|
4
|
my $self = shift; |
97
|
|
|
|
|
|
|
|
98
|
1
|
50
|
|
|
|
3
|
croak 'Type of track is not vertical' unless $self->{V_or_H} eq 'V'; |
99
|
|
|
|
|
|
|
|
100
|
1
|
|
|
|
|
4
|
return $self->{grid_layout}->line_x($self->{position} + 1); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
} #_} |
103
|
|
|
|
|
|
|
sub line_above { #_{ |
104
|
|
|
|
|
|
|
#_{ POD |
105
|
|
|
|
|
|
|
=head2 line_left |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Returns the line above the track. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Only applicable if the track is vertical (C<< $self->{V_or_H} eq 'H' >>). |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |
112
|
|
|
|
|
|
|
#_} |
113
|
|
|
|
|
|
|
|
114
|
2
|
|
|
2
|
0
|
8
|
my $self = shift; |
115
|
|
|
|
|
|
|
|
116
|
2
|
50
|
|
|
|
5
|
croak 'Type of track is not horizontal' unless $self->{V_or_H} eq 'H'; |
117
|
|
|
|
|
|
|
|
118
|
2
|
|
|
|
|
4
|
return $self->{grid_layout}->line_y($self->{position}); |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
} #_} |
121
|
|
|
|
|
|
|
sub line_beneath { #_{ |
122
|
|
|
|
|
|
|
#_{ POD |
123
|
|
|
|
|
|
|
=head2 line_beneath |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Returns the line beneath the track. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Only applicable if the track is vertical (C<< $self->{V_or_H} eq 'H' >>). |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |
130
|
|
|
|
|
|
|
#_} |
131
|
|
|
|
|
|
|
|
132
|
1
|
|
|
1
|
0
|
393
|
my $self = shift; |
133
|
|
|
|
|
|
|
|
134
|
1
|
50
|
|
|
|
5
|
croak 'Type of track is not horizontal' unless $self->{V_or_H} eq 'H'; |
135
|
|
|
|
|
|
|
|
136
|
1
|
|
|
|
|
5
|
return $self->{grid_layout}->line_y($self->{position} + 1); |
137
|
|
|
|
|
|
|
} #_} |
138
|
|
|
|
|
|
|
#_} |
139
|
|
|
|
|
|
|
sub cells { #_{ |
140
|
|
|
|
|
|
|
#_{ POD |
141
|
|
|
|
|
|
|
=head2 cells |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
my @cells = $track->cells(); |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Return an array of the L<< cells|Grid::Layout::Cell >> in the track. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=cut |
148
|
|
|
|
|
|
|
#_} |
149
|
|
|
|
|
|
|
|
150
|
20
|
|
|
20
|
0
|
463
|
my $self = shift; |
151
|
|
|
|
|
|
|
|
152
|
20
|
|
|
|
|
30
|
my @ret=(); |
153
|
20
|
|
|
|
|
52
|
for my $p (0 .. $self->{grid_layout}->_size(Grid::Layout::VH_opposite($self->{V_or_H}))-1) { |
154
|
134
|
100
|
|
|
|
204
|
if ($self->{V_or_H} eq 'V') { |
155
|
10
|
|
|
|
|
18
|
push @ret, $self->{grid_layout}->cell($self->{position}, $p); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
else { |
158
|
124
|
|
|
|
|
224
|
push @ret, $self->{grid_layout}->cell($p, $self->{position}); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
20
|
|
|
|
|
50
|
return @ret; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
} #_} |
165
|
|
|
|
|
|
|
sub area { #_{ |
166
|
|
|
|
|
|
|
#_{ POD |
167
|
|
|
|
|
|
|
=head2 area |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
my $track_v = $gl->add_vertical_track(…); |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
my $track_h_from = $gl->add_horizontal_track(…); |
172
|
|
|
|
|
|
|
my $track_h_to = $gl->add_horizontal_track(…); |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
my $line_h_from = $gl->add_line(…); |
175
|
|
|
|
|
|
|
my $line_h_to = $gl->add_line(…); |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
my $area_1 = $track_v->area($track_h_from, $track_h_to); |
179
|
|
|
|
|
|
|
my $area_2 = $track_v->area($line_h_from , $line_h_to ); |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Defines an L<< area|Grid::Layout::Area >> lying on C<< $track_v >> between C<< $track_h_from >> and C<< $track_h_to >>. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
An area that is bound by four tracks can be created with L<< Grid::Layout/area >>. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=cut |
186
|
|
|
|
|
|
|
#_} |
187
|
|
|
|
|
|
|
|
188
|
4
|
|
|
4
|
0
|
14
|
my $self = shift; |
189
|
4
|
|
|
|
|
11
|
my $from = shift; |
190
|
4
|
|
|
|
|
9
|
my $to = shift; |
191
|
|
|
|
|
|
|
|
192
|
4
|
50
|
66
|
|
|
20
|
croak '$from must be a Grid::Layout::Track/Line' unless $from->isa('Grid::Layout::Track') or $from->isa('Grid::Layout::Line'); |
193
|
4
|
50
|
66
|
|
|
24
|
croak '$to must be a Grid::Layout::Track/Line' unless $to ->isa('Grid::Layout::Track') or $to ->isa('Grid::Layout::Line'); |
194
|
|
|
|
|
|
|
|
195
|
4
|
|
|
|
|
7
|
my $track_from; |
196
|
|
|
|
|
|
|
my $track_to; |
197
|
|
|
|
|
|
|
|
198
|
4
|
100
|
|
|
|
12
|
if ($from->isa('Grid::Layout::Track')) { |
199
|
2
|
|
|
|
|
4
|
$track_from = $from; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
else { |
202
|
2
|
|
|
|
|
6
|
$track_from = $from->_next_track; |
203
|
|
|
|
|
|
|
} |
204
|
4
|
100
|
|
|
|
12
|
if ($to->isa('Grid::Layout::Track')) { |
205
|
3
|
|
|
|
|
3
|
$track_to = $to; |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
else { |
208
|
1
|
|
|
|
|
3
|
$track_to = $to->_previous_track; |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
4
|
50
|
|
|
|
13
|
croak '$track_from must be other direction' unless $track_from->{V_or_H} eq Grid::Layout::VH_opposite($self->{V_or_H}); |
212
|
4
|
50
|
|
|
|
10
|
croak '$track_from must be other direction' unless $track_to ->{V_or_H} eq Grid::Layout::VH_opposite($self->{V_or_H}); |
213
|
|
|
|
|
|
|
|
214
|
4
|
100
|
|
|
|
9
|
if ($self->{V_or_H} eq 'V') { |
215
|
2
|
|
|
|
|
6
|
return $self->{grid_layout}->area($self, $track_from, $self, $track_to); |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
else { |
218
|
2
|
|
|
|
|
6
|
return $self->{grid_layout}->area($track_from, $self, $track_to, $self); |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
} #_} |
223
|
|
|
|
|
|
|
#_} |
224
|
|
|
|
|
|
|
#_{ POD: Copyright |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head1 Copyright |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
Copyright © 2017 René Nyffenegger, Switzerland. All rights reserved. |
229
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
230
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
231
|
|
|
|
|
|
|
copy of the full license at: L |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=cut |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
#_} |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
'tq84'; |