PlanePath/GrayCode.pm

filter: Statementstmt 62.4% 118 / 189 Branchbran 22.9% 11 / 48 Conditioncond 10.5% 6 / 57 MC/DCmcdc 3.2% 1 / 31 Subroutinesub 64.5% 20 / 31 Podpod 100% 10 / 10 totaltotal 45.3% 166 / 366 CC 50 SCAR 33.0
CC
50
Cov
46%
xy_to_n
132.0
rect_to_n_range
30.0
_is_peano
20.0
CRAP 27.0
« PlanePath/QuadricIslands.pm ↑ Summary PlanePath/SierpinskiCurve.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 # cf. A164677 position of Gray bit change, +/- according to 0->1 or 1->0.
20 # (a signed version of A001511)
21  
22 package Math::PlanePath::GrayCode;
23 3 ▶use 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 3 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
26 #use List::Util 'max';
27 3 *max = \&Math::PlanePath::_max;
28  
29 3 ▶use vars '$VERSION', '@ISA';
Subroutine BEGIN: called CC=1 SCAR=0.0
30 3 $VERSION = 128;
31 3 ▶use Math::PlanePath;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 3 @ISA = ('Math::PlanePath');
33  
34 use Math::PlanePath::Base::Generic
35 3 'is_infinite',
36 3 ▶ 'round_nearest';
Subroutine BEGIN: called CC=1 SCAR=0.0
37 use Math::PlanePath::Base::Digits
38 3 'round_down_pow',
39 'digit_split_lowtohigh',
40 3 ▶ 'digit_join_lowtohigh';
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 # uncomment this to run the ### lines
43 #use Smart::Comments;
44  
45  
46 3 ▶use constant n_start => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 3 ▶use constant class_x_negative => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 3 ▶use constant class_y_negative => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 3 *xy_is_visited = \&Math::PlanePath::Base::Generic::xy_is_visited_quad1;
50  
51 use constant parameter_info_array =>
52 [
53 { name => 'apply_type',
54 share_key => 'apply_type_TsF',
55 display => 'Apply Type',
56 type => 'enum',
57 default => 'TsF',
58 choices => ['TsF','Ts','Fs','FsT','sT','sF'],
59 choices_display => ['TsF','Ts','Fs','FsT','sT','sF'],
60 description => 'How to apply the Gray coding to/from and split.',
61 },
62 { name => 'gray_type',
63 display => 'Gray Type',
64 type => 'enum',
65 default => 'reflected',
66 choices => ['reflected','modular'],
67 choices_dispaly => ['Reflected','Modular'],
68 description => 'The type of Gray code.',
69 },
70 3 { %{Math::PlanePath::Base::Digits::parameter_info_radix2()},
71 description => 'Radix, for both the Gray code and splitting.',
72 },
73 3 ▶ ];
Subroutine BEGIN: called CC=1 SCAR=0.0
74  
75 sub _is_peano {
76 0 ▶ my ($self) = @_;
Subroutine _is_peano: not called CC=4 SCAR=30.0
77 return ($self->{'radix'} % 2 == 1
78 && $self->{'gray_type'} eq 'reflected'
79 && ($self->{'apply_type'} eq 'TsF'
80 0 ▶ || $self->{'apply_type'} eq 'FsT'));
Condition0%0/9
$self->{'radix'} % 2 == 1 && $self->{'gray_type'} eq 'reflected' && ($self->{'apply_type'} eq 'TsF' || $self->{'apply_type'} eq 'FsT')
!ll&&!rl&&r
000
$self->{"radix"} % 2 == 1 and $self->{"gray_type"} eq "reflected"
!ll&&!rl&&r
000
$self->{"apply_type"} eq "TsF" or $self->{"apply_type"} eq "FsT"
l!l&&r!l&&!r
000
MC/DC0%0/4
$self->{'radix'} % 2 == 1 && $self->{'gray_type'} eq 'reflected' && ($self->{'apply_type'} eq 'TsF' || $self->{'apply_type'} eq 'FsT')
$self->{"radix"} % 2 == 1 $self->{"gray_type"} eq "reflected" $self->{"apply_type"} eq "TsF" $self->{"apply_type"} eq "FsT"
Truth table0%0/5
A and B && C or D
A= $self->{"radix"} % 2 == 1B= $self->{"gray_type"} eq "reflected"C= $self->{"apply_type"} eq "TsF"D= $self->{"apply_type"} eq "FsT"
ABCDresult
0XXX0
10XX0
11000
111X1
11011
81 }
82 sub dx_minimum {
83 0 ▶ my ($self) = @_;
Subroutine dx_minimum: not called CC=2 SCAR=17.9
Pod documented
84 0 ▶ return (_is_peano($self) ? -1 : undef);
Branch: 1 branch
BranchTrueFalseTotal
_is_peano($self) ? : 0 0 0
85 }
86 3 *dy_minimum = \&dx_minimum;
87  
88 sub dx_maximum {
89 0 ▶ my ($self) = @_;
Subroutine dx_maximum: not called CC=2 SCAR=17.9
Pod documented
90 0 ▶ return (_is_peano($self) ? 1 : undef);
Branch: 1 branch
BranchTrueFalseTotal
_is_peano($self) ? : 0 0 0
91 }
92 3 *dy_maximum = \&dx_maximum;
93  
94 {
95 # Ror sT and sF the split X coordinate changes from N to N+1 and so does
96 # the to-gray or from-gray transformation, so X always changes.
97 #
98 3 my %absdx_minimum = (
99 reflected => {
100 # TsF => 0,
101 # FsT => 0,
102 # Ts => 0,
103 # Fs => 0,
104 sT => 1,
105 sF => 1,
106 },
107 modular => {
108 # TsF => 0,
109 # Ts => 0,
110 Fs => 1,
111 FsT => 1,
112 sT => 1,
113 sF => 1,
114 },
115 );
116 sub absdx_minimum {
117 0 ▶ my ($self) = @_;
Subroutine absdx_minimum: not called CC=3 SCAR=24.8
Pod documented
118 my $gray_type = ($self->{'radix'} == 2
119 ? 'reflected'
120 0 ▶ : $self->{'gray_type'});
Branch: 1 branch
BranchTrueFalseTotal
$self->{'radix'} == 2 ? : 0 0 0
121 0 ▶ return ($absdx_minimum{$gray_type}->{$self->{'apply_type'}} || 0);
Condition0%0/2
$absdx_minimum{$gray_type}{$self->{'apply_type'}} || 0
l!l
00
MC/DC0%0/1
$absdx_minimum{$gray_type}{$self->{'apply_type'}} || 0
$absdx_minimum{$gray_type}{$self->{'apply_type'}}
Truth table0%0/2
A
A= $absdx_minimum{$gray_type}{$self->{'apply_type'}}
Aresult
11
00
122 }
123 }
124  
125 3 *dsumxy_minimum = \&dx_minimum;
126 3 *dsumxy_maximum = \&dx_maximum;
127 3 *ddiffxy_minimum = \&dx_minimum;
128 3 *ddiffxy_maximum = \&dx_maximum;
129  
130 {
131 3 my %dir_maximum_supremum = (
132 # # radix==2 always "reflected"
133 # # TsF => 0,
134 # # FsT => 0,
135 # # Ts => 0,
136 # # Fs => 0,
137 # sT => 4,
138 # sF => 4,
139  
140 reflected => {
141 # TsF => 0,
142 # FsT => 0,
143 # Ts => 0,
144 # Fs => 0,
145 sT => 4,
146 sF => 4,
147 },
148 modular => {
149 # TsF => 0,
150 # Ts => 0,
151 Fs => 4,
152 FsT => 4,
153 sT => 4,
154 sF => 4,
155 },
156 );
157 sub dir_maximum_dxdy {
158 0 ▶ my ($self) = @_;
Subroutine dir_maximum_dxdy: not called CC=3 SCAR=24.8
Pod documented
159 my $gray_type = ($self->{'radix'} == 2
160 ? 'reflected'
161 0 ▶ : $self->{'gray_type'});
Branch: 1 branch
BranchTrueFalseTotal
$self->{'radix'} == 2 ? : 0 0 0
162 0 ▶ return ($dir_maximum_supremum{$gray_type}->{$self->{'apply_type'}}
Branch: 1 branch
BranchTrueFalseTotal
$dir_maximum_supremum{$gray_type}{$self->{'apply_type'}} ? : 0 0 0
163 ? (0,0) # supremum
164 : (0,-1)); # South
165 }
166 }
167  
168 # radix=2 TsF==Fs is always straight or left
169 3 sub turn_any_right {
170 0 ▶ my ($self) = @_;
Subroutine turn_any_right: not called CC=4 SCAR=30.0
Pod documented
171 0 ▶ if ($self->{'radix'} == 2
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"radix"} == 2 and $self->{"apply_type"} eq "TsF" || $self->{"apply_type"} eq "Fs") 0 0 0
Condition0%0/6
$self->{"radix"} == 2 and $self->{"apply_type"} eq "TsF" || $self->{"apply_type"} eq "Fs"
!ll&&!rl&&r
000
$self->{"apply_type"} eq "TsF" or $self->{"apply_type"} eq "Fs"
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->{"radix"} == 2 and $self->{"apply_type"} eq "TsF" || $self->{"apply_type"} eq "Fs"
$self->{"radix"} == 2 $self->{"apply_type"} eq "TsF" $self->{"apply_type"} eq "Fs"
Truth table0%0/4
A and B or C
A= $self->{"radix"} == 2B= $self->{"apply_type"} eq "TsF"C= $self->{"apply_type"} eq "Fs"
ABCresult
0XX0
1000
11X1
1011
172 && ($self->{'apply_type'} eq 'TsF'
173 || $self->{'apply_type'} eq 'Fs')) {
174 0 return 0; # never right
175 }
176 0 return 1;
177 }
178 sub turn_any_straight {
179 0 ▶ my ($self) = @_;
Subroutine turn_any_straight: not called CC=4 SCAR=30.0
Pod documented
180 return ($self->{'radix'} == 2
181 0 ▶ && ($self->{'apply_type'} eq 'sT' || $self->{'apply_type'} eq 'sF')
Branch: 1 branch
BranchTrueFalseTotal
$self->{'radix'} == 2 && ($self->{'apply_type'} eq 'sT' || $self->{'apply_type'} eq 'sF') ? : 0 0 0
Condition0%0/6
$self->{"radix"} == 2 and $self->{"apply_type"} eq "sT" || $self->{"apply_type"} eq "sF"
!ll&&!rl&&r
000
$self->{"apply_type"} eq "sT" or $self->{"apply_type"} eq "sF"
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->{"radix"} == 2 and $self->{"apply_type"} eq "sT" || $self->{"apply_type"} eq "sF"
$self->{"radix"} == 2 $self->{"apply_type"} eq "sT" $self->{"apply_type"} eq "sF"
Truth table0%0/4
A and B or C
A= $self->{"radix"} == 2B= $self->{"apply_type"} eq "sT"C= $self->{"apply_type"} eq "sF"
ABCresult
0XX0
1000
11X1
1011
182 ? 0 # never straight
183 : 1);
184 }
185  
186 sub _UNDOCUMENTED__turn_any_left_at_n {
187 0 ▶ my ($self) = @_;
Subroutine _UNDOCUMENTED__turn_any_left_at_n: not called CC=1 SCAR=6.9
188 0 return $self->{'radix'} - 1;
189 }
190 sub _UNDOCUMENTED__turn_any_right_at_n {
191 0 ▶ my ($self) = @_;
Subroutine _UNDOCUMENTED__turn_any_right_at_n: not called CC=4 SCAR=30.0
192 0 ▶ if ($self->{'apply_type'} eq 'TsF' && $self->{'gray_type'} eq 'reflected'
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"apply_type"} eq "TsF" and $self->{"gray_type"} eq "reflected" and $self->{"radix"} > 2) 0 0 0
Condition0%0/6
$self->{"apply_type"} eq "TsF" and $self->{"gray_type"} eq "reflected" and $self->{"radix"} > 2
!ll&&!rl&&r
000
$self->{"apply_type"} eq "TsF" and $self->{"gray_type"} eq "reflected"
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"apply_type"} eq "TsF" and $self->{"gray_type"} eq "reflected" and $self->{"radix"} > 2
$self->{"apply_type"} eq "TsF" $self->{"gray_type"} eq "reflected" $self->{"radix"} > 2
Truth table0%0/4
A and B and C
A= $self->{"apply_type"} eq "TsF"B= $self->{"gray_type"} eq "reflected"C= $self->{"radix"} > 2
ABCresult
0XX0
10X0
1100
1111
193 && $self->{'radix'} > 2) {
194 0 return 2*$self->{'radix'} - 1;
195 }
196 0 return undef;
197 }
198  
199  
200 #------------------------------------------------------------------------------
201 3 my %funcbase = (T => '_digits_to_gray',
202 F => '_digits_from_gray',
203 '' => '_noop');
204 3 my %inv = (T => 'F',
205 F => 'T',
206 '' => '');
207  
208 sub new {
209 1 ▶ my $self = shift->SUPER::new(@_);
Subroutine new: called CC=7 SCAR=21.2
Pod documented
210  
211 1 ▶ if (! $self->{'radix'} || $self->{'radix'} < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"radix"} or $self->{"radix"} < 2) 1 0 1
Condition33%1/3
not $self->{"radix"} or $self->{"radix"} < 2
l!l&&r!l&&!r
100
MC/DC0%0/2
not $self->{"radix"} or $self->{"radix"} < 2
not $self->{"radix"} $self->{"radix"} < 2
Truth table33%1/3
not(A) or B
A= not $self->{"radix"}B= $self->{"radix"} < 2
ABresult
1X1
011
000
212 1 $self->{'radix'} = 2;
213 }
214  
215 1 ▶ my $apply_type = ($self->{'apply_type'} ||= 'TsF');
Condition50%1/2
$self->{"apply_type"} ||= "TsF"
l!l
01
MC/DC0%0/1
$self->{"apply_type"} ||= "TsF"
$self->{"apply_type"}
Truth table50%1/2
A
A= $self->{"apply_type"}
Aresult
11
00
216 1 ▶ my $gray_type = ($self->{'gray_type'} ||= 'reflected');
Condition50%1/2
$self->{"gray_type"} ||= "reflected"
l!l
01
MC/DC0%0/1
$self->{"gray_type"} ||= "reflected"
$self->{"gray_type"}
Truth table50%1/2
A
A= $self->{"gray_type"}
Aresult
11
00
217  
218 1 ▶ unless ($apply_type =~ /^([TF]?)s([TF]?)$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($apply_type =~ /^([TF]?)s([TF]?)$/) 0 1 1
219 0 croak "Unrecognised apply_type \"$apply_type\"";
220 }
221 1 my $nf = $1; # "T" or "F" or ""
222 1 my $xyf = $2;
223  
224 1 ▶ $self->{'n_func'} = $self->can("$funcbase{$nf}_$gray_type")
Condition33%1/3
$self->can("$funcbase{$nf}_$gray_type") || croak(qq[Unrecognised gray_type "$self->{'gray_type'}"])
l!l&&r!l&&!r
100
MC/DC0%0/2
$self->can("$funcbase{$nf}_$gray_type") || croak(qq[Unrecognised gray_type "$self->{'gray_type'}"])
$self->can("$funcbase{$nf}_$gray_type") croak(qq[Unrecognised gray_type "$self->{'gray_type'}"])
Truth table33%1/3
A || B
A= $self->can("$funcbase{$nf}_$gray_type")B= croak(qq[Unrecognised gray_type "$self->{'gray_type'}"])
ABresult
1X1
011
000
225 || croak "Unrecognised gray_type \"$self->{'gray_type'}\"";
226 1 $self->{'xy_func'} = $self->can("$funcbase{$xyf}_$gray_type");
227  
228 1 $nf = $inv{$nf};
229 1 $xyf = $inv{$xyf};
230  
231 1 $self->{'inverse_n_func'} = $self->can("$funcbase{$nf}_$gray_type");
232 1 $self->{'inverse_xy_func'} = $self->can("$funcbase{$xyf}_$gray_type");
233  
234 1 return $self;
235 }
236  
237 sub n_to_xy {
238 4000 ▶ my ($self, $n) = @_;
Subroutine n_to_xy: called CC=6 SCAR=19.4
Pod documented
239 ### GrayCode n_to_xy(): $n
240  
241 4000 ▶ if ($n < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n < 0) 0 4000 4000
242 0 return;
243 }
244 4000 ▶ if (is_infinite($n)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_infinite($n)) 0 4000 4000
245 0 return ($n,$n);
246 }
247  
248 {
249 # ENHANCE-ME: N and N+1 differ by not much ...
250 4000 my $int = int($n);
251 ### $int
252 4000 ▶ if ($n != $int) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n != $int) 0 4000 4000
253 0 my $frac = $n - $int; # inherit possible BigFloat/BigRat
254 ### $frac
255 0 my ($x1,$y1) = $self->n_to_xy($int);
256 0 my ($x2,$y2) = $self->n_to_xy($int+1);
257 0 my $dx = $x2-$x1;
258 0 my $dy = $y2-$y1;
259 0 return ($frac*$dx + $x1, $frac*$dy + $y1);
260 }
261 4000 $n = $int; # BigFloat int() gives BigInt, use that
262 }
263  
264 4000 my $radix = $self->{'radix'};
265 4000 my @digits = digit_split_lowtohigh($n,$radix);
266 4000 $self->{'n_func'}->(\@digits, $radix);
267  
268 4000 my @xdigits;
269 my @ydigits;
270 4000 ▶ while (@digits) {
Branch: 1 branch
BranchTrueFalseTotal
if (@digits) 17310 4000 21310
271 17310 push @xdigits, shift @digits; # low to high
272 17310 ▶ push @ydigits, shift @digits || 0;
Condition100%2/2
shift @digits || 0
l!l
81289182
MC/DC100%1/1
shift @digits || 0
shift @digits
Truth table100%2/2
A
A= shift @digits
Aresult
11
00
273 }
274 4000 my $xdigits = \@xdigits;
275 4000 my $ydigits = \@ydigits;
276 4000 $self->{'xy_func'}->($xdigits,$radix);
277 4000 $self->{'xy_func'}->($ydigits,$radix);
278  
279 4000 return (digit_join_lowtohigh($xdigits,$radix),
280 digit_join_lowtohigh($ydigits,$radix));
281 }
282  
283 sub xy_to_n {
284 0 ▶ my ($self, $x, $y) = @_;
Subroutine xy_to_n: not called CC=11 SCAR=48.8
Pod documented
285 ### GrayCode xy_to_n(): "$x, $y"
286  
287 0 $x = round_nearest ($x);
288 0 $y = round_nearest ($y);
289 0 ▶ if ($x < 0 || $y < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < 0 or $y < 0) 0 0 0
Condition0%0/3
$x < 0 or $y < 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$x < 0 or $y < 0
$x < 0 $y < 0
Truth table0%0/3
A or B
A= $x < 0B= $y < 0
ABresult
1X1
011
000
290 0 return undef;
291 }
292 0 ▶ if (is_infinite($x)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_infinite($x)) 0 0 0
293 0 return $x;
294 }
295 0 ▶ if (is_infinite($y)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_infinite($y)) 0 0 0
296 0 return $y;
297 }
298  
299 0 my $radix = $self->{'radix'};
300 0 my @xdigits = digit_split_lowtohigh ($x, $radix);
301 0 my @ydigits = digit_split_lowtohigh ($y, $radix);
302  
303 0 $self->{'inverse_xy_func'}->(\@xdigits, $radix);
304 0 $self->{'inverse_xy_func'}->(\@ydigits, $radix);
305  
306 0 my @digits;
307 0 for (;;) {
308 0 ▶ (@xdigits || @ydigits) or last;
Branch: 1 branch
BranchTrueFalseTotal
@xdigits or @ydigits or last 0 0 0
Condition0%0/3
@xdigits or @ydigits
l!l&&r!l&&!r
000
MC/DC0%0/2
@xdigits or @ydigits
@xdigits @ydigits
Truth table0%0/3
A or B
A= @xdigitsB= @ydigits
ABresult
1X1
011
000
309 0 ▶ push @digits, shift @xdigits || 0;
Condition0%0/2
shift @xdigits || 0
l!l
00
MC/DC0%0/1
shift @xdigits || 0
shift @xdigits
Truth table0%0/2
A
A= shift @xdigits
Aresult
11
00
310 0 ▶ (@xdigits || @ydigits) or last;
Branch: 1 branch
BranchTrueFalseTotal
@xdigits or @ydigits or last 0 0 0
Condition0%0/3
@xdigits or @ydigits
l!l&&r!l&&!r
000
MC/DC0%0/2
@xdigits or @ydigits
@xdigits @ydigits
Truth table0%0/3
A or B
A= @xdigitsB= @ydigits
ABresult
1X1
011
000
311 0 ▶ push @digits, shift @ydigits || 0;
Condition0%0/2
shift @ydigits || 0
l!l
00
MC/DC0%0/1
shift @ydigits || 0
shift @ydigits
Truth table0%0/2
A
A= shift @ydigits
Aresult
11
00
312 }
313  
314 0 my $digits = \@digits;
315 0 $self->{'inverse_n_func'}->($digits,$radix);
316  
317 0 return digit_join_lowtohigh($digits,$radix);
318 }
319  
320 # not exact
321 sub rect_to_n_range {
322 0 ▶ my ($self, $x1,$y1, $x2,$y2) = @_;
Subroutine rect_to_n_range: not called CC=5 SCAR=34.0
Pod documented
323  
324 0 $x1 = round_nearest($x1);
325 0 $y1 = round_nearest($y1);
326 0 $x2 = round_nearest($x2);
327 0 $y2 = round_nearest($y2);
328  
329 0 ▶ if ($x1 > $x2) { ($x1,$x2) = ($x2,$x1); } # x1 smaller
Branch: 1 branch
BranchTrueFalseTotal
if ($x1 > $x2) 0 0 0
330 0 ▶ if ($y1 > $y2) { ($y1,$y2) = ($y2,$y1); } # y1 smaller
Branch: 1 branch
BranchTrueFalseTotal
if ($y1 > $y2) 0 0 0
331  
332 0 ▶ if ($y2 < 0 || $x2 < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y2 < 0 or $x2 < 0) 0 0 0
Condition0%0/3
$y2 < 0 or $x2 < 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$y2 < 0 or $x2 < 0
$y2 < 0 $x2 < 0
Truth table0%0/3
A or B
A= $y2 < 0B= $x2 < 0
ABresult
1X1
011
000
333 0 return (1, 0); # rect all negative, no N
334 }
335  
336 0 my $radix = $self->{'radix'};
337 0 my ($pow_max) = round_down_pow (max($x2,$y2), $radix);
338 0 $pow_max *= $radix;
339 0 return (0, $pow_max*$pow_max - 1);
340 }
341  
342 #------------------------------------------------------------------------------
343  
344 3 ▶use constant 1.02 _noop_reflected => undef;
Subroutine BEGIN: called CC=1 SCAR=0.0
345 3 ▶use constant 1.02 _noop_modular => undef;
Subroutine BEGIN: called CC=1 SCAR=0.0
346  
347 # $aref->[0] low digit
348 sub _digits_to_gray_reflected {
349 5159 ▶ my ($aref, $radix) = @_;
Subroutine _digits_to_gray_reflected: called CC=3 SCAR=11.0
350 ### _digits_to_gray(): $aref
351 5159 $radix -= 1;
352 5159 my $reverse = 0;
353 5159 foreach my $digit (reverse @$aref) { # high to low
354 35753 ▶ if ($reverse & 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reverse & 1) 17249 18504 35753
355 17249 $digit = $radix - $digit; # radix-1 - digit
356 }
357 35753 $reverse ^= $digit;
358 }
359 }
360 # $aref->[0] low digit
361 sub _digits_to_gray_modular {
362 1231 ▶ my ($aref, $radix) = @_;
Subroutine _digits_to_gray_modular: called CC=2 SCAR=6.9
363 1231 my $prev = 0;
364 1231 foreach my $digit (reverse @$aref) { # high to low
365 3914 ($digit,$prev) = (($digit - $prev) % $radix, # mutate $aref->[i]
366 $digit);
367 }
368 }
369  
370 # $aref->[0] low digit
371 sub _digits_from_gray_reflected {
372 9159 ▶ my ($aref, $radix) = @_;
Subroutine _digits_from_gray_reflected: called CC=3 SCAR=11.0
373 9159 $radix -= 1; # radix-1
374 9159 my $reverse = 0;
375 9159 foreach my $digit (reverse @$aref) { # high to low
376 38391 ▶ if ($reverse & 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reverse & 1) { } 15489 22902 38391
377 15489 $reverse ^= $digit; # before this reversal
378 15489 $digit = $radix - $digit; # radix-1 - digit, mutate array
379 } else {
380 22902 $reverse ^= $digit;
381 }
382 }
383 }
384 # $aref->[0] low digit
385 sub _digits_from_gray_modular {
386 1231 ▶ my ($aref, $radix) = @_;
Subroutine _digits_from_gray_modular: called CC=2 SCAR=6.9
387 ### _digits_from_gray_modular(): $aref
388  
389 1231 my $offset = 0;
390 1231 foreach my $digit (reverse @$aref) { # high to low
391 3914 $offset = ($digit = ($digit + $offset) % $radix); # mutate $aref->[i]
392 }
393 }
394  
395 #------------------------------------------------------------------------------
396 # levels
397  
398 3 ▶use Math::PlanePath::ZOrderCurve;
Subroutine BEGIN: called CC=1 SCAR=0.0
399 3 *level_to_n_range = \&Math::PlanePath::ZOrderCurve::level_to_n_range;
400 3 *n_to_level = \&Math::PlanePath::ZOrderCurve::n_to_level;
401  
402 #------------------------------------------------------------------------------
403 3 1;
404 __END__
« PlanePath/QuadricIslands.pm ↑ Summary PlanePath/SierpinskiCurve.pm »