PlanePath/QuintetCentres.pm

filter: Statementstmt 91.0% 245 / 269 Branchbran 86.5% 71 / 82 Conditioncond 75.0% 15 / 20 MC/DCmcdc 69.2% 9 / 13 Subroutinesub 80.6% 25 / 31 Podpod 100% 9 / 9 totaltotal 88.2% 374 / 424 CC 56 SCAR 25.5
CC
56
Cov
89%
rect_to_n_range
27.2
n_to_xy
12.0
n_to_level
12.0
CRAP 12.8
« PlanePath/CCurve.pm ↑ Summary PlanePath/GreekKeySpiral.pm »
1 # Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 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 # Boundary of unit squares:
20 # 4*3^n
21 # QuintetCentres unit squares boundary a(n) = 4*3^(n-3)
22 # 12,36,108,324,972
23 # match 12,36,108,324,972
24 # A003946 G.f.: (1+x)/(1-3*x).
25 # A025579 a(1)=1, a(2)=2, a(n) = 4*3^(n-3) for n >= 3.
26 # A027327 a(n) = Sum{(k+1)*T(n,m-k)}, 0<=k<=m, where m=0 for n=0,1; m=n for n >= 2; T given by A026120.
27  
28  
29 package Math::PlanePath::QuintetCentres;
30 2 ▶use 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 2 ▶use POSIX 'ceil';
Subroutine BEGIN: called CC=1 SCAR=0.0
33 #use List::Util 'min','max';
34 2 *min = \&Math::PlanePath::_min;
35 2 *max = \&Math::PlanePath::_max;
36  
37 2 ▶use vars '$VERSION', '@ISA';
Subroutine BEGIN: called CC=1 SCAR=0.0
38 2 $VERSION = 128;
39 2 ▶use Math::PlanePath;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 2 @ISA = ('Math::PlanePath');
41 2 *_divrem_mutate = \&Math::PlanePath::_divrem_mutate;
42  
43 2 ▶use Math::PlanePath::SacksSpiral;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 2 *_rect_to_radius_range = \&Math::PlanePath::SacksSpiral::_rect_to_radius_range;
45  
46 use Math::PlanePath::Base::Generic
47 2 'is_infinite',
48 2 ▶ 'round_nearest';
Subroutine BEGIN: called CC=1 SCAR=0.0
49 use Math::PlanePath::Base::Digits
50 2 'digit_split_lowtohigh',
51 2 ▶ 'round_up_pow';
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53 # uncomment this to run the ### lines
54 # use Smart::Comments;
55  
56  
57 2 ▶use constant n_start => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
58 2 use constant parameter_info_array => [ { name => 'arms',
59 share_key => 'arms_4',
60 display => 'Arms',
61 type => 'integer',
62 minimum => 1,
63 maximum => 4,
64 default => 1,
65 width => 1,
66 description => 'Arms',
67 2 ▶ } ];
Subroutine BEGIN: called CC=1 SCAR=0.0
68  
69 {
70 2 my @x_negative_at_n = (undef, 112, 9, 2, 2);
71 sub x_negative_at_n {
72 0 ▶ my ($self) = @_;
Subroutine x_negative_at_n: not called CC=1 SCAR=6.9
Pod documented
73 0 return $x_negative_at_n[$self->{'arms'}];
74 }
75 }
76 {
77 2 my @y_negative_at_n = (undef, 2, 4, 6, 7);
78 sub y_negative_at_n {
79 0 ▶ my ($self) = @_;
Subroutine y_negative_at_n: not called CC=1 SCAR=6.9
Pod documented
80 0 return $y_negative_at_n[$self->{'arms'}];
81 }
82 }
83  
84 2 ▶use constant dx_minimum => -1;
Subroutine BEGIN: called CC=1 SCAR=0.0
85 2 ▶use constant dx_maximum => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
86 2 ▶use constant dy_minimum => -1;
Subroutine BEGIN: called CC=1 SCAR=0.0
87 2 ▶use constant dy_maximum => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
88  
89 2 *_UNDOCUMENTED__dxdy_list = \&Math::PlanePath::_UNDOCUMENTED__dxdy_list_eight;
90 {
91 2 my @_UNDOCUMENTED__dxdy_list_at_n = (undef, 18, 14, 11, 11);
92 sub _UNDOCUMENTED__dxdy_list_at_n {
93 0 ▶ my ($self) = @_;
Subroutine _UNDOCUMENTED__dxdy_list_at_n: not called CC=1 SCAR=6.9
94 0 return $_UNDOCUMENTED__dxdy_list_at_n[$self->{'arms'}];
95 }
96 }
97  
98 2 ▶use constant dsumxy_minimum => -2; # diagonals
Subroutine BEGIN: called CC=1 SCAR=0.0
99 2 ▶use constant dsumxy_maximum => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
100 2 ▶use constant ddiffxy_minimum => -2;
Subroutine BEGIN: called CC=1 SCAR=0.0
101 2 ▶use constant ddiffxy_maximum => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
102 2 ▶use constant dir_maximum_dxdy => (1,-1); # South-East
Subroutine BEGIN: called CC=1 SCAR=0.0
103  
104 # N=9 first straight, then for other arms 18,27,36
105 sub _UNDOCUMENTED__turn_any_straight_at_n {
106 0 ▶ my ($self) = @_;
Subroutine _UNDOCUMENTED__turn_any_straight_at_n: not called CC=1 SCAR=6.9
107 0 return 9*$self->arms_count;
108 }
109  
110  
111 #------------------------------------------------------------------------------
112  
113 sub new {
114 45 ▶ my $self = shift->SUPER::new(@_);
Subroutine new: called CC=2 SCAR=6.9
Pod documented
115 45 ▶ $self->{'arms'} = max(1, min(4, $self->{'arms'} || 1));
Condition100%2/2
$self->{'arms'} || 1
l!l
3213
MC/DC100%1/1
$self->{'arms'} || 1
$self->{'arms'}
Truth table100%2/2
A
A= $self->{'arms'}
Aresult
11
00
116 45 return $self;
117 }
118  
119 2 my @rot_to_x = (0,0,-1,-1);
120 2 my @rot_to_y = (0,1,1,0);
121 2 my @dir4_to_dx = (1,0,-1,0);
122 2 my @dir4_to_dy = (0,1,0,-1);
123 2 my @digit_reverse = (0,1,0,0,1);
124  
125 sub n_to_xy {
126 23735 ▶ my ($self, $n) = @_;
Subroutine n_to_xy: called CC=12 SCAR=24.9
Pod documented
127 ### QuintetCentres n_to_xy(): "arms=$self->{'arms'} $n"
128  
129 23735 ▶ if ($n < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n < 0) 0 23735 23735
130 0 return;
131 }
132 23735 ▶ if (is_infinite($n)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_infinite($n)) 0 23735 23735
133 0 return ($n,$n);
134 }
135  
136 {
137 23735 my $int = int($n);
138 23735 ▶ if ($n != $int) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n != $int) 63 23672 23735
139 63 my ($x1,$y1) = $self->n_to_xy($int);
140 63 my ($x2,$y2) = $self->n_to_xy($int+$self->{'arms'});
141 63 my $frac = $n - $int; # inherit possible BigFloat
142 63 my $dx = $x2-$x1;
143 63 my $dy = $y2-$y1;
144 63 return ($frac*$dx + $x1, $frac*$dy + $y1);
145 }
146 23672 $n = $int; # BigFloat int() gives BigInt, use that
147 }
148 23672 my $zero = ($n * 0); # inherit BigInt 0
149  
150 # arm as initial rotation
151 23672 my $rot = _divrem_mutate ($n, $self->{'arms'});
152  
153 23672 my @digits = digit_split_lowtohigh($n,5);
154 23672 my @sx;
155 my @sy;
156 {
157 23672 my $sx = $zero + $dir4_to_dx[$rot];
158 23672 my $sy = $zero + $dir4_to_dy[$rot];
159 23672 foreach (@digits) {
160 111556 push @sx, $sx;
161 111556 push @sy, $sy;
162  
163 # 2*(sx,sy) + rot+90(sx,sy)
164 111556 ($sx,$sy) = (2*$sx - $sy,
165 2*$sy + $sx);
166 }
167 ### @digits
168 23672 my $rev = 0;
169 23672 ▶ for (my $i = $#digits; $i >= 0; $i--) { # high to low
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 111556 23672 135228
170 ### digit: $digits[$i]
171 111556 ▶ if ($rev) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rev) 46511 65045 111556
172 ### reverse: "$digits[$i] to ".(5 - $digits[$i])
173 46511 $digits[$i] = 4 - $digits[$i];
174 }
175 111556 $rev ^= $digit_reverse[$digits[$i]];
176 ### now rev: $rev
177 }
178 }
179 ### reversed n: @digits
180  
181  
182 23672 my $x =
183 my $y =
184 my $ox =
185 my $oy = $zero;
186  
187 23672 ▶ while (defined (my $digit = shift @digits)) { # low to high
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $digit = shift @digits)) 111556 23672 135228
188 111556 my $sx = shift @sx;
189 111556 my $sy = shift @sy;
190 ### at: "$x,$y digit $digit side $sx,$sy"
191  
192 # if ($rot & 2) {
193 # ($sx,$sy) = (-$sx,-$sy);
194 # }
195 # if ($rot & 1) {
196 # ($sx,$sy) = (-$sy,$sx);
197 # }
198  
199 111556 ▶ if ($digit == 0) {
Branch: 4 branches
BranchTrueFalseTotal
if ($digit == 0) { } 29049 82507 111556
elsif ($digit == 1) { } 23341 59166 82507
elsif ($digit == 2) { } 18838 40328 59166
elsif ($digit == 3) { } 17942 22386 40328
200 29049 $x -= $sx; # left at 180
201 29049 $y -= $sy;
202  
203 } elsif ($digit == 1) {
204 # centre
205 23341 ($x,$y) = (-$y,$x); # rotate -90
206 ### rotate to: "$x,$y"
207 # $rot--;
208  
209 } elsif ($digit == 2) {
210 18838 $x += $sy; # down at -90
211 18838 $y -= $sx;
212 ### offset to: "$x,$y"
213  
214 } elsif ($digit == 3) {
215 17942 ($x,$y) = (-$y,$x); # rotate -90
216 17942 $x += $sx; # right at 0
217 17942 $y += $sy;
218 # $rot++;
219  
220 } else { # $digit == 4
221 22386 ($x,$y) = ($y,-$x); # rotate +90
222 22386 $x -= $sy; # up at +90
223 22386 $y += $sx;
224 # $rot++;
225 }
226  
227 111556 $ox += $sx;
228 111556 $oy += $sy;
229 }
230  
231 ### final: "$x,$y origin $ox,$oy"
232 23672 return ($x + $ox + $rot_to_x[$rot],
233 $y + $oy + $rot_to_y[$rot]);
234 }
235  
236  
237 # modulus 2*X+Y
238 # 3
239 # 0 2 4
240 # 1
241 #
242 # 0 is X=0,Y=0
243 #
244 2 my @modulus_to_x = (0,1,1,1,2);
245 2 my @modulus_to_y = (0,-1,0,1,0);
246  
247 my @modulus_to_digit
248 2 = (0,2,1,4,3, 0,0,10,30,20, # 0 base
249 0,4,3,1,2, 0,10,50,40,10, # 10
250 4,0,1,3,2, 60,20,40,50,20, # 20 rotated +90
251 2,1,3,4,0, 30,60,0,30,50, # 30
252 1,0,3,2,4, 30,20,70,40,40, # 40
253 3,4,1,2,0, 70,10,30,50,50, # 50 rotated +180
254 4,2,3,0,1, 60,60,20,70,10, # 60
255 2,3,1,0,4, 70,0,60,70,40, # 70 rotated +270
256 );
257 sub xy_to_n {
258 18659 ▶ my ($self, $x, $y) = @_;
Subroutine xy_to_n: called CC=11 SCAR=24.0
Pod documented
259 ### QuintetCentres xy_to_n(): "$x, $y"
260  
261 18659 $x = round_nearest($x);
262 18659 $y = round_nearest($y);
263  
264 18659 foreach my $overflow (2*$x + 2*$y, 2*$x - 2*$y) {
265 37318 ▶ if (is_infinite($overflow)) { return $overflow; }
Branch: 1 branch
BranchTrueFalseTotal
if (is_infinite($overflow)) 0 37318 37318
266 }
267  
268 # my $level_limit = log($x*$x + $y*$y + 1) * 1 * 2;
269 # if (is_infinite($level_limit)) { return $level_limit; }
270  
271 18659 my @digits;
272 my $arm;
273 18659 my $state;
274 18659 for (;;) {
275 # if ($level_limit-- < 0) {
276 # ### oops, level limit ...
277 # return undef;
278 # }
279 94483 ▶ if ($x == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($x == 0) { } 19761 74722 94483
elsif ($x == -1) { } 7986 66736 74722
280 19761 ▶ if ($y == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y == 0) 9644 10117 19761
281 ### found first arm 0,0 ...
282 9644 $arm = 0;
283 9644 $state = 0;
284 9644 last;
285 }
286 10117 ▶ if ($y == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y == 1) 4935 5182 10117
287 ### found second arm 0,1 ...
288 4935 $arm = 1;
289 4935 $state = 20;
290 4935 last;
291 }
292 } elsif ($x == -1) {
293 7986 ▶ if ($y == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y == 1) 2768 5218 7986
294 ### found third arm -1,1 ...
295 2768 $arm = 2;
296 2768 $state = 50;
297 2768 last;
298 }
299 5218 ▶ if ($y == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y == 0) 1312 3906 5218
300 ### found fourth arm -1,0 ...
301 1312 $arm = 3;
302 1312 $state = 70;
303 1312 last;
304 }
305 }
306 75824 my $m = (2*$x + $y) % 5;
307 ### at: "$x,$y digits=".join(',',@digits)
308 ### mod remainder: $m
309  
310 75824 $x -= $modulus_to_x[$m];
311 75824 $y -= $modulus_to_y[$m];
312 75824 push @digits, $m;
313  
314 ### digit: "$m to $x,$y"
315 ### shrink to: ((2*$x + $y) / 5).','.((2*$y - $x) / 5)
316 ### assert: (2*$x + $y) % 5 == 0
317 ### assert: (2*$y - $x) % 5 == 0
318  
319 # shrink
320 # (2 -1) inverse (2 1)
321 # (1 2) (-1 2)
322 #
323 75824 ($x,$y) = ((2*$x + $y) / 5,
324 (2*$y - $x) / 5);
325 }
326  
327 ### @digits
328 18659 my $arms = $self->{'arms'};
329 18659 ▶ if ($arm >= $arms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arm >= $arms) 137 18522 18659
330 137 return undef;
331 }
332  
333 18522 my $n = 0;
334 18522 foreach my $m (reverse @digits) { # high to low
335 ### $m
336 ### digit: $modulus_to_digit[$state + $m]
337 ### state: $state
338 ### next state: $modulus_to_digit[$state+5 + $m]
339  
340 75307 $n = 5*$n + $modulus_to_digit[$state + $m];
341 75307 $state = $modulus_to_digit[$state+5 + $m];
342 }
343 ### final n along arm: $n
344  
345 18522 return $n*$arms + $arm;
346 }
347  
348 #------------------------------------------------------------------------------
349  
350 # whole plane covered when arms==4
351 sub xy_is_visited {
352 0 ▶ my ($self, $x, $y) = @_;
Subroutine xy_is_visited: not called CC=2 SCAR=17.9
Pod documented
353 0 ▶ return ($self->{'arms'} == 4
Condition0%0/3
$self->{'arms'} == 4 || defined $self->xy_to_n($x, $y)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'arms'} == 4 || defined $self->xy_to_n($x, $y)
$self->{'arms'} == 4 defined $self->xy_to_n($x, $y)
Truth table0%0/3
A || B
A= $self->{'arms'} == 4B= defined $self->xy_to_n($x, $y)
ABresult
1X1
011
000
354 || defined($self->xy_to_n($x,$y)));
355 }
356  
357 #------------------------------------------------------------------------------
358  
359 # exact
360 sub rect_to_n_range {
361 134 ▶ my ($self, $x1,$y1, $x2,$y2) = @_;
Subroutine rect_to_n_range: called CC=27 SCAR=33.0
Pod documented
362 ### QuintetCurve rect_to_n_range(): "$x1,$y1 $x2,$y2"
363  
364 134 my ($r_lo, $r_hi) = _rect_to_radius_range($x1,$y1, $x2,$y2);
365 134 $r_hi *= 2;
366 134 my $level_plus_1 = ceil( log(max(1,$r_hi/4)) / log(sqrt(5)) ) + 2;
367  
368 # Simple over-estimate would be: return (0, 5**$level_plus_1);
369  
370 134 my $level_limit = $level_plus_1;
371 ### $level_limit
372 134 ▶ if (is_infinite($level_limit)) { return ($level_limit,$level_limit); }
Branch: 1 branch
BranchTrueFalseTotal
if (is_infinite($level_limit)) 0 134 134
373  
374 134 $x1 = round_nearest ($x1);
375 134 $y1 = round_nearest ($y1);
376 134 $x2 = round_nearest ($x2);
377 134 $y2 = round_nearest ($y2);
378 134 ▶ ($x1,$x2) = ($x2,$x1) if $x1 > $x2;
Branch: 1 branch
BranchTrueFalseTotal
if $x1 > $x2 0 134 134
379 134 ▶ ($y1,$y2) = ($y2,$y1) if $y1 > $y2;
Branch: 1 branch
BranchTrueFalseTotal
if $y1 > $y2 3 131 134
380 ### sorted range: "$x1,$y1 $x2,$y2"
381  
382 my $rect_dist = sub {
383 24425 ▶ my ($x,$y) = @_;
Subroutine __ANON__: called CC=5 SCAR=16.1
384 24425 ▶ my $xd = ($x < $x1 ? $x1 - $x
Branch: 2 branches
BranchTrueFalseTotal
$x < $x1 ? : 9674 14751 24425
$x > $x2 ? : 13270 1481 14751
385 : $x > $x2 ? $x - $x2
386 : 0);
387 24425 ▶ my $yd = ($y < $y1 ? $y1 - $y
Branch: 2 branches
BranchTrueFalseTotal
$y < $y1 ? : 11601 12824 24425
$y > $y2 ? : 11220 1604 12824
388 : $y > $y2 ? $y - $y2
389 : 0);
390 24425 return ($xd*$xd + $yd*$yd);
391 134 };
392  
393 134 my $arms = $self->{'arms'};
394 ### $arms
395 134 my $n_lo;
396 {
397 134 my @hypot = (4);
398 134 my $top = 0;
399 134 for (;;) {
400 434 ARM_LO: foreach my $arm (0 .. $arms-1) {
401 434 my $i = 0;
402 434 my @digits;
403 434 ▶ if ($top > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($top > 0) { } 300 134 434
404 300 @digits = ((0)x($top-1), 1);
405 } else {
406 134 @digits = (0);
407 }
408  
409 434 for (;;) {
410 11742 my $n = 0;
411 11742 foreach my $digit (reverse @digits) { # high to low
412 60069 $n = 5*$n + $digit;
413 }
414 11742 $n = $n*$arms + $arm;
415 ### lo consider: "i=$i digits=".join(',',reverse @digits)." is n=$n"
416  
417 11742 my ($nx,$ny) = $self->n_to_xy($n);
418 11742 my $nh = &$rect_dist ($nx,$ny);
419 11742 ▶ if ($i == 0 && $nh == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 0 and $nh == 0) 134 11608 11742
Condition100%3/3
$i == 0 and $nh == 0
!ll&&!rl&&r
76713937134
MC/DC100%2/2
$i == 0 and $nh == 0
$i == 0 $nh == 0
Truth table100%3/3
A and B
A= $i == 0B= $nh == 0
ABresult
0X0
100
111
420 ### lo found inside: $n
421 134 ▶ if (! defined $n_lo || $n < $n_lo) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $n_lo or $n < $n_lo) 134 0 134
Condition33%1/3
not defined $n_lo or $n < $n_lo
l!l&&r!l&&!r
13400
MC/DC0%0/2
not defined $n_lo or $n < $n_lo
not defined $n_lo $n < $n_lo
Truth table33%1/3
not(A) or B
A= not defined $n_loB= $n < $n_lo
ABresult
1X1
011
000
422 134 $n_lo = $n;
423 }
424 134 next ARM_LO;
425 }
426  
427 11608 ▶ if ($i == 0 || $nh > $hypot[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 0 or $nh > $hypot[$i]) { } 10186 1422 11608
Condition100%3/3
$i == 0 or $nh > $hypot[$i]
l!l&&r!l&&!r
393762491422
MC/DC100%2/2
$i == 0 or $nh > $hypot[$i]
$i == 0 $nh > $hypot[$i]
Truth table100%3/3
A or B
A= $i == 0B= $nh > $hypot[$i]
ABresult
1X1
011
000
428 ### too far away: "nxy=$nx,$ny nh=$nh vs ".$hypot[$i]
429  
430 10186 ▶ while (++$digits[$i] > 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$digits[$i] > 4) 2342 9886 12228
431 2342 $digits[$i] = 0;
432 2342 ▶ if (++$i <= $top) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$i <= $top) { } 2042 300 2342
433 ### backtrack up ...
434 } else {
435 ### not found within this top and arm, next arm ...
436 300 next ARM_LO;
437 }
438 }
439 } else {
440 ### lo descend ...
441 ### assert: $i > 0
442 1422 $i--;
443 1422 $digits[$i] = 0;
444 }
445 }
446 }
447  
448 # if an $n_lo was found on any arm within this $top then done
449 434 ▶ if (defined $n_lo) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $n_lo) 134 300 434
450 134 last;
451 }
452  
453 ### lo extend top ...
454 300 ▶ if (++$top > $level_limit) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$top > $level_limit) 0 300 300
455 ### nothing below level limit ...
456 0 return (1,0);
457 }
458 300 $hypot[$top] = 5 * $hypot[$top-1];
459 }
460 }
461  
462 134 my $n_hi = 0;
463 134 ARM_HI: foreach my $arm (reverse 0 .. $arms-1) {
464 134 my @digits = ((4) x $level_limit);
465 134 my $i = $#digits;
466 134 for (;;) {
467 12683 my $n = 0;
468 12683 foreach my $digit (reverse @digits) { # high to low
469 84826 $n = 5*$n + $digit;
470 }
471 12683 $n = $n*$arms + $arm;
472 ### hi consider: "arm=$arm i=$i digits=".join(',',reverse @digits)." is n=$n"
473  
474 12683 my ($nx,$ny) = $self->n_to_xy($n);
475 12683 my $nh = &$rect_dist ($nx,$ny);
476 12683 ▶ if ($i == 0 && $nh == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 0 and $nh == 0) 134 12549 12683
Condition100%3/3
$i == 0 and $nh == 0
!ll&&!rl&&r
90383511134
MC/DC100%2/2
$i == 0 and $nh == 0
$i == 0 $nh == 0
Truth table100%3/3
A and B
A= $i == 0B= $nh == 0
ABresult
0X0
100
111
477 ### hi found inside: $n
478 134 ▶ if ($n > $n_hi) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n > $n_hi) 128 6 134
479 128 $n_hi = $n;
480 128 next ARM_HI;
481 }
482 }
483  
484 12555 ▶ if ($i == 0 || $nh > (4 * 5**$i)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 0 or $nh > 4 * 5 ** $i) { } 9980 2575 12555
Condition100%3/3
$i == 0 or $nh > 4 * 5 ** $i
l!l&&r!l&&!r
351764632575
MC/DC100%2/2
$i == 0 or $nh > 4 * 5 ** $i
$i == 0 $nh > 4 * 5 ** $i
Truth table100%3/3
A or B
A= $i == 0B= $nh > 4 * 5 ** $i
ABresult
1X1
011
000
485 ### too far away: "$nx,$ny nh=$nh vs ".(4 * 5**$i)
486  
487 9980 ▶ while (--$digits[$i] < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$digits[$i] < 0) 2120 9974 12094
488 2120 $digits[$i] = 4;
489 2120 ▶ if (++$i < $level_limit) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$i < $level_limit) { } 2114 6 2120
490 ### hi backtrack up ...
491 } else {
492 ### hi nothing within level limit for this arm ...
493 6 next ARM_HI;
494 }
495 }
496  
497 } else {
498 ### hi descend
499 ### assert: $i > 0
500 2575 $i--;
501 2575 $digits[$i] = 4;
502 }
503 }
504 }
505  
506 134 ▶ if ($n_hi == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n_hi == 0) 6 128 134
507 ### oops, lo found but hi not found
508 6 $n_hi = $n_lo;
509 }
510  
511 134 return ($n_lo, $n_hi);
512 }
513  
514 #------------------------------------------------------------------------------
515 # levels
516  
517 # level=0
518 # level=1 0 to 4
519 # level=2 0 to 24 is 5^level-1
520 #
521 # multiple arms the same full points of arms=1
522 # so arms*5^level points numbered starting 0
523 # = 5^level*arms - 1
524 sub level_to_n_range {
525 6 ▶ my ($self, $level) = @_;
Subroutine level_to_n_range: called CC=1 SCAR=0.0
Pod documented
526 6 return (0, 5**$level * $self->{'arms'} - 1);
527 }
528 sub n_to_level {
529 0 ▶ my ($self, $n) = @_;
Subroutine n_to_level: not called CC=3 SCAR=24.8
Pod documented
530 0 ▶ if ($n < 0) { return undef; }
Branch: 1 branch
BranchTrueFalseTotal
if ($n < 0) 0 0 0
531 0 ▶ if (is_infinite($n)) { return $n; }
Branch: 1 branch
BranchTrueFalseTotal
if (is_infinite($n)) 0 0 0
532 0 $n = round_nearest($n);
533 0 _divrem_mutate ($n, $self->{'arms'});
534 0 my ($pow, $exp) = round_up_pow ($n+1, 5);
535 0 return $exp;
536 }
537  
538 #------------------------------------------------------------------------------
539 2 1;
540 __END__
« PlanePath/CCurve.pm ↑ Summary PlanePath/GreekKeySpiral.pm »