PlanePath/SierpinskiCurveStair.pm

filter: Statementstmt 86.8% 178 / 205 Branchbran 76.4% 52 / 68 Conditioncond 50.0% 26 / 52 MC/DCmcdc 39.1% 9 / 23 Subroutinesub 95.8% 23 / 24 Podpod 100% 8 / 8 totaltotal 77.8% 296 / 380 CC 54 SCAR 30.7
CC
54
Cov
79%
rect_to_n_range
52.9
xy_to_n
18.0
n_to_xy
16.5
CRAP 21.6
« PlanePath/KochSquareflakes.pm ↑ Summary PlanePath/DekkingCentres.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  
20  
21 # math-image --path=SierpinskiCurveStair --lines --scale=10
22 #
23 # math-image --path=SierpinskiCurveStair,diagonal_length=1 --all --output=numbers_dash --offset=-10,-7 --size=78x30
24  
25  
26  
27 package Math::PlanePath::SierpinskiCurveStair;
28 1 ▶use 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use List::Util 'min','max';
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 1 ▶use vars '$VERSION', '@ISA';
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 $VERSION = 128;
34 1 ▶use Math::PlanePath;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 1 ▶use Math::PlanePath::Base::NSEW;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 1 @ISA = ('Math::PlanePath::Base::NSEW',
37 'Math::PlanePath');
38  
39 use Math::PlanePath::Base::Generic
40 1 'is_infinite',
41 1 ▶ 'round_nearest';
Subroutine BEGIN: called CC=1 SCAR=0.0
42 use Math::PlanePath::Base::Digits
43 1 'round_up_pow',
44 1 ▶ 'round_down_pow';
Subroutine BEGIN: called CC=1 SCAR=0.0
45 1 *_divrem_mutate = \&Math::PlanePath::_divrem_mutate;
46  
47 # uncomment this to run the ### lines
48 #use Smart::Comments;
49  
50  
51 1 ▶use constant n_start => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 sub x_negative {
53 6 ▶ my ($self) = @_;
Subroutine x_negative: called CC=1 SCAR=0.0
Pod documented
54 6 return ($self->{'arms'} >= 3);
55 }
56 sub y_negative {
57 6 ▶ my ($self) = @_;
Subroutine y_negative: called CC=1 SCAR=0.0
Pod documented
58 6 return ($self->{'arms'} >= 5);
59 }
60  
61 1 use constant parameter_info_array =>
62 [
63 { name => 'diagonal_length',
64 display => 'Diagonal Length',
65 type => 'integer',
66 minimum => 1,
67 default => 1,
68 width => 1,
69 description => 'Length of the diagonal in the base pattern.',
70 },
71 { name => 'arms',
72 share_key => 'arms_8',
73 display => 'Arms',
74 type => 'integer',
75 minimum => 1,
76 maximum => 8,
77 default => 1,
78 width => 1,
79 },
80 1 ▶ ];
Subroutine BEGIN: called CC=1 SCAR=0.0
81  
82 1 ▶use Math::PlanePath::SierpinskiCurve;
Subroutine BEGIN: called CC=1 SCAR=0.0
83 1 *x_negative_at_n = \&Math::PlanePath::SierpinskiCurve::x_negative_at_n;
84 1 *y_negative_at_n = \&Math::PlanePath::SierpinskiCurve::y_negative_at_n;
85 1 *x_minimum = \&Math::PlanePath::SierpinskiCurve::x_minimum;
86 1 *sumxy_minimum = \&Math::PlanePath::SierpinskiCurve::sumxy_minimum;
87 1 ▶use constant sumabsxy_minimum => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
88 1 *diffxy_minimum = \&Math::PlanePath::SierpinskiCurve::diffxy_minimum;
89 1 ▶use constant absdiffxy_minimum => 1; # X=Y never occurs
Subroutine BEGIN: called CC=1 SCAR=0.0
90 1 ▶use constant rsquared_minimum => 1; # minimum X=1,Y=0
Subroutine BEGIN: called CC=1 SCAR=0.0
91 1 ▶use constant turn_any_straight => 0; # never straight
Subroutine BEGIN: called CC=1 SCAR=0.0
92  
93  
94 #------------------------------------------------------------------------------
95  
96 sub new {
97 41 ▶ my $self = shift->SUPER::new(@_);
Subroutine new: called CC=3 SCAR=11.0
Pod documented
98 41 ▶ $self->{'arms'} = max(1, min(8, $self->{'arms'} || 1));
Condition100%2/2
$self->{'arms'} || 1
l!l
383
MC/DC100%1/1
$self->{'arms'} || 1
$self->{'arms'}
Truth table100%2/2
A
A= $self->{'arms'}
Aresult
11
00
99 41 ▶ $self->{'diagonal_length'} ||= 1;
Condition100%2/2
$self->{"diagonal_length"} ||= 1
l!l
329
MC/DC100%1/1
$self->{"diagonal_length"} ||= 1
$self->{"diagonal_length"}
Truth table100%2/2
A
A= $self->{"diagonal_length"}
Aresult
11
00
100 41 return $self;
101 }
102  
103 # 20--21
104 # | |
105 # 18--19 22--23
106 # | |
107 # 16--17 24--25
108 # | |
109 # 15--14 27--26
110 # | |
111 # 4---5 13--12 29--28 36--37
112 # | | | | | |
113 # 2---3 6---7 10--11 30--31 34--35 38--39 42--43
114 # | | | | | | |
115 # 0---1 8---9 32--33 40--41
116  
117 # len=5
118 # N=0 to 9 is 10
119 # next N=0 to 41 is 42=4*10+2
120 # next is 4*42+2=166
121 # points(level) = 4*points(level-1)+2
122 #
123 # or side 5 points
124 # points(level) = 4*points(level-1)+1
125 # = 4*(4*points(level-2)+1)+1
126 # = 16*points(level-2) + 4 + 1
127 # = 64*points(level-3) + 16 + 4 + 1
128 # = 5 * 4^level + 1+...+4^(level-1)
129 # = 5 * 4^level + (4^level - 1) / 3
130 # = (15 * 4^level + 4^level - 1) / 3
131 # = (16 * 4^level - 1) / 3
132 # = (4^(level+2) - 1) / 3
133 # level=0 (16*1-1)/3=5
134 # level=1 (16*4-1)/3=21
135 # level=2 (16*16-1)/3=85
136 #
137 # n = (16 * 4^level - 1) / 3
138 # 3n+1 = 16 * 4^level
139 # 4^level = (3n+1)/16
140 # level = log4 ( (3n+1)/16)
141 # = log4(3n+1) - 2
142 # N=21 log4(64)-2=3-2=1
143 #
144 # nlen=4^(level+2)
145 # n = (nlen-1)/3
146 # next_n = (nlen/4-1)/3
147 # = (nlen-4)/3 /4
148 # = ((nlen-1)/3 -1) /4
149 #
150 # len=2,6,14
151 # len(k)=2*len(k-1) + 2
152 # = 2^k + 2*(2^(k-1)-1)
153 # = 2^k + 2^k - 2
154 # = 2*(2^k - 1)
155 # k=1 len=2*(2-1) = 2
156 # k=2 len=2*(4-1) = 6
157 # k=3 len=2*(8-1) = 14
158  
159 # len(k)-2=2*len(k-1)
160 # (len(k)-2)/2=len(k-1)
161 # len(k-1) = (len(k)-2)/2
162 # = len(k)/2-1
163 #
164 # ---------
165 # with P=2*L+1 points per side
166 # points(level) = 64*points(level-3) + 16 + 4 + 1
167 # = P*4^level + 1+...+4^(level-1)
168 # = P*4^level + (4^level - 1) / 3
169 # = (3P*4^level + 4^level - 1) / 3
170 # = ((3P+1)*4^level - 1) / 3
171 # = ((3*(2L+1)+1)*4^level - 1) / 3
172 # = ((6L+3+1)*4^level - 1) / 3
173 # = ((6L+4)*4^level - 1) / 3
174 # n = ((6L+4)*4^level - 1) / 3
175 # 3n+1 = (6L+4)*4^level
176 #
177 # len(k) = 2*len(k-1) + 2
178 # = 2*len(k-2) + 2 + 4
179 # = 2*len(k-3) + 2 + 4 + 8
180 # = 2^(k-1)*L + 2^k - 2
181 # = (L+2)*2^(k-1) - 2
182 # L=2 k=3 len=(2+2)*2^2-2=14
183 #
184 # ----------
185 # Nlevel = ((6L+4)*4^level - 1) / 3 - 1
186 # = ((6L+4)*4^level - 4) / 3
187 # Xlevel = (L+2)*2^level - 2 + 1
188 # = (L+2)*2^level - 1
189 #
190 # fill = Nlevel / (Xlevel*(Xlevel-1)/2)
191 # = (((6L+4)*4^level - 1) / 3 - 1) / (((L+2)*2^level - 1)*((L+2)*2^level - 2))
192 # -> (((6L+4)*4^level) / 3) / ((L+2)*2^level)^2
193 # = ((6L+4)*4^level) / ((L+2)^2*4^level) *2/3
194 # = ((6L+4)) / ((L+2)^2) * 2/3
195 # = 2*(3L+2) / ((L+2)^2) * 2/3
196 # = 4/3 * (3L+2)/(L+2)^2
197 # = (12L+8) / (3*L^2+12L+12)
198 # L=1 (12+8)/(3+12+12) = 20/27
199  
200  
201 sub n_to_xy {
202 19 ▶ my ($self, $n) = @_;
Subroutine n_to_xy: called CC=13 SCAR=28.0
Pod documented
203 ### SierpinskiCurveStair n_to_xy(): $n
204  
205 19 ▶ if ($n < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n < 0) 0 19 19
206 0 return;
207 }
208 19 ▶ if (is_infinite($n)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_infinite($n)) 0 19 19
209 0 return ($n,$n);
210 }
211  
212 19 my $frac;
213 {
214 19 my $int = int($n);
215 19 $frac = $n - $int; # inherit possible BigFloat
216 19 ▶ if ($frac) {
Branch: 1 branch
BranchTrueFalseTotal
if ($frac) 0 19 19
217 0 my ($x1,$y1) = $self->n_to_xy($int);
218 0 my ($x2,$y2) = $self->n_to_xy($int+$self->{'arms'});
219  
220 0 my $dx = $x2-$x1;
221 0 my $dy = $y2-$y1;
222 0 return ($frac*$dx + $x1, $frac*$dy + $y1);
223 }
224 19 $n = $int; # BigFloat int() gives BigInt, use that
225 }
226 ### $frac
227 19 my $zero = ($n * 0); # inherit bignum 0
228  
229 19 my $arm = _divrem_mutate ($n, $self->{'arms'});
230  
231 19 my $diagonal_length = $self->{'diagonal_length'};
232 19 my $diagonal_div = 6*$diagonal_length + 4;
233  
234 19 my ($nlen,$level) = round_down_pow ((3*$n+1)/$diagonal_div, 4);
235 ### $nlen
236 ### $level
237 19 ▶ if (is_infinite($level)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_infinite($level)) 0 19 19
238 0 return $level;
239 }
240  
241 19 my $x = $zero;
242 19 my $y = $zero;
243 19 my $dx = 1;
244 19 my $dy = 0;
245  
246 # (L+2)*2^(level-1) - 2
247 19 my $len = ($diagonal_length+2)*2**$level - 2;
248 19 $nlen = ($diagonal_div*$nlen-1)/3;
249  
250 19 ▶ while ($level-- >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level-- >= 0) 52 19 71
251 ### at: "n=$n xy=$x,$y nlen=$nlen len=$len"
252  
253 52 ▶ if ($n < 2*$nlen+1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n < 2 * $nlen + 1) { } 19 33 52
254 19 ▶ if ($n < $nlen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n < $nlen) { } 1 18 19
255 ### part 0 ...
256 } else {
257 ### part 1 ...
258 18 $x += ($len+1)*$dx - $len*$dy;
259 18 $y += ($len+1)*$dy + $len*$dx;
260 18 ($dx,$dy) = ($dy,-$dx); # rotate -90
261 18 $n -= $nlen;
262 }
263 } else {
264 33 $n -= 2*$nlen+1;
265 33 ▶ if ($n < $nlen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n < $nlen) { } 0 33 33
266 ### part 2 ...
267 0 $x += (2*$len+2)*$dx - $dy;
268 0 $y += (2*$len+2)*$dy + $dx;
269 0 ($dx,$dy) = (-$dy,$dx); # rotate +90
270 } else {
271 ### part 3 ...
272 33 $x += ($len+2)*$dx - ($len+2)*$dy;
273 33 $y += ($len+2)*$dy + ($len+2)*$dx;
274 33 $n -= $nlen;
275 }
276 }
277  
278 52 $nlen = ($nlen-1)/4;
279 52 $len = $len/2-1;
280 }
281  
282 19 my $lowdigit_x = int(($n+1)/2);
283 19 ▶ if ($n == 2*$diagonal_length+1) { $lowdigit_x -= 2; }
Branch: 1 branch
BranchTrueFalseTotal
if ($n == 2 * $diagonal_length + 1) 5 14 19
284 19 my $lowdigit_y = int($n/2);
285  
286 ### final: "n=$n xy=$x,$y dxdy=$dx,$dy"
287 ### $lowdigit_x
288 ### $lowdigit_y
289  
290 19 $x += $lowdigit_x*$dx - $lowdigit_y*$dy + 1; # +1 start at x=1,y=0
291 19 $y += $lowdigit_x*$dy + $lowdigit_y*$dx;
292  
293 19 ▶ if ($arm & 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arm & 1) 0 19 19
294 0 ($x,$y) = ($y,$x); # mirror 45
295 }
296 19 ▶ if ($arm & 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arm & 2) 0 19 19
297 0 ($x,$y) = (-1-$y,$x); # rotate +90
298 }
299 19 ▶ if ($arm & 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arm & 4) 0 19 19
300 0 $x = -1-$x; # rotate 180
301 0 $y = -1-$y;
302 }
303  
304 19 return ($x,$y);
305 }
306  
307 sub xy_to_n {
308 19776 ▶ my ($self, $x, $y) = @_;
Subroutine xy_to_n: called CC=18 SCAR=28.9
Pod documented
309 ### SierpinskiCurveStair xy_to_n(): "$x, $y"
310  
311 19776 $x = round_nearest($x);
312 19776 $y = round_nearest($y);
313  
314 19776 my $arm = 0;
315 19776 ▶ if ($y < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < 0) 2720 17056 19776
316 2720 $arm = 4;
317 2720 $x = -1-$x; # rotate -180
318 2720 $y = -1-$y;
319 }
320 19776 ▶ if ($x < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < 0) 4608 15168 19776
321 4608 $arm += 2;
322 4608 ($x,$y) = ($y, -1-$x); # rotate -90
323 }
324 19776 ▶ if ($y > $x) { # second octant
Branch: 1 branch
BranchTrueFalseTotal
if ($y > $x) 9344 10432 19776
325 9344 $arm++;
326 9344 ($x,$y) = ($y,$x); # mirror 45
327 }
328  
329 19776 my $arms = $self->{'arms'};
330 19776 ▶ if ($arm >= $arms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arm >= $arms) 3680 16096 19776
331 3680 return undef;
332 }
333  
334 16096 $x -= 1;
335 16096 ▶ if ($x < 0 || $x < $y) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < 0 or $x < $y) 1008 15088 16096
Condition100%3/3
$x < 0 or $x < $y
l!l&&r!l&&!r
4896015088
MC/DC100%2/2
$x < 0 or $x < $y
$x < 0 $x < $y
Truth table100%3/3
A or B
A= $x < 0B= $x < $y
ABresult
1X1
011
000
336 1008 return undef;
337 }
338 ### x adjust to zero: "$x,$y"
339 ### assert: $x >= 0
340 ### assert: $y >= 0
341  
342 # len=2*(2^level - 1)
343 # len/2+1 = 2^level
344 # 2^level = len/2+1
345 # 2^(level+1) = len+2
346  
347 # len=(L+2)*2^(level-1) - 2
348 # (len+2)/(L+2) = 2^(level-1)
349  
350 15088 my $diagonal_length = $self->{'diagonal_length'};
351 15088 my ($len,$level) = round_down_pow (($x+1)/($diagonal_length+2), 2);
352 ### $level
353 ### $len
354 15088 ▶ if (is_infinite($level)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_infinite($level)) 0 15088 15088
355 0 return $level;
356 }
357  
358 15088 my $n = 0;
359 15088 my $nlen = ((6*$diagonal_length+4)*$len*$len-1)/3;
360 15088 $len *= ($self->{'diagonal_length'}+2);
361 ### $len
362 ### $nlen
363  
364 15088 my $n_last_1;
365 15088 foreach (0 .. $level) {
366 ### at: "loop=$_ x=$x,y=$y n=$n nlen=$nlen len=$len diag cmp ".(2*$len-2)
367 ### assert: $x >= 0
368 ### assert: $y >= 0
369  
370 37510 ▶ if ($x+$y <= 2*$len-2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x + $y <= 2 * $len - 2) { } 20665 16845 37510
371 ### part 0 or 1...
372 20665 ▶ if ($x < $len-1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len - 1) { } 6256 14409 20665
373 ### part 0 ...
374 6256 $n_last_1 = 0;
375 } else {
376 ### part 1 ...
377 14409 ($x,$y) = ($len-2-$y, $x-($len-1)); # shift then rotate +90
378 14409 $n += $nlen;
379 14409 $n_last_1 = 1;
380 }
381 } else {
382 16845 $n += 2*$nlen + 1; # +1 for middle point
383 ### part 2 or 3 ...
384 16845 ▶ if ($y < $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len) { } 8671 8174 16845
385 ### part 2...
386 8671 ($x,$y) = ($y-1, 2*$len-2-$x); # shift y-1 then rotate -90
387 8671 $n_last_1 = 0;
388 } else {
389 #### digit 3...
390 8174 $x -= $len;
391 8174 $y -= $len;
392 8174 $n += $nlen;
393 }
394 16845 ▶ if ($x < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < 0) 81 16764 16845
395 81 return undef;
396 }
397 }
398 37429 $len /= 2;
399 37429 $nlen = ($nlen-1)/4;
400 }
401  
402 ### end at: "x=$x,y=$y n=$n last2=$n_last_1"
403 ### assert: $x >= 0
404 ### assert: $y >= 0
405  
406 15007 ▶ if ($x == $y || $x == $y+1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($x == $y or $x == $y + 1) { } 8932 6075 15007
elsif ($n_last_1 and $x == $diagonal_length - 1 and $y == $diagonal_length) { } 458 5617 6075
Condition100%3/3
$x == $y or $x == $y + 1
l!l&&r!l&&!r
518037526075
MC/DC100%2/2
$x == $y or $x == $y + 1
$x == $y $x == $y + 1
Truth table100%3/3
A or B
A= $x == $yB= $x == $y + 1
ABresult
1X1
011
000
407 8932 $n += $x+$y;
408 ▶ } elsif ($n_last_1 && $x == $diagonal_length-1 && $y == $diagonal_length) {
Condition100%6/6
$n_last_1 and $x == $diagonal_length - 1 and $y == $diagonal_length
!ll&&!rl&&r
5254363458
$n_last_1 and $x == $diagonal_length - 1
!ll&&!rl&&r
30022252821
MC/DC100%3/3
$n_last_1 and $x == $diagonal_length - 1 and $y == $diagonal_length
$n_last_1 $x == $diagonal_length - 1 $y == $diagonal_length
Truth table100%4/4
A and B and C
A= $n_last_1B= $x == $diagonal_length - 1C= $y == $diagonal_length
ABCresult
0XX0
10X0
1100
1111
409 # in between diagonals
410 458 $n += 2*$diagonal_length+1;
411 } else {
412 5617 return undef;
413 }
414  
415 9390 return $n*$arms + $arm;
416 }
417  
418 # not exact
419 sub rect_to_n_range {
420 32 ▶ my ($self, $x1,$y1, $x2,$y2) = @_;
Subroutine rect_to_n_range: called CC=20 SCAR=39.7
Pod documented
421 ### SierpinskiCurveStair rect_to_n_range(): "$x1,$y1 $x2,$y2"
422  
423 32 $x1 = round_nearest ($x1);
424 32 $x2 = round_nearest ($x2);
425 32 $y1 = round_nearest ($y1);
426 32 $y2 = round_nearest ($y2);
427 32 ▶ ($x1,$x2) = ($x2,$x1) if $x1 > $x2;
Branch: 1 branch
BranchTrueFalseTotal
if $x1 > $x2 0 32 32
428 32 ▶ ($y1,$y2) = ($y2,$y1) if $y1 > $y2;
Branch: 1 branch
BranchTrueFalseTotal
if $y1 > $y2 0 32 32
429  
430 # x2
431 # y2 +-------+ *
432 # | | *
433 # y1 +-------+ *
434 # *
435 # *
436 # *
437 # ------------------
438 #
439 #
440 # *
441 # x1 * x2 *
442 # +-----*-+y2*
443 # | *| *
444 # | * *
445 # | |* *
446 # | | **
447 # +-------+y1*
448 # ----------------
449 #
450 32 my $arms = $self->{'arms'};
451 32 ▶ if (($arms <= 4
Branch: 2 branches
BranchTrueFalseTotal
if ($arms <= 4 ? $y2 < 0 || $arms == 1 && $x2 <= $y1 || $arms == 2 && $x2 < 0 || $arms == 3 && $x2 < -$y2 : $y2 < 0 && ($arms == 5 && $x1 >= $y2 || $arms == 6 && $x1 >= 0 || $arms == 7 && $x1 > 3 - $y2)) 0 32 32
$arms <= 4 ? : 16 16 32
Condition27%10/36
$y2 < 0 or $arms == 1 and $x2 <= $y1 or $arms == 2 and $x2 < 0 or $arms == 3 and $x2 < -$y2
l!l&&r!l&&!r
0016
$y2 < 0 or $arms == 1 and $x2 <= $y1 or $arms == 2 and $x2 < 0
l!l&&r!l&&!r
0016
$y2 < 0 or $arms == 1 and $x2 <= $y1
l!l&&r!l&&!r
0016
$arms == 1 and $x2 <= $y1
!ll&&!rl&&r
1240
$arms == 2 and $x2 < 0
!ll&&!rl&&r
1240
$arms == 3 and $x2 < -$y2
!ll&&!rl&&r
1240
$y2 < 0 and $arms == 5 && $x1 >= $y2 || $arms == 6 && $x1 >= 0 || $arms == 7 && $x1 > 3 - $y2
!ll&&!rl&&r
1600
$arms == 5 and $x1 >= $y2 or $arms == 6 and $x1 >= 0 or $arms == 7 and $x1 > 3 - $y2
l!l&&r!l&&!r
000
$arms == 5 and $x1 >= $y2 or $arms == 6 and $x1 >= 0
l!l&&r!l&&!r
000
$arms == 5 and $x1 >= $y2
!ll&&!rl&&r
000
$arms == 6 and $x1 >= 0
!ll&&!rl&&r
000
$arms == 7 and $x1 > 3 - $y2
!ll&&!rl&&r
000
MC/DC0%0/7
$y2 < 0 or $arms == 1 and $x2 <= $y1 or $arms == 2 and $x2 < 0 or $arms == 3 and $x2 < -$y2
$y2 < 0 $arms == 1 $x2 <= $y1 $arms == 2 $x2 < 0 $arms == 3 $x2 < -$y2
MC/DC0%0/7
$y2 < 0 and $arms == 5 && $x1 >= $y2 || $arms == 6 && $x1 >= 0 || $arms == 7 && $x1 > 3 - $y2
$y2 < 0 $arms == 5 $x1 >= $y2 $arms == 6 $x1 >= 0 $arms == 7 $x1 > 3 - $y2
Truth table6%1/16
A or B and C or D and E or F and G
A= $y2 < 0B= $arms == 1C= $x2 <= $y1D= $arms == 2E= $x2 < 0F= $arms == 3G= $x2 < -$y2
ABCDEFGresult
1XXXXXX1
011XXXX1
00X11XX1
01011XX1
00X0X111
00X10111
0100X111
01010111
00X0X0X0
00X0X100
00X100X0
00X10100
0100X0X0
0100X100
010100X0
01010100
Truth table6%1/16
A and B and C or D and E or F and G
A= $y2 < 0B= $arms == 5C= $x1 >= $y2D= $arms == 6E= $x1 >= 0F= $arms == 7G= $x1 > 3 - $y2
ABCDEFGresult
0XXXXXX0
10X0X0X0
10X0X100
10X100X0
10X10100
1100X0X0
1100X100
110100X0
11010100
111XXXX1
10X11XX1
11011XX1
10X0X111
10X10111
1100X111
11010111
452 ? ($y2 < 0 # y2 negative, nothing ...
453 || ($arms == 1 && $x2 <= $y1)
454 || ($arms == 2 && $x2 < 0)
455 || ($arms == 3 && $x2 < -$y2))
456  
457 # arms >= 5
458 : ($y2 < 0
459 && (($arms == 5 && $x1 >= $y2)
460 || ($arms == 6 && $x1 >= 0)
461 || ($arms == 7 && $x1 > 3-$y2))))) {
462 ### rect outside octants, for arms: $arms
463 ### $x1
464 ### $y2
465 0 return (1,0);
466 }
467  
468 32 my $max = $x2; # arms 1,8 using X, starting at X=1
469 32 ▶ if ($arms >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arms >= 2) 28 4 32
470 # arms 2,3 upper using Y, starting at Y=1
471 28 _apply_max ($max, $y2);
472  
473 28 ▶ if ($arms >= 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arms >= 4) 20 8 28
474 # arms 4,5 right using X, starting at X=-2
475 20 _apply_max ($max, -1-$x1);
476  
477 20 ▶ if ($arms >= 6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arms >= 6) 12 8 20
478 # arms 6,7 down using Y, starting at Y=-2
479 12 _apply_max ($max, -1-$y1);
480 }
481 }
482 }
483 ### $max
484  
485  
486 # points(level) = (4^(level+2) - 1) / 3
487 # Nlast(level) = (4^(level+2) - 1) / 3 - 1
488 # = (4^(level+2) - 4) / 3
489 # then + arms-1 for last of arms
490 # Nhi = Nlast(level) * arms + arms-1
491 # = (Nlast(level + 1)) * arms - 1
492 # = ((4^(level+2) - 4) / 3 + 1) * arms - 1
493 # = ((4^(level+2) - 1) / 3) * arms - 1
494 #
495 # len(level) = = (L+2)*2^(level-1) - 2
496 # points(level) = ((3*P+1)*4^level - 1) / 3
497 #
498 32 my ($pow,$level) = round_down_pow ($max/($self->{'diagonal_length'}+2),
499 2);
500 return (0,
501 32 ((6*$self->{'diagonal_length'}+4)*4*$pow*$pow - 1) / 3
502 * $arms - 1);
503 }
504  
505 # set $_[0] to the max of $_[0] and $_[1]
506 sub _apply_max {
507 ### _apply_max(): "$_[0] cf $_[1]"
508 60 ▶ unless ($_[0] > $_[1]) {
Subroutine _apply_max: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless ($_[0] > $_[1]) 28 32 60
509 28 $_[0] = $_[1];
510 }
511 }
512  
513  
514 #------------------------------------------------------------------------------
515  
516 # Nlevel = ((3L+2)*4^level - 5) / 3
517 # LevelPoints = Nlevel+1
518 # Nlevel(arms) = (Nlevel+1)*arms - 1
519 #
520 # Eg. L=1 level=1 (5*4-5)/3 = 5
521 # arms=8 ((5*4-5)/3+1)*8 - 1 = 47
522 #
523  
524 sub level_to_n_range {
525 12 ▶ my ($self, $level) = @_;
Subroutine level_to_n_range: called CC=1 SCAR=0.0
Pod documented
526 return (0,
527 (4**$level * (3*$self->{'diagonal_length'}+2) - 2) / 3
528 12 * $self->{'arms'} - 1);
529 }
530 sub n_to_level {
531 0 ▶ my ($self, $n) = @_;
Subroutine n_to_level: not called CC=3 SCAR=24.8
Pod documented
532 0 ▶ if ($n < 0) { return undef; }
Branch: 1 branch
BranchTrueFalseTotal
if ($n < 0) 0 0 0
533 0 ▶ if (is_infinite($n)) { return $n; }
Branch: 1 branch
BranchTrueFalseTotal
if (is_infinite($n)) 0 0 0
534 0 $n = round_nearest($n);
535 0 _divrem_mutate ($n, $self->{'arms'});
536 0 my $diagonal_div = 3*$self->{'diagonal_length'} + 2;
537 0 my ($pow,$exp) = round_up_pow ((3*$n+3) / (3*$self->{'diagonal_length'}+2),
538 4);
539 0 return $exp;
540 }
541  
542 #------------------------------------------------------------------------------
543 1 1;
544 __END__
« PlanePath/KochSquareflakes.pm ↑ Summary PlanePath/DekkingCentres.pm »