lib/LaTeXML/Common/Color/hsb.pm untested

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 80 CC 10 SCAR 34.5
CC
10
Cov
0%
rgb
72.0
complement
12.0
hsb
2.0
CRAP 31.5
1 # /=====================================================================\ #
2 # | LaTeXML::Common::Color::hsb | #
3 # | A representation of colors in the hsb color model | #
4 # |=====================================================================| #
5 # | Part of LaTeXML: | #
6 # | Public domain software, produced as part of work done by the | #
7 # | United States Government & not subject to copyright in the US. | #
8 # |---------------------------------------------------------------------| #
9 # | Bruce Miller <bruce.miller@nist.gov> #_# | #
10 # | http://dlmf.nist.gov/LaTeXML/ (o o) | #
11 # \=========================================================ooo==U==ooo=/ #
12 package LaTeXML::Common::Color::hsb;
13 use strict;
14 use warnings;
15 use base qw(LaTeXML::Common::Color);
16 use LaTeXML::Global;
17  
18 sub hsb { my ($self) = @_; return $self; }
19  
20 sub rgb {
21 my ($self) = @_;
22 my ($model, $h, $s, $b) = @$self;
23 my $i = int(6 * $h);
24 my $f = 6 * $h - $i;
25 my $u = $b * (1 - $s * (1 - $f));
26 my $v = $b * (1 - $s * $f);
27 my $w = $b * (1 - $s);
28 if ($i == 0) { return LaTeXML::Common::Color->new('rgb', $b, $u, $w); }
29 elsif ($i == 1) { return LaTeXML::Common::Color->new('rgb', $v, $b, $w); }
30 elsif ($i == 2) { return LaTeXML::Common::Color->new('rgb', $w, $b, $u); }
31 elsif ($i == 3) { return LaTeXML::Common::Color->new('rgb', $w, $v, $b); }
32 elsif ($i == 4) { return LaTeXML::Common::Color->new('rgb', $u, $w, $b); }
33 elsif ($i == 5) { return LaTeXML::Common::Color->new('rgb', $b, $w, $v); }
34 elsif ($i == 6) { return LaTeXML::Common::Color->new('rgb', $b, $w, $w); } }
35  
36 sub cmy { my ($self) = @_; return $self->rgb->cmy; }
37 sub cmyk { my ($self) = @_; return $self->rgb->cmyk; }
38 sub gray { my ($self) = @_; return $self->rgb->gray; }
39  
40 sub complement {
41 my ($self) = @_;
42 my ($h, $s, $b) = $self->components;
43 my $hp = ($h < 0.5 ? $h + 0.5 : $h - 0.5);
44 my $bp = 1 - $b * (1 - $s);
45 my $sp = ($bp == 0 ? 0 : $b * $s / $bp);
46 return $self->new($hp, $sp, $bp); }
47  
48 sub mix {
49 my ($self, $color, $fraction) = @_;
50 # I don't quite follow what Kern's saying, on a quick read,
51 # so we'll punt by doing the conversion in rgb space, then converting back.
52 return $self->rgb->mix($color, $fraction)->hsb; }
53  
54 #======================================================================
55 1;
56  
57 __END__