Color/Space/Instance/HSL.pm

filter: Statementstmt 100% 26 / 26 Branchbran 95.0% 19 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 94.3% 50 / 53 CC 11 SCAR 16.1
CC
11
Cov
98%
to_hsl
6.0
from_hsl
6.0
BEGIN
1.0
CRAP 5.0
« Color/Values.pm ↑ Summary Color/Space/Instance/CIELUV.pm »
1  
2 # HSL color space specific code
3  
4 package Graphics::Toolkit::Color::Space::Instance::HSL;
5 16 ▶use v5.12;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 16 ▶use Graphics::Toolkit::Color::Space qw/min max mod_real/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 97 ▶sub from_hsl {
Subroutine from_hsl: called CC=6 SCAR=17.9
Pod undocumented
10 97 my ($h, $s, $l) = @{$_[0]};
11 97 $h *= 6;
12 97 my $C = $s * (1 - abs($l * 2 - 1));
13 97 my $X = $C * (1 - abs( mod_real($h, 2) - 1) );
14 97 my $m = $l - ($C / 2);
15 97 ▶ my @rgb = ($h < 1) ? ($C + $m, $X + $m, $m)
Branch: 5 branches
BranchTrueFalseTotal
$h < 1 ? : 39 58 97
$h < 2 ? : 9 49 58
$h < 3 ? : 10 39 49
$h < 4 ? : 19 20 39
$h < 5 ? : 7 13 20
16 : ($h < 2) ? ($X + $m, $C + $m, $m)
17 : ($h < 3) ? ( $m, $C + $m, $X + $m)
18 : ($h < 4) ? ( $m, $X + $m, $C + $m)
19 : ($h < 5) ? ($X + $m, $m, $C + $m)
20 : ($C + $m, $m, $X + $m);
21 97 return \@rgb;
22 }
23 75 ▶sub to_hsl {
Subroutine to_hsl: called CC=6 SCAR=17.9
Pod undocumented
24 75 my ($r, $g, $b) = @{$_[0]};
25 75 my $vmax = max($r, $g, $b),
26 my $vmin = min($r, $g, $b);
27 75 my $l = ($vmax + $vmin) / 2;
28 75 ▶ return ([0, 0, $l]) if $vmax == $vmin;
Branch: 1 branch
BranchTrueFalseTotal
if $vmax == $vmin 30 45 75
29 45 my $d = $vmax - $vmin;
30 45 ▶ my $s = ($l > 0.5) ? ($d / (2 - $vmax - $vmin)) : ($d / ($vmax + $vmin));
Branch: 1 branch
BranchTrueFalseTotal
$l > 0.5 ? : 6 39 45
31 45 ▶ my $h = ($vmax == $r) ? (($g - $b) / $d + ($g < $b ? 6 : 0)) :
Branch: 3 branches
BranchTrueFalseTotal
$vmax == $r ? : 19 26 45
$g < $b ? : 0 19 19
$vmax == $g ? : 1 25 26
32 ($vmax == $g) ? (($b - $r) / $d + 2)
33 : (($r - $g) / $d + 4);
34 45 return ([$h/6, $s, $l]);
35 }
36  
37 16 Graphics::Toolkit::Color::Space->new(
38 family => 'HSL',
39 axis => [qw/hue saturation lightness/],
40 range => [ 360, 100, 100 ],
41 precision => 0,
42 type => [qw/angular linear linear/],
43 #suffix => ['', '%', '%'],
44 convert => {RGB => [\&from_hsl, \&to_hsl]},
45 );
« Color/Values.pm ↑ Summary Color/Space/Instance/CIELUV.pm »