| 1 | # Copyright 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Kevin Ryde | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | # This file is part of Math-PlanePath. | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # Math-PlanePath is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # it under the terms of the GNU General Public License as published by the | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # Free Software Foundation; either version 3, or (at your option) any later | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # version. | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # Math-PlanePath is distributed in the hope that it will be useful, but | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # for more details. | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||||||||||||||||
| 15 | # You should have received a copy of the GNU General Public License along | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # with Math-PlanePath. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | package Math::PlanePath::Rows; | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 3 | ▶ | use 5.004; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 3 | ▶ | use vars '$VERSION', '@ISA'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 3 | $VERSION = 128; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 3 | ▶ | use Math::PlanePath; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 3 | @ISA = ('Math::PlanePath'); | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | use Math::PlanePath::Base::Generic | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 3 | 'round_nearest', | |||||||||||||||||||||||||||||||||||||||||
| 30 | 3 | ▶ | 'floor'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | # uncomment this to run the ### lines | ||||||||||||||||||||||||||||||||||||||||||
| 33 | #use Smart::Comments; | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 3 | ▶ | use constant class_x_negative => 0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 3 | ▶ | use constant class_y_negative => 0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 3 | ▶ | use constant n_frac_discontinuity => .5; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 3 | use constant parameter_info_array => | |||||||||||||||||||||||||||||||||||||||||
| 41 | 3 | ▶ | [ Math::PlanePath::Base::Generic::parameter_info_nstart1() ]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | sub x_maximum { | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_maximum: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | return $self->{'width'} - 1; | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | sub dx_minimum { | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dx_minimum: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | return - ($self->{'width'}-1); | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | sub dx_maximum { | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dx_maximum: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | return ($self->{'width'} <= 1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | ? 0 # single column only | ||||||||||||||||||||||||||||||||||||||||||
| 56 | : 1); | ||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | sub dy_minimum { | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dy_minimum: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | return ($self->{'width'} <= 1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | ? 1 # single column only | ||||||||||||||||||||||||||||||||||||||||||
| 63 | : 0); | ||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 3 | ▶ | use constant dy_maximum => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | sub _UNDOCUMENTED__dxdy_list { | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_UNDOCUMENTED__dxdy_list: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | return (($self->{'width'} >= 2 ? (1,0) # E too | ||||||||||||||||||||||||||||||||||||||||||
| 69 | : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | 1-$self->{'width'}, 1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | sub _UNDOCUMENTED__dxdy_list_at_n { | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_UNDOCUMENTED__dxdy_list_at_n: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | return $self->n_start + $self->{'width'} - 1; | |||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | sub absdx_minimum { | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
absdx_minimum: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | return ($self->{'width'} <= 1 ? 0 : 1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | sub absdy_minimum { | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
absdy_minimum: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | return ($self->{'width'} <= 1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | ? 1 # single column only | ||||||||||||||||||||||||||||||||||||||||||
| 85 | : 0); | ||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | sub dsumxy_minimum { | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dsumxy_minimum: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | return 2 - $self->{'width'}; # dX=-(width-1) dY=+1 | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 3 | ▶ | use constant dsumxy_maximum => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | sub ddiffxy_minimum { | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ddiffxy_minimum: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | # dX=-(width-1) dY=+1 gives dDiffXY=-width+1-1=-width | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | return - $self->{'width'}; | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | sub ddiffxy_maximum { | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ddiffxy_maximum: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | return ($self->{'width'} == 1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | ? -1 # constant dY=-1 | ||||||||||||||||||||||||||||||||||||||||||
| 102 | : 1); # straight E | ||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | sub dir_minimum_dxdy { | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dir_minimum_dxdy: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | return ($self->{'width'} == 1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | ? (0,1) # width=1 North only | ||||||||||||||||||||||||||||||||||||||||||
| 109 | : (1,0)); # width>1 East | ||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | sub dir_maximum_dxdy { | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dir_maximum_dxdy: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | return (1-$self->{'width'}, 1); | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | sub turn_any_left { | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
turn_any_left: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | return ($self->{'width'} > 1); # width==1 only straight ahead | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | sub _UNDOCUMENTED__turn_any_left_at_n { | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_UNDOCUMENTED__turn_any_left_at_n: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | return ($self->{'width'} == 1 ? undef | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | : $self->n_start + $self->{'width'} - 1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 3 | *turn_any_right = \&turn_any_left; | |||||||||||||||||||||||||||||||||||||||||
| 127 | sub _UNDOCUMENTED__turn_any_right_at_n { | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_UNDOCUMENTED__turn_any_right_at_n: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | return ($self->{'width'} == 1 ? undef | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | : $self->n_start + $self->{'width'}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | sub turn_any_straight { | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
turn_any_straight: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | return ($self->{'width'} != 2); # width=2 never straight | |||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 10 | ▶ | my $self = shift->SUPER::new (@_); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 10 | ▶ | if (! exists $self->{'width'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 2 | $self->{'width'} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 10 | ▶ | if (! defined $self->{'n_start'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 10 | $self->{'n_start'} = $self->default_n_start; | |||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | ### width: $self->{'width'} | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 10 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | sub n_to_xy { | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 11 | ▶ | my ($self, $n) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
n_to_xy: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | ### Rows n_to_xy(): "$n" | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | # no division by width=0, and width<0 not meaningful for now | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 11 | my $width; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 11 | ▶ | if (($width = $self->{'width'}) <= 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | ### no points for width<=0 | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 11 | $n = $n - $self->{'n_start'}; # zero based | |||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 11 | my $int = int($n); # BigFloat int() gives BigInt, use that | |||||||||||||||||||||||||||||||||||||||||
| 167 | 11 | $n -= $int; # fraction part, preserve any BigFloat | |||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 11 | ▶ | if (2*$n >= 1) { # if $n >= 0.5, but BigInt friendly | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 4 | $n -= 1; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 4 | $int += 1; | |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | ### $n | ||||||||||||||||||||||||||||||||||||||||||
| 174 | ### $int | ||||||||||||||||||||||||||||||||||||||||||
| 175 | ### assert: $n >= -0.5 | ||||||||||||||||||||||||||||||||||||||||||
| 176 | ### assert: $n < 0.5 | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 11 | my $y = int ($int / $width); | |||||||||||||||||||||||||||||||||||||||||
| 179 | 11 | $int -= $y*$width; | |||||||||||||||||||||||||||||||||||||||||
| 180 | 11 | ▶ | if ($int < 0) { # ensure round down when $int negative | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | $int += $width; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | $y -= 1; | |||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 184 | ### floor y: $y | ||||||||||||||||||||||||||||||||||||||||||
| 185 | ### remainder: $int | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 11 | return ($n + $int, | |||||||||||||||||||||||||||||||||||||||||
| 188 | $y); | ||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | sub xy_to_n { | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 7 | ▶ | my ($self, $x, $y) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xy_to_n: called CC=3 SCAR=12.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | 7 | $x = round_nearest ($x); | |||||||||||||||||||||||||||||||||||||||||
| 195 | 7 | ▶ | if ($x < 0 || $x >= $self->{'width'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$x < 0 or $x >= $self->{"width"}
MC/DC0%0/2
$x < 0 or $x >= $self->{"width"}
$x < 0
$x >= $self->{"width"}
Truth table33%1/3
A or B
A= $x < 0B= $x >= $self->{"width"}
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | return undef; # outside the column | |||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | 7 | $y = round_nearest ($y); | |||||||||||||||||||||||||||||||||||||||||
| 199 | 7 | return $x + $y * $self->{'width'} + $self->{'n_start'}; | |||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | # exact | ||||||||||||||||||||||||||||||||||||||||||
| 203 | sub rect_to_n_range { | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 6 | ▶ | my ($self, $x1,$y1, $x2,$y2) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rect_to_n_range: called CC=8 SCAR=21.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | ### rect_to_n_range: "$x1,$y1 $x2,$y2" | ||||||||||||||||||||||||||||||||||||||||||
| 206 | 6 | my $width = $self->{'width'}; | |||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | 6 | $x1 = round_nearest ($x1); | |||||||||||||||||||||||||||||||||||||||||
| 209 | 6 | $x2 = round_nearest ($x2); | |||||||||||||||||||||||||||||||||||||||||
| 210 | 6 | ▶ | if ($x2 < $x1) { ($x1,$x2) = ($x2,$x1) } # swap to x1<x2 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | ### x range: "$x1 to $x2" | ||||||||||||||||||||||||||||||||||||||||||
| 213 | ### assert: $x1<=$x2 | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 6 | ▶ | if ($width <= 0 || $x1 >= $width || $x2 < 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$width <= 0 or $x1 >= $width or $x2 < 0
$width <= 0 or $x1 >= $width
MC/DC0%0/3
$width <= 0 or $x1 >= $width or $x2 < 0
$width <= 0
$x1 >= $width
$x2 < 0
Truth table25%1/4
A or B or C
A= $width <= 0B= $x1 >= $widthC= $x2 < 0
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | ### completely outside 0 to width, or width<=0 | ||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | return (1,0); | |||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 6 | $y1 = round_nearest ($y1); | |||||||||||||||||||||||||||||||||||||||||
| 220 | 6 | $y2 = round_nearest ($y2); | |||||||||||||||||||||||||||||||||||||||||
| 221 | 6 | ▶ | if ($y2 < $y1) { ($y1,$y2) = ($y2,$y1) } # swap to y1<y2 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | ### assert: $y1<=$y2 | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 6 | ▶ | if ($x1 < 0) { $x1 *= 0; } # preserve bignum | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 6 | ▶ | if ($x2 >= $width) { $x2 = ($x2 * 0) + $width-1; } # preserve bignum | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | ### rect exact on: "$x1,$y1 $x2,$y2" | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | # exact range bottom left to top right | ||||||||||||||||||||||||||||||||||||||||||
| 230 | return ($x1 + $y1 * $width + $self->{'n_start'}, | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 6 | $x2 + $y2 * $width + $self->{'n_start'}); | |||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 235 | __END__ | ||||||||||||||||||||||||||||||||||||||||||