| 1 | |||||||||||||||||||||||||||||
| 2 | # utilities for color value calculation | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | package Graphics::Toolkit::Color::Space::Util; | ||||||||||||||||||||||||||||
| 5 | 53 | ▶ | use v5.12; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 53 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 53 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 53 | our @EXPORT_OK = qw/min max uniq round_int round_decimals mod_real spow mult_matrix_vector_3 is_nr number_re/; | |||||||||||||||||||||||||||
| 9 | 53 | our %EXPORT_TAGS = (all => [@EXPORT_OK]); | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | #### lists ############################################################# | ||||||||||||||||||||||||||||
| 12 | 149 | ▶ | sub min { | ||||||||||||||||||||||||||
|
Subroutine
min: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | 149 | my $v = shift; | |||||||||||||||||||||||||||
| 14 | 149 | ▶ | for (@_) { next unless defined $_; $v = $_ if $v > $_ } | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 15 | 149 | return $v; | |||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 169 | ▶ | sub max { | ||||||||||||||||||||||||||
|
Subroutine
max: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 19 | 169 | my $v = shift; | |||||||||||||||||||||||||||
| 20 | 169 | ▶ | for (@_) { next unless defined $_; $v = $_ if $v < $_ } | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 21 | 169 | return $v; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 571 | ▶ | sub uniq { | ||||||||||||||||||||||||||
|
Subroutine
uniq: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | 571 | ▶ | return undef unless @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 570 | my %seen = (); | |||||||||||||||||||||||||||
| 27 | 570 | grep {not $seen{$_}++} @_; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | #### basic math ######################################################## | ||||||||||||||||||||||||||||
| 31 | 53 | my $half = 0.50000000000008; | |||||||||||||||||||||||||||
| 32 | 53 | my $tolerance = 0.00000000000008; | |||||||||||||||||||||||||||
| 33 | 4221 | ▶ | sub round_int { | ||||||||||||||||||||||||||
|
Subroutine
round_int: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 34 | 4221 | ▶ | $_[0] >= 0 ? int ($_[0] + $half) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | : int ($_[0] - $half) | ||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 4213 | ▶ | sub round_decimals { | ||||||||||||||||||||||||||
|
Subroutine
round_decimals: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 39 | 4213 | my ($nr, $precision) = @_; | |||||||||||||||||||||||||||
| 40 | 4213 | ▶ | return round_int( $nr ) unless defined $precision and $precision; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $precision and $precision
MC/DC100%2/2
defined $precision and $precision
defined $precision
$precision
Truth table100%3/3
A and B
A= defined $precisionB= $precision
| |||||||||||||||||||||||||||||
| 41 | 1793 | $precision = 10 ** $precision; | |||||||||||||||||||||||||||
| 42 | 1793 | return round_int( $nr * $precision ) / $precision; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 104 | ▶ | sub mod_real { # real value modulo | ||||||||||||||||||||||||||
|
Subroutine
mod_real: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 46 | 104 | ▶ | return 0 unless defined $_[1] and $_[1]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $_[1] and $_[1]
MC/DC100%2/2
defined $_[1] and $_[1]
defined $_[1]
$_[1]
Truth table100%3/3
A and B
A= defined $_[1]B= $_[1]
| |||||||||||||||||||||||||||||
| 47 | 101 | return $_[0] - (int($_[0] / $_[1]) * $_[1]); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 1661 | ▶ | sub spow { # sign preserving power function | ||||||||||||||||||||||||||
|
Subroutine
spow: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 51 | 1661 | my ($base, $exponent) = @_; | |||||||||||||||||||||||||||
| 52 | 1661 | ▶ | return $base ** $exponent if $base >= 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 23 | return -((-$base) ** $exponent); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 53 | my $number_re = qr/^\-?(?:\d+|(?:\d*\.\d+))(?:e-?\d+)?$/; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 522 | ▶ | sub number_re { $number_re } | ||||||||||||||||||||||||||
|
Subroutine
number_re: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 59 | 15193 | ▶ | sub is_nr { ($_[0] =~ $number_re) ? 1 : 0 } | ||||||||||||||||||||||||||
|
Subroutine
is_nr: called CC=2 SCAR=6.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | #### color computation ################################################# | ||||||||||||||||||||||||||||
| 62 | 837 | ▶ | sub mult_matrix_vector_3 { | ||||||||||||||||||||||||||
|
Subroutine
mult_matrix_vector_3: called CC=3 SCAR=12.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 63 | 837 | my ($mat, $v1, $v2, $v3) = @_; | |||||||||||||||||||||||||||
| 64 | 837 | ▶ | return unless ref $mat eq 'ARRAY' and defined $v3; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $mat eq "ARRAY" and defined $v3
MC/DC0%0/2
ref $mat eq "ARRAY" and defined $v3
ref $mat eq "ARRAY"
defined $v3
Truth table33%1/3
A and B
A= ref $mat eq "ARRAY"B= defined $v3
| |||||||||||||||||||||||||||||
| 65 | 837 | 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 | 53 | 1; | |||||||||||||||||||||||||||