color 1.7.1 → 2.0.0.pre.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -13
- data/CHANGELOG.md +298 -0
- data/CODE_OF_CONDUCT.md +128 -0
- data/CONTRIBUTING.md +70 -0
- data/CONTRIBUTORS.md +10 -0
- data/LICENCE.md +27 -0
- data/Manifest.txt +11 -21
- data/README.md +54 -0
- data/Rakefile +74 -53
- data/SECURITY.md +34 -0
- data/lib/color/cielab.rb +348 -0
- data/lib/color/cmyk.rb +279 -213
- data/lib/color/grayscale.rb +128 -160
- data/lib/color/hsl.rb +205 -173
- data/lib/color/rgb/colors.rb +177 -163
- data/lib/color/rgb.rb +534 -537
- data/lib/color/version.rb +5 -0
- data/lib/color/xyz.rb +214 -0
- data/lib/color/yiq.rb +91 -46
- data/lib/color.rb +208 -141
- data/test/fixtures/cielab.json +444 -0
- data/test/minitest_helper.rb +20 -4
- data/test/test_cmyk.rb +49 -71
- data/test/test_color.rb +58 -106
- data/test/test_grayscale.rb +35 -56
- data/test/test_hsl.rb +72 -76
- data/test/test_rgb.rb +195 -267
- data/test/test_yiq.rb +12 -30
- metadata +165 -150
- checksums.yaml.gz.sig +0 -0
- data/.autotest +0 -5
- data/.gemtest +0 -0
- data/.hoerc +0 -2
- data/.minitest.rb +0 -2
- data/.travis.yml +0 -35
- data/Contributing.rdoc +0 -60
- data/Gemfile +0 -9
- data/History.rdoc +0 -172
- data/Licence.rdoc +0 -27
- data/README.rdoc +0 -50
- data/lib/color/css.rb +0 -7
- data/lib/color/palette/adobecolor.rb +0 -260
- data/lib/color/palette/gimp.rb +0 -104
- data/lib/color/palette/monocontrast.rb +0 -164
- data/lib/color/palette.rb +0 -4
- data/lib/color/rgb/contrast.rb +0 -57
- data/lib/color/rgb/metallic.rb +0 -28
- data/test/test_adobecolor.rb +0 -405
- data/test/test_css.rb +0 -19
- data/test/test_gimp.rb +0 -87
- data/test/test_monocontrast.rb +0 -130
- data.tar.gz.sig +0 -0
- metadata.gz.sig +0 -0
data/test/test_color.rb
CHANGED
@@ -1,128 +1,80 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "color"
|
4
|
+
require "minitest_helper"
|
5
5
|
|
6
6
|
module TestColor
|
7
7
|
class TestColor < Minitest::Test
|
8
8
|
def setup
|
9
|
-
|
10
|
-
alias old_warn warn
|
11
|
-
|
12
|
-
def warn(message)
|
13
|
-
$last_warn = message
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def teardown
|
19
|
-
Kernel.module_eval do
|
20
|
-
undef warn
|
21
|
-
alias warn old_warn
|
22
|
-
undef old_warn
|
23
|
-
end
|
9
|
+
@subject = Object.new.extend(Color)
|
24
10
|
end
|
25
11
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
$last_warn = nil # Do this twice to make sure it always happens...
|
32
|
-
assert(Color::AliceBlue)
|
33
|
-
assert_equal("Color::AliceBlue has been deprecated. Use Color::RGB::AliceBlue instead.", $last_warn)
|
34
|
-
|
35
|
-
$last_warn = nil
|
36
|
-
assert_equal(Color::COLOR_VERSION, Color::VERSION)
|
37
|
-
assert_equal("Color::VERSION has been deprecated. Use Color::COLOR_VERSION instead.", $last_warn)
|
38
|
-
|
39
|
-
$last_warn = nil
|
40
|
-
assert_equal(Color::COLOR_VERSION, Color::COLOR_TOOLS_VERSION)
|
41
|
-
assert_equal("Color::COLOR_TOOLS_VERSION has been deprecated. Use Color::COLOR_VERSION instead.", $last_warn)
|
42
|
-
|
43
|
-
$last_warn = nil
|
44
|
-
assert(Color::COLOR_VERSION)
|
45
|
-
assert_nil($last_warn)
|
46
|
-
assert(Color::COLOR_EPSILON)
|
47
|
-
assert_nil($last_warn)
|
48
|
-
|
49
|
-
assert_raises(NameError) { assert(Color::MISSING_VALUE) }
|
50
|
-
end
|
12
|
+
# def test_equivalent
|
13
|
+
# assert Color.equivalent?(Color::RGB::Red, Color::HSL.from_values(0, 100, 50))
|
14
|
+
# refute Color.equivalent?(Color::RGB::Red, nil)
|
15
|
+
# refute Color.equivalent?(nil, Color::RGB::Red)
|
16
|
+
# end
|
51
17
|
|
52
18
|
def test_normalize
|
19
|
+
normalize = @subject.method(:normalize)
|
20
|
+
|
53
21
|
(1..10).each do |i|
|
54
|
-
assert_equal(0.0,
|
55
|
-
assert_equal(0.0,
|
56
|
-
assert_equal(0.0,
|
57
|
-
assert_equal(1.0,
|
58
|
-
assert_equal(1.0,
|
59
|
-
assert_equal(1.0,
|
22
|
+
assert_equal(0.0, normalize.call(-7 * i))
|
23
|
+
assert_equal(0.0, normalize.call(-7 / i))
|
24
|
+
assert_equal(0.0, normalize.call(0 - i))
|
25
|
+
assert_equal(1.0, normalize.call(255 + i))
|
26
|
+
assert_equal(1.0, normalize.call(256 * i))
|
27
|
+
assert_equal(1.0, normalize.call(65536 / i))
|
60
28
|
end
|
29
|
+
|
61
30
|
(0..255).each do |i|
|
62
|
-
assert_in_delta(i / 255.0,
|
63
|
-
1e-2)
|
31
|
+
assert_in_delta(i / 255.0, normalize.call(i / 255.0), 1e-2)
|
64
32
|
end
|
65
33
|
end
|
66
34
|
|
67
|
-
def
|
68
|
-
|
69
|
-
assert_equal(0, Color.normalize_8bit(0))
|
70
|
-
assert_equal(127, Color.normalize_8bit(127))
|
71
|
-
assert_equal(172, Color.normalize_8bit(172))
|
72
|
-
assert_equal(255, Color.normalize_8bit(255))
|
73
|
-
assert_equal(255, Color.normalize_8bit(256))
|
74
|
-
|
75
|
-
assert_equal(0, Color.normalize_16bit(-1))
|
76
|
-
assert_equal(0, Color.normalize_16bit(0))
|
77
|
-
assert_equal(127, Color.normalize_16bit(127))
|
78
|
-
assert_equal(172, Color.normalize_16bit(172))
|
79
|
-
assert_equal(255, Color.normalize_16bit(255))
|
80
|
-
assert_equal(256, Color.normalize_16bit(256))
|
81
|
-
assert_equal(65535, Color.normalize_16bit(65535))
|
82
|
-
assert_equal(65535, Color.normalize_16bit(66536))
|
35
|
+
def test_normalize_byte
|
36
|
+
normalize_byte = @subject.method(:normalize_byte)
|
83
37
|
|
84
|
-
assert_equal(
|
85
|
-
assert_equal(
|
86
|
-
assert_equal(
|
87
|
-
assert_equal(
|
88
|
-
assert_equal(
|
89
|
-
assert_equal(
|
90
|
-
assert_equal(-50.5, Color.normalize_to_range(-50.5, -100..100))
|
91
|
-
assert_equal(0, Color.normalize_to_range(0, -100..100))
|
92
|
-
assert_equal(50, Color.normalize_to_range(50, -100..100))
|
93
|
-
assert_equal(50.5, Color.normalize_to_range(50.5, -100..100))
|
94
|
-
assert_equal(99, Color.normalize_to_range(99, -100..100))
|
95
|
-
assert_equal(99.5, Color.normalize_to_range(99.5, -100..100))
|
96
|
-
assert_equal(100, Color.normalize_to_range(100, -100..100))
|
97
|
-
assert_equal(100, Color.normalize_to_range(100.0, -100..100))
|
98
|
-
assert_equal(100, Color.normalize_to_range(100.5, -100..100))
|
99
|
-
assert_equal(100, Color.normalize_to_range(101, -100..100))
|
38
|
+
assert_equal(0, normalize_byte.call(-1))
|
39
|
+
assert_equal(0, normalize_byte.call(0))
|
40
|
+
assert_equal(127, normalize_byte.call(127))
|
41
|
+
assert_equal(172, normalize_byte.call(172))
|
42
|
+
assert_equal(255, normalize_byte.call(255))
|
43
|
+
assert_equal(255, normalize_byte.call(256))
|
100
44
|
end
|
101
45
|
|
102
|
-
def
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
assert_equal(
|
107
|
-
assert_equal(
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
assert_equal(
|
113
|
-
|
114
|
-
|
115
|
-
$last_warn = nil
|
116
|
-
c = Color.new([10, 20, 30], :hsl)
|
117
|
-
assert_kind_of(Color::HSL, c)
|
118
|
-
assert_equal(Color::HSL.new(10, 20, 30), c)
|
119
|
-
assert_equal("Color.new has been deprecated. Use Color::HSL.new instead.", $last_warn)
|
46
|
+
def test_normalize_word
|
47
|
+
normalize_word = @subject.method(:normalize_word)
|
48
|
+
|
49
|
+
assert_equal(0, normalize_word.call(-1))
|
50
|
+
assert_equal(0, normalize_word.call(0))
|
51
|
+
assert_equal(127, normalize_word.call(127))
|
52
|
+
assert_equal(172, normalize_word.call(172))
|
53
|
+
assert_equal(255, normalize_word.call(255))
|
54
|
+
assert_equal(256, normalize_word.call(256))
|
55
|
+
assert_equal(65535, normalize_word.call(65535))
|
56
|
+
assert_equal(65535, normalize_word.call(66536))
|
57
|
+
end
|
120
58
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
assert_equal(
|
125
|
-
assert_equal(
|
59
|
+
def test_normalize_range
|
60
|
+
normalize_to_range = @subject.method(:normalize_to_range)
|
61
|
+
|
62
|
+
assert_equal(-100, normalize_to_range.call(-101, -100..100))
|
63
|
+
assert_equal(-100, normalize_to_range.call(-100.5, -100..100))
|
64
|
+
assert_equal(-100, normalize_to_range.call(-100, -100..100))
|
65
|
+
assert_equal(-100, normalize_to_range.call(-100.0, -100..100))
|
66
|
+
assert_equal(-99.5, normalize_to_range.call(-99.5, -100..100))
|
67
|
+
assert_equal(-50, normalize_to_range.call(-50, -100..100))
|
68
|
+
assert_equal(-50.5, normalize_to_range.call(-50.5, -100..100))
|
69
|
+
assert_equal(0, normalize_to_range.call(0, -100..100))
|
70
|
+
assert_equal(50, normalize_to_range.call(50, -100..100))
|
71
|
+
assert_equal(50.5, normalize_to_range.call(50.5, -100..100))
|
72
|
+
assert_equal(99, normalize_to_range.call(99, -100..100))
|
73
|
+
assert_equal(99.5, normalize_to_range.call(99.5, -100..100))
|
74
|
+
assert_equal(100, normalize_to_range.call(100, -100..100))
|
75
|
+
assert_equal(100, normalize_to_range.call(100.0, -100..100))
|
76
|
+
assert_equal(100, normalize_to_range.call(100.5, -100..100))
|
77
|
+
assert_equal(100, normalize_to_range.call(101, -100..100))
|
126
78
|
end
|
127
79
|
end
|
128
80
|
end
|
data/test/test_grayscale.rb
CHANGED
@@ -1,105 +1,84 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "color"
|
4
|
+
require "minitest_helper"
|
5
5
|
|
6
6
|
module TestColor
|
7
|
-
class
|
7
|
+
class TestGrayscale < Minitest::Test
|
8
8
|
def setup
|
9
|
-
@gs = Color::
|
9
|
+
@gs = Color::Grayscale.from_percentage(33)
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_brightness
|
13
|
-
|
13
|
+
assert_in_tolerance(0.33, @gs.brightness)
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_darken_by
|
17
|
-
|
17
|
+
assert_in_tolerance(29.7, @gs.darken_by(10).gray)
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_g
|
21
|
-
|
22
|
-
|
23
|
-
@gs.gray = 40
|
24
|
-
|
25
|
-
@gs.g = 2.0
|
26
|
-
|
27
|
-
@gs.
|
28
|
-
|
21
|
+
assert_in_tolerance(0.33, @gs.g)
|
22
|
+
assert_in_tolerance(33, @gs.gray)
|
23
|
+
# @gs.gray = 40
|
24
|
+
# assert_in_tolerance(0.4, @gs.g)
|
25
|
+
# @gs.g = 2.0
|
26
|
+
# assert_in_tolerance(100, @gs.gray)
|
27
|
+
# @gs.gray = -2.0
|
28
|
+
# assert_in_tolerance(0.0, @gs.g)
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
31
|
+
def test_css
|
32
32
|
assert_equal("#545454", @gs.html)
|
33
|
-
assert_equal("rgb(33.00
|
34
|
-
assert_equal("
|
33
|
+
assert_equal("rgb(33.00% 33.00% 33.00%)", @gs.css)
|
34
|
+
assert_equal("rgb(33.00% 33.00% 33.00% / 1.00)", @gs.css(alpha: 1))
|
35
|
+
assert_equal("rgb(33.00% 33.00% 33.00% / 0.20)", @gs.css(alpha: 0.2))
|
35
36
|
end
|
36
37
|
|
37
38
|
def test_lighten_by
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_pdf_fill
|
42
|
-
assert_equal("0.330 g", @gs.pdf_fill)
|
43
|
-
assert_equal("0.330 G", @gs.pdf_stroke)
|
39
|
+
assert_in_tolerance(0.363, @gs.lighten_by(10).g)
|
44
40
|
end
|
45
41
|
|
46
42
|
def test_to_cmyk
|
47
43
|
cmyk = @gs.to_cmyk
|
48
44
|
assert_kind_of(Color::CMYK, cmyk)
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
45
|
+
assert_in_tolerance(0.0, cmyk.c)
|
46
|
+
assert_in_tolerance(0.0, cmyk.m)
|
47
|
+
assert_in_tolerance(0.0, cmyk.y)
|
48
|
+
assert_in_tolerance(0.67, cmyk.k)
|
53
49
|
end
|
54
50
|
|
55
51
|
def test_to_grayscale
|
56
52
|
assert_equal(@gs, @gs.to_grayscale)
|
57
|
-
assert_equal(@gs, @gs.
|
53
|
+
assert_equal(@gs, @gs.to_grayscale)
|
58
54
|
end
|
59
55
|
|
60
56
|
def test_to_hsl
|
61
57
|
hsl = @gs.to_hsl
|
62
58
|
assert_kind_of(Color::HSL, hsl)
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
assert_equal("hsl(0.00, 0.00%, 33.00%)", @gs.css_hsl)
|
67
|
-
assert_equal("hsla(0.00, 0.00%, 33.00%, 1.00)", @gs.css_hsla)
|
59
|
+
assert_in_tolerance(0.0, hsl.h)
|
60
|
+
assert_in_tolerance(0.0, hsl.s)
|
61
|
+
assert_in_tolerance(0.33, hsl.l)
|
68
62
|
end
|
69
63
|
|
70
64
|
def test_to_rgb
|
71
65
|
rgb = @gs.to_rgb
|
72
66
|
assert_kind_of(Color::RGB, rgb)
|
73
|
-
|
74
|
-
|
75
|
-
|
67
|
+
assert_in_tolerance(0.33, rgb.r)
|
68
|
+
assert_in_tolerance(0.33, rgb.g)
|
69
|
+
assert_in_tolerance(0.33, rgb.b)
|
76
70
|
end
|
77
71
|
|
78
72
|
def test_to_yiq
|
79
73
|
yiq = @gs.to_yiq
|
80
74
|
assert_kind_of(Color::YIQ, yiq)
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_add
|
87
|
-
delta = @gs + Color::GrayScale.new(20)
|
88
|
-
max = @gs + Color::GrayScale.new(80)
|
89
|
-
|
90
|
-
assert_in_delta(1.0, max.g, Color::COLOR_TOLERANCE)
|
91
|
-
assert_in_delta(0.53, delta.g, Color::COLOR_TOLERANCE)
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_subtract
|
95
|
-
delta = @gs - Color::GrayScale.new(20)
|
96
|
-
max = @gs - Color::GrayScale.new(80)
|
97
|
-
assert_in_delta(0.0, max.g, Color::COLOR_TOLERANCE)
|
98
|
-
assert_in_delta(0.13, delta.g, Color::COLOR_TOLERANCE)
|
75
|
+
assert_in_tolerance(0.33, yiq.y)
|
76
|
+
assert_in_tolerance(0.0, yiq.i)
|
77
|
+
assert_in_tolerance(0.0, yiq.q)
|
99
78
|
end
|
100
79
|
|
101
80
|
def test_inspect
|
102
|
-
assert_equal("
|
81
|
+
assert_equal("Grayscale [33.00%]", @gs.inspect)
|
103
82
|
end
|
104
83
|
end
|
105
84
|
end
|
data/test/test_hsl.rb
CHANGED
@@ -1,135 +1,131 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "color"
|
4
|
+
require "minitest_helper"
|
5
5
|
|
6
6
|
module TestColor
|
7
7
|
class TestHSL < Minitest::Test
|
8
8
|
def setup
|
9
|
-
|
10
|
-
@hsl = Color::HSL.new(145, 20, 30)
|
11
|
-
# @rgb = Color::RGB.new(88, 35, 179)
|
9
|
+
@hsl = Color::HSL.from_values(145, 20, 30)
|
12
10
|
end
|
13
11
|
|
14
12
|
def test_rgb_roundtrip_conversion
|
15
|
-
hsl = Color::HSL.
|
13
|
+
hsl = Color::HSL.from_values(262, 67, 42)
|
16
14
|
c = hsl.to_rgb.to_hsl
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
assert_in_tolerance hsl.h, c.h, "Hue"
|
16
|
+
assert_in_tolerance hsl.s, c.s, "Saturation"
|
17
|
+
assert_in_tolerance hsl.l, c.l, "Luminance"
|
20
18
|
end
|
21
19
|
|
22
20
|
def test_brightness
|
23
|
-
|
21
|
+
assert_in_tolerance 0.3, @hsl.brightness
|
24
22
|
end
|
25
23
|
|
26
24
|
def test_hue
|
27
|
-
|
28
|
-
|
29
|
-
@hsl.hue = 33
|
30
|
-
|
31
|
-
@hsl.hue = -33
|
32
|
-
|
33
|
-
@hsl.h = 3.3
|
34
|
-
|
35
|
-
@hsl.h = -3.3
|
36
|
-
|
37
|
-
@hsl.hue = 0
|
38
|
-
@hsl.hue -= 20
|
39
|
-
|
40
|
-
@hsl.hue += 45
|
41
|
-
|
25
|
+
assert_in_tolerance 0.4027, @hsl.h
|
26
|
+
assert_in_tolerance 145, @hsl.hue
|
27
|
+
# @hsl.hue = 33
|
28
|
+
# assert_in_tolerance 0.09167, @hsl.h
|
29
|
+
# @hsl.hue = -33
|
30
|
+
# assert_in_tolerance 0.90833, @hsl.h
|
31
|
+
# @hsl.h = 3.3
|
32
|
+
# assert_in_tolerance 360, @hsl.hue
|
33
|
+
# @hsl.h = -3.3
|
34
|
+
# assert_in_tolerance 0.0, @hsl.h
|
35
|
+
# @hsl.hue = 0
|
36
|
+
# @hsl.hue -= 20
|
37
|
+
# assert_in_tolerance 340, @hsl.hue
|
38
|
+
# @hsl.hue += 45
|
39
|
+
# assert_in_tolerance 25, @hsl.hue
|
42
40
|
end
|
43
41
|
|
44
42
|
def test_saturation
|
45
|
-
|
46
|
-
|
47
|
-
@hsl.saturation = 33
|
48
|
-
|
49
|
-
@hsl.s = 3.3
|
50
|
-
|
51
|
-
@hsl.s = -3.3
|
52
|
-
|
43
|
+
assert_in_tolerance 0.2, @hsl.s
|
44
|
+
assert_in_tolerance 20, @hsl.saturation
|
45
|
+
# @hsl.saturation = 33
|
46
|
+
# assert_in_tolerance 0.33, @hsl.s
|
47
|
+
# @hsl.s = 3.3
|
48
|
+
# assert_in_tolerance 100, @hsl.saturation
|
49
|
+
# @hsl.s = -3.3
|
50
|
+
# assert_in_tolerance 0.0, @hsl.s
|
53
51
|
end
|
54
52
|
|
55
53
|
def test_luminance
|
56
|
-
|
57
|
-
|
58
|
-
@hsl.luminosity = 33
|
59
|
-
|
60
|
-
@hsl.l = 3.3
|
61
|
-
|
62
|
-
@hsl.l = -3.3
|
63
|
-
|
54
|
+
assert_in_tolerance 0.3, @hsl.l
|
55
|
+
assert_in_tolerance 30, @hsl.luminosity
|
56
|
+
# @hsl.luminosity = 33
|
57
|
+
# assert_in_tolerance 0.33, @hsl.l
|
58
|
+
# @hsl.l = 3.3
|
59
|
+
# assert_in_tolerance 100, @hsl.lightness
|
60
|
+
# @hsl.l = -3.3
|
61
|
+
# assert_in_tolerance 0.0, @hsl.l
|
64
62
|
end
|
65
63
|
|
66
|
-
def
|
67
|
-
assert_equal "hsl(145.
|
68
|
-
assert_equal "
|
64
|
+
def test_css
|
65
|
+
assert_equal "hsl(145.00deg 20.00% 30.00%)", @hsl.css
|
66
|
+
assert_equal "hsl(145.00deg 20.00% 30.00% / 1.00)", @hsl.css(alpha: 1)
|
69
67
|
end
|
70
68
|
|
71
69
|
def test_to_cmyk
|
72
70
|
cmyk = @hsl.to_cmyk
|
73
71
|
assert_kind_of Color::CMYK, cmyk
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
72
|
+
assert_in_tolerance 0.3223, cmyk.c
|
73
|
+
assert_in_tolerance 0.2023, cmyk.m
|
74
|
+
assert_in_tolerance 0.2723, cmyk.y
|
75
|
+
assert_in_tolerance 0.4377, cmyk.k
|
78
76
|
end
|
79
77
|
|
80
78
|
def test_to_grayscale
|
81
79
|
gs = @hsl.to_grayscale
|
82
|
-
assert_kind_of Color::
|
83
|
-
|
80
|
+
assert_kind_of Color::Grayscale, gs
|
81
|
+
assert_in_tolerance 30, gs.gray
|
84
82
|
end
|
85
83
|
|
86
84
|
def test_to_rgb
|
87
85
|
rgb = @hsl.to_rgb
|
88
86
|
assert_kind_of Color::RGB, rgb
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
assert_equal "rgb(24.00%, 36.00%, 29.00%)", @hsl.css_rgb
|
94
|
-
assert_equal "rgba(24.00%, 36.00%, 29.00%, 1.00)", @hsl.css_rgba
|
87
|
+
assert_in_tolerance 0.24, rgb.r
|
88
|
+
assert_in_tolerance 0.36, rgb.g
|
89
|
+
assert_in_tolerance 0.29, rgb.b
|
90
|
+
|
95
91
|
# The following tests address a bug reported by Jean Krohn on June 6,
|
96
|
-
# 2006 and
|
97
|
-
assert_equal Color::RGB::Black, Color::HSL.
|
98
|
-
assert_equal Color::RGB::White, Color::HSL.
|
99
|
-
assert_equal Color::RGB::Gray80, Color::HSL.
|
92
|
+
# 2006 and exercise some previously unexercised code in to_rgb.
|
93
|
+
assert_equal Color::RGB::Black, Color::HSL.from_values(75, 75, 0)
|
94
|
+
assert_equal Color::RGB::White, Color::HSL.from_values(75, 75, 100)
|
95
|
+
assert_equal Color::RGB::Gray80, Color::HSL.from_values(75, 0, 80)
|
100
96
|
|
101
97
|
# The following tests a bug reported by Adam Johnson on 29 October
|
102
98
|
# 2010.
|
103
99
|
rgb = Color::RGB.from_fraction(0.34496, 0.1386, 0.701399)
|
104
|
-
c = Color::HSL.
|
105
|
-
|
106
|
-
|
107
|
-
|
100
|
+
c = Color::HSL.from_values(262, 67, 42).to_rgb
|
101
|
+
assert_in_tolerance rgb.r, c.r, "Red"
|
102
|
+
assert_in_tolerance rgb.g, c.g, "Green"
|
103
|
+
assert_in_tolerance rgb.b, c.b, "Blue"
|
108
104
|
end
|
109
105
|
|
110
106
|
def test_to_yiq
|
111
107
|
yiq = @hsl.to_yiq
|
112
108
|
assert_kind_of Color::YIQ, yiq
|
113
|
-
|
114
|
-
|
115
|
-
|
109
|
+
assert_in_tolerance 0.3161, yiq.y
|
110
|
+
assert_in_tolerance 0.0, yiq.i
|
111
|
+
assert_in_tolerance 0.0, yiq.q
|
116
112
|
end
|
117
113
|
|
118
114
|
def test_mix_with
|
119
|
-
red
|
120
|
-
yellow
|
121
|
-
|
122
|
-
|
115
|
+
red = Color::RGB::Red.to_hsl
|
116
|
+
yellow = Color::RGB::Yellow.to_hsl
|
117
|
+
assert_in_tolerance 0, red.hue
|
118
|
+
assert_in_tolerance 60, yellow.hue
|
123
119
|
ry25 = red.mix_with yellow, 0.25
|
124
|
-
|
120
|
+
assert_in_tolerance 15, ry25.hue
|
125
121
|
ry50 = red.mix_with yellow, 0.50
|
126
|
-
|
122
|
+
assert_in_tolerance 30, ry50.hue
|
127
123
|
ry75 = red.mix_with yellow, 0.75
|
128
|
-
|
124
|
+
assert_in_tolerance 45, ry75.hue
|
129
125
|
end
|
130
126
|
|
131
127
|
def test_inspect
|
132
|
-
assert_equal "HSL [145.
|
128
|
+
assert_equal "HSL [145.00deg 20.00% 30.00%]", @hsl.inspect
|
133
129
|
end
|
134
130
|
end
|
135
131
|
end
|