| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
# utilities for color value calculation |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Graphics::Toolkit::Color::Space::Util; |
|
5
|
53
|
|
|
53
|
|
741948
|
use v5.12; |
|
|
53
|
|
|
|
|
154
|
|
|
6
|
53
|
|
|
53
|
|
204
|
use warnings; |
|
|
53
|
|
|
|
|
64
|
|
|
|
53
|
|
|
|
|
2154
|
|
|
7
|
53
|
|
|
53
|
|
205
|
use Exporter 'import'; |
|
|
53
|
|
|
|
|
68
|
|
|
|
53
|
|
|
|
|
32274
|
|
|
8
|
|
|
|
|
|
|
our @EXPORT_OK = qw/min max uniq round_int round_decimals mod_real spow mult_matrix_vector_3 is_nr number_re/; |
|
9
|
|
|
|
|
|
|
our %EXPORT_TAGS = (all => [@EXPORT_OK]); |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
#### lists ############################################################# |
|
12
|
|
|
|
|
|
|
sub min { |
|
13
|
149
|
|
|
149
|
0
|
996
|
my $v = shift; |
|
14
|
149
|
50
|
|
|
|
203
|
for (@_) { next unless defined $_; $v = $_ if $v > $_ } |
|
|
266
|
100
|
|
|
|
470
|
|
|
|
266
|
|
|
|
|
399
|
|
|
15
|
149
|
|
|
|
|
242
|
return $v; |
|
16
|
|
|
|
|
|
|
} |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub max { |
|
19
|
169
|
|
|
169
|
0
|
211
|
my $v = shift; |
|
20
|
169
|
50
|
|
|
|
270
|
for (@_) { next unless defined $_; $v = $_ if $v < $_ } |
|
|
351
|
100
|
|
|
|
471
|
|
|
|
351
|
|
|
|
|
575
|
|
|
21
|
169
|
|
|
|
|
357
|
return $v; |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub uniq { |
|
25
|
571
|
100
|
|
571
|
0
|
5243
|
return undef unless @_; |
|
26
|
570
|
|
|
|
|
644
|
my %seen = (); |
|
27
|
570
|
|
|
|
|
682
|
grep {not $seen{$_}++} @_; |
|
|
1389
|
|
|
|
|
3284
|
|
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
#### basic math ######################################################## |
|
31
|
|
|
|
|
|
|
my $half = 0.50000000000008; |
|
32
|
|
|
|
|
|
|
my $tolerance = 0.00000000000008; |
|
33
|
|
|
|
|
|
|
sub round_int { |
|
34
|
4221
|
100
|
|
4221
|
0
|
15489
|
$_[0] >= 0 ? int ($_[0] + $half) |
|
35
|
|
|
|
|
|
|
: int ($_[0] - $half) |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub round_decimals { |
|
39
|
4213
|
|
|
4213
|
0
|
9114
|
my ($nr, $precision) = @_; |
|
40
|
4213
|
100
|
100
|
|
|
9586
|
return round_int( $nr ) unless defined $precision and $precision; |
|
41
|
1793
|
|
|
|
|
2070
|
$precision = 10 ** $precision; |
|
42
|
1793
|
|
|
|
|
2803
|
return round_int( $nr * $precision ) / $precision; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub mod_real { # real value modulo |
|
46
|
104
|
100
|
100
|
104
|
0
|
329
|
return 0 unless defined $_[1] and $_[1]; |
|
47
|
101
|
|
|
|
|
276
|
return $_[0] - (int($_[0] / $_[1]) * $_[1]); |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub spow { # sign preserving power function |
|
51
|
1661
|
|
|
1661
|
0
|
1792
|
my ($base, $exponent) = @_; |
|
52
|
1661
|
100
|
|
|
|
3977
|
return $base ** $exponent if $base >= 0; |
|
53
|
23
|
|
|
|
|
69
|
return -((-$base) ** $exponent); |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $number_re = qr/^\-?(?:\d+|(?:\d*\.\d+))(?:e-?\d+)?$/; |
|
57
|
|
|
|
|
|
|
|
|
58
|
522
|
|
|
522
|
0
|
640
|
sub number_re { $number_re } |
|
59
|
15193
|
100
|
|
15193
|
0
|
68282
|
sub is_nr { ($_[0] =~ $number_re) ? 1 : 0 } |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
#### color computation ################################################# |
|
62
|
|
|
|
|
|
|
sub mult_matrix_vector_3 { |
|
63
|
837
|
|
|
837
|
0
|
5530
|
my ($mat, $v1, $v2, $v3) = @_; |
|
64
|
837
|
50
|
33
|
|
|
2018
|
return unless ref $mat eq 'ARRAY' and defined $v3; |
|
65
|
837
|
|
|
|
|
2960
|
return ($v1 * $mat->[0][0] + $v2 * $mat->[0][1] + $v3 * $mat->[0][2]) , |
|
66
|
|
|
|
|
|
|
($v1 * $mat->[1][0] + $v2 * $mat->[1][1] + $v3 * $mat->[1][2]) , |
|
67
|
|
|
|
|
|
|
($v1 * $mat->[2][0] + $v2 * $mat->[2][1] + $v3 * $mat->[2][2]) ; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |