PlanePath/AlternatePaper.pm

filter: Statementstmt 68.7% 213 / 310 Branchbran 53.6% 73 / 136 Conditioncond 50.8% 59 / 116 MC/DCmcdc 38.1% 21 / 55 Subroutinesub 60.0% 21 / 35 Podpod 100% 12 / 12 totaltotal 60.0% 399 / 664 CC 111 SCAR 35.5
CC
111
Cov
61%
_UNDOCUMENTED__n_segment_is_left_boundary
156.0
_UNDOCUMENTED__n_is_x_positive
56.0
_UNDOCUMENTED__n_is_diagonal_NE
42.0
CRAP 34.8
« PlanePath/WythoffArray.pm ↑ Summary PlanePath/DigitGroups.pm »
1 # Copyright 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 # ENHANCE-ME: Explanation for this bit ...
20 # 'arms=4' =>
21 # { dSum => 'A020985', # GRS
22 # # OEIS-Other: A020985 planepath=AlternatePaper,arms=4 delta_type=dSum
23 # },
24  
25  
26 package Math::PlanePath::AlternatePaper;
27 2 ▶use 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 2 ▶use List::Util 'min'; # 'max'
Subroutine BEGIN: called CC=1 SCAR=0.0
30 2 *max = \&Math::PlanePath::_max;
31  
32 2 ▶use vars '$VERSION', '@ISA';
Subroutine BEGIN: called CC=1 SCAR=0.0
33 2 $VERSION = 128;
34 2 ▶use Math::PlanePath;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 2 ▶use Math::PlanePath::Base::NSEW;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 2 @ISA = ('Math::PlanePath::Base::NSEW',
37 'Math::PlanePath');
38  
39 use Math::PlanePath::Base::Generic
40 2 'is_infinite',
41 2 ▶ 'round_nearest';
Subroutine BEGIN: called CC=1 SCAR=0.0
42 use Math::PlanePath::Base::Digits
43 2 'round_down_pow',
44 'digit_split_lowtohigh',
45 'digit_join_lowtohigh',
46 2 ▶ 'bit_split_lowtohigh';
Subroutine BEGIN: called CC=1 SCAR=0.0
47 2 *_divrem = \&Math::PlanePath::_divrem;
48 2 *_divrem_mutate = \&Math::PlanePath::_divrem_mutate;
49  
50 # uncomment this to run the ### lines
51 # use Smart::Comments;
52  
53  
54 2 use constant parameter_info_array => [ { name => 'arms',
55 share_key => 'arms_8',
56 display => 'Arms',
57 type => 'integer',
58 minimum => 1,
59 maximum => 8,
60 default => 1,
61 width => 1,
62 description => 'Arms',
63 2 ▶ } ];
Subroutine BEGIN: called CC=1 SCAR=0.0
64  
65 2 ▶use constant n_start => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 sub x_negative {
67 6 ▶ my ($self) = @_;
Subroutine x_negative: called CC=1 SCAR=0.0
Pod documented
68 6 return ($self->{'arms'} >= 3);
69 }
70 sub y_negative {
71 6 ▶ my ($self) = @_;
Subroutine y_negative: called CC=1 SCAR=0.0
Pod documented
72 6 return ($self->{'arms'} >= 5);
73 }
74 {
75 2 my @x_negative_at_n = (undef,
76 undef,undef,8,7,
77 4,4,4,4);
78 sub x_negative_at_n {
79 0 ▶ my ($self) = @_;
Subroutine x_negative_at_n: not called CC=1 SCAR=6.9
Pod documented
80 0 return $x_negative_at_n[$self->{'arms'}];
81 }
82 }
83 {
84 2 my @y_negative_at_n = (undef,
85 undef,undef,undef,undef,
86 44,23,13,14);
87 sub y_negative_at_n {
88 0 ▶ my ($self) = @_;
Subroutine y_negative_at_n: not called CC=1 SCAR=6.9
Pod documented
89 0 return $y_negative_at_n[$self->{'arms'}];
90 }
91 }
92  
93 2 sub sumxy_minimum {
94 0 ▶ my ($self) = @_;
Subroutine sumxy_minimum: not called CC=2 SCAR=17.9
Pod documented
95 0 ▶ return ($self->arms_count <= 3
Branch: 1 branch
BranchTrueFalseTotal
$self->arms_count <= 3 ? : 0 0 0
96 ? 0 # 1,2,3 arms above X=-Y diagonal
97 : undef);
98 }
99 sub diffxy_minimum {
100 0 ▶ my ($self) = @_;
Subroutine diffxy_minimum: not called CC=2 SCAR=17.9
Pod documented
101 0 ▶ return ($self->arms_count == 1
Branch: 1 branch
BranchTrueFalseTotal
$self->arms_count == 1 ? : 0 0 0
102 ? 0 # 1 arms right of X=Y diagonal
103 : undef);
104 }
105  
106 2 ▶use constant turn_any_straight => 0; # never straight
Subroutine BEGIN: called CC=1 SCAR=0.0
107  
108  
109 #------------------------------------------------------------------------------
110  
111 sub new {
112 37 ▶ my $self = shift->SUPER::new(@_);
Subroutine new: called CC=2 SCAR=6.9
Pod documented
113 37 ▶ $self->{'arms'} = max(1, min(8, $self->{'arms'} || 1));
Condition100%2/2
$self->{'arms'} || 1
l!l
334
MC/DC100%1/1
$self->{'arms'} || 1
$self->{'arms'}
Truth table100%2/2
A
A= $self->{'arms'}
Aresult
11
00
114 37 return $self;
115 }
116  
117 {
118 # <------
119 # state=0 /| +----+----+
120 # (dir=0) / | |\ 1||<--/
121 # /2 | |^\ || 0/
122 # /-->| || \v| /
123 # +----+ ||3 \|/
124 # /|\ 3|| +----+
125 # / |^\ || |<--/ state=4
126 # / 0|| \v| | 2/ (dir=2)
127 # /-->||1 \| | /
128 # +----+----+ |/
129 # -------->
130 #
131 # |\ state=8 +----+----+ state=12
132 # ^ |^\ (dir=1) \ 1||<--/| | (dir=3)
133 # | || \ \ || 0/ | |
134 # | ||3 \ \v| /2 | |
135 # | +----+ \|/-->| |
136 # | |<--/|\ +----+ |
137 # | | 2/ |^\ \ 3|| |
138 # | | /0 || \ \ || |
139 # | |/-->||1 \ \v| v
140 # +----+----+ \|
141  
142 2 my @next_state = (0, 8, 0, 12, # forward
143 4, 12, 4, 8, # forward NW
144 0, 8, 4, 8, # reverse
145 4, 12, 0, 12, # reverse NE
146 );
147 2 my @digit_to_x = (0,1,1,1,
148 1,0,0,0,
149 0,1,0,0,
150 1,0,1,1,
151 );
152 2 my @digit_to_y = (0,0,1,0,
153 1,1,0,1,
154 0,0,0,1,
155 1,1,1,0,
156 );
157  
158 # state_to_dx[S] == state_to_x[S+3] - state_to_x[S+0]
159 2 my @state_to_dx = (1, -1, 0, 0);
160 2 my @state_to_dy = (0, 0, 1, -1);
161  
162 sub n_to_xy {
163 7847 ▶ my ($self, $n) = @_;
Subroutine n_to_xy: called CC=7 SCAR=19.5
Pod documented
164 ### AlternatePaper n_to_xy(): $n
165  
166 7847 ▶ if ($n < 0) { return; }
Branch: 1 branch
BranchTrueFalseTotal
if ($n < 0) 0 7847 7847
167 7847 ▶ if (is_infinite($n)) { return ($n, $n); }
Branch: 1 branch
BranchTrueFalseTotal
if (is_infinite($n)) 0 7847 7847
168  
169 7847 my $int = int($n); # integer part
170 7847 $n -= $int; # fraction part
171 ### $int
172 ### $n
173  
174 7847 my $zero = ($int * 0); # inherit bignum 0
175 7847 my $arm = _divrem_mutate ($int, $self->{'arms'});
176  
177 ### $arm
178 ### $int
179  
180 7847 my @digits = digit_split_lowtohigh($int,4);
181 7847 my $state = 0;
182 7847 my (@xbits,@ybits); # bits low to high (like @digits)
183  
184 7847 foreach my $i (reverse 0 .. $#digits) { # high to low
185 19090 $state += $digits[$i];
186 19090 $xbits[$i] = $digit_to_x[$state];
187 19090 $ybits[$i] = $digit_to_y[$state];
188 19090 $state = $next_state[$state];
189 }
190 7847 my $x = digit_join_lowtohigh(\@xbits,2,$zero);
191 7847 my $y = digit_join_lowtohigh(\@ybits,2,$zero);
192  
193 # X+1,Y+1 for final state=4 or state=12
194 7847 $x += $digit_to_x[$state];
195 7847 $y += $digit_to_y[$state];
196  
197 ### final: "xy=$x,$y state=$state"
198  
199 # apply possible fraction part of $n in direction of $state
200 7847 $x = $n * $state_to_dx[$state >>= 2] + $x;
201 7847 $y = $n * $state_to_dy[$state] + $y;
202  
203 # rotate,transpose for arm number
204 7847 ▶ if ($arm & 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arm & 1) 3368 4479 7847
205 3368 ($x,$y) = ($y,$x); # transpose
206 }
207 7847 ▶ if ($arm & 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arm & 2) 2888 4959 7847
208 2888 ($x,$y) = (-$y,$x+1); # rotate +90 and shift origin to X=0,Y=1
209 }
210 7847 ▶ if ($arm & 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arm & 4) 2028 5819 7847
211 2028 $x = -1 - $x; # rotate +180 and shift origin to X=-1,Y=1
212 2028 $y = 1 - $y;
213 }
214  
215 ### rotated return: "$x,$y"
216 7847 return ($x,$y);
217 }
218 }
219  
220 # 8
221 #
222 # 42 43 7
223 #
224 # 40 41/45 44 6
225 #
226 # 34 35/39 38/46 47 5
227 #
228 # 32-33/53-36/52-37/49---48 4
229 # | \
230 # 10 11/31 30/54 51/55 50/58 59 3
231 # | \
232 # 8 9/13 12/28 25/29 24/56 57/61 60 2
233 # | \
234 # 2 3/7 6/14 15/27 18/26 19/23 22/62 63 1
235 # | \
236 # 0 1 4 5 16 17 20 21 ==64 0
237 #
238 # 0 1 2 3 4 5 6 7 8
239  
240 2 sub xy_to_n {
241 121 ▶ return scalar((shift->xy_to_n_list(@_))[0]);
Subroutine xy_to_n: called CC=1 SCAR=0.0
Pod documented
242 }
243 sub xy_to_n_list {
244 159 ▶ my ($self, $x, $y) = @_;
Subroutine xy_to_n_list: called CC=6 SCAR=18.1
Pod documented
245 ### AlternatePaper xy_to_n(): "$x, $y"
246  
247 159 $x = round_nearest($x);
248 159 $y = round_nearest($y);
249 159 ▶ if (is_infinite($x)) { return $x; }
Branch: 1 branch
BranchTrueFalseTotal
if (is_infinite($x)) 0 159 159
250 159 ▶ if (is_infinite($y)) { return $y; }
Branch: 1 branch
BranchTrueFalseTotal
if (is_infinite($y)) 0 159 159
251  
252 159 my $arms = $self->{'arms'};
253 159 my $arm = 0;
254 159 my @ret;
255 159 foreach (1 .. 4) {
256 231 push @ret, map {$_*$arms+$arm} _xy_to_n_list__onearm($self,$x,$y);
257 231 ▶ last if ++$arm >= $arms;
Branch: 1 branch
BranchTrueFalseTotal
if ++$arm >= $arms 118 113 231
258  
259 113 ($x,$y) = ($y,$x); # transpose
260 113 push @ret, map {$_*$arms+$arm} _xy_to_n_list__onearm($self,$x,$y);
261 113 ▶ last if ++$arm >= $arms;
Branch: 1 branch
BranchTrueFalseTotal
if ++$arm >= $arms 41 72 113
262  
263 # X,Y -> Y,X
264 # -> Y,X-1 # Y-1 shift
265 # -> X-1,-Y # rot -90
266 # ie. mirror across X axis and shift
267 72 ($x,$y) = ($x-1,-$y);
268 }
269 159 return sort {$a<=>$b} @ret;
270 }
271  
272 sub _xy_to_n_list__onearm {
273 344 ▶ my ($self, $x, $y) = @_;
Subroutine _xy_to_n_list__onearm: called CC=41 SCAR=37.2
274 ### _xy_to_n_list__onearm(): "$x,$y"
275  
276 344 ▶ if ($y < 0 || $y > $x || $x < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < 0 or $y > $x or $x < 0) 95 163 258
Condition83%5/6
$y < 0 or $y > $x or $x < 0
l!l&&r!l&&!r
1810163
$y < 0 or $y > $x
l!l&&r!l&&!r
8695163
MC/DC66%2/3
$y < 0 or $y > $x or $x < 0
$y < 0 $y > $x $x < 0
Truth table75%3/4
A or B or C
A= $y < 0B= $y > $xC= $x < 0
ABCresult
1XX1
01X1
0011
0000
277 ### outside first octant ...
278 181 return;
279 }
280  
281 163 my ($len,$level) = round_down_pow($x, 2);
282 ### $len
283 ### $level
284 163 ▶ if (is_infinite($level)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_infinite($level)) 0 163 163
285 0 return;
286 }
287  
288 163 my $n = my $big_n = $x * 0 * $y; # inherit bignum 0
289 163 my $rev = 0;
290  
291 163 my $big_x = $x;
292 163 my $big_y = $y;
293 163 my $big_rev = 0;
294  
295 163 ▶ while ($level-- >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level-- >= 0) 457 163 620
296 ### at: "$x,$y len=$len n=$n"
297  
298 # the smaller N
299 {
300 457 $n *= 4;
301 457 ▶ if ($rev) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rev) { } 139 318 457
302 139 ▶ if ($x+$y < 2*$len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x + $y < 2 * $len) { } 47 92 139
303 ### rev 0 or 1 ...
304 47 ▶ if ($x < $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len) { } 24 23 47
305 } else {
306 ### rev 1 ...
307 23 $rev = 0;
308 23 $n -= 2;
309 23 ($x,$y) = ($len-$y, $x-$len); # x-len,y-len then rotate +90
310 }
311  
312 } else {
313 ### rev 2 or 3 ...
314 92 ▶ if ($y > $len || ($x==$len && $y==$len)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y > $len or $x == $len and $y == $len) { } 38 54 92
Condition83%5/6
$y > $len or $x == $len and $y == $len
l!l&&r!l&&!r
281054
$x == $len and $y == $len
!ll&&!rl&&r
54010
MC/DC66%2/3
$y > $len or $x == $len and $y == $len
$y > $len $x == $len $y == $len
Truth table75%3/4
A or B and C
A= $y > $lenB= $x == $lenC= $y == $len
ABCresult
1XX1
0111
00X0
0100
315 ### rev 2 ...
316 38 $n -= 2;
317 38 $x -= $len;
318 38 $y -= $len;
319 } else {
320 ### rev 3 ...
321 54 $n -= 4;
322 54 $rev = 0;
323 54 ($x,$y) = ($y, 2*$len-$x); # to origin then rotate -90
324 }
325 }
326 } else {
327 318 ▶ if ($x+$y <= 2*$len
Branch: 1 branch
BranchTrueFalseTotal
if ($x + $y <= 2 * $len and not $x == $len && $y == $len and not $x == 2 * $len && $y == 0) { } 187 131 318
Condition91%11/12
$x + $y <= 2 * $len and not $x == $len && $y == $len and not $x == 2 * $len && $y == 0
!ll&&!rl&&r
11516187
$x + $y <= 2 * $len and not $x == $len && $y == $len
!ll&&!rl&&r
8035203
$x == $len && $y == $len
!ll&&!rl&&r
1376635
$x == 2 * $len && $y == 0
!ll&&!rl&&r
187016
MC/DC80%4/5
$x + $y <= 2 * $len and not $x == $len && $y == $len and not $x == 2 * $len && $y == 0
$x + $y <= 2 * $len $x == $len $y == $len $x == 2 * $len $y == 0
Truth table62%5/8
A and not(B && C) and not(D && E)
A= $x + $y <= 2 * $lenB= $x == $lenC= $y == $lenD= $x == 2 * $lenE= $y == 0
ABCDEresult
0XXXX0
111XX0
10X110
110110
10X0X1
10X101
1100X1
110101
328 && !($x==$len && $y==$len)
329 && !($x==2*$len && $y==0)) {
330 ### 0 or 1 ...
331 187 ▶ if ($x <= $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x <= $len) { } 128 59 187
332 } else {
333 ### 1 ...
334 59 $n += 2;
335 59 $rev = 1;
336 59 ($x,$y) = ($len-$y, $x-$len); # x-len,y-len then rotate +90
337 }
338  
339 } else {
340 ### 2 or 3 ...
341 131 ▶ if ($y >= $len && !($x==2*$len && $y==$len)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y >= $len and not $x == 2 * $len && $y == $len) { } 72 59 131
Condition100%6/6
$y >= $len and not $x == 2 * $len && $y == $len
!ll&&!rl&&r
392072
$x == 2 * $len && $y == $len
!ll&&!rl&&r
65720
MC/DC100%3/3
$y >= $len and not $x == 2 * $len && $y == $len
$y >= $len $x == 2 * $len $y == $len
Truth table100%4/4
A and not(B && C)
A= $y >= $lenB= $x == 2 * $lenC= $y == $len
ABCresult
0XX0
1110
10X1
1101
342 72 $n += 2;
343 72 $x -= $len;
344 72 $y -= $len;
345 } else {
346 59 $n += 4;
347 59 $rev = 1;
348 59 ($x,$y) = ($y, 2*$len-$x); # to origin then rotate -90
349 }
350 }
351 }
352 }
353  
354 # the bigger N
355 {
356 457 $big_n *= 4;
357 457 ▶ if ($big_rev) {
Branch: 1 branch
BranchTrueFalseTotal
if ($big_rev) { } 188 269 457
358 188 ▶ if ($big_x+$big_y <= 2*$len
Branch: 1 branch
BranchTrueFalseTotal
if ($big_x + $big_y <= 2 * $len and not $big_x == $len && $big_y == $len and not $big_x == 2 * $len && $big_y == 0) { } 77 111 188
Condition91%11/12
$big_x + $big_y <= 2 * $len and not $big_x == $len && $big_y == $len and not $big_x == 2 * $len && $big_y == 0
!ll&&!rl&&r
951677
$big_x + $big_y <= 2 * $len and not $big_x == $len && $big_y == $len
!ll&&!rl&&r
851093
$big_x == $len && $big_y == $len
!ll&&!rl&&r
692410
$big_x == 2 * $len && $big_y == 0
!ll&&!rl&&r
77016
MC/DC80%4/5
$big_x + $big_y <= 2 * $len and not $big_x == $len && $big_y == $len and not $big_x == 2 * $len && $big_y == 0
$big_x + $big_y <= 2 * $len $big_x == $len $big_y == $len $big_x == 2 * $len $big_y == 0
Truth table62%5/8
A and not(B && C) and not(D && E)
A= $big_x + $big_y <= 2 * $lenB= $big_x == $lenC= $big_y == $lenD= $big_x == 2 * $lenE= $big_y == 0
ABCDEresult
0XXXX0
111XX0
10X110
110110
10X0X1
10X101
1100X1
110101
359 && !($big_x==$len && $big_y==$len)
360 && !($big_x==2*$len && $big_y==0)) {
361 ### rev 0 or 1 ...
362 77 ▶ if ($big_x <= $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($big_x <= $len) { } 50 27 77
363 } else {
364 ### rev 1 ...
365 27 $big_rev = 0;
366 27 $big_n -= 2;
367 27 ($big_x,$big_y) = ($len-$big_y, $big_x-$len); # x-len,y-len then rotate +90
368 }
369  
370 } else {
371 ### rev 2 or 3 ...
372 111 ▶ if ($big_y >= $len && !($big_x==2*$len && $big_y==$len)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($big_y >= $len and not $big_x == 2 * $len && $big_y == $len) { } 48 63 111
Condition100%6/6
$big_y >= $len and not $big_x == 2 * $len && $big_y == $len
!ll&&!rl&&r
392448
$big_x == 2 * $len && $big_y == $len
!ll&&!rl&&r
351324
MC/DC100%3/3
$big_y >= $len and not $big_x == 2 * $len && $big_y == $len
$big_y >= $len $big_x == 2 * $len $big_y == $len
Truth table100%4/4
A and not(B && C)
A= $big_y >= $lenB= $big_x == 2 * $lenC= $big_y == $len
ABCresult
0XX0
1110
10X1
1101
373 ### rev 2 ...
374 48 $big_n -= 2;
375 48 $big_x -= $len;
376 48 $big_y -= $len;
377 } else {
378 ### rev 3 ...
379 63 $big_n -= 4;
380 63 $big_rev = 0;
381 63 ($big_x,$big_y) = ($big_y, 2*$len-$big_x); # to origin then rotate -90
382 }
383 }
384 } else {
385 269 ▶ if ($big_x+$big_y < 2*$len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($big_x + $big_y < 2 * $len) { } 164 105 269
386 ### 0 or 1 ...
387 164 ▶ if ($big_x < $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($big_x < $len) { } 62 102 164
388 } else {
389 ### 1 ...
390 102 $big_n += 2;
391 102 $big_rev = 1;
392 102 ($big_x,$big_y) = ($len-$big_y, $big_x-$len); # x-len,y-len then rotate +90
393 }
394  
395 } else {
396 ### 2 or 3 ...
397 105 ▶ if ($big_y > $len || ($big_x==$len && $big_y==$len)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($big_y > $len or $big_x == $len and $big_y == $len) { } 55 50 105
Condition83%5/6
$big_y > $len or $big_x == $len and $big_y == $len
l!l&&r!l&&!r
203550
$big_x == $len and $big_y == $len
!ll&&!rl&&r
50035
MC/DC66%2/3
$big_y > $len or $big_x == $len and $big_y == $len
$big_y > $len $big_x == $len $big_y == $len
Truth table75%3/4
A or B and C
A= $big_y > $lenB= $big_x == $lenC= $big_y == $len
ABCresult
1XX1
0111
00X0
0100
398 55 $big_n += 2;
399 55 $big_x -= $len;
400 55 $big_y -= $len;
401 } else {
402 50 $big_n += 4;
403 50 $big_rev = 1;
404 50 ($big_x,$big_y) = ($big_y, 2*$len-$big_x); # to origin then rotate -90
405 }
406 }
407 }
408 }
409 457 $len /= 2;
410 }
411  
412 163 ▶ if ($x) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x) 66 97 163
413 66 ▶ $n += ($rev ? -1 : 1);
Branch: 1 branch
BranchTrueFalseTotal
$rev ? : 15 51 66
414 }
415 163 ▶ if ($big_x) {
Branch: 1 branch
BranchTrueFalseTotal
if ($big_x) 66 97 163
416 66 ▶ $big_n += ($big_rev ? -1 : 1);
Branch: 1 branch
BranchTrueFalseTotal
$big_rev ? : 47 19 66
417 }
418  
419 ### final: "$x,$y n=$n rev=$rev"
420 ### final: "$x,$y big_n=$n big_rev=$rev"
421  
422 163 ▶ return ($n,
Branch: 1 branch
BranchTrueFalseTotal
$n == $big_n ? : 103 60 163
423 ($n == $big_n ? () : ($big_n)));
424 }
425  
426  
427 # not exact
428 sub rect_to_n_range {
429 40 ▶ my ($self, $x1,$y1, $x2,$y2) = @_;
Subroutine rect_to_n_range: called CC=12 SCAR=27.2
Pod documented
430 ### AlternatePaper rect_to_n_range(): "$x1,$y1 $x2,$y2"
431  
432 40 $x1 = round_nearest($x1);
433 40 $x2 = round_nearest($x2);
434 40 $y1 = round_nearest($y1);
435 40 $y2 = round_nearest($y2);
436  
437 40 ▶ ($x1,$x2) = ($x2,$x1) if $x1 > $x2;
Branch: 1 branch
BranchTrueFalseTotal
if $x1 > $x2 0 40 40
438 40 ▶ ($y1,$y2) = ($y2,$y1) if $y1 > $y2;
Branch: 1 branch
BranchTrueFalseTotal
if $y1 > $y2 0 40 40
439  
440 ### rounded: "$x1,$y1 $x2,$y2"
441  
442 40 my $arms = $self->{'arms'};
443 40 ▶ if (($arms == 1 && $y1 > $x2) # x2,y1 bottom right corner
Branch: 1 branch
BranchTrueFalseTotal
if ($arms == 1 and $y1 > $x2 or $arms <= 2 and $x2 < 0 or $arms <= 4 and $y2 < 0) 0 40 40
Condition53%8/15
$arms == 1 and $y1 > $x2 or $arms <= 2 and $x2 < 0 or $arms <= 4 and $y2 < 0
l!l&&r!l&&!r
0040
$arms == 1 and $y1 > $x2 or $arms <= 2 and $x2 < 0
l!l&&r!l&&!r
0040
$arms == 1 and $y1 > $x2
!ll&&!rl&&r
3550
$arms <= 2 and $x2 < 0
!ll&&!rl&&r
30100
$arms <= 4 and $y2 < 0
!ll&&!rl&&r
20200
MC/DC0%0/6
$arms == 1 and $y1 > $x2 or $arms <= 2 and $x2 < 0 or $arms <= 4 and $y2 < 0
$arms == 1 $y1 > $x2 $arms <= 2 $x2 < 0 $arms <= 4 $y2 < 0
Truth table20%3/15
A and B or C and D or E and F
A= $arms == 1B= $y1 > $x2C= $arms <= 2D= $x2 < 0E= $arms <= 4F= $y2 < 0
ABCDEFresult
11XXXX1
0X11XX1
1011XX1
0X0X111
0X10111
100X111
1010111
0X0X0X0
0X0X100
0X100X0
0X10100
100X0X0
100X100
10100X0
1010100
444 || ($arms <= 2 && $x2 < 0)
445 || ($arms <= 4 && $y2 < 0)) {
446 ### outside ...
447 0 return (1,0);
448 }
449  
450 # arm start 0,1 at X=0,Y=0
451 # 2,3 at X=0,Y=1
452 # 4,5 at X=-1,Y=1
453 # 6,7 at X=-1,Y=1
454 # arms>=6 is arm=5 starting at Y=+1, so 1-$y1
455 # arms>=8 starts at X=-1 so extra +1 for x2 to the right in that case
456 40 ▶ my ($len, $level) =round_down_pow (max ($x2+($arms>=8),
Branch: 3 branches
BranchTrueFalseTotal
$arms >= 2 ? : 35 5 40
$arms >= 4 ? : 25 15 40
$arms >= 6 ? : 15 25 40
457 ($arms >= 2 ? $y2 : ()),
458 ($arms >= 4 ? -$x1 : ()),
459 ($arms >= 6 ? 1-$y1 : ())),
460 2);
461 40 return (0, 4*$arms*$len*$len-1);
462 }
463  
464  
465 2 my @dir4_to_dx = (1,0,-1,0);
466 2 my @dir4_to_dy = (0,1,0,-1);
467  
468 sub n_to_dxdy {
469 2000 ▶ my ($self, $n) = @_;
Subroutine n_to_dxdy: called CC=10 SCAR=28.7
Pod documented
470 ### n_to_dxdy(): $n
471  
472 2000 ▶ if ($n < 0) { return; }
Branch: 1 branch
BranchTrueFalseTotal
if ($n < 0) 0 2000 2000
473 2000 ▶ if (is_infinite($n)) { return ($n,$n); }
Branch: 1 branch
BranchTrueFalseTotal
if (is_infinite($n)) 0 2000 2000
474 2000 my $int = int($n);
475 2000 $n -= $int; # $n fraction part
476 ### $int
477 ### $n
478  
479 2000 my $arm = _divrem_mutate ($int, $self->{'arms'});
480 ### $arm
481 ### $int
482  
483 # $dir initial direction from the arm.
484 # $inc +/-1 according to the bit position odd or even, but also odd
485 # numbered arms are transposed so flip them.
486 #
487 2000 my @bits = bit_split_lowtohigh($int);
488 2000 my $dir = ($arm+1) >> 1;
489 2000 ▶ my $inc = (($#bits ^ $arm) & 1 ? -1 : 1);
Branch: 1 branch
BranchTrueFalseTotal
($#bits ^ $arm) & 1 ? : 681 1319 2000
490 2000 my $prev = 0;
491  
492 ### @bits
493 ### initial dir: $dir
494 ### initial inc: $inc
495  
496 2000 foreach my $bit (reverse @bits) {
497 15991 ▶ if ($bit != $prev) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bit != $prev) 9088 6903 15991
498 9088 $dir += $inc;
499 9088 $prev = $bit;
500 }
501 15991 $inc = -$inc; # opposite at each bit
502 }
503 2000 $dir &= 3;
504 2000 my $dx = $dir4_to_dx[$dir];
505 2000 my $dy = $dir4_to_dy[$dir];
506 ### $dx
507 ### $dy
508  
509 2000 ▶ if ($n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n) 0 2000 2000
510 ### apply fraction part: $n
511  
512 # maybe:
513 # +/- $n as dx or dy
514 # +/- (1-$n) as other dy or dx
515  
516 # strip any low 1-bits, and the 0-bit above them
517 # $inc is +1 at an even bit position or -1 at an odd bit position
518 0 ▶ $inc = my $inc = ($arm & 1 ? -1 : 1);
Branch: 1 branch
BranchTrueFalseTotal
$arm & 1 ? : 0 0 0
519 0 ▶ while (shift @bits) {
Branch: 1 branch
BranchTrueFalseTotal
if (shift @bits) 0 0 0
520 0 $inc = -$inc;
521 }
522 0 ▶ if ($bits[0]) { # bit above lowest 0-bit, 1=right,0=left
Branch: 1 branch
BranchTrueFalseTotal
if ($bits[0]) 0 0 0
523 0 $inc = -$inc;
524 }
525 0 $dir += $inc; # apply turn to give $dir at $n+1
526 0 $dir &= 3;
527 0 $dx += $n*($dir4_to_dx[$dir] - $dx);
528 0 $dy += $n*($dir4_to_dy[$dir] - $dy);
529 }
530  
531 ### result: "$dx, $dy"
532 2000 return ($dx,$dy);
533 }
534  
535 # {
536 # sub print_table {
537 # my ($name, $aref) = @_;
538 # print "my \@$name = (";
539 # my $entry_width = max (map {length($_//'')} @$aref);
540 #
541 # foreach my $i (0 .. $#$aref) {
542 # printf "%*s", $entry_width, $aref->[$i]//'undef';
543 # if ($i == $#$aref) {
544 # print ");\n";
545 # } else {
546 # print ",";
547 # if (($i % 16) == 15
548 # || ($entry_width >= 3 && ($i % 4) == 3)) {
549 # print "\n ".(" " x length($name));
550 # } elsif (($i % 4) == 3) {
551 # print " ";
552 # }
553 # }
554 # }
555 # }
556 #
557 # my @next_state;
558 # my @state_to_dxdy;
559 #
560 # sub make_state {
561 # my %values = @_;
562 # # if ($oddpos) { $rot = ($rot-1)&3; }
563 # my $state = delete $values{'nextturn'};
564 # $state <<= 2; $state |= delete $values{'rot'};
565 # $state <<= 1; $state |= delete $values{'oddpos'};
566 # $state <<= 1; $state |= delete $values{'lowerbit'};
567 # $state <<= 1; $state |= delete $values{'bit'};
568 # die if %values;
569 # return $state;
570 # }
571 # sub state_string {
572 # my ($state) = @_;
573 # my $bit = $state & 1; $state >>= 1;
574 # my $lowerbit = $state & 1; $state >>= 1;
575 # my $oddpos = $state & 1; $state >>= 1;
576 # my $rot = $state & 3; $state >>= 2;
577 # my $nextturn = $state;
578 # # if ($oddpos) { $rot = ($rot+1)&3; }
579 # return "rot=$rot,oddpos=$oddpos nextturn=$nextturn lowerbit=$lowerbit (bit=$bit)";
580 # }
581 #
582 # foreach my $nextturn (0, 1, 2) {
583 # foreach my $rot (0, 1, 2, 3) {
584 # foreach my $oddpos (0, 1) {
585 # foreach my $lowerbit (0, 1) {
586 # foreach my $bit (0, 1) {
587 # my $state = make_state (bit => $bit,
588 # lowerbit => $lowerbit,
589 # rot => $rot,
590 # oddpos => $oddpos,
591 # nextturn => $nextturn);
592 # ### $state
593 #
594 # my $new_nextturn = $nextturn;
595 # my $new_lowerbit = $bit;
596 # my $new_rot = $rot;
597 # my $new_oddpos = $oddpos ^ 1;
598 #
599 # if ($bit != $lowerbit) {
600 # if ($oddpos) {
601 # $new_rot++;
602 # } else {
603 # $new_rot--;
604 # }
605 # $new_rot &= 3;
606 # }
607 # if ($lowerbit == 0 && ! $nextturn) {
608 # $new_nextturn = ($bit ^ $oddpos ? 1 : 2); # bit above lowest 0
609 # }
610 #
611 # my $dx = 1;
612 # my $dy = 0;
613 # if ($rot & 2) {
614 # $dx = -$dx;
615 # $dy = -$dy;
616 # }
617 # if ($rot & 1) {
618 # ($dx,$dy) = (-$dy,$dx); # rotate +90
619 # }
620 # ### rot to: "$dx, $dy"
621 #
622 # # if ($oddpos) {
623 # # ($dx,$dy) = (-$dy,$dx); # rotate +90
624 # # } else {
625 # # ($dx,$dy) = ($dy,-$dx); # rotate -90
626 # # }
627 #
628 # my $next_dx = $dx;
629 # my $next_dy = $dy;
630 # if ($nextturn == 2) {
631 # ($next_dx,$next_dy) = (-$next_dy,$next_dx); # left, rotate +90
632 # } else {
633 # ($next_dx,$next_dy) = ($next_dy,-$next_dx); # right, rotate -90
634 # }
635 # my $frac_dx = $next_dx - $dx;
636 # my $frac_dy = $next_dy - $dy;
637 #
638 # # mask to rot,oddpos only, ignore bit,lowerbit
639 # my $masked_state = $state & ~3;
640 # $state_to_dxdy[$masked_state] = $dx;
641 # $state_to_dxdy[$masked_state + 1] = $dy;
642 # $state_to_dxdy[$masked_state + 2] = $frac_dx;
643 # $state_to_dxdy[$masked_state + 3] = $frac_dy;
644 #
645 # my $next_state = make_state (bit => 0,
646 # lowerbit => $new_lowerbit,
647 # rot => $new_rot,
648 # oddpos => $new_oddpos,
649 # nextturn => $new_nextturn);
650 # $next_state[$state] = $next_state;
651 # }
652 # }
653 # }
654 # }
655 # }
656 #
657 # my @arm_to_state;
658 # foreach my $arm (0 .. 7) {
659 # my $rot = $arm >> 1;
660 # my $oddpos = 0;
661 # if ($arm & 1) {
662 # $rot++;
663 # $oddpos ^= 1;
664 # }
665 # $arm_to_state[$arm] = make_state (bit => 0,
666 # lowerbit => 0,
667 # rot => $rot,
668 # oddpos => $oddpos,
669 # nextturn => 0);
670 # }
671 #
672 # ### @next_state
673 # ### @state_to_dxdy
674 # ### next_state length: 4*(4*2*2 + 4*2)
675 #
676 # print "# next_state length ", scalar(@next_state), "\n";
677 # print_table ("next_state", \@next_state);
678 # print_table ("state_to_dxdy", \@state_to_dxdy);
679 # print_table ("arm_to_state", \@arm_to_state);
680 # print "\n";
681 #
682 # foreach my $arm (0 .. 7) {
683 # print "# arm=$arm ",state_string($arm_to_state[$arm]),"\n";
684 # }
685 # print "\n";
686 #
687 #
688 #
689 # use Smart::Comments;
690 #
691 # sub n_to_dxdy {
692 # my ($self, $n) = @_;
693 # ### n_to_dxdy(): $n
694 #
695 # my $int = int($n);
696 # $n -= $int; # $n fraction part
697 # ### $int
698 # ### $n
699 #
700 # my $state = _divrem_mutate ($int, $self->{'arms'}) << 2;
701 # ### arm as initial state: $state
702 #
703 # foreach my $bit (bit_split_lowtohigh($int)) {
704 # $state = $next_state[$state + $bit];
705 # }
706 # $state &= 0x1C; # mask out "prevbit"
707 #
708 # ### final state: $state
709 # ### dx: $state_to_dxdy[$state]
710 # ### dy: $state_to_dxdy[$state+1],
711 # ### frac dx: $state_to_dxdy[$state+2],
712 # ### frac dy: $state_to_dxdy[$state+3],
713 #
714 # return ($state_to_dxdy[$state] + $n * $state_to_dxdy[$state+2],
715 # $state_to_dxdy[$state+1] + $n * $state_to_dxdy[$state+3]);
716 # }
717 #
718 # }
719  
720 #------------------------------------------------------------------------------
721 # levels
722  
723 2 ▶use Math::PlanePath::DragonCurve;
Subroutine BEGIN: called CC=1 SCAR=0.0
724 2 *level_to_n_range = \&Math::PlanePath::DragonCurve::level_to_n_range;
725 2 *n_to_level = \&Math::PlanePath::DragonCurve::n_to_level;
726  
727 #------------------------------------------------------------------------------
728  
729 sub _UNDOCUMENTED_level_to_right_line_boundary {
730 0 ▶ my ($self, $level) = @_;
Subroutine _UNDOCUMENTED_level_to_right_line_boundary: not called CC=3 SCAR=24.8
731 0 ▶ if ($level == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level == 0) 0 0 0
732 0 return 1;
733 }
734 0 my ($h,$odd) = _divrem($level,2);
735 0 ▶ return ($odd
Branch: 1 branch
BranchTrueFalseTotal
$odd ? : 0 0 0
736 ? 6 * 2**$h - 4
737 : 2 * 2**$h);
738 }
739 sub _UNDOCUMENTED_level_to_left_line_boundary {
740 0 ▶ my ($self, $level) = @_;
Subroutine _UNDOCUMENTED_level_to_left_line_boundary: not called CC=3 SCAR=24.8
741 0 ▶ if ($level == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level == 0) 0 0 0
742 0 return 1;
743 }
744 0 my ($h,$odd) = _divrem($level,2);
745 0 ▶ return ($odd
Branch: 1 branch
BranchTrueFalseTotal
$odd ? : 0 0 0
746 ? 2 * 2**$h
747 : 4 * 2**$h - 4);
748 }
749 sub _UNDOCUMENTED_level_to_line_boundary {
750 0 ▶ my ($self, $level) = @_;
Subroutine _UNDOCUMENTED_level_to_line_boundary: not called CC=2 SCAR=17.9
751 0 my ($h,$odd) = _divrem($level,2);
752 0 ▶ return (($odd?8:6) * 2**$h - 4);
Branch: 1 branch
BranchTrueFalseTotal
$odd ? : 0 0 0
753 }
754  
755 sub _UNDOCUMENTED_level_to_hull_area {
756 0 ▶ my ($self, $level) = @_;
Subroutine _UNDOCUMENTED_level_to_hull_area: not called CC=1 SCAR=6.9
757 0 return (2**$level - 1)/2;
758 }
759  
760 sub _UNDOCUMENTED__n_is_x_positive {
761 0 ▶ my ($self, $n) = @_;
Subroutine _UNDOCUMENTED__n_is_x_positive: not called CC=7 SCAR=40.3
762 0 ▶ if (! ($n >= 0) || is_infinite($n)) { return 0; }
Branch: 1 branch
BranchTrueFalseTotal
if (not $n >= 0 or is_infinite($n)) 0 0 0
Condition0%0/3
not $n >= 0 or is_infinite($n)
l!l&&r!l&&!r
000
MC/DC0%0/2
not $n >= 0 or is_infinite($n)
not $n >= 0 is_infinite($n)
Truth table0%0/3
not(A) or B
A= not $n >= 0B= is_infinite($n)
ABresult
1X1
011
000
763  
764 0 $n = int($n);
765 {
766 0 my $arm = _divrem_mutate($n, $self->{'arms'});
767  
768 # arm 1 good only on N=1 which is remaining $n==0
769 0 ▶ if ($arm == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arm == 1) 0 0 0
770 0 return ($n == 0);
771 }
772  
773 # arm 0 good
774 # arm 8 good for N>=15 which is remaining $n>=1
775 0 ▶ unless ($arm == 0
Branch: 1 branch
BranchTrueFalseTotal
unless ($arm == 0 or $arm == 7 and $n > 0) 0 0 0
Condition0%0/6
$arm == 0 or $arm == 7 and $n > 0
l!l&&r!l&&!r
000
$arm == 7 and $n > 0
!ll&&!rl&&r
000
MC/DC0%0/3
$arm == 0 or $arm == 7 and $n > 0
$arm == 0 $arm == 7 $n > 0
Truth table0%0/4
A or B and C
A= $arm == 0B= $arm == 7C= $n > 0
ABCresult
1XX1
0111
00X0
0100
776 || ($arm == 7 && $n > 0)) {
777 0 return 0;
778 }
779 }
780  
781 0 return _is_base4_01($n);
782 }
783  
784 sub _UNDOCUMENTED__n_is_diagonal_NE {
785 0 ▶ my ($self, $n) = @_;
Subroutine _UNDOCUMENTED__n_is_diagonal_NE: not called CC=6 SCAR=37.4
786 0 ▶ if (! ($n >= 0) || is_infinite($n)) { return 0; }
Branch: 1 branch
BranchTrueFalseTotal
if (not $n >= 0 or is_infinite($n)) 0 0 0
Condition0%0/3
not $n >= 0 or is_infinite($n)
l!l&&r!l&&!r
000
MC/DC0%0/2
not $n >= 0 or is_infinite($n)
not $n >= 0 is_infinite($n)
Truth table0%0/3
not(A) or B
A= not $n >= 0B= is_infinite($n)
ABresult
1X1
011
000
787  
788 0 $n = int($n);
789 0 ▶ if ($self->{'arms'} >= 8 && $n == 15) { return 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"arms"} >= 8 and $n == 15) 0 0 0
Condition0%0/3
$self->{"arms"} >= 8 and $n == 15
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"arms"} >= 8 and $n == 15
$self->{"arms"} >= 8 $n == 15
Truth table0%0/3
A and B
A= $self->{"arms"} >= 8B= $n == 15
ABresult
0X0
100
111
790 0 ▶ if (_divrem_mutate($n, $self->{'arms'}) >= 2) { return 0; }
Branch: 1 branch
BranchTrueFalseTotal
if (_divrem_mutate($n, $self->{"arms"}) >= 2) 0 0 0
791 0 return _is_base4_02($n);
792 }
793  
794 # X axis N is base4 digits 0,1
795 # and -1 from even is 0,1 low 0333333
796 # and -2 from even is 0,1 low 0333332
797 # so $n+2 low digit any then 0,1s above
798 sub _UNDOCUMENTED__n_segment_is_right_boundary {
799 0 ▶ my ($self, $n) = @_;
Subroutine _UNDOCUMENTED__n_segment_is_right_boundary: not called CC=5 SCAR=34.0
800 0 ▶ if ($self->{'arms'} >= 8
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"arms"} >= 8 or not $n >= 0 or is_infinite($n)) 0 0 0
Condition0%0/6
$self->{"arms"} >= 8 or not $n >= 0 or is_infinite($n)
l!l&&r!l&&!r
000
$self->{"arms"} >= 8 or not $n >= 0
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->{"arms"} >= 8 or not $n >= 0 or is_infinite($n)
$self->{"arms"} >= 8 not $n >= 0 is_infinite($n)
Truth table0%0/4
A or not(B) or C
A= $self->{"arms"} >= 8B= not $n >= 0C= is_infinite($n)
ABCresult
1XX1
01X1
0011
0000
801 || ! ($n >= 0)
802 || is_infinite($n)) {
803 0 return 0;
804 }
805 0 $n = int($n);
806  
807 0 ▶ if (_divrem_mutate($n, $self->{'arms'}) >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (_divrem_mutate($n, $self->{"arms"}) >= 1) 0 0 0
808 0 return 0;
809 }
810 0 $n += 2;
811 0 _divrem_mutate($n,4);
812 0 return _is_base4_01($n);
813 }
814  
815 # diagonal N is base4 digits 0,2,
816 # and -1 from there is 0,2 low 1
817 # or 0,2 low 13333
818 # so $n+1 low digit possible 1 or 3 then 0,2s above
819 # which means $n+1 low digit any and 0,2s above
820 #use Smart::Comments;
821  
822 sub _UNDOCUMENTED__n_segment_is_left_boundary {
823 0 ▶ my ($self, $n) = @_;
Subroutine _UNDOCUMENTED__n_segment_is_left_boundary: not called CC=12 SCAR=50.5
824 ### _UNDOCUMENTED__n_segment_is_left_boundary(): $n
825  
826 0 my $arms = $self->{'arms'};
827 0 ▶ if ($arms >= 8
Branch: 1 branch
BranchTrueFalseTotal
if ($arms >= 8 or not $n >= 0 or is_infinite($n)) 0 0 0
Condition0%0/6
$arms >= 8 or not $n >= 0 or is_infinite($n)
l!l&&r!l&&!r
000
$arms >= 8 or not $n >= 0
l!l&&r!l&&!r
000
MC/DC0%0/3
$arms >= 8 or not $n >= 0 or is_infinite($n)
$arms >= 8 not $n >= 0 is_infinite($n)
Truth table0%0/4
A or not(B) or C
A= $arms >= 8B= not $n >= 0C= is_infinite($n)
ABCresult
1XX1
01X1
0011
0000
828 || ! ($n >= 0)
829 || is_infinite($n)) {
830 0 return 0;
831 }
832 0 $n = int($n);
833  
834 0 ▶ if (($n == 1 && $arms >= 4)
Branch: 1 branch
BranchTrueFalseTotal
if ($n == 1 and $arms >= 4 or $n == 3 and $arms >= 5 or $n == 5 and $arms == 7) 0 0 0
Condition0%0/15
$n == 1 and $arms >= 4 or $n == 3 and $arms >= 5 or $n == 5 and $arms == 7
l!l&&r!l&&!r
000
$n == 1 and $arms >= 4 or $n == 3 and $arms >= 5
l!l&&r!l&&!r
000
$n == 1 and $arms >= 4
!ll&&!rl&&r
000
$n == 3 and $arms >= 5
!ll&&!rl&&r
000
$n == 5 and $arms == 7
!ll&&!rl&&r
000
MC/DC0%0/6
$n == 1 and $arms >= 4 or $n == 3 and $arms >= 5 or $n == 5 and $arms == 7
$n == 1 $arms >= 4 $n == 3 $arms >= 5 $n == 5 $arms == 7
Truth table0%0/15
A and B or C and D or E and F
A= $n == 1B= $arms >= 4C= $n == 3D= $arms >= 5E= $n == 5F= $arms == 7
ABCDEFresult
11XXXX1
0X11XX1
1011XX1
0X0X111
0X10111
100X111
1010111
0X0X0X0
0X0X100
0X100X0
0X10100
100X0X0
100X100
10100X0
1010100
835 || ($n == 3 && $arms >= 5)
836 || ($n == 5 && $arms == 7)) {
837 0 return 1;
838 }
839 0 ▶ if (_divrem_mutate($n, $arms) < $arms-1) {
Branch: 1 branch
BranchTrueFalseTotal
if (_divrem_mutate($n, $arms) < $arms - 1) 0 0 0
840 ### no, not last arm ...
841 0 return 0;
842 }
843  
844 0 ▶ if ($arms % 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arms % 2) { } 0 0 0
845 ### odd arms, stair-step boundary ...
846 0 $n += 1;
847 0 _divrem_mutate($n,4);
848 0 return _is_base4_02($n);
849 } else {
850 # even arms, notched like right boundary
851 0 $n += 2;
852 0 _divrem_mutate($n,4);
853 0 return _is_base4_01($n);
854 }
855 }
856  
857 sub _is_base4_01 {
858 0 ▶ my ($n) = @_;
Subroutine _is_base4_01: not called CC=3 SCAR=24.8
859 0 ▶ while ($n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n) 0 0 0
860 0 my $digit = _divrem_mutate($n,4);
861 0 ▶ if ($digit >= 2) { return 0; }
Branch: 1 branch
BranchTrueFalseTotal
if ($digit >= 2) 0 0 0
862 }
863 0 return 1;
864 }
865 sub _is_base4_02 {
866 0 ▶ my ($n) = @_;
Subroutine _is_base4_02: not called CC=4 SCAR=30.0
867 0 ▶ while ($n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n) 0 0 0
868 0 my $digit = _divrem_mutate($n,4);
869 0 ▶ if ($digit == 1 || $digit == 3) { return 0; }
Branch: 1 branch
BranchTrueFalseTotal
if ($digit == 1 or $digit == 3) 0 0 0
Condition0%0/3
$digit == 1 or $digit == 3
l!l&&r!l&&!r
000
MC/DC0%0/2
$digit == 1 or $digit == 3
$digit == 1 $digit == 3
Truth table0%0/3
A or B
A= $digit == 1B= $digit == 3
ABresult
1X1
011
000
870 }
871 0 return 1;
872 }
873  
874 2 1;
875 __END__
« PlanePath/WythoffArray.pm ↑ Summary PlanePath/DigitGroups.pm »