File Coverage

lib/Graphics/Toolkit/Color/Space/Instance/CIELCHuv.pm
Criterion Covered Total %
statement 21 21 100.0
branch 6 6 100.0
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 32 34 94.1


line stmt bran cond sub pod time code
1              
2             # CIE LCh(uv) cylindrical color space variant of CIELUV
3              
4             package Graphics::Toolkit::Color::Space::Instance::CIELCHuv;
5 15     15   239634 use v5.12;
  15         61  
6 15     15   108 use warnings;
  15         28  
  15         972  
7 15     15   880 use Graphics::Toolkit::Color::Space qw/round_decimals/;
  15         43  
  15         5892  
8              
9             my $TAU = 6.283185307;
10              
11             sub from_luv {
12 6     6 0 17 my ($luv) = shift;
13 6         23 my $u = $luv->[1] * 354 - 134;
14 6         20 my $v = $luv->[2] * 262 - 140;
15 6 100       24 $u = 0 if round_decimals($u, 5) == 0;
16 6 100       21 $v = 0 if round_decimals($v, 5) == 0;
17 6         31 my $c = sqrt( ($u**2) + ($v**2));
18 6         62 my $h = atan2($v, $u);
19 6 100       25 $h += $TAU if $h < 0;
20 6         37 return ([$luv->[0], $c / 261, $h / $TAU ]);
21             }
22             sub to_luv {
23 6     6 0 18 my ($lch) = shift;
24 6         67 my $u = $lch->[1] * cos($lch->[2] * $TAU) * 261;
25 6         24 my $v = $lch->[1] * sin($lch->[2] * $TAU) * 261;
26 6         40 return ([$lch->[0], ($u+134) / 354, ($v+140) / 262 ]);
27             }
28              
29             Graphics::Toolkit::Color::Space->new(
30             name => 'CIELCHuv',
31             alias => 'LCHuv',
32             axis => [qw/luminance chroma hue/],
33             type => [qw/linear linear angular/],
34             range => [100, 261, 360],
35             precision => 3,
36             convert => {LUV => [\&to_luv, \&from_luv]},
37             );