PlanePath/TerdragonCurve.pm

filter: Statementstmt 60.9% 195 / 320 Branchbran 31.1% 33 / 106 Conditioncond 55.3% 26 / 47 MC/DCmcdc 51.8% 14 / 27 Subroutinesub 63.6% 28 / 44 Podpod 100% 13 / 13 totaltotal 55.4% 309 / 557 CC 73 SCAR 38.4
CC
73
Cov
54%
_UNDOCUMENTED__n_segment_is_left_boundary
240.0
_UNDOCUMENTED__left_boundary_i_to_n
90.0
_UNDOCUMENTED__n_segment_is_right_boundary
56.0
CRAP 46.5
« PlanePath/CincoCurve.pm ↑ Summary PlanePath/DivisibleColumns.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  
20 # points singles A052548 2^n + 2
21 # points doubles A000918 2^n - 2
22 # points triples A028243 3^(n-1) - 2*2^(n-1) + 1 cf A[k] = 2*3^(k-1) - 2*2^(k-1)
23  
24 # T(3*N) = (w+1)*T(N) dir(N)=w^(2*count1digits)
25 # T(3*N+1) = (w+1)*T(N) + 1*dir(N)
26 # T(3*N+2) = (w+1)*T(N) + w*dir(N)
27  
28 # T(0*3^k + N) = T(N)
29 # T(1*3^k + N) = 2^k + w^2*T(N) # rotate and offset
30 # T(2*3^k + N) = w*2^k + T(N) # offset only
31  
32  
33  
34 package Math::PlanePath::TerdragonCurve;
35 1 ▶use 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 1 ▶use List::Util 'first';
Subroutine BEGIN: called CC=1 SCAR=0.0
38 1 ▶use List::Util 'min'; # 'max'
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 *max = \&Math::PlanePath::_max;
40  
41 1 ▶use Math::PlanePath;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 1 *_divrem_mutate = \&Math::PlanePath::_divrem_mutate;
43  
44 use Math::PlanePath::Base::Generic
45 1 'is_infinite',
46 'round_nearest',
47 1 ▶ 'xy_is_even';
Subroutine BEGIN: called CC=1 SCAR=0.0
48 use Math::PlanePath::Base::Digits
49 1 'digit_split_lowtohigh',
50 'digit_join_lowtohigh',
51 1 ▶ 'round_up_pow';
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53 1 ▶use vars '$VERSION', '@ISA';
Subroutine BEGIN: called CC=1 SCAR=0.0
54 1 $VERSION = 128;
55 1 @ISA = ('Math::PlanePath');
56  
57 1 ▶use Math::PlanePath::TerdragonMidpoint;
Subroutine BEGIN: called CC=1 SCAR=0.0
58  
59 # uncomment this to run the ### lines
60 # use Smart::Comments;
61  
62  
63 1 ▶use constant n_start => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
64 1 use constant parameter_info_array =>
65 [ { name => 'arms',
66 share_key => 'arms_6',
67 display => 'Arms',
68 type => 'integer',
69 minimum => 1,
70 maximum => 6,
71 default => 1,
72 width => 1,
73 description => 'Arms',
74 1 ▶ } ];
Subroutine BEGIN: called CC=1 SCAR=0.0
75  
76 {
77 1 my @x_negative_at_n = (undef, 13, 5, 5, 6, 7, 8);
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 1 my @y_negative_at_n = (undef, 159, 75, 20, 11, 9, 10);
85 sub y_negative_at_n {
86 0 ▶ my ($self) = @_;
Subroutine y_negative_at_n: not called CC=1 SCAR=6.9
Pod documented
87 0 return $y_negative_at_n[$self->{'arms'}];
88 }
89 }
90 1 sub dx_minimum {
91 0 ▶ my ($self) = @_;
Subroutine dx_minimum: not called CC=2 SCAR=17.9
Pod documented
92 0 ▶ return ($self->{'arms'} == 1 ? -1 : -2);
Branch: 1 branch
BranchTrueFalseTotal
$self->{'arms'} == 1 ? : 0 0 0
93 }
94 1 ▶use constant dx_maximum => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
95 1 ▶use constant dy_minimum => -1;
Subroutine BEGIN: called CC=1 SCAR=0.0
96 1 ▶use constant dy_maximum => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
97  
98 sub _UNDOCUMENTED__dxdy_list {
99 0 ▶ my ($self) = @_;
Subroutine _UNDOCUMENTED__dxdy_list: not called CC=2 SCAR=17.9
100 0 ▶ return ($self->{'arms'} == 1
Branch: 1 branch
BranchTrueFalseTotal
$self->{'arms'} == 1 ? : 0 0 0
101 ? Math::PlanePath::_UNDOCUMENTED__dxdy_list_three()
102 : Math::PlanePath::_UNDOCUMENTED__dxdy_list_six());
103 }
104 {
105 1 my @_UNDOCUMENTED__dxdy_list_at_n = (undef, 4, 9, 13, 7, 8, 5);
106 sub _UNDOCUMENTED__dxdy_list_at_n {
107 0 ▶ my ($self) = @_;
Subroutine _UNDOCUMENTED__dxdy_list_at_n: not called CC=1 SCAR=6.9
108 0 return $_UNDOCUMENTED__dxdy_list_at_n[$self->{'arms'}];
109 }
110 }
111 1 ▶use constant absdx_minimum => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
112 1 ▶use constant dsumxy_minimum => -2; # diagonals
Subroutine BEGIN: called CC=1 SCAR=0.0
113 1 ▶use constant dsumxy_maximum => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
114 1 ▶use constant ddiffxy_minimum => -2;
Subroutine BEGIN: called CC=1 SCAR=0.0
115 1 ▶use constant ddiffxy_maximum => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
116  
117 # arms=1 curve goes at 0,120,240 degrees
118 # arms=2 second +60 to 60,180,300 degrees
119 # so when arms==1 dir maximum is 240 degrees
120 sub dir_maximum_dxdy {
121 0 ▶ my ($self) = @_;
Subroutine dir_maximum_dxdy: not called CC=2 SCAR=17.9
Pod documented
122 0 ▶ return ($self->{'arms'} == 1
Branch: 1 branch
BranchTrueFalseTotal
$self->{'arms'} == 1 ? : 0 0 0
123 ? (-1,-1) # 0,2,4 only South-West
124 : ( 1,-1)); # rotated to 1,3,5 too South-East
125 }
126  
127 1 ▶use constant turn_any_straight => 0; # never straight
Subroutine BEGIN: called CC=1 SCAR=0.0
128  
129  
130 #------------------------------------------------------------------------------
131  
132 sub new {
133 24 ▶ my $self = shift->SUPER::new(@_);
Subroutine new: called CC=2 SCAR=6.9
Pod documented
134 24 ▶ $self->{'arms'} = max(1, min(6, $self->{'arms'} || 1));
Condition100%2/2
$self->{'arms'} || 1
l!l
177
MC/DC100%1/1
$self->{'arms'} || 1
$self->{'arms'}
Truth table100%2/2
A
A= $self->{'arms'}
Aresult
11
00
135 24 return $self;
136 }
137  
138 1 my @dir6_to_si = (1,0,0, -1,0,0);
139 1 my @dir6_to_sj = (0,1,0, 0,-1,0);
140 1 my @dir6_to_sk = (0,0,1, 0,0,-1);
141  
142 sub n_to_xy {
143 441 ▶ my ($self, $n) = @_;
Subroutine n_to_xy: called CC=9 SCAR=22.0
Pod documented
144 ### TerdragonCurve n_to_xy(): $n
145  
146 441 ▶ if ($n < 0) { return; }
Branch: 1 branch
BranchTrueFalseTotal
if ($n < 0) 0 441 441
147 441 ▶ if (is_infinite($n)) { return ($n, $n); }
Branch: 1 branch
BranchTrueFalseTotal
if (is_infinite($n)) 0 441 441
148  
149 441 my $zero = ($n * 0); # inherit bignum 0
150  
151 441 my $i = 0;
152 441 my $j = 0;
153 441 my $k = 0;
154 441 my $si = $zero;
155 441 my $sj = $zero;
156 441 my $sk = $zero;
157  
158 # initial rotation from arm number
159 {
160 441 my $int = int($n);
161 441 my $frac = $n - $int; # inherit possible BigFloat
162 441 $n = $int; # BigFloat int() gives BigInt, use that
163  
164 441 my $rot = _divrem_mutate ($n, $self->{'arms'});
165  
166 441 my $s = $zero + 1; # inherit bignum 1
167 441 ▶ if ($rot >= 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rot >= 3) 27 414 441
168 27 $s = -$s; # rotate 180
169 27 $frac = -$frac;
170 27 $rot -= 3;
171 }
172 441 ▶ if ($rot == 0) { $i = $frac; $si = $s; } # rotate 0
Branch: 2 branches
BranchTrueFalseTotal
if ($rot == 0) { } 259 182 441
elsif ($rot == 1) { } 106 76 182
173 106 elsif ($rot == 1) { $j = $frac; $sj = $s; } # rotate +60
174 76 else { $k = $frac; $sk = $s; } # rotate +120
175 }
176  
177 441 foreach my $digit (digit_split_lowtohigh($n,3)) {
178 ### at: "$i,$j,$k side $si,$sj,$sk"
179 ### $digit
180  
181 2976 ▶ if ($digit == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($digit == 1) { } 1103 1873 2976
elsif ($digit == 2) { } 970 903 1873
182 1103 ($i,$j,$k) = ($si-$j, $sj-$k, $sk+$i); # rotate +120 and add
183 } elsif ($digit == 2) {
184 970 $i -= $sk; # add rotated +60
185 970 $j += $si;
186 970 $k += $sj;
187 }
188  
189 # add rotated +60
190 2976 ($si,$sj,$sk) = ($si - $sk,
191 $sj + $si,
192 $sk + $sj);
193 }
194  
195 ### final: "$i,$j,$k side $si,$sj,$sk"
196 ### is: (2*$i + $j - $k).",".($j+$k)
197  
198 441 return (2*$i + $j - $k, $j+$k);
199 }
200  
201  
202 # all even points when arms==6
203 sub xy_is_visited {
204 0 ▶ my ($self, $x, $y) = @_;
Subroutine xy_is_visited: not called CC=2 SCAR=17.9
Pod documented
205 0 ▶ if ($self->{'arms'} == 6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'arms'} == 6) { } 0 0 0
206 0 return xy_is_even($self,$x,$y);
207 } else {
208 0 return defined($self->xy_to_n($x,$y));
209 }
210 }
211  
212 sub xy_to_n {
213 26 ▶ return scalar((shift->xy_to_n_list(@_))[0]);
Subroutine xy_to_n: called CC=1 SCAR=0.0
Pod documented
214 }
215 sub xy_to_n_list {
216 55 ▶ my ($self, $x,$y) = @_;
Subroutine xy_to_n_list: called CC=8 SCAR=20.9
Pod documented
217 ### TerdragonCurve xy_to_n_list(): "$x, $y"
218  
219 55 $x = round_nearest($x);
220 55 $y = round_nearest($y);
221 {
222 # nothing at an odd point, and trap overflows in $x+$y dividing out b
223 55 my $sum = abs($x) + abs($y);
224 55 ▶ if (is_infinite($sum)) { return $sum; } # infinity
Branch: 1 branch
BranchTrueFalseTotal
if (is_infinite($sum)) 0 55 55
225 55 ▶ if ($sum % 2) { return; }
Branch: 1 branch
BranchTrueFalseTotal
if ($sum % 2) 0 55 55
226 }
227  
228 55 ▶ if ($x==0 && $y==0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x == 0 and $y == 0) 11 44 55
Condition100%3/3
$x == 0 and $y == 0
!ll&&!rl&&r
41311
MC/DC100%2/2
$x == 0 and $y == 0
$x == 0 $y == 0
Truth table100%3/3
A and B
A= $x == 0B= $y == 0
ABresult
0X0
100
111
229 11 return 0 .. $self->{'arms'}-1;
230 }
231  
232 44 my $arms_count = $self->arms_count;
233 44 my $zero = ($x * 0 * $y); # inherit bignum 0
234  
235 44 my @n_list;
236 44 foreach my $d (0,1,2) {
237 132 my ($ndigits,$arm) = _xy_d_to_ndigits_and_arm($x,$y,$d);
238 132 ▶ next if $arm >= $arms_count;
Branch: 1 branch
BranchTrueFalseTotal
if $arm >= $arms_count 22 110 132
239 110 my $odd = ($arm & 1);
240 110 ▶ if ($odd) {
Branch: 1 branch
BranchTrueFalseTotal
if ($odd) 37 73 110
241 37 @$ndigits = (map {2-$_} @$ndigits);
242 ### flip to: $ndigits
243 }
244 110 push @n_list,
245 (digit_join_lowtohigh($ndigits, 3, $zero) + $odd) * $arms_count + $arm;
246 }
247  
248 ### @n_list
249 44 return sort {$a<=>$b} @n_list;
250 }
251  
252 1 my @x_to_digit = (0, 2, 1); # digit = -X mod 3
253 1 my @digit_to_x = ([0,2,1], [0,-1,-2], [0,-1, 1]);
254 1 my @digit_to_y = ([0,0,1], [0, 1, 0], [0,-1,-1]);
255  
256 # $d = 0,1,2 for segment leaving $x,$y at direction $d*120 degrees.
257 # For odd arms the digits are 0<->2 reversals.
258 sub _xy_d_to_ndigits_and_arm {
259 132 ▶ my ($x,$y, $d) = @_;
Subroutine _xy_d_to_ndigits_and_arm: called CC=13 SCAR=25.6
260 132 my @ndigits;
261 my $arm;
262 132 for (;;) {
263 ### at: "$x,$y d=$d"
264 710 ▶ if ($x==0 && $y==0) { $arm = 2*$d; last; }
Branch: 1 branch
BranchTrueFalseTotal
if ($x == 0 and $y == 0) 74 636 710
Condition100%3/3
$x == 0 and $y == 0
!ll&&!rl&&r
6072974
MC/DC100%2/2
$x == 0 and $y == 0
$x == 0 $y == 0
Truth table100%3/3
A and B
A= $x == 0B= $y == 0
ABresult
0X0
100
111
265 636 ▶ if ($d==0 && $x==-2 && $y==0) { $arm = 3; last; }
Branch: 1 branch
BranchTrueFalseTotal
if ($d == 0 and $x == -2 and $y == 0) 9 627 636
Condition100%6/6
$d == 0 and $x == -2 and $y == 0
!ll&&!rl&&r
617109
$d == 0 and $x == -2
!ll&&!rl&&r
41620119
MC/DC100%3/3
$d == 0 and $x == -2 and $y == 0
$d == 0 $x == -2 $y == 0
Truth table100%4/4
A and B and C
A= $d == 0B= $x == -2C= $y == 0
ABCresult
0XX0
10X0
1100
1111
266 627 ▶ if ($d==2 && $x==1 && $y==1) { $arm = 1; last; }
Branch: 1 branch
BranchTrueFalseTotal
if ($d == 2 and $x == 1 and $y == 1) 31 596 627
Condition100%6/6
$d == 2 and $x == 1 and $y == 1
!ll&&!rl&&r
592431
$d == 2 and $x == 1
!ll&&!rl&&r
45014235
MC/DC100%3/3
$d == 2 and $x == 1 and $y == 1
$d == 2 $x == 1 $y == 1
Truth table100%4/4
A and B and C
A= $d == 2B= $x == 1C= $y == 1
ABCresult
0XX0
10X0
1100
1111
267 596 ▶ if ($d==1 && $x==1 && $y==-1) { $arm = 5; last; }
Branch: 1 branch
BranchTrueFalseTotal
if ($d == 1 and $x == 1 and $y == -1) 18 578 596
Condition100%6/6
$d == 1 and $x == 1 and $y == -1
!ll&&!rl&&r
5591918
$d == 1 and $x == 1
!ll&&!rl&&r
35720237
MC/DC100%3/3
$d == 1 and $x == 1 and $y == -1
$d == 1 $x == 1 $y == -1
Truth table100%4/4
A and B and C
A= $d == 1B= $x == 1C= $y == -1
ABCresult
0XX0
10X0
1100
1111
268  
269 578 my $digit = $x_to_digit[$x%3];
270 578 push @ndigits, $digit;
271  
272 578 ▶ if ($digit == 1) { $d = ($d-1) % 3; }
Branch: 1 branch
BranchTrueFalseTotal
if ($digit == 1) 234 344 578
273 578 $x -= $digit_to_x[$d]->[$digit];
274 578 $y -= $digit_to_y[$d]->[$digit];
275  
276 ### $digit
277 ### new d: $d
278 ### subtract: "$digit_to_x[$d]->[$digit],$digit_to_y[$d]->[$digit] to $x,$y"
279  
280 # ### assert: ($x+$y) % 2 == 0
281 # ### assert: $x % 3 == 0
282 # ### assert: ($y-$x/3) % 2 == 0
283 578 ($x,$y) = (($x+$y)/2, # divide b = w6+1
284 ($y-$x/3)/2);
285 }
286 ### $arm
287 ### @ndigits
288 132 return (\@ndigits, $arm);
289 }
290 # x+y*w3
291 # (x-y)+y*w3
292 # x/2 + y*sqrt3i/2
293 # sqrt3i/2 = w3+1/2
294 # x/2 + y*(w3+1/2) == 1/2*(x+y) + y*w3
295 # a = x+y = (x+3*y)/2
296 # GP-Test my(x=0,y=0); (-x)%3 == 0
297 # GP-Test my(x=2,y=0); (-x)%3 == 1
298 # GP-Test my(x=1,y=1); (-x)%3 == 2
299  
300 # minimum -- no, not quite right
301 #
302 # *----------*
303 # \
304 # \ *
305 # * \
306 # \
307 # *----------*
308 #
309 # width = side/2
310 # minimum = side*sqrt(3)/2 - width
311 # = side*(sqrt(3)/2 - 1)
312 #
313 # minimum 4/9 * 2.9^level roughly
314 # h = 4/9 * 2.9^level
315 # 2.9^level = h*9/4
316 # level = log(h*9/4)/log(2.9)
317 # 3^level = 3^(log(h*9/4)/log(2.9))
318 # = h*9/4, but big bigger for log
319 #
320 # not exact
321 sub rect_to_n_range {
322 31 ▶ my ($self, $x1,$y1, $x2,$y2) = @_;
Subroutine rect_to_n_range: called CC=1 SCAR=0.0
Pod documented
323 ### TerdragonCurve rect_to_n_range(): "$x1,$y1 $x2,$y2"
324 31 my $xmax = int(max(abs($x1),abs($x2)));
325 31 my $ymax = int(max(abs($y1),abs($y2)));
326 return (0,
327 ($xmax*$xmax + 3*$ymax*$ymax + 1)
328 * 2
329 31 * $self->{'arms'});
330 }
331  
332 # direction
333 #
334 1 my @dir6_to_dx = (2, 1,-1,-2, -1, 1);
335 1 my @dir6_to_dy = (0, 1, 1, 0, -1,-1);
336 1 my @digit_to_nextturn = (2,-2);
337 sub n_to_dxdy {
338 1000 ▶ my ($self, $n) = @_;
Subroutine n_to_dxdy: called CC=4 SCAR=15.7
Pod documented
339 ### n_to_dxdy(): $n
340  
341 1000 ▶ if ($n < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n < 0) 0 1000 1000
342 0 return; # first direction at N=0
343 }
344 1000 ▶ if (is_infinite($n)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_infinite($n)) 0 1000 1000
345 0 return ($n,$n);
346 }
347  
348 1000 my $int = int($n); # integer part
349 1000 $n -= $int; # fraction part
350  
351 # initial direction from arm
352 1000 my $dir6 = _divrem_mutate ($int, $self->{'arms'});
353  
354 1000 my @ndigits = digit_split_lowtohigh($int,3);
355 1000 $dir6 += 2 * scalar(grep {$_==1} @ndigits); # count 1s for total turn
356 1000 $dir6 %= 6;
357 1000 my $dx = $dir6_to_dx[$dir6];
358 1000 my $dy = $dir6_to_dy[$dir6];
359  
360 1000 ▶ if ($n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n) 0 1000 1000
361 # fraction part
362  
363 # find lowest non-2 digit, or zero if all 2s or no digits at all
364 0 ▶ $dir6 += $digit_to_nextturn[ first {$_!=2} @ndigits, 0];
Subroutine __ANON__: not called CC=1 SCAR=6.9
365 0 $dir6 %= 6;
366 0 $dx += $n*($dir6_to_dx[$dir6] - $dx);
367 0 $dy += $n*($dir6_to_dy[$dir6] - $dy);
368 }
369 1000 return ($dx, $dy);
370 }
371  
372  
373 #-----------------------------------------------------------------------------
374 # eg. arms=5 0 .. 5*3^k step by 5s
375 # 1 .. 5*3^k+1 step by 5s
376 # 4 .. 5*3^k+4 step by 5s
377 #
378 sub level_to_n_range {
379 6 ▶ my ($self, $level) = @_;
Subroutine level_to_n_range: called CC=1 SCAR=0.0
Pod documented
380 6 return (0, (3**$level + 1) * $self->{'arms'} - 1);
381 }
382 sub n_to_level {
383 0 ▶ my ($self, $n) = @_;
Subroutine n_to_level: not called CC=3 SCAR=24.8
Pod documented
384 0 ▶ if ($n < 0) { return undef; }
Branch: 1 branch
BranchTrueFalseTotal
if ($n < 0) 0 0 0
385 0 ▶ if (is_infinite($n)) { return $n; }
Branch: 1 branch
BranchTrueFalseTotal
if (is_infinite($n)) 0 0 0
386 0 $n = round_nearest($n);
387 0 _divrem_mutate ($n, $self->{'arms'});
388 0 my ($pow, $exp) = round_up_pow ($n, 3);
389 0 return $exp;
390 }
391  
392 #-----------------------------------------------------------------------------
393 # right boundary N
394  
395 # mixed radix binary, ternary
396 # no 11, 12, 20
397 # 11 -> 21, including low digit
398 # run of 11111 becomes 22221
399 # low to high 1 or 0 <- 0 cannot 20 can 10 00
400 # 2 or 0 <- 1 cannot 11 can 21 01
401 # 2 or 0 <- 2 cannot 12 can 02 22
402 sub _UNDOCUMENTED__right_boundary_i_to_n {
403 0 ▶ my ($self, $i) = @_;
Subroutine _UNDOCUMENTED__right_boundary_i_to_n: not called CC=4 SCAR=30.0
404 0 my @digits = _digit_split_mix23_lowtohigh($i);
405 0 ▶ for ($i = $#digits; $i >= 1; $i--) { # high to low
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 1) 0 0 0
406 0 ▶ if ($digits[$i] == 1 && $digits[$i-1] != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($digits[$i] == 1 and $digits[$i - 1] != 0) 0 0 0
Condition0%0/3
$digits[$i] == 1 and $digits[$i - 1] != 0
!ll&&!rl&&r
000
MC/DC0%0/2
$digits[$i] == 1 and $digits[$i - 1] != 0
$digits[$i] == 1 $digits[$i - 1] != 0
Truth table0%0/3
A and B
A= $digits[$i] == 1B= $digits[$i - 1] != 0
ABresult
0X0
100
111
407 0 $digits[$i] = 2;
408 }
409 }
410 0 return digit_join_lowtohigh(\@digits, 3, $i*0);
411  
412 # {
413 # for (my $i = 0; $i < $#digits; $i++) { # low to high
414 # if ($digits[$i+1] == 1 && ($digits[$i] == 1 || $digits[$i] == 2)) {
415 # $digits[$i+1] = 2;
416 # }
417 # }
418 # return digit_join_lowtohigh(\@digits,3);
419 # }
420 }
421  
422 # Return a list of digits, low to high, which is a mixed radix
423 # representation low digit ternary and the rest binary.
424 sub _digit_split_mix23_lowtohigh {
425 0 ▶ my ($n) = @_;
Subroutine _digit_split_mix23_lowtohigh: not called CC=2 SCAR=17.9
426 0 ▶ if ($n == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n == 0) 0 0 0
427 0 return ();
428 }
429 0 my $low = _divrem_mutate($n,3);
430 0 return ($low, digit_split_lowtohigh($n,2));
431 }
432  
433 {
434 # disallowed digit pairs $disallowed[high][low]
435 1 my @disallowed;
436 1 $disallowed[1][1] = 1;
437 1 $disallowed[1][2] = 1;
438 1 $disallowed[2][0] = 1;
439  
440 sub _UNDOCUMENTED__n_segment_is_right_boundary {
441 0 ▶ my ($self, $n) = @_;
Subroutine _UNDOCUMENTED__n_segment_is_right_boundary: not called CC=7 SCAR=40.3
442 0 ▶ if (is_infinite($n)) { return 0; }
Branch: 1 branch
BranchTrueFalseTotal
if (is_infinite($n)) 0 0 0
443 0 ▶ unless ($n >= 0) { return 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($n >= 0) 0 0 0
444 0 $n = int($n);
445  
446 # no boundary when arms=6, right boundary is only in arm 0
447 {
448 0 my $arms = $self->{'arms'};
449 0 ▶ if ($arms == 6) { return 0; }
Branch: 1 branch
BranchTrueFalseTotal
if ($arms == 6) 0 0 0
450 0 ▶ if (_divrem_mutate($n,$arms)) { return 0; }
Branch: 1 branch
BranchTrueFalseTotal
if (_divrem_mutate($n, $arms)) 0 0 0
451 }
452  
453 0 my $prev = _divrem_mutate($n,3);
454 0 ▶ while ($n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n) 0 0 0
455 0 my $digit = _divrem_mutate($n,3);
456 0 ▶ if ($disallowed[$digit][$prev]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($disallowed[$digit][$prev]) 0 0 0
457 0 return 0;
458 }
459 0 $prev = $digit;
460 }
461 0 return 1;
462 }
463 }
464  
465 #-----------------------------------------------------------------------------
466 # left boundary N
467  
468  
469 # mixed 0,1, 2, 10, 11, 12, 100, 101, 102, 110, 111, 112, 1000, 1001, 1002, 1010, 1011, 1012, 1100, 1101, 1102,
470 # vals 0,1,12,120,121,122,1200,1201,1212,1220,1221,1222,12000,12001,12012,12120,12121,12122,12200,12201,12212,
471 {
472 1 my @_UNDOCUMENTED__left_boundary_i_to_n = ([0,2], # 0
473 [0,2], # 1
474 [1,2]); # 2
475 sub _UNDOCUMENTED__left_boundary_i_to_n {
476 0 ▶ my ($self, $i, $level) = @_;
Subroutine _UNDOCUMENTED__left_boundary_i_to_n: not called CC=9 SCAR=45.0
477 ### _UNDOCUMENTED__left_boundary_i_to_n(): $i
478 ### $level
479  
480 0 ▶ if (defined $level && $level < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $level and $level < 0) 0 0 0
Condition0%0/3
defined $level and $level < 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $level and $level < 0
defined $level $level < 0
Truth table0%0/3
A and B
A= defined $levelB= $level < 0
ABresult
0X0
100
111
481 0 ▶ if ($i <= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= 2) 0 0 0
482 0 return $i;
483 }
484 0 $i += 2;
485 }
486  
487 0 my @digits = _digit_split_mix23_lowtohigh($i);
488 ### @digits
489  
490 0 ▶ if (defined $level) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $level) { } 0 0 0
491 0 ▶ if ($level >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level >= 0) { } 0 0 0
492 0 ▶ if (@digits > $level) {
Branch: 1 branch
BranchTrueFalseTotal
if (@digits > $level) 0 0 0
493 ### beyond given level ...
494 0 return undef;
495 }
496 # pad for $level, total $level many digits
497 0 push @digits, (0) x ($level - scalar(@digits));
498 } else {
499 ### union all levels ...
500 0 pop @digits;
501 0 ▶ if ($digits[-1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($digits[-1]) { } 0 0 0
502 0 push @digits, 0; # high 0,1 or 0,2 when i=3
503 } else {
504 0 $digits[-1] = 1; # high 1
505 }
506 }
507 } else {
508 ### infinite curve, an extra high 0 ...
509 0 push @digits, 0;
510 }
511 ### @digits
512  
513 0 my $prev = $digits[0];
514 0 foreach my $i (1 .. $#digits) {
515 0 $prev = $digits[$i] = $_UNDOCUMENTED__left_boundary_i_to_n[$prev][$digits[$i]];
516 }
517 ### ternary: @digits
518 0 return digit_join_lowtohigh(\@digits, 3, $i*0);
519 }
520 }
521  
522 {
523 # disallowed digit pairs $disallowed[high][low]
524 1 my @disallowed;
525 1 $disallowed[0][2] = 1;
526 1 $disallowed[1][0] = 1;
527 1 $disallowed[1][1] = 1;
528  
529 sub _UNDOCUMENTED__n_segment_is_left_boundary {
530 0 ▶ my ($self, $n, $level) = @_;
Subroutine _UNDOCUMENTED__n_segment_is_left_boundary: not called CC=15 SCAR=54.8
531 ### _UNDOCUMENTED__n_segment_is_left_boundary(): $n
532 ### $level
533  
534 0 ▶ if (is_infinite($n)) { return 0; }
Branch: 1 branch
BranchTrueFalseTotal
if (is_infinite($n)) 0 0 0
535 0 ▶ unless ($n >= 0) { return 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($n >= 0) 0 0 0
536 0 $n = int($n);
537  
538 0 ▶ if (defined $level && $level == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $level and $level == 0) 0 0 0
Condition0%0/3
defined $level and $level == 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $level and $level == 0
defined $level $level == 0
Truth table0%0/3
A and B
A= defined $levelB= $level == 0
ABresult
0X0
100
111
539 ### level 0 curve, N=0 is only segment: ($n == 0)
540 0 return ($n == 0);
541 }
542  
543 {
544 0 my $arms = $self->{'arms'};
545 0 ▶ if ($arms == 6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arms == 6) 0 0 0
546 0 return 0;
547 }
548 0 my $arm = _divrem_mutate($n,$arms);
549 0 ▶ if ($arm != $arms-1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arm != $arms - 1) 0 0 0
550 0 return 0;
551 }
552 }
553  
554 0 my $prev = _divrem_mutate($n,3);
555 0 ▶ if (defined $level) { $level -= 1; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $level) 0 0 0
556  
557 0 for (;;) {
558 0 ▶ if (defined $level && $level == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $level and $level == 0) 0 0 0
Condition0%0/3
defined $level and $level == 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $level and $level == 0
defined $level $level == 0
Truth table0%0/3
A and B
A= defined $levelB= $level == 0
ABresult
0X0
100
111
559 ### end of level many digits, must be N < 3**$level
560 0 return ($n == 0);
561 }
562 0 ▶ last unless $n;
Branch: 1 branch
BranchTrueFalseTotal
unless $n 0 0 0
563  
564 0 my $digit = _divrem_mutate($n,3);
565 0 ▶ if ($disallowed[$digit][$prev]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($disallowed[$digit][$prev]) 0 0 0
566 0 return 0;
567 }
568 0 ▶ if (defined $level) { $level -= 1; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $level) 0 0 0
569 0 $prev = $digit;
570 }
571  
572 0 ▶ return ((defined $level && $level < 0) # union all levels
Condition0%0/6
defined $level && $level < 0 || $prev != 2
l!l&&r!l&&!r
000
defined $level and $level < 0
!ll&&!rl&&r
000
MC/DC0%0/3
defined $level && $level < 0 || $prev != 2
defined $level $level < 0 $prev != 2
Truth table0%0/5
A and B || C
A= defined $levelB= $level < 0C= $prev != 2
ABCresult
11X1
0X11
1011
0X00
1000
573 || ($prev != 2)); # not high 2 otherwise
574 }
575  
576 sub _UNDOCUMENTED__n_segment_is_any_left_boundary {
577 0 ▶ my ($self, $n) = @_;
Subroutine _UNDOCUMENTED__n_segment_is_any_left_boundary: not called CC=3 SCAR=24.8
578 0 my $prev = _divrem_mutate($n,3);
579 0 ▶ while ($n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n) 0 0 0
580 0 my $digit = _divrem_mutate($n,3);
581 0 ▶ if ($disallowed[$digit][$prev]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($disallowed[$digit][$prev]) 0 0 0
582 0 return 0;
583 }
584 0 $prev = $digit;
585 }
586 0 return 1;
587 }
588  
589 # sub left_boundary_n_pred {
590 # my ($n) = @_;
591 # my $n3 = '0' . Math::BaseCnv::cnv($n,10,3);
592 # return ($n3 =~ /02|10|11/ ? 0 : 1);
593 # }
594 }
595 1 sub _UNDOCUMENTED__n_segment_is_boundary {
596 0 ▶ my ($self, $n, $level) = @_;
Subroutine _UNDOCUMENTED__n_segment_is_boundary: not called CC=2 SCAR=17.9
597 0 ▶ return $self->_UNDOCUMENTED__n_segment_is_right_boundary($n)
Condition0%0/3
$self->_UNDOCUMENTED__n_segment_is_right_boundary($n) || $self->_UNDOCUMENTED__n_segment_is_left_boundary($n, $level)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->_UNDOCUMENTED__n_segment_is_right_boundary($n) || $self->_UNDOCUMENTED__n_segment_is_left_boundary($n, $level)
$self->_UNDOCUMENTED__n_segment_is_right_boundary($n) $self->_UNDOCUMENTED__n_segment_is_left_boundary($n, $level)
Truth table0%0/3
A || B
A= $self->_UNDOCUMENTED__n_segment_is_right_boundary($n)B= $self->_UNDOCUMENTED__n_segment_is_left_boundary($n, $level)
ABresult
1X1
011
000
598 || $self->_UNDOCUMENTED__n_segment_is_left_boundary($n,$level);
599 }
600  
601 1 1;
602 __END__
« PlanePath/CincoCurve.pm ↑ Summary PlanePath/DivisibleColumns.pm »