| 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 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | #_} | ||||||||||||||||||||||||||||
| 15 | 5 | 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 | 44 | ▶ | sub new { #_{ | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 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 | my $class = shift; | |||||||||||||||||||||||||||
| 47 | 44 | my $grid_layout = shift; | |||||||||||||||||||||||||||
| 48 | 44 | my $V_or_H = shift; | |||||||||||||||||||||||||||
| 49 | 44 | my $position = shift; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 44 | ▶ | croak 'Grid::Layout expected' unless $grid_layout->isa('Grid::Layout'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 44 | ▶ | croak 'V or H expected' unless $V_or_H eq 'V' or $V_or_H eq 'H'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$V_or_H eq "V" or $V_or_H eq "H"
MC/DC0%0/2
$V_or_H eq "V" or $V_or_H eq "H"
$V_or_H eq "V"
$V_or_H eq "H"
Truth table66%2/3
A or B
A= $V_or_H eq "V"B= $V_or_H eq "H"
| |||||||||||||||||||||||||||||
| 53 | 44 | ▶ | croak 'position not a number' unless $position =~ /^\d+$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 44 | my $self = {}; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 44 | $self -> {grid_layout} = $grid_layout; | |||||||||||||||||||||||||||
| 58 | 44 | $self -> {V_or_H } = $V_or_H; | |||||||||||||||||||||||||||
| 59 | 44 | $self -> {position } = $position; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 44 | bless $self, $class; | |||||||||||||||||||||||||||
| 63 | 44 | return $self; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | } #_} | ||||||||||||||||||||||||||||
| 66 | #_{ line_left/right/above/beneath | ||||||||||||||||||||||||||||
| 67 | 2 | ▶ | sub line_left { #_{ | ||||||||||||||||||||||||||
|
Subroutine
line_left: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 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 | my $self = shift; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 2 | ▶ | croak 'Type of track is not vertical' unless $self->{V_or_H} eq 'V'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 2 | return $self->{grid_layout}->line_x($self->{position}); | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | } #_} | ||||||||||||||||||||||||||||
| 85 | 1 | ▶ | sub line_right { #_{ | ||||||||||||||||||||||||||
|
Subroutine
line_right: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 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 | my $self = shift; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 1 | ▶ | croak 'Type of track is not vertical' unless $self->{V_or_H} eq 'V'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 1 | return $self->{grid_layout}->line_x($self->{position} + 1); | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | } #_} | ||||||||||||||||||||||||||||
| 103 | 2 | ▶ | sub line_above { #_{ | ||||||||||||||||||||||||||
|
Subroutine
line_above: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 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 | my $self = shift; | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 2 | ▶ | croak 'Type of track is not horizontal' unless $self->{V_or_H} eq 'H'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 2 | return $self->{grid_layout}->line_y($self->{position}); | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | } #_} | ||||||||||||||||||||||||||||
| 121 | 1 | ▶ | sub line_beneath { #_{ | ||||||||||||||||||||||||||
|
Subroutine
line_beneath: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 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 | my $self = shift; | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 1 | ▶ | croak 'Type of track is not horizontal' unless $self->{V_or_H} eq 'H'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 1 | return $self->{grid_layout}->line_y($self->{position} + 1); | |||||||||||||||||||||||||||
| 137 | } #_} | ||||||||||||||||||||||||||||
| 138 | #_} | ||||||||||||||||||||||||||||
| 139 | 20 | ▶ | sub cells { #_{ | ||||||||||||||||||||||||||
|
Subroutine
cells: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 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 | my $self = shift; | |||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 20 | my @ret=(); | |||||||||||||||||||||||||||
| 153 | 20 | for my $p (0 .. $self->{grid_layout}->_size(Grid::Layout::VH_opposite($self->{V_or_H}))-1) { | |||||||||||||||||||||||||||
| 154 | 134 | ▶ | if ($self->{V_or_H} eq 'V') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | 10 | push @ret, $self->{grid_layout}->cell($self->{position}, $p); | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | else { | ||||||||||||||||||||||||||||
| 158 | 124 | push @ret, $self->{grid_layout}->cell($p, $self->{position}); | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 20 | return @ret; | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | } #_} | ||||||||||||||||||||||||||||
| 165 | 4 | ▶ | sub area { #_{ | ||||||||||||||||||||||||||
|
Subroutine
area: called CC=10 SCAR=23.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 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 | my $self = shift; | |||||||||||||||||||||||||||
| 189 | 4 | my $from = shift; | |||||||||||||||||||||||||||
| 190 | 4 | my $to = shift; | |||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 4 | ▶ | croak '$from must be a Grid::Layout::Track/Line' unless $from->isa('Grid::Layout::Track') or $from->isa('Grid::Layout::Line'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$from->isa("Grid::Layout::Track") or $from->isa("Grid::Layout::Line")
MC/DC0%0/2
$from->isa("Grid::Layout::Track") or $from->isa("Grid::Layout::Line")
$from->isa("Grid::Layout::Track")
$from->isa("Grid::Layout::Line")
Truth table66%2/3
A or B
A= $from->isa("Grid::Layout::Track")B= $from->isa("Grid::Layout::Line")
| |||||||||||||||||||||||||||||
| 193 | 4 | ▶ | croak '$to must be a Grid::Layout::Track/Line' unless $to ->isa('Grid::Layout::Track') or $to ->isa('Grid::Layout::Line'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$to->isa("Grid::Layout::Track") or $to->isa("Grid::Layout::Line")
MC/DC0%0/2
$to->isa("Grid::Layout::Track") or $to->isa("Grid::Layout::Line")
$to->isa("Grid::Layout::Track")
$to->isa("Grid::Layout::Line")
Truth table66%2/3
A or B
A= $to->isa("Grid::Layout::Track")B= $to->isa("Grid::Layout::Line")
| |||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 4 | my $track_from; | |||||||||||||||||||||||||||
| 196 | my $track_to; | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 4 | ▶ | if ($from->isa('Grid::Layout::Track')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | 2 | $track_from = $from; | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | else { | ||||||||||||||||||||||||||||
| 202 | 2 | $track_from = $from->_next_track; | |||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | 4 | ▶ | if ($to->isa('Grid::Layout::Track')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 205 | 3 | $track_to = $to; | |||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | else { | ||||||||||||||||||||||||||||
| 208 | 1 | $track_to = $to->_previous_track; | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 4 | ▶ | croak '$track_from must be other direction' unless $track_from->{V_or_H} eq Grid::Layout::VH_opposite($self->{V_or_H}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 212 | 4 | ▶ | croak '$track_from must be other direction' unless $track_to ->{V_or_H} eq Grid::Layout::VH_opposite($self->{V_or_H}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 4 | ▶ | if ($self->{V_or_H} eq 'V') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 215 | 2 | return $self->{grid_layout}->area($self, $track_from, $self, $track_to); | |||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | else { | ||||||||||||||||||||||||||||
| 218 | 2 | 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<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | =cut | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | #_} | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 5 | 'tq84'; | |||||||||||||||||||||||||||