lib/ICC/Support/akima.pm

filter: Statementstmt 6.2% 22 / 350 Branchbran 1.4% 2 / 136 Conditioncond 1.1% 1 / 89 MC/DCmcdc 0.0% 0 / 50 Subroutinesub 18.1% 6 / 33 Podpod 7.6% 1 / 13 totaltotal 4.7% 32 / 671 CC 114 SCAR 41.7
CC
114
Cov
4%
_local
182.0
inverse
156.0
normalize
132.0
CRAP 64.7
« lib/ICC/Profile/mft2.pm ↑ Summary lib/ICC/Profile/mft1.pm »
1 package ICC::Support::akima;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = 0.15;
7  
8 # revised 2017-03-11
9 #
10 # Copyright © 2004-2018 by William B. Birkett
11  
12 # add development directory
13 2 ▶use lib 'lib';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # inherit from Shared
16 2 ▶use parent qw(ICC::Shared);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # enable static variables
19 2 ▶use feature 'state';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 # create new akima object
22 # arrays are sorted so that input values are increasing
23 # array structure: [[input_values_array], [output_values_array]]
24 # flag enables setting endpoint derivatives with least-squares fit
25 # parameters: ([ref_to_array, [endpoint_flag]])
26 # returns: (ref_to_object)
27 sub new {
28  
29 # get object class
30 1 ▶ my $class = shift();
Subroutine new: called CC=10 SCAR=41.8
Pod undocumented
31
32 # create empty akima object
33 1 my $self = [
34 {}, # object header
35 [], # x-values
36 [], # y-values
37 [] # derivatives
38 ];
39  
40 # if one or two parameters supplied
41 1 ▶ if (@_ == 1 || @_ == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1 or @_ == 2) { } 0 1 1
elsif (@_) { } 0 1 1
Condition33%1/3
@_ == 1 or @_ == 2
l!l&&r!l&&!r
001
MC/DC0%0/2
@_ == 1 or @_ == 2
@_ == 1 @_ == 2
Truth table33%1/3
A or B
A= @_ == 1B= @_ == 2
ABresult
1X1
011
000
42
43 # verify parameters are array references
44 0 ▶ ((ref($_[0]) eq 'ARRAY' || UNIVERSAL::isa($_[0], 'Math::Matrix')) && ref($_[0][0]) eq 'ARRAY' && ref($_[0][1]) eq 'ARRAY') || croak('parameter(s) not an array reference');
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq "ARRAY" || UNIVERSAL::isa($_[0], "Math::Matrix") and ref $_[0][0] eq "ARRAY" and ref $_[0][1] eq "ARRAY" or croak("parameter(s) not an array reference") 0 0 0
Condition0%0/9
ref $_[0] eq "ARRAY" || UNIVERSAL::isa($_[0], "Math::Matrix") and ref $_[0][0] eq "ARRAY" and ref $_[0][1] eq "ARRAY"
!ll&&!rl&&r
000
ref $_[0] eq "ARRAY" || UNIVERSAL::isa($_[0], "Math::Matrix") and ref $_[0][0] eq "ARRAY"
!ll&&!rl&&r
000
ref $_[0] eq "ARRAY" or UNIVERSAL::isa($_[0], "Math::Matrix")
l!l&&r!l&&!r
000
MC/DC0%0/4
ref $_[0] eq "ARRAY" || UNIVERSAL::isa($_[0], "Math::Matrix") and ref $_[0][0] eq "ARRAY" and ref $_[0][1] eq "ARRAY"
ref $_[0] eq "ARRAY" UNIVERSAL::isa($_[0], "Math::Matrix") ref $_[0][0] eq "ARRAY" ref $_[0][1] eq "ARRAY"
Truth table0%0/7
A or B and C and D
A= ref $_[0] eq "ARRAY"B= UNIVERSAL::isa($_[0], "Math::Matrix")C= ref $_[0][0] eq "ARRAY"D= ref $_[0][1] eq "ARRAY"
ABCDresult
00XX0
1X0X0
010X0
1X100
01100
1X111
01111
45
46 # verify arrays are same length
47 0 ▶ ($#{$_[0][0]} == $#{$_[0][1]}) || croak('arrays have different lengths');
Branch: 1 branch
BranchTrueFalseTotal
$#{$_[0][0];} == $#{$_[0][1];} or croak("arrays have different lengths") 0 0 0
48
49 # verify arrays contain two or more points
50 0 ▶ ($#{$_[0][0]} > 0) || croak('arrays must contain two or more points');
Branch: 1 branch
BranchTrueFalseTotal
$#{$_[0][0];} > 0 or croak("arrays must contain two or more points") 0 0 0
51
52 # make index array
53 0 my @ix = (0 .. $#{$_[0][0]});
54
55 # sort index by x-values, in ascending order
56 0 @ix = sort {$_[0][0][$a] <=> $_[0][0][$b]} @ix;
57
58 # store x-values
59 0 $self->[1] = [@{$_[0][0]}[@ix]];
60
61 # store y-values
62 0 $self->[2] = [@{$_[0][1]}[@ix]];
63
64 # compute object derivatives
65 0 _objderv($self, $_[1]);
66
67 # add local min/max values
68 0 _minmax($self);
69
70 # compute range of y-values
71 0 _range($self);
72
73 } elsif (@_) {
74
75 # error
76 0 croak('too many parameters');
77
78 }
79  
80 # bless object
81 1 bless($self, $class);
82
83 # return object reference
84 1 return($self);
85  
86 }
87  
88 # write akima object to ICC profile
89 # note: writes an equivalent curv object
90 # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry)
91 sub write_fh {
92  
93 # get tag reference
94 0 ▶ my $self = shift();
Subroutine write_fh: not called CC=2 SCAR=17.9
Pod undocumented
95  
96 # verify 3 parameters
97 0 ▶ (@_ == 3) || croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("wrong number of parameters") 0 0 0
98  
99 # write akima data to profile
100 0 _writeICCakima($self, @_);
101  
102 }
103  
104 # get tag size (for writing to profile)
105 # note: writes an equivalent curv object
106 # returns: (tag_size)
107 sub size {
108
109 # get parameters
110 0 ▶ my ($self) = @_;
Subroutine size: not called CC=2 SCAR=17.9
Pod undocumented
111
112 # get count value (defaults to 4370)
113 0 ▶ my $n = $self->[0]{'curv_points'} || 4370;
Condition0%0/2
$self->[0]{'curv_points'} || 4370
l!l
00
MC/DC0%0/1
$self->[0]{'curv_points'} || 4370
$self->[0]{'curv_points'}
Truth table0%0/2
A
A= $self->[0]{'curv_points'}
Aresult
11
00
114
115 # return size
116 0 return(12 + $n * 2);
117
118 }
119  
120 # compute curve function
121 # parameters: (input_value)
122 # returns: (output_value)
123 sub transform {
124
125 # get parameters
126 0 ▶ my ($self, $in) = @_;
Subroutine transform: not called CC=6 SCAR=37.4
Pod undocumented
127
128 # local variable
129 0 my ($low);
130
131 # if input value <= x-min
132 0 ▶ if ($in <= $self->[1][0]) {
Branch: 2 branches
BranchTrueFalseTotal
if ($in <= $self->[1][0]) { } 0 0 0
elsif ($in >= $self->[1][-1]) { } 0 0 0
133
134 # return extrapolated value
135 0 return($self->[2][0] + $self->[3][0] * ($in - $self->[1][0]));
136
137 # if input value >= x-max
138 } elsif ($in >= $self->[1][-1]) {
139
140 # return extrapolated value
141 0 return($self->[2][-1] + $self->[3][-1] * ($in - $self->[1][-1]));
142
143 } else {
144
145 # if x-value not within current interval
146 0 ▶ if (! defined($low = $self->[0]{'low'}) || ($in < $self->[1][$low]) || ($in > $self->[1][$low + 1])) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined($low = $self->[0]{"low"}) or $in < $self->[1][$low] or $in > $self->[1][$low + 1]) 0 0 0
Condition0%0/6
not defined($low = $self->[0]{"low"}) or $in < $self->[1][$low] or $in > $self->[1][$low + 1]
l!l&&r!l&&!r
000
not defined($low = $self->[0]{"low"}) or $in < $self->[1][$low]
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined($low = $self->[0]{"low"}) or $in < $self->[1][$low] or $in > $self->[1][$low + 1]
not defined($low = $self->[0]{"low"}) $in < $self->[1][$low] $in > $self->[1][$low + 1]
Truth table0%0/4
not(A) or B or C
A= not defined($low = $self->[0]{"low"})B= $in < $self->[1][$low]C= $in > $self->[1][$low + 1]
ABCresult
1XX1
01X1
0011
0000
147
148 # locate interval with binary search
149 0 $self->[0]{'low'} = _binsearch($self->[1], $in);
150
151 }
152
153 # return interpolated value
154 0 return(_fwd($self, $in));
155
156 }
157  
158 }
159  
160 # compute inverse curve function
161 # note: there may be multiple solutions
162 # parameters: (input_value)
163 # returns: (output_value -or- array_of_output_values)
164 sub inverse {
165  
166 # get parameters
167 0 ▶ my ($self, $in) = @_;
Subroutine inverse: not called CC=12 SCAR=50.5
Pod undocumented
168  
169 # local variables
170 0 my (@sol, @sir, @low);
171  
172 # if an extrapolated solution with x < x-min
173 0 ▶ if (($in < $self->[2][0] && $self->[3][0] > 0) || ($in > $self->[2][0] && $self->[3][0] < 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in < $self->[2][0] and $self->[3][0] > 0 or $in > $self->[2][0] and $self->[3][0] < 0) 0 0 0
Condition0%0/9
$in < $self->[2][0] and $self->[3][0] > 0 or $in > $self->[2][0] and $self->[3][0] < 0
l!l&&r!l&&!r
000
$in < $self->[2][0] and $self->[3][0] > 0
!ll&&!rl&&r
000
$in > $self->[2][0] and $self->[3][0] < 0
!ll&&!rl&&r
000
MC/DC0%0/4
$in < $self->[2][0] and $self->[3][0] > 0 or $in > $self->[2][0] and $self->[3][0] < 0
$in < $self->[2][0] $self->[3][0] > 0 $in > $self->[2][0] $self->[3][0] < 0
Truth table0%0/7
A and B or C and D
A= $in < $self->[2][0]B= $self->[3][0] > 0C= $in > $self->[2][0]D= $self->[3][0] < 0
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
174
175 # add solution
176 0 push(@sol, $self->[1][0] - ($self->[2][0] - $in)/$self->[3][0]);
177
178 }
179  
180 # locate solution interval(s) with x-min <= x <= x-max
181 0 @low = _linsearch($self->[2], $in);
182  
183 # for each interval
184 0 for my $i (@low) {
185
186 # set interval
187 0 $self->[0]{'low'} = $i;
188
189 # add solution
190 0 push(@sol, _rev($self, $in));
191
192 # add solution in range
193 0 push(@sir, $sol[-1]);
194
195 }
196  
197 # if an extrapolated solution with x > x-max
198 0 ▶ if (($in > $self->[2][-1] && $self->[3][-1] > 0) || ($in < $self->[2][-1] && $self->[3][-1] < 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in > $self->[2][-1] and $self->[3][-1] > 0 or $in < $self->[2][-1] and $self->[3][-1] < 0) 0 0 0
Condition0%0/9
$in > $self->[2][-1] and $self->[3][-1] > 0 or $in < $self->[2][-1] and $self->[3][-1] < 0
l!l&&r!l&&!r
000
$in > $self->[2][-1] and $self->[3][-1] > 0
!ll&&!rl&&r
000
$in < $self->[2][-1] and $self->[3][-1] < 0
!ll&&!rl&&r
000
MC/DC0%0/4
$in > $self->[2][-1] and $self->[3][-1] > 0 or $in < $self->[2][-1] and $self->[3][-1] < 0
$in > $self->[2][-1] $self->[3][-1] > 0 $in < $self->[2][-1] $self->[3][-1] < 0
Truth table0%0/7
A and B or C and D
A= $in > $self->[2][-1]B= $self->[3][-1] > 0C= $in < $self->[2][-1]D= $self->[3][-1] < 0
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
199
200 # add solution
201 0 push(@sol, $self->[1][-1] - ($self->[2][-1] - $in)/$self->[3][-1]);
202
203 }
204  
205 # return result (array or first solution in range, if possible)
206 0 ▶ return(wantarray ? @sol : defined($sir[0]) ? $sir[0] : $sol[0]);
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 0 0 0
defined $sir[0] ? : 0 0 0
207  
208 }
209  
210 # compute curve derivative
211 # parameters: (input_value)
212 # returns: (derivative_value)
213 sub derivative {
214
215 # get parameters
216 0 ▶ my ($self, $in) = @_;
Subroutine derivative: not called CC=6 SCAR=37.4
Pod undocumented
217
218 # local variable
219 0 my ($low);
220
221 # if input value <= x-min
222 0 ▶ if ($in <= $self->[1][0]) {
Branch: 2 branches
BranchTrueFalseTotal
if ($in <= $self->[1][0]) { } 0 0 0
elsif ($in >= $self->[1][-1]) { } 0 0 0
223
224 # return endpoint derivative
225 0 return($self->[3][0]);
226
227 # if input value >= x-max
228 } elsif ($in >= $self->[1][-1]) {
229
230 # return endpoint derivative
231 0 return($self->[3][-1]);
232
233 } else {
234
235 # if x-value not within current interval
236 0 ▶ if (! defined($low = $self->[0]{'low'}) || ($in < $self->[1][$low]) || ($in > $self->[1][$low + 1])) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined($low = $self->[0]{"low"}) or $in < $self->[1][$low] or $in > $self->[1][$low + 1]) 0 0 0
Condition0%0/6
not defined($low = $self->[0]{"low"}) or $in < $self->[1][$low] or $in > $self->[1][$low + 1]
l!l&&r!l&&!r
000
not defined($low = $self->[0]{"low"}) or $in < $self->[1][$low]
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined($low = $self->[0]{"low"}) or $in < $self->[1][$low] or $in > $self->[1][$low + 1]
not defined($low = $self->[0]{"low"}) $in < $self->[1][$low] $in > $self->[1][$low + 1]
Truth table0%0/4
not(A) or B or C
A= not defined($low = $self->[0]{"low"})B= $in < $self->[1][$low]C= $in > $self->[1][$low + 1]
ABCresult
1XX1
01X1
0011
0000
237
238 # locate interval with binary search
239 0 $self->[0]{'low'} = _binsearch($self->[1], $in);
240
241 }
242
243 # return derivative
244 0 return(_derv($self, $in));
245
246 }
247
248 }
249  
250 # get/set reference to header hash
251 # parameters: ([ref_to_new_hash])
252 # returns: (ref_to_hash)
253 sub header {
254
255 # get object reference
256 0 ▶ my $self = shift();
Subroutine header: not called CC=4 SCAR=30.0
Pod undocumented
257
258 # if there are parameters
259 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
260
261 # if one parameter, a hash reference
262 0 ▶ if (@_ == 1 && ref($_[0]) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'HASH') { } 0 0 0
Condition0%0/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
263
264 # set header to new hash
265 0 $self->[0] = shift();
266
267 } else {
268
269 # error
270 0 croak('parameter must be a hash reference');
271
272 }
273
274 }
275
276 # return reference
277 0 return($self->[0]);
278
279 }
280  
281 # get/set array reference
282 # array contains x-values, y-values and derivatives
283 # parameters: ([ref_to_array])
284 # returns: (ref_to_array)
285 sub array {
286  
287 # get object reference
288 0 ▶ my $self = shift();
Subroutine array: not called CC=6 SCAR=37.4
Pod undocumented
289
290 # if one parameter supplied
291 0 ▶ if (@_ == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
elsif (@_) { } 0 0 0
292
293 # verify parameter is an array reference
294 0 ▶ (ref($_[0]) eq 'ARRAY') || croak('parameter not an array reference');
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq "ARRAY" or croak("parameter not an array reference") 0 0 0
295
296 # verify array contents
297 0 ▶ ((3 == @{$_[0]}) && (3 == grep {ref() eq 'ARRAY'} @{$_[0]})) || croak('invalid array contents');
Branch: 1 branch
BranchTrueFalseTotal
3 == @{$_[0];} and 3 == grep({ref $_ eq "ARRAY";} @{$_[0];}) or croak("invalid array contents") 0 0 0
Condition0%0/3
3 == @{$_[0];} and 3 == grep({ref $_ eq "ARRAY";} @{$_[0];})
!ll&&!rl&&r
000
MC/DC0%0/2
3 == @{$_[0];} and 3 == grep({ref $_ eq "ARRAY";} @{$_[0];})
3 == @{$_[0];} 3 == grep({ref $_ eq "ARRAY";} @{$_[0];})
Truth table0%0/3
A and B
A= 3 == @{$_[0];}B= 3 == grep({ref $_ eq "ARRAY";} @{$_[0];})
ABresult
0X0
100
111
298
299 # store x-values
300 0 $self->[1] = [@{$_[0][0]}];
301
302 # store y-values
303 0 $self->[2] = [@{$_[0][1]}];
304
305 # store derivatives
306 0 $self->[3] = [@{$_[0][2]}];
307
308 } elsif (@_) {
309
310 # error
311 0 croak('too many parameters');
312
313 }
314
315 # return array reference
316 0 return([[@{$self->[1]}], [@{$self->[2]}], [@{$self->[3]}]]);
317  
318 }
319  
320 # check if monotonic
321 # computes number of min/max points (0 if monotonic)
322 # parameters: ()
323 # returns: (number)
324 sub monotonic {
325
326 # get object reference
327 0 ▶ my $self = shift();
Subroutine monotonic: not called CC=6 SCAR=37.4
Pod undocumented
328
329 # local variables
330 0 my ($flag);
331
332 # init flag
333 0 $flag = 0;
334
335 # for each interval
336 0 for my $i (0 .. ($#{$self->[1]} - 1)) {
337
338 # set interval
339 0 $self->[0]{'low'} = $i;
340
341 # increment flag if a min/max point
342 0 ▶ $flag++ if ($self->[3][$i] == 0 && _derv2($self, 0) != 0);
Branch: 1 branch
BranchTrueFalseTotal
if $self->[3][$i] == 0 and _derv2($self, 0) != 0 0 0 0
Condition0%0/3
$self->[3][$i] == 0 and _derv2($self, 0) != 0
!ll&&!rl&&r
000
MC/DC0%0/2
$self->[3][$i] == 0 and _derv2($self, 0) != 0
$self->[3][$i] == 0 _derv2($self, 0) != 0
Truth table0%0/3
A and B
A= $self->[3][$i] == 0B= _derv2($self, 0) != 0
ABresult
0X0
100
111
343
344 }
345
346 # increment flag if a min/max point (last knot)
347 0 ▶ $flag++ if ($self->[3][-1] == 0 && _derv2($self, 1) != 0);
Branch: 1 branch
BranchTrueFalseTotal
if $self->[3][-1] == 0 and _derv2($self, 1) != 0 0 0 0
Condition0%0/3
$self->[3][-1] == 0 and _derv2($self, 1) != 0
!ll&&!rl&&r
000
MC/DC0%0/2
$self->[3][-1] == 0 and _derv2($self, 1) != 0
$self->[3][-1] == 0 _derv2($self, 1) != 0
Truth table0%0/3
A and B
A= $self->[3][-1] == 0B= _derv2($self, 1) != 0
ABresult
0X0
100
111
348
349 # return
350 0 return($flag);
351
352 }
353  
354 # make table for 'curv' objects
355 # assumes curve domain/range is (0 - 1)
356 # parameters: (number_of_table_entries, [direction])
357 # returns: (ref_to_table_array)
358 sub table {
359
360 # get parameters
361 0 ▶ my ($self, $n, $dir) = @_;
Subroutine table: not called CC=5 SCAR=34.0
Pod undocumented
362
363 # local variables
364 0 my ($up, $table);
365
366 # validate number of table entries
367 0 ▶ ($n == int($n) && $n >= 2) || carp('invalid number of table entries');
Branch: 1 branch
BranchTrueFalseTotal
$n == int $n and $n >= 2 or carp("invalid number of table entries") 0 0 0
Condition0%0/3
$n == int $n and $n >= 2
!ll&&!rl&&r
000
MC/DC0%0/2
$n == int $n and $n >= 2
$n == int $n $n >= 2
Truth table0%0/3
A and B
A= $n == int $nB= $n >= 2
ABresult
0X0
100
111
368
369 # purify direction flag
370 0 ▶ $dir = ($dir) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$dir ? : 0 0 0
371
372 # array upper index
373 0 $up = $n - 1;
374
375 # for each table entry
376 0 for my $i (0 .. $up) {
377
378 # compute table value
379 0 $table->[$i] = _transform($self, $dir, $i/$up);
380
381 }
382
383 # return table reference
384 0 return($table);
385
386 }
387  
388 # make 'curv' object
389 # assumes curve domain/range is (0 - 1)
390 # parameters: (number_of_table_entries, [direction])
391 # returns: (ref_to_curv_object)
392 sub curv {
393  
394 # return 'curv' object reference
395 0 ▶ return(ICC::Profile::curv->new(table(@_)));
Subroutine curv: not called CC=1 SCAR=6.9
Pod undocumented
396  
397 }
398  
399 # normalize transform
400 # adjusts object values linearly
401 # so that min/max values are 0/1
402 # parameter: () - adjust both x-values and y-values
403 # parameter: (0) - adjust x-values only
404 # parameter: (1) - adjust y-values only
405 sub normalize {
406
407 # get object reference
408 0 ▶ my $self = shift();
Subroutine normalize: not called CC=11 SCAR=48.8
Pod undocumented
409
410 # local variables
411 0 my ($flag, $cx0, $cx1, $cy0, $cy1, $dsf);
412
413 # if no parameters
414 0 ▶ if (@_ == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 0) { } 0 0 0
elsif (@_ == 1) { } 0 0 0
415
416 # set flag (adjust x-values and y-values)
417 0 $flag = 3;
418
419 } elsif (@_ == 1) {
420
421 # if valid parameter
422 0 ▶ if ($_[0] == 0 || $_[0] == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] == 0 or $_[0] == 1) { } 0 0 0
Condition0%0/3
$_[0] == 0 or $_[0] == 1
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0] == 0 or $_[0] == 1
$_[0] == 0 $_[0] == 1
Truth table0%0/3
A or B
A= $_[0] == 0B= $_[0] == 1
ABresult
1X1
011
000
423
424 # set flag
425 0 $flag = shift() + 1;
426
427 } else {
428
429 # error
430 0 croak('invalid parameter');
431
432 }
433
434 } else {
435
436 # error
437 0 croak('too many parameters')
438
439 }
440
441 # initialize scale factors
442 0 $cx1 = $cy1 = 1;
443
444 # if x-values adjusted
445 0 ▶ if ($flag & 0x01) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag & 1) 0 0 0
446
447 # compute scale factor
448 0 $cx1 = $self->[1][-1] - $self->[1][0];
449
450 # compute offset
451 0 $cx0 = $self->[1][0]/$cx1;
452
453 # for each x-value
454 0 for my $i (0 .. $#{$self->[1]}) {
455
456 # normalize
457 0 $self->[1][$i] = $self->[1][$i]/$cx1 - $cx0;
458
459 }
460
461 }
462
463 # if y-values adjusted
464 0 ▶ if ($flag & 0x02) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag & 2) 0 0 0
465
466 # compute scaling coefficient
467 0 $cy1 = abs($self->[2][-1] - $self->[2][0]);
468
469 # compute offset
470 0 ▶ $cy0 = ($self->[2][-1] < $self->[2][0] ? $self->[2][-1] : $self->[2][0])/$cy1;
Branch: 1 branch
BranchTrueFalseTotal
$self->[2][-1] < $self->[2][0] ? : 0 0 0
471
472 # for each y-value
473 0 for my $i (0 .. $#{$self->[2]}) {
474
475 # normalize
476 0 $self->[2][$i] = $self->[2][$i]/$cy1 - $cy0;
477
478 }
479
480 # set range of y-values
481 0 $self->[0]{'ymin'} = $self->[0]{'ymin'}/$cy1 - $cy0;
482 0 $self->[0]{'ymax'} = $self->[0]{'ymax'}/$cy1 - $cy0;
483
484 }
485
486 # compute derivative scale factor
487 0 $dsf = $cx1/$cy1;
488
489 # for each derivative value
490 0 for my $i (0 .. $#{$self->[3]}) {
491
492 # normalize
493 0 $self->[3][$i] *= $dsf;
494
495 }
496
497 }
498  
499 # print object contents to string
500 # format is an array structure
501 # parameter: ([format])
502 # returns: (string)
503 sub sdump {
504  
505 # get parameters
506 0 ▶ my ($self, $p) = @_;
Subroutine sdump: not called CC=5 SCAR=34.0
Pod documented
507  
508 # local variables
509 0 my ($s, $fmt);
510  
511 # resolve parameter to an array reference
512 0 ▶ $p = defined($p) ? ref($p) eq 'ARRAY' ? $p : [$p] : [];
Branch: 2 branches
BranchTrueFalseTotal
defined $p ? : 0 0 0
ref $p eq 'ARRAY' ? : 0 0 0
513  
514 # get format string
515 0 ▶ $fmt = defined($p->[0]) && ! ref($p->[0]) ? $p->[0] : 'undef';
Branch: 1 branch
BranchTrueFalseTotal
defined $p->[0] && !ref($p->[0]) ? : 0 0 0
Condition0%0/3
defined $p->[0] and not ref $p->[0]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $p->[0] and not ref $p->[0]
defined $p->[0] not ref $p->[0]
Truth table0%0/3
A and not(B)
A= defined $p->[0]B= not ref $p->[0]
ABresult
0X0
100
111
516  
517 # set string to object ID
518 0 $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self);
519  
520 # return
521 0 return($s);
522  
523 }
524  
525 # compute parametric partial derivatives
526 # direction: 0 - normal, 1 - inverse
527 # parameters: (object_reference, direction, input_value)
528 # returns: (partial_derivative_array)
529 sub _parametric {
530
531 # get parameters
532 0 ▶ my ($self, $dir, $in) = @_;
Subroutine _parametric: not called CC=1 SCAR=6.9
533
534 # unimplemented function error
535 0 croak('unimplemented function');
536
537 }
538  
539 # combined derivative
540 # direction: 0 - normal, 1 - inverse
541 # parameters: (object_reference, direction, input_value)
542 # returns: (derivative_value)
543 sub _derivative {
544
545 # get parameters
546 0 ▶ my ($self, $dir, $in) = @_;
Subroutine _derivative: not called CC=2 SCAR=17.9
547
548 # if inverse direction
549 0 ▶ if ($dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) { } 0 0 0
550
551 # unimplemented function error
552 0 croak('unimplemented function');
553
554 } else {
555
556 # return derivative
557 0 return($self->derivative($in));
558
559 }
560
561 }
562  
563 # combined transform
564 # direction: 0 - normal, 1 - inverse
565 # parameters: (object_reference, direction, input_value)
566 # returns: (output_value)
567 sub _transform {
568
569 # get parameters
570 0 ▶ my ($self, $dir, $in) = @_;
Subroutine _transform: not called CC=2 SCAR=17.9
571
572 # if inverse direction
573 0 ▶ if ($dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) { } 0 0 0
574
575 # return inverse
576 0 return(scalar($self->inverse($in)));
577
578 } else {
579
580 # return transform
581 0 return($self->transform($in));
582
583 }
584
585 }
586  
587 # compute object derivatives
588 # for spline knots using Akima's method
589 # parameters: (ref_to_object, endpoint_flag)
590 sub _objderv {
591  
592 # get parameters
593 0 ▶ my ($self, $flag) = @_;
Subroutine _objderv: not called CC=8 SCAR=42.8
594
595 # local variables
596 0 my ($p, @m, $d, $d1, $d2, $dm);
597  
598 # get array length
599 0 $p = $#{$self->[1]};
600
601 # compute segment slopes
602 0 for my $i (0 .. ($p - 1)) {
603
604 # compute and test denominator
605 0 ▶ ($d = $self->[1][$i] - $self->[1][$i + 1]) || croak('zero x-value interval in spline data');
Branch: 1 branch
BranchTrueFalseTotal
$d = $self->[1][$i] - $self->[1][$i + 1] or croak("zero x-value interval in spline data") 0 0 0
606
607 # now, compute slope
608 0 $m[$i + 2] = ($self->[2][$i] - $self->[2][$i + 1])/$d;
609
610 }
611  
612 # if 2 points
613 0 ▶ if ($p == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p == 1) { } 0 0 0
614
615 # linear slopes
616 0 $m[0] = $m[1] = $m[3] = $m[4] = $m[2];
617
618 # if 3 or more points
619 } else {
620
621 # quadratic slopes
622 0 $m[1] = 2 * $m[2] - $m[3];
623 0 $m[0] = 2 * $m[1] - $m[2];
624 0 $m[$p + 2] = 2 * $m[$p + 1] - $m[$p];
625 0 $m[$p + 3] = 2 * $m[$p + 2] - $m[$p + 1];
626
627 }
628
629 # compute Akima derivative
630 0 for my $i (0 .. $p) {
631
632 # if denominator not 0
633 0 ▶ if ($d = abs($m[$i + 3] - $m[$i + 2]) + abs($m[$i + 1] - $m[$i])) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d = abs($m[$i + 3] - $m[$i + 2]) + abs($m[$i + 1] - $m[$i])) { } 0 0 0
634
635 # use Akima estimate of slope
636 0 $self->[3][$i] = (abs($m[$i + 3] - $m[$i + 2]) * $m[$i + 1] + abs($m[$i + 1] - $m[$i]) * $m[$i + 2])/$d;
637
638 } else {
639
640 # otherwise, use average slope of adjoining segments
641 0 $self->[3][$i] = ($m[$i + 1] + $m[$i + 2])/2;
642
643 }
644
645 }
646
647 # if four or more points and flag set
648 0 ▶ if ($p >= 3 && $flag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p >= 3 and $flag) 0 0 0
Condition0%0/3
$p >= 3 and $flag
!ll&&!rl&&r
000
MC/DC0%0/2
$p >= 3 and $flag
$p >= 3 $flag
Truth table0%0/3
A and B
A= $p >= 3B= $flag
ABresult
0X0
100
111
649
650 # compute endpoint derivatives using weighted least squares
651 0 $self->[3][0] = _endpoint($self, 0);
652 0 $self->[3][-1] = _endpoint($self, -1);
653
654 }
655
656 }
657  
658 # determine derivative of endpoint
659 # using weighted least squares method
660 # endpoint index is either 0 or -1
661 # parameters: (ref_to_object, endpoint_index)
662 # returns: (derivative)
663 sub _endpoint {
664
665 # get parameters
666 0 ▶ my ($self, $ix) = @_;
Subroutine _endpoint: not called CC=3 SCAR=24.8
667
668 # local variables
669 0 my ($x, $y, $v, $r, $w, $info, $c);
670
671 # get x and y references
672 0 $x = $self->[1];
673 0 $y = $self->[2];
674
675 # for each data point
676 0 for my $i (0 .. $#{$x}) {
677
678 # for each cubic coefficient
679 0 for my $j (0 .. 3) {
680
681 # add element to Vandermonde matrix
682 0 $v->[$i][$j] = $x->[$i]**$j;
683
684 }
685
686 # add element to residual matrix
687 0 $r->[$i][0] = $y->[$i];
688
689 # add element to weight matrix
690 0 $w->[$i][0] = exp(-5 * abs(($x->[$i] - $x->[$ix])/($x->[0] - $x->[-1])));
691
692 }
693
694 # solve normal equations
695 0 ($info, $c) = ICC::Support::Lapack::normal($v, $r, $w);
696
697 # return derivative
698 0 return($c->[1][0] + 2 * $c->[2][0] * $x->[$ix] + 3 * $c->[3][0] * $x->[$ix]**2);
699
700 }
701  
702 # compute range of y-values
703 # parameters: (ref_to_object)
704 sub _range {
705
706 # get object reference
707 0 ▶ my $self = shift();
Subroutine _range: not called CC=4 SCAR=30.0
708
709 # local variables
710 0 my ($min, $max);
711
712 # initialize min/max values
713 0 $min = $max = $self->[2][0];
714
715 # for each y-value
716 0 for my $i (1 .. $#{$self->[2]}) {
717
718 # update min and max
719 0 ▶ $min = $self->[2][$i] if ($min > $self->[2][$i]);
Branch: 1 branch
BranchTrueFalseTotal
if $min > $self->[2][$i] 0 0 0
720 0 ▶ $max = $self->[2][$i] if ($max < $self->[2][$i]);
Branch: 1 branch
BranchTrueFalseTotal
if $max < $self->[2][$i] 0 0 0
721
722 }
723
724 # save result
725 0 $self->[0]{'ymin'} = $min;
726 0 $self->[0]{'ymax'} = $max;
727
728 }
729  
730 # add local min/max values
731 # parameters: (ref_to_object)
732 sub _minmax {
733  
734 # get object reference
735 0 ▶ my $self = shift();
Subroutine _minmax: not called CC=3 SCAR=24.8
736  
737 # local variables
738 0 my (@s, @ix);
739  
740 # for each interval
741 0 for my $i (0 .. ($#{$self->[1]} - 1)) {
742
743 # if local min/max values
744 0 ▶ if (@s = _local($self, $i)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@s = _local($self, $i)) 0 0 0
745
746 # set lower index
747 0 $self->[0]{'low'} = $i;
748
749 # add to x-value array
750 0 push(@{$self->[1]}, @s);
751
752 # add to y-value array
753 0 push(@{$self->[2]}, map {_fwd($self, $_)} @s);
754
755 # add to derivative array
756 0 push(@{$self->[3]}, (0) x @s);
757
758 }
759
760 }
761  
762 # make index array
763 0 @ix = (0 .. $#{$self->[1]});
764  
765 # sort index by x-values, in ascending order
766 0 @ix = sort {$self->[1][$a] <=> $self->[1][$b]} @ix;
767  
768 # reorder x-values
769 0 $self->[1] = [@{$self->[1]}[@ix]];
770  
771 # reorder y-values
772 0 $self->[2] = [@{$self->[2]}[@ix]];
773  
774 # reorder derivatives
775 0 $self->[3] = [@{$self->[3]}[@ix]];
776  
777 }
778  
779 # compute local min/max value(s)
780 # note: includes inflection points
781 # parameters: (ref_to_object, lower_index)
782 # returns: (value_array)
783 sub _local {
784  
785 # get parameters
786 0 ▶ my ($self, $i) = @_;
Subroutine _local: not called CC=13 SCAR=52.0
787  
788 # local variables
789 0 my ($x1, $x2, $y1, $y2, $m1, $m2);
790 0 my ($dy, $dx, $t, $a, $b, $c, $d, @s);
791  
792 # get endpoint values
793 0 $x1 = $self->[1][$i];
794 0 $x2 = $self->[1][$i + 1];
795 0 $y1 = $self->[2][$i];
796 0 $y2 = $self->[2][$i + 1];
797 0 $m1 = $self->[3][$i];
798 0 $m2 = $self->[3][$i + 1];
799  
800 # compute intermediate values
801 0 ▶ ($dx = $x2 - $x1) || croak('zero interval in spline data');
Branch: 1 branch
BranchTrueFalseTotal
$dx = $x2 - $x1 or croak("zero interval in spline data") 0 0 0
802 0 $dy = $y1 - $y2;
803 0 $a = 6 * $dy/$dx + 3 * ($m1 + $m2);
804 0 $b = -6 * $dy/$dx - 2 * $m2 - 4 * $m1;
805 0 $c = $m1;
806
807 # return if constant
808 0 ▶ return() if ($a == 0 && $b == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $a == 0 and $b == 0 0 0 0
Condition0%0/3
$a == 0 and $b == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$a == 0 and $b == 0
$a == 0 $b == 0
Truth table0%0/3
A and B
A= $a == 0B= $b == 0
ABresult
0X0
100
111
809
810 # if linear equation
811 0 ▶ if ($a == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a == 0) { } 0 0 0
812
813 # compute solution
814 0 $t = -$c/$b;
815
816 # push if solution within interval (but not endpoints)
817 0 ▶ push(@s, $t * $dx + $x1) if ($t > 0 && $t < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $t > 0 and $t < 1 0 0 0
Condition0%0/3
$t > 0 and $t < 1
!ll&&!rl&&r
000
MC/DC0%0/2
$t > 0 and $t < 1
$t > 0 $t < 1
Truth table0%0/3
A and B
A= $t > 0B= $t < 1
ABresult
0X0
100
111
818
819 # if quadratic equation
820 } else {
821
822 # compute discriminant
823 0 $d = $b**2 - 4 * $a * $c;
824
825 # return if complex solutions
826 0 ▶ return() if ($d < 0);
Branch: 1 branch
BranchTrueFalseTotal
if $d < 0 0 0 0
827
828 # compute first solution
829 0 $t = (-$b + sqrt($d))/(2 * $a);
830
831 # push if solution within interval (but not endpoints)
832 0 ▶ push(@s, $t * $dx + $x1) if ($t > 0 && $t < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $t > 0 and $t < 1 0 0 0
Condition0%0/3
$t > 0 and $t < 1
!ll&&!rl&&r
000
MC/DC0%0/2
$t > 0 and $t < 1
$t > 0 $t < 1
Truth table0%0/3
A and B
A= $t > 0B= $t < 1
ABresult
0X0
100
111
833
834 # if discriminant > 0 (two real solutions)
835 0 ▶ if ($d > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d > 0) 0 0 0
836
837 # compute second solution
838 0 $t = (-$b - sqrt($d))/(2 * $a);
839
840 # push if solution within interval (but not endpoints)
841 0 ▶ push(@s, $t * $dx + $x1) if ($t > 0 && $t < 1);
Branch: 1 branch
BranchTrueFalseTotal
if $t > 0 and $t < 1 0 0 0
Condition0%0/3
$t > 0 and $t < 1
!ll&&!rl&&r
000
MC/DC0%0/2
$t > 0 and $t < 1
$t > 0 $t < 1
Truth table0%0/3
A and B
A= $t > 0B= $t < 1
ABresult
0X0
100
111
842
843 }
844
845 }
846
847 # return solution(s)
848 0 return (@s);
849
850 }
851  
852 # compute second derivative
853 # parameters: (ref_to_object, x-value)
854 # returns: (second_derivative)
855 sub _derv2 {
856  
857 # get parameters
858 0 ▶ my ($self, $in) = @_;
Subroutine _derv2: not called CC=2 SCAR=17.9
859  
860 # local variables
861 0 my ($i, $x1, $x2, $y1, $y2, $m1, $m2);
862 0 my ($dy, $dx, $t, $h1, $h2, $h3);
863  
864 # get lower index
865 0 $i = $self->[0]{'low'};
866  
867 # get endpoint values
868 0 $x1 = $self->[1][$i];
869 0 $x2 = $self->[1][$i + 1];
870 0 $y1 = $self->[2][$i];
871 0 $y2 = $self->[2][$i + 1];
872 0 $m1 = $self->[3][$i];
873 0 $m2 = $self->[3][$i + 1];
874  
875 # compute intermediate values
876 0 ▶ ($dx = $x2 - $x1) || croak('zero interval in spline data');
Branch: 1 branch
BranchTrueFalseTotal
$dx = $x2 - $x1 or croak("zero interval in spline data") 0 0 0
877 0 $dy = $y1 - $y2;
878 0 $t = ($in - $x1)/$dx;
879 0 $h1 = 12 * $t - 6;
880 0 $h2 = 6 * $t - 2;
881 0 $h3 = 6 * $t - 4;
882  
883 # return second derivative
884 0 return (($h1 * $dy/$dx + $h2 * $m2 + $h3 * $m1)/$dx);
885  
886 }
887  
888 # compute derivative
889 # parameters: (ref_to_object, x-value)
890 # returns: (derivative)
891 sub _derv {
892  
893 # get parameters
894 0 ▶ my ($self, $in) = @_;
Subroutine _derv: not called CC=2 SCAR=17.9
895  
896 # local variables
897 0 my ($i, $x1, $x2, $y1, $y2, $m1, $m2);
898 0 my ($dy, $dx, $t, $h1, $h2, $h3);
899  
900 # get lower index
901 0 $i = $self->[0]{'low'};
902  
903 # get endpoint values
904 0 $x1 = $self->[1][$i];
905 0 $x2 = $self->[1][$i + 1];
906 0 $y1 = $self->[2][$i];
907 0 $y2 = $self->[2][$i + 1];
908 0 $m1 = $self->[3][$i];
909 0 $m2 = $self->[3][$i + 1];
910  
911 # compute intermediate values
912 0 ▶ ($dx = $x2 - $x1) || croak('zero interval in spline data');
Branch: 1 branch
BranchTrueFalseTotal
$dx = $x2 - $x1 or croak("zero interval in spline data") 0 0 0
913 0 $dy = $y1 - $y2;
914 0 $t = ($in - $x1)/$dx;
915 0 $h1 = 6 * $t * ($t - 1);
916 0 $h2 = $t * (3 * $t - 2);
917 0 $h3 = $h2 - 2 * $t + 1;
918  
919 # return derivative
920 0 return ($h1 * $dy/$dx + $h2 * $m2 + $h3 * $m1);
921  
922 }
923  
924 # compute transform value
925 # parameters: (ref_to_object, x-value)
926 # returns: (y-value)
927 sub _fwd {
928  
929 # get parameters
930 0 ▶ my ($self, $in) = @_;
Subroutine _fwd: not called CC=4 SCAR=30.0
931  
932 # local variables
933 0 my ($i, $x0, $x1, $y0, $y1, $m0, $m1);
934 0 my ($dx, $t, $tc, $h00, $h01, $h10, $h11);
935  
936 # check if ICC::Support::Lapack module is loaded
937 0 state $lapack = defined($INC{'ICC/Support/Lapack.pm'});
938  
939 # get lower index
940 0 $i = $self->[0]{'low'};
941  
942 # get endpoint values
943 0 $x0 = $self->[1][$i];
944 0 $x1 = $self->[1][$i + 1];
945 0 $y0 = $self->[2][$i];
946 0 $y1 = $self->[2][$i + 1];
947 0 $m0 = $self->[3][$i];
948 0 $m1 = $self->[3][$i + 1];
949  
950 # compute intermediate values
951 0 ▶ ($dx = $x1 - $x0) || croak('zero interval in spline data');
Branch: 1 branch
BranchTrueFalseTotal
$dx = $x1 - $x0 or croak("zero interval in spline data") 0 0 0
952 0 $t = ($in - $x0)/$dx;
953  
954 # if ratio is non-zero
955 0 ▶ if ($t) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t) { } 0 0 0
956
957 # if ICC::Support::Lapack module is loaded
958 0 ▶ if ($lapack) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lapack) { } 0 0 0
959
960 # return interpolated value
961 0 return(ICC::Support::Lapack::hermite($t, $y0, $y1, $m0 * $dx, $m1 * $dx));
962
963 } else {
964
965 # compute Hermite coefficients
966 0 $tc = 1 - $t;
967 0 $h00 = (1 + 2 * $t) * $tc * $tc;
968 0 $h01 = 1 - $h00;
969 0 $h10 = $t * $tc * $tc;
970 0 $h11 = -$t * $t * $tc;
971
972 # return interpolated value
973 0 return($h00 * $x0 + $h01 * $x1 + $h10 * $m0 * $dx + $h11 * $m1 * $dx);
974
975 }
976
977 } else {
978
979 # use lower source value
980 0 return($y0);
981
982 }
983
984 }
985  
986 # compute inverse value
987 # parameters: (ref_to_object, y-value)
988 # returns: (x-value)
989 sub _rev {
990  
991 # get parameters
992 0 ▶ my ($self, $in) = @_;
Subroutine _rev: not called CC=5 SCAR=34.0
993  
994 # local variables
995 0 my ($i, $x, $y, $dydx, $dx);
996  
997 # get lower index
998 0 $i = $self->[0]{'low'};
999
1000 # if input is lower y-value
1001 0 ▶ if ($self->[2][$i] == $in) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[2][$i] == $in) { } 0 0 0
1002
1003 # return lower x-value
1004 0 return($self->[1][$i]);
1005
1006 } else {
1007
1008 # set initial x-value
1009 0 $x = ($self->[1][$i] + $self->[1][$i + 1])/2;
1010
1011 # loop
1012 0 for (0 .. 10) {
1013
1014 # get y-value
1015 0 $y = _fwd($self, $x);
1016
1017 # get derivative
1018 0 $dydx = _derv($self, $x);
1019
1020 # compute x-delta
1021 0 ▶ $dx = ($y - $in)/($dydx ? $dydx : rand);
Branch: 1 branch
BranchTrueFalseTotal
$dydx ? : 0 0 0
1022
1023 # adjust x
1024 0 $x -= $dx;
1025
1026 # quit if error < limit
1027 0 ▶ last if (abs($dx) < 1E-12 * ($self->[1][-1] - $self->[1][0]));
Branch: 1 branch
BranchTrueFalseTotal
if abs $dx < "1e-12" * ($self->[1][-1] - $self->[1][0]) 0 0 0
1028
1029 }
1030
1031 }
1032
1033 # return
1034 0 return($x);
1035  
1036 }
1037  
1038 # binary search
1039 # finds the array interval containing the value
1040 # note: assumes array values are in ascending order
1041 # parameters: (ref_to_array, value)
1042 # returns: (lower_index)
1043 sub _binsearch {
1044  
1045 # get parameters
1046 0 ▶ my ($vref, $v) = @_;
Subroutine _binsearch: not called CC=3 SCAR=24.8
1047  
1048 # local variables
1049 0 my ($k, $klo, $khi);
1050  
1051 # set low and high indices
1052 0 $klo = 0;
1053 0 $khi = $#{$vref};
1054  
1055 # repeat until interval is found
1056 0 ▶ while (($khi - $klo) > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($khi - $klo > 1) 0 0 0
1057
1058 # compute the midpoint
1059 0 $k = int(($khi + $klo)/2);
1060
1061 # if midpoint value > value
1062 0 ▶ if ($vref->[$k] > $v) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vref->[$k] > $v) { } 0 0 0
1063
1064 # set high index to midpoint
1065 0 $khi = $k;
1066
1067 } else {
1068
1069 # set low index to midpoint
1070 0 $klo = $k;
1071
1072 }
1073
1074 }
1075  
1076 # return low index
1077 0 return ($klo);
1078  
1079 }
1080  
1081 # linear search
1082 # finds the array interval(s) containing the value
1083 # parameters: (ref_to_array, value)
1084 # returns: (lower_index_array)
1085 sub _linsearch {
1086  
1087 # get parameters
1088 0 ▶ my ($vref, $v) = @_;
Subroutine _linsearch: not called CC=6 SCAR=37.4
1089  
1090 # local variables
1091 0 my (@low);
1092  
1093 # for each point
1094 0 for my $i (0 .. $#{$vref}) {
1095
1096 # if value equals point
1097 0 ▶ if ($v == $vref->[$i]) {
Branch: 2 branches
BranchTrueFalseTotal
if ($v == $vref->[$i]) { } 0 0 0
elsif ($i < $#{$vref;} and $v > $vref->[$i] ^ $v > $$vref[$i + 1] and $v < $vref->[$i] ^ $v < $$vref[$i + 1]) { } 0 0 0
1098
1099 # push index
1100 0 push(@low, $i);
1101
1102 # if value inside interval (not including end points)
1103 0 ▶ } elsif ($i < $#{$vref} && (($v > $vref->[$i]) ^ ($v > $vref->[$i + 1])) && (($v < $vref->[$i]) ^ ($v < $vref->[$i + 1]))) {
Condition0%0/6
$i < $#{$vref;} and $v > $vref->[$i] ^ $v > $$vref[$i + 1] and $v < $vref->[$i] ^ $v < $$vref[$i + 1]
!ll&&!rl&&r
000
$i < $#{$vref;} and $v > $vref->[$i] ^ $v > $$vref[$i + 1]
!ll&&!rl&&r
000
MC/DC0%0/3
$i < $#{$vref;} and $v > $vref->[$i] ^ $v > $$vref[$i + 1] and $v < $vref->[$i] ^ $v < $$vref[$i + 1]
$i < $#{$vref;} $v > $vref->[$i] ^ $v > $$vref[$i + 1] $v < $vref->[$i] ^ $v < $$vref[$i + 1]
Truth table0%0/4
A and B and C
A= $i < $#{$vref;}B= $v > $vref->[$i] ^ $v > $$vref[$i + 1]C= $v < $vref->[$i] ^ $v < $$vref[$i + 1]
ABCresult
0XX0
10X0
1100
1111
1104
1105 # push index
1106 0 push(@low, $i);
1107
1108 }
1109
1110 }
1111  
1112 # return
1113 0 return(@low);
1114  
1115 }
1116  
1117 # write akima object to ICC profile
1118 # note: writes an equivalent curv object
1119 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
1120 sub _writeICCakima {
1121  
1122 # get parameters
1123 0 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _writeICCakima: not called CC=7 SCAR=40.3
1124  
1125 # local variables
1126 0 my ($n, $up, @table);
1127  
1128 # get count value (defaults to 4096, the maximum allowed in an 'mft2' tag)
1129 0 ▶ $n = defined($self->[0]{'curv_points'}) ? $self->[0]{'curv_points'} : 4096;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->[0]{'curv_points'} ? : 0 0 0
1130  
1131 # validate number of table entries
1132 0 ▶ ($n == int($n) && $n >= 2) || carp('invalid number of table entries');
Branch: 1 branch
BranchTrueFalseTotal
$n == int $n and $n >= 2 or carp("invalid number of table entries") 0 0 0
Condition0%0/3
$n == int $n and $n >= 2
!ll&&!rl&&r
000
MC/DC0%0/2
$n == int $n and $n >= 2
$n == int $n $n >= 2
Truth table0%0/3
A and B
A= $n == int $nB= $n >= 2
ABresult
0X0
100
111
1133  
1134 # array upper index
1135 0 $up = $n - 1;
1136  
1137 # for each table entry
1138 0 for my $i (0 .. $up) {
1139
1140 # transform value
1141 0 $table[$i] = transform($self, $i/$up);
1142
1143 }
1144  
1145 # seek start of tag
1146 0 seek($fh, $tag->[1], 0);
1147  
1148 # write tag type signature and count
1149 0 print $fh pack('a4 x4 N', 'curv', $n);
1150  
1151 # write array
1152 0 ▶ print $fh pack('n*', map {$_ < 0 ? 0 : ($_ > 1 ? 65535 : $_ * 65535 + 0.5)} @table);
Branch: 2 branches
BranchTrueFalseTotal
$_ < 0 ? : 0 0 0
$_ > 1 ? : 0 0 0
1153  
1154 }
1155  
1156 2 1;
« lib/ICC/Profile/mft2.pm ↑ Summary lib/ICC/Profile/mft1.pm »