PlanePath/AlternatePaper.pm

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