Color/HSV.pm

filter: Statementstmt 74.7% 62 / 83 Branchbran 50.0% 15 / 30 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 100% 6 / 6 totaltotal 72.3% 94 / 130 CC 16 SCAR 25.5
CC
16
Cov
68%
to_rgb
25.4
equal_to
7.3
BEGIN
1.0
CRAP 12.8
↑ Summary Color/RGB.pm »
1 package Graphics::Color::HSV;
2 4 $Graphics::Color::HSV::VERSION = '0.31';
3 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use MooseX::Aliases;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 extends qw(Graphics::Color);
7  
8 4 with 'Graphics::Color::Equal';
9  
10 4 ▶use Graphics::Color::Types qw(Number360OrLess NumberOneOrLess);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Graphics::Color::RGB;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 4 has 'hue' => (
15 is => 'rw',
16 isa => Number360OrLess,
17 default => 1,
18 alias => 'h'
19 );
20  
21  
22 4 has 'saturation' => (
23 is => 'rw',
24 isa => NumberOneOrLess,
25 default => 1,
26 alias => 's'
27 );
28  
29  
30 4 has 'value' => (
31 is => 'rw',
32 isa => NumberOneOrLess,
33 default => 1,
34 alias => 'v'
35 );
36  
37  
38 4 has 'alpha' => (
39 is => 'rw',
40 isa => NumberOneOrLess,
41 default => 1,
42 alias => 'a'
43 );
44  
45  
46 4 has 'name' => ( is => 'rw', isa => 'Str' );
47  
48  
49 1 ▶sub as_string {
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
50 1 my ($self) = @_;
51  
52 1 return sprintf('%d,%0.2f,%0.2f,%0.2f',
53 $self->hue, $self->saturation, $self->value, $self->alpha
54 );
55 }
56  
57  
58 1 ▶sub as_percent_string {
Subroutine as_percent_string: called CC=1 SCAR=0.0
Pod documented
59 1 my ($self) = @_;
60  
61 1 return sprintf("%d, %d%%, %d%%, %0.2f",
62 $self->hue, $self->saturation * 100, $self->value * 100,
63 $self->alpha
64 );
65 }
66  
67  
68 1 ▶sub as_array {
Subroutine as_array: called CC=1 SCAR=0.0
Pod documented
69 1 my ($self) = @_;
70  
71 1 return ($self->hue, $self->saturation, $self->value);
72 }
73  
74  
75 1 ▶sub as_array_with_alpha {
Subroutine as_array_with_alpha: called CC=1 SCAR=0.0
Pod documented
76 1 my ($self) = @_;
77  
78 1 return ($self->hue, $self->saturation, $self->value, $self->alpha);
79 }
80  
81  
82 2 ▶sub equal_to {
Subroutine equal_to: called CC=6 SCAR=19.9
Pod documented
83 2 my ($self, $other) = @_;
84  
85 2 ▶ return 0 unless defined($other);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $other 0 2 2
86  
87 2 ▶ unless($self->hue == $other->hue) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->hue == $other->hue) 0 2 2
88 0 return 0;
89 }
90 2 ▶ unless($self->saturation == $other->saturation) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->saturation == $other->saturation) 1 1 2
91 1 return 0;
92 }
93 1 ▶ unless($self->value == $other->value) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->value == $other->value) 0 1 1
94 0 return 0;
95 }
96 1 ▶ unless($self->alpha == $other->alpha) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->alpha == $other->alpha) 0 1 1
97 0 return 0;
98 }
99  
100 1 return 1;
101 }
102  
103  
104  
105 3 ▶sub to_rgb {
Subroutine to_rgb: called CC=11 SCAR=32.3
Pod documented
106 3 my ($self) = @_;
107  
108 3 my ($h, $s, $v) = ($self->h, $self->s, $self->v);
109  
110 3 my ($red, $green, $blue);
111  
112 3 ▶ if($v == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($v == 0) { } 0 3 3
elsif ($s == 0) { } 0 3 3
113 0 ($red, $green, $blue) = (0, 0, 0);
114 } elsif($s == 0) {
115 0 ($red, $green, $blue) = ($v, $v, $v);
116 } else {
117 3 my $hf = $h / 60;
118 3 my $i = int($hf);
119 3 my $f = $hf - $i;
120 3 my $pv = $v * (1 - $s);
121 3 my $qv = $v * (1 - $s * $f);
122 3 my $tv = $v * (1 - $s * (1 - $f));
123  
124 3 ▶ if($i == 0) {
Branch: 8 branches
BranchTrueFalseTotal
if ($i == 0) { } 1 2 3
elsif ($i == 1) { } 0 2 2
elsif ($i == 2) { } 1 1 2
elsif ($i == 3) { } 0 1 1
elsif ($i == 4) { } 1 0 1
elsif ($i == 5) { } 0 0 0
elsif ($i == 6) { } 0 0 0
elsif ($i == -1) { } 0 0 0
125 1 $red = $v;
126 1 $green = $tv;
127 1 $blue = $pv;
128 } elsif($i == 1) {
129 0 $red = $qv;
130 0 $green = $v;
131 0 $blue = $pv;
132 } elsif($i == 2) {
133 1 $red = $pv;
134 1 $green = $v;
135 1 $blue = $tv;
136 } elsif($i == 3) {
137 0 $red = $pv;
138 0 $green = $qv;
139 0 $blue = $v;
140 } elsif($i == 4) {
141 1 $red = $tv;
142 1 $green = $pv;
143 1 $blue = $v;
144 } elsif($i == 5) {
145 0 $red = $v;
146 0 $green = $pv;
147 0 $blue = $qv;
148 } elsif($i == 6) {
149 0 $red = $v;
150 0 $blue = $tv;
151 0 $green = $pv;
152 } elsif($i == -1) {
153 0 $red = $v;
154 0 $green = $pv;
155 0 $blue = $qv;
156 } else {
157 0 die('Invalid HSV -> RGB conversion.')
158 }
159 }
160  
161 3 return Graphics::Color::RGB->new(
162 red => $red, green => $green, blue => $blue
163 );
164 }
165  
166 4 __PACKAGE__->meta->make_immutable;
167  
168 4 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
169 4 1;
170  
171 __END__
↑ Summary Color/RGB.pm »