color 2.1.1 → 2.2.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.
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # Color -- Color Math in Ruby
2
2
 
3
+ [![RubyGems Version][shield-gems]][rubygems] ![Coveralls][shield-coveralls]
4
+ [![Build Status][shield-ci]][ci-workflow]
5
+
3
6
  - code :: <https://github.com/halostatue/color>
4
7
  - issues :: <https://github.com/halostatue/color/issues>
8
+ - docs :: <https://halostatue.github.io/color/>
5
9
  - changelog :: <https://github.com/halostatue/color/blob/main/CHANGELOG.md>
6
- - continuous integration ::
7
- [![Build Status](https://github.com/halostatue/color/actions/workflows/ci.yml/badge.svg)][ci-workflow]
8
- - test coverage ::
9
- [![Coverage](https://coveralls.io/repos/halostatue/color/badge.svg?branch=main&service=github)][coveralls]
10
10
 
11
11
  ## Description
12
12
 
@@ -22,11 +22,11 @@ reliably converted to relative color spaces (like RGB) without color profiles.
22
22
  When necessary for conversions, Color provides D65 and D50 reference white
23
23
  values in Color::XYZ.
24
24
 
25
- Color 2.1 fixes a Color::XYZ bug where the values were improperly clamped and
26
- adds more Color::XYZ white points for standard illuminants. It builds on the
27
- Color 2.0 major release, dropping support for all versions of Ruby prior to 3.2
28
- as well as removing or renaming a number of features. The main breaking changes
29
- are:
25
+ Color 2.2 adds a minor feature where an RGB color created from values can
26
+ silently inherit the `#name` of a predefined color if `color/rgb/colors` has
27
+ already been loaded. It builds on the Color 2.0 major release, dropping support
28
+ for all versions of Ruby prior to 3.2 as well as removing or renaming a number
29
+ of features. The main breaking changes are:
30
30
 
31
31
  - Color classes are immutable Data objects; they are no longer mutable.
32
32
  - RGB named colors are no longer loaded on gem startup, but must be required
@@ -52,5 +52,16 @@ end
52
52
  c.to_rgb
53
53
  ```
54
54
 
55
+ ## Color Semantic Versioning
56
+
57
+ The Color library uses a [Semantic Versioning][semver] scheme with one change:
58
+
59
+ - When PATCH is zero (`0`), it will be omitted from version references.
60
+
55
61
  [ci-workflow]: https://github.com/halostatue/color/actions/workflows/ci.yml
56
62
  [coveralls]: https://coveralls.io/github/halostatue/color?branch=main
63
+ [rubygems]: https://rubygems.org/gems/color
64
+ [semver]: https://semver.org/
65
+ [shield-ci]: https://img.shields.io/github/actions/workflow/status/halostatue/color/ci.yml?style=for-the-badge "Build Status"
66
+ [shield-coveralls]: https://img.shields.io/coverallsCoverage/github/halostatue/color?style=for-the-badge
67
+ [shield-gems]: https://img.shields.io/gem/v/color?style=for-the-badge "Version"
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rubygems"
2
4
  require "hoe"
3
5
  require "rake/clean"
@@ -6,7 +8,6 @@ require "minitest"
6
8
  require "minitest/test_task"
7
9
 
8
10
  Hoe.plugin :halostatue
9
- Hoe.plugin :rubygems
10
11
 
11
12
  Hoe.plugins.delete :debug
12
13
  Hoe.plugins.delete :newb
@@ -29,18 +30,16 @@ hoe = Hoe.spec "color" do
29
30
  }
30
31
 
31
32
  extra_dev_deps << ["hoe", "~> 4.0"]
32
- extra_dev_deps << ["hoe-halostatue", "~> 2.1", ">= 2.1.1"]
33
- extra_dev_deps << ["hoe-git", "~> 1.6"]
34
- extra_dev_deps << ["minitest", "~> 5.8"]
33
+ extra_dev_deps << ["hoe-halostatue", "~> 3.0"]
34
+ extra_dev_deps << ["json", ">= 0.0"]
35
+ extra_dev_deps << ["minitest", "~> 6.0"]
35
36
  extra_dev_deps << ["minitest-autotest", "~> 1.0"]
36
37
  extra_dev_deps << ["minitest-focus", "~> 1.1"]
37
- extra_dev_deps << ["minitest-moar", "~> 0.0"]
38
38
  extra_dev_deps << ["rake", ">= 10.0", "< 14"]
39
- extra_dev_deps << ["rdoc", ">= 0.0", "< 7"]
40
- extra_dev_deps << ["standard", "~> 1.0"]
41
- extra_dev_deps << ["json", ">= 0.0"]
39
+ extra_dev_deps << ["rdoc", ">= 6.0", "< 8"]
42
40
  extra_dev_deps << ["simplecov", "~> 0.22"]
43
41
  extra_dev_deps << ["simplecov-lcov", "~> 0.8"]
42
+ extra_dev_deps << ["standard", "~> 1.50"]
44
43
  end
45
44
 
46
45
  Minitest::TestTask.create :test
data/SECURITY.md CHANGED
@@ -1,4 +1,4 @@
1
- # color Security
1
+ # color Security Policy
2
2
 
3
3
  ## LLM-Generated Security Report Policy
4
4
 
@@ -8,32 +8,23 @@ agents.
8
8
  ## Supported Versions
9
9
 
10
10
  Security reports are accepted for the most recent major release and the previous
11
- version for a limited time after the initial major release version. After a
12
- major release, the previous version will receive full support for three months
13
- and security support for an additional three months (for a total of six months).
11
+ version for a limited time after the initial major release version.
12
+
13
+ After a major release, the previous version will receive full support for three
14
+ months and security support for an additional three months (for a total of six
15
+ months).
14
16
 
15
17
  Because color 1.x supports a wide range of Ruby versions that are themselves end
16
18
  of life, security reports will only be accepted when they can be demonstrated on
17
19
  Ruby 3.2 or higher.
18
20
 
19
- > | Version | Release Date | Support Ends | Security Support Ends |
20
- > | ------- | ------------ | -------------- | --------------------- |
21
- > | 1.x | 2015-10-26 | 2.x + 3 months | 2.x + 6 months |
22
- > | 2.x | 2025-MM-DD | - | - |
21
+ > | Version | Release Date | Support Ends | Security Support Ends |
22
+ > | ------- | ------------ | ------------ | --------------------- |
23
+ > | 1.x | 2015-10-26 | 2025-11-07 | 2026-02-07 |
24
+ > | 2.x | 2025-08-07 | - | - |
23
25
 
24
26
  ## Reporting a Vulnerability
25
27
 
26
- By preference, use the [Tidelift security contact][tidelift]. Tidelift will
27
- coordinate the fix and disclosure.
28
-
29
- Alternatively, Send an email to [color@halostatue.ca][email] with the text
30
- `Color` in the subject. Emails sent to this address should be encrypted using
31
- [age][age] with the following public key:
32
-
33
- ```
34
- age1fc6ngxmn02m62fej5cl30lrvwmxn4k3q2atqu53aatekmnqfwumqj4g93w
35
- ```
28
+ Create a [private vulnerability report][advisory] with GitHub.
36
29
 
37
- [tidelift]: https://tidelift.com/security
38
- [email]: mailto:color@halostatue.ca
39
- [age]: https://github.com/FiloSottile/age
30
+ [advisory]: https://github.com/halostatue/color/security/advisories/new
data/lib/color/cielab.rb CHANGED
@@ -140,7 +140,7 @@ class Color::CIELAB
140
140
  fx = a / 500.0 + fy
141
141
 
142
142
  xr = ((fx3 = fx**3) > Color::XYZ::E) ? fx3 : (116.0 * fx - 16) / Color::XYZ::K
143
- yr = (l > Color::XYZ::EK) ? ((l + 16.0) / 116)**3 : l
143
+ yr = (l > Color::XYZ::EK) ? ((l + 16.0) / 116)**3 : l / Color::XYZ::K
144
144
  zr = ((fz3 = fz**3) > Color::XYZ::E) ? fz3 : (116.0 * fz - 16) / Color::XYZ::K
145
145
 
146
146
  ref = kwargs[:white] || args.first
@@ -149,6 +149,10 @@ class Color::CIELAB
149
149
  ref.scale(xr, yr, zr)
150
150
  end
151
151
 
152
+ ##
153
+ # Converts \CIELAB to Color::YIQ via Color::XYZ.
154
+ def to_yiq(...) = to_xyz(...).to_yiq(...)
155
+
152
156
  ##
153
157
  # Render the CSS `lab()` function for this \CIELAB object, adding an `alpha` if
154
158
  # provided.
data/lib/color/cmyk.rb CHANGED
@@ -255,14 +255,13 @@ class Color::CMYK
255
255
  q.text "CMYK"
256
256
  q.breakable
257
257
  q.group 2, "[", "]" do
258
- q.text ".2f%%" % cyan
258
+ q.text "%.2f%%" % cyan
259
259
  q.fill_breakable
260
- q.text ".2f%%" % magenta
260
+ q.text "%.2f%%" % magenta
261
261
  q.fill_breakable
262
- q.text ".2f%%" % yellow
263
- q.fill_breakable
264
- q.text ".2f%%" % key
262
+ q.text "%.2f%%" % yellow
265
263
  q.fill_breakable
264
+ q.text "%.2f%%" % key
266
265
  end
267
266
  end
268
267
 
@@ -81,6 +81,10 @@ class Color::Grayscale
81
81
  ##
82
82
  def to_grayscale(...) = self
83
83
 
84
+ ##
85
+ # Converts \Grayscale to Color::XYZ via Color::RGB.
86
+ def to_xyz(...) = to_rgb(...).to_xyz(...)
87
+
84
88
  ##
85
89
  # Convert \Grayscale to Color::YIQ.
86
90
  #
data/lib/color/hsl.rb CHANGED
@@ -98,8 +98,8 @@ class Color::HSL
98
98
  # - Saturation values <= 0 always translate to a shade of gray using luminance as
99
99
  # a percentage of gray.
100
100
  #
101
- # [1] http://bobpowell.net/RGBHSB.aspx
102
- # [2] http://support.microsoft.com/kb/29240
101
+ # [1] https://web.archive.org/web/20150311023529/http://bobpowell.net/RGBHSB.aspx
102
+ # [2] https://support.microsoft.com/kb/29240
103
103
  def to_rgb(...)
104
104
  if near_zero_or_less?(l)
105
105
  Color::RGB::Black000
data/lib/color/rgb.rb CHANGED
@@ -69,13 +69,21 @@ class Color::RGB
69
69
  ##
70
70
  # :attr_reader: name
71
71
  # The primary name for this \RGB color.
72
+ #
73
+ # If there are no defined names, the color will be checked in the name registry and if
74
+ # there's a match, it will be returned.
72
75
 
73
76
  ##
74
77
  # :attr_reader: names
75
- # The names for this \RGB color.
78
+ # The defined names for this \RGB color.
76
79
 
77
80
  ##
78
- def name = names&.first # :nodoc:
81
+ def name # :nodoc:
82
+ name = names&.first
83
+ return name if name
84
+
85
+ self.class.send(:__by_hex)[hex]&.name if defined?(Color::RGB::Metallic)
86
+ end
79
87
 
80
88
  ##
81
89
  # Coerces the other Color object into \RGB.
@@ -144,7 +152,7 @@ class Color::RGB
144
152
  ##
145
153
  # Converts \RGB to Color::HSL.
146
154
  #
147
- # The conversion here is based on formulas from http://www.easyrgb.com/math.php and
155
+ # The conversion here is based on formulas from https://www.easyrgb.com/math.php and
148
156
  # elsewhere.
149
157
  def to_hsl(...)
150
158
  min, max = [r, g, b].minmax
@@ -163,7 +171,7 @@ class Color::RGB
163
171
  end
164
172
 
165
173
  # This is based on the conversion algorithm from
166
- # http://en.wikipedia.org/wiki/HSV_color_space#Conversion_from_RGB_to_HSL_or_HSV
174
+ # https://en.wikipedia.org/wiki/HSV_color_space#Conversion_from_RGB_to_HSL_or_HSV
167
175
  # Contributed by Adam Johnson
168
176
  sixth = 1 / 6.0
169
177
  if r == max # near_zero_or_less?(r - max)
@@ -192,7 +200,7 @@ class Color::RGB
192
200
  # other \RGB color spaces are currently supported.
193
201
  #
194
202
  # :call-seq:
195
- # to_xyz(color_space: :srgb)
203
+ # to_xyz(color_space: :sRGB)
196
204
  def to_xyz(*args, **kwargs)
197
205
  color_space = kwargs[:color_space] || args.first || :sRGB
198
206
 
@@ -430,7 +438,7 @@ class Color::RGB
430
438
  def max_rgb_as_grayscale = Color::Grayscale.from_fraction([r, g, b].max)
431
439
 
432
440
  ##
433
- def inspect = "RGB [#{html}]" # :nodoc:
441
+ def inspect = names ? "RGB [#{html}] {#{names.join(" ")}}" : "RGB [#{html}]" # :nodoc:
434
442
 
435
443
  ##
436
444
  def pretty_print(q) # :nodoc:
@@ -439,6 +447,17 @@ class Color::RGB
439
447
  q.group 2, "[", "]" do
440
448
  q.text html
441
449
  end
450
+
451
+ if names
452
+ q.breakable
453
+ q.group 2, "{", "}" do
454
+ last = names.last
455
+ names.each {
456
+ q.text _1
457
+ q.fill_breakable unless _1 == last
458
+ }
459
+ end
460
+ end
442
461
  end
443
462
 
444
463
  ##
data/lib/color/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Color
4
- VERSION = "2.1.1" # :nodoc:
4
+ VERSION = "2.2.0" # :nodoc:
5
5
  end
data/lib/color/xyz.rb CHANGED
@@ -214,7 +214,7 @@ class Color::XYZ
214
214
  rel = scale(1.0 / ref.x, 1.0 / ref.y, 1.0 / ref.z)
215
215
 
216
216
  # And now transform
217
- # http://en.wikipedia.org/wiki/Lab_color_space#Forward_transformation
217
+ # https://en.wikipedia.org/wiki/Lab_color_space#Forward_transformation
218
218
  # There is a brief explanation there as far as the nature of the calculations,
219
219
  # as well as a much nicer looking modeling of the algebra.
220
220
  f = rel.map { |t|
@@ -245,7 +245,7 @@ class Color::XYZ
245
245
  x * -0.9689307 + y * 1.8757561 + z * 0.0415175,
246
246
  x * 0.0557101 + y * -0.2040211 + z * 1.0569959
247
247
  ].map {
248
- if _1.abs <= 0.0031308
248
+ if _1 <= 0.0031308
249
249
  _1 * 12.92
250
250
  else
251
251
  1.055 * (_1**(1 / 2.4)) - 0.055
@@ -260,7 +260,7 @@ class Color::XYZ
260
260
 
261
261
  def to_internal = [x, y, z] # :nodoc:
262
262
 
263
- def inspect = "XYZ [#{x} #{y} #{z}]" # :nodoc:
263
+ def inspect = "XYZ [%.4f %.4f %.4f]" % [x, y, z] # :nodoc:
264
264
 
265
265
  def pretty_print(q) # :nodoc:
266
266
  q.text "XYZ"
data/lib/color/yiq.rb CHANGED
@@ -88,15 +88,15 @@ class Color::YIQ
88
88
 
89
89
  def inspect = "YIQ [%.2f%% %.2f%% %.2f%%]" % [y * 100, i * 100, q * 100] # :nodoc:
90
90
 
91
- def pretty_print(q) # :nodoc:
92
- q.text "YIQ"
93
- q.breakable
94
- q.group 2, "[", "]" do
95
- q.text "%.2f%%" % y
96
- q.fill_breakable
97
- q.text "%.2f%%" % i
98
- q.fill_breakable
99
- q.text "%.2f%%" % q
91
+ def pretty_print(pq) # :nodoc:
92
+ pq.text "YIQ"
93
+ pq.breakable
94
+ pq.group 2, "[", "]" do
95
+ pq.text "%.2f%%" % (y * 100)
96
+ pq.fill_breakable
97
+ pq.text "%.2f%%" % (i * 100)
98
+ pq.fill_breakable
99
+ pq.text "%.2f%%" % (q * 100)
100
100
  end
101
101
  end
102
102
 
@@ -3,6 +3,8 @@
3
3
  require "color"
4
4
  require "color/rgb/colors"
5
5
 
6
+ require "pp"
7
+
6
8
  gem "minitest"
7
9
  require "minitest/autorun"
8
10
  require "minitest/focus"
@@ -18,5 +20,11 @@ module Minitest::ColorExtensions
18
20
  assert_in_delta expected, actual, Color::TOLERANCE, msg
19
21
  end
20
22
 
23
+ def assert_pretty_inspect(expected, object, msg = nil)
24
+ actual = PP.pp(object, +"", 8)
25
+
26
+ assert_equal expected, actual, message(msg, nil) { diff expected, actual }
27
+ end
28
+
21
29
  Minitest::Test.send(:include, self)
22
30
  end
data/test/test_cmyk.rb CHANGED
@@ -30,31 +30,66 @@ module TestColor
30
30
  assert_in_tolerance(40, @cmyk.black)
31
31
  end
32
32
 
33
+ def test_inspect
34
+ assert_equal("CMYK [10.00% 20.00% 30.00% 40.00%]", @cmyk.inspect)
35
+ end
36
+
37
+ def test_pretty_print
38
+ assert_pretty_inspect "CMYK\n[10.00%\n 20.00%\n 30.00%\n 40.00%]\n", @cmyk
39
+ end
40
+
41
+ def test_css
42
+ assert_equal("device-cmyk(10.00% 20.00% 30.00% 40.00%, rgb(54.00% 48.00% 42.00%))", @cmyk.css)
43
+ assert_equal("device-cmyk(10.00% 20.00% 30.00% 40.00% / 0.50, rgb(54.00% 48.00% 42.00% / 0.50))", @cmyk.css(alpha: 0.5))
44
+ assert_equal("device-cmyk(10.00% 20.00% 30.00% 40.00%)", @cmyk.css(fallback: false))
45
+ assert_equal("device-cmyk(10.00% 20.00% 30.00% 40.00% / 0.50)", @cmyk.css(alpha: 0.5, fallback: false))
46
+ assert_equal("device-cmyk(10.00% 20.00% 30.00% 40.00%, rgb(0 0 100.00%))", @cmyk.css(fallback: Color::RGB::Blue))
47
+ assert_equal("device-cmyk(10.00% 20.00% 30.00% 40.00% / 0.50, rgb(0 0 100.00% / 0.50))", @cmyk.css(alpha: 0.5, fallback: Color::RGB::Blue))
48
+ assert_equal("device-cmyk(10.00% 20.00% 30.00% 40.00% / 0.50, rgb(0 0 100.00%))", @cmyk.css(alpha: 0.5, fallback: {color: Color::RGB::Blue}))
49
+ assert_equal("device-cmyk(10.00% 20.00% 30.00% 40.00% / 0.50, rgb(0 0 100.00% / 0.30))", @cmyk.css(alpha: 0.5, fallback: {color: Color::RGB::Blue, alpha: 0.3}))
50
+ assert_equal("device-cmyk(10.00% 20.00% 30.00% 40.00% / 0.50, rgb(54.00% 48.00% 42.00% / 0.30))", @cmyk.css(alpha: 0.5, fallback: {alpha: 0.3}))
51
+ end
52
+ end
53
+
54
+ class TestCMYKConversions < Minitest::Test
55
+ def setup
56
+ @cmyk = Color::CMYK.from_percentage(10, 20, 30, 40)
57
+ end
58
+
33
59
  def test_to_cmyk
34
- assert(@cmyk.to_cmyk == @cmyk)
60
+ assert_equal(@cmyk, @cmyk.to_cmyk)
61
+ assert_kind_of(Color::CMYK, @cmyk.to_cmyk)
35
62
  end
36
63
 
37
64
  def test_to_grayscale
38
65
  gs = @cmyk.to_grayscale
39
66
  assert_kind_of(Color::Grayscale, gs)
40
67
  assert_in_tolerance(0.4185, gs.g)
41
- assert_kind_of(Color::Grayscale, @cmyk.to_grayscale)
42
68
  end
43
69
 
44
- # def test_to_hsl
45
- # hsl = @cmyk.to_hsl
46
- # assert_kind_of(Color::HSL, hsl)
47
- # assert_in_tolerance(0.48, hsl.l)
48
- # assert_in_tolerance(0.125, hsl.s)
49
- # assert_in_tolerance(0.08333, hsl.h)
50
- # end
70
+ def test_to_hsl
71
+ hsl = @cmyk.to_hsl
72
+ assert_kind_of(Color::HSL, hsl)
73
+ assert_in_tolerance(0.48, hsl.l)
74
+ assert_in_tolerance(0.125, hsl.s)
75
+ assert_in_tolerance(0.08333, hsl.h)
76
+ end
77
+
78
+ def test_to_lab
79
+ lab = @cmyk.to_lab
80
+ assert_kind_of(Color::CIELAB, lab)
81
+ assert_in_tolerance(52.35269, lab.l)
82
+ assert_in_tolerance(3.268274, lab.a)
83
+ assert_in_tolerance(10.52531, lab.b)
84
+ assert_equal(Color::CIELAB.from_values(0, 0, 0), Color::CMYK.from_percentage(0, 0, 0, 100).to_lab)
85
+ end
51
86
 
52
87
  def test_to_rgb
53
- rgb = @cmyk.to_rgb(rgb_method: :adobe)
54
- assert_kind_of(Color::RGB, rgb)
55
- assert_in_tolerance(0.5, rgb.r)
56
- assert_in_tolerance(0.4, rgb.g)
57
- assert_in_tolerance(0.3, rgb.b)
88
+ rgb_adobe = @cmyk.to_rgb(rgb_method: :adobe)
89
+ assert_kind_of(Color::RGB, rgb_adobe)
90
+ assert_in_tolerance(0.5, rgb_adobe.r)
91
+ assert_in_tolerance(0.4, rgb_adobe.g)
92
+ assert_in_tolerance(0.3, rgb_adobe.b)
58
93
 
59
94
  rgb = @cmyk.to_rgb
60
95
  assert_kind_of(Color::RGB, rgb)
@@ -63,28 +98,26 @@ module TestColor
63
98
  assert_in_tolerance(0.42, rgb.b)
64
99
  end
65
100
 
66
- def test_inspect
67
- assert_equal("CMYK [10.00% 20.00% 30.00% 40.00%]", @cmyk.inspect)
101
+ def test_to_xyz
102
+ xyz = @cmyk.to_xyz
103
+ assert_kind_of(Color::XYZ, xyz)
104
+ assert_in_tolerance(0.200995, xyz.x)
105
+ assert_in_tolerance(0.204594, xyz.y)
106
+ assert_in_tolerance(0.168249, xyz.z)
107
+ assert_equal(Color::XYZ.from_values(0, 0, 0), Color::CMYK.from_percentage(0, 0, 0, 100).to_xyz)
68
108
  end
69
109
 
70
- def test_css
71
- assert_equal("device-cmyk(10.00% 20.00% 30.00% 40.00%, rgb(54.00% 48.00% 42.00%))", @cmyk.css)
72
- assert_equal("device-cmyk(10.00% 20.00% 30.00% 40.00% / 0.50, rgb(54.00% 48.00% 42.00% / 0.50))", @cmyk.css(alpha: 0.5))
73
- assert_equal("device-cmyk(10.00% 20.00% 30.00% 40.00%)", @cmyk.css(fallback: false))
74
- assert_equal("device-cmyk(10.00% 20.00% 30.00% 40.00% / 0.50)", @cmyk.css(alpha: 0.5, fallback: false))
75
- assert_equal("device-cmyk(10.00% 20.00% 30.00% 40.00%, rgb(0 0 100.00%))", @cmyk.css(fallback: Color::RGB::Blue))
76
- assert_equal("device-cmyk(10.00% 20.00% 30.00% 40.00% / 0.50, rgb(0 0 100.00% / 0.50))", @cmyk.css(alpha: 0.5, fallback: Color::RGB::Blue))
77
- assert_equal("device-cmyk(10.00% 20.00% 30.00% 40.00% / 0.50, rgb(0 0 100.00%))", @cmyk.css(alpha: 0.5, fallback: {color: Color::RGB::Blue}))
78
- assert_equal("device-cmyk(10.00% 20.00% 30.00% 40.00% / 0.50, rgb(0 0 100.00% / 0.30))", @cmyk.css(alpha: 0.5, fallback: {color: Color::RGB::Blue, alpha: 0.3}))
79
- assert_equal("device-cmyk(10.00% 20.00% 30.00% 40.00% / 0.50, rgb(54.00% 48.00% 42.00% / 0.30))", @cmyk.css(alpha: 0.5, fallback: {alpha: 0.3}))
110
+ def test_to_yiq
111
+ yiq = @cmyk.to_yiq
112
+ assert_kind_of(Color::YIQ, yiq)
113
+ assert_in_tolerance(0.4911, yiq.y)
114
+ assert_in_tolerance(0.05502, yiq.i)
115
+ assert_in_tolerance(0.0, yiq.q)
116
+ assert_equal(Color::YIQ.from_values(0, 0, 0), Color::CMYK.from_percentage(0, 0, 0, 100).to_yiq)
80
117
  end
81
118
 
82
- # def test_to_yiq
83
- # yiq = @cmyk.to_yiq
84
- # assert_kind_of(Color::YIQ, yiq)
85
- # assert_in_tolerance(0.4911, yiq.y)
86
- # assert_in_tolerance(0.05502, yiq.i)
87
- # assert_in_tolerance(0.0, yiq.q)
88
- # end
119
+ def test_to_internal
120
+ assert_equal([0.0, 0.0, 0.0, 1.0], Color::CMYK.from_percentage(0, 0, 0, 100).to_internal)
121
+ end
89
122
  end
90
123
  end
@@ -39,6 +39,20 @@ module TestColor
39
39
  assert_in_tolerance(0.363, @gs.lighten_by(10).g)
40
40
  end
41
41
 
42
+ def test_inspect
43
+ assert_equal("Grayscale [33.00%]", @gs.inspect)
44
+ end
45
+
46
+ def test_pretty_print
47
+ assert_pretty_inspect "Grayscale\n[33.00%]\n", @gs
48
+ end
49
+ end
50
+
51
+ class TestGrayscaleConversions < Minitest::Test
52
+ def setup
53
+ @gs = Color::Grayscale.from_percentage(33)
54
+ end
55
+
42
56
  def test_to_cmyk
43
57
  cmyk = @gs.to_cmyk
44
58
  assert_kind_of(Color::CMYK, cmyk)
@@ -46,11 +60,12 @@ module TestColor
46
60
  assert_in_tolerance(0.0, cmyk.m)
47
61
  assert_in_tolerance(0.0, cmyk.y)
48
62
  assert_in_tolerance(0.67, cmyk.k)
63
+ assert_equal(Color::CMYK.from_percentage(0, 0, 0, 100), Color::Grayscale.from_percentage(0).to_cmyk)
49
64
  end
50
65
 
51
66
  def test_to_grayscale
52
67
  assert_equal(@gs, @gs.to_grayscale)
53
- assert_equal(@gs, @gs.to_grayscale)
68
+ assert_kind_of(Color::Grayscale, @gs.to_grayscale)
54
69
  end
55
70
 
56
71
  def test_to_hsl
@@ -59,6 +74,16 @@ module TestColor
59
74
  assert_in_tolerance(0.0, hsl.h)
60
75
  assert_in_tolerance(0.0, hsl.s)
61
76
  assert_in_tolerance(0.33, hsl.l)
77
+ assert_equal(Color::HSL.from_values(0, 0, 0), Color::Grayscale.from_percentage(0).to_hsl)
78
+ end
79
+
80
+ def test_to_lab
81
+ lab = @gs.to_lab
82
+ assert_kind_of(Color::CIELAB, lab)
83
+ assert_in_tolerance(35.78746, lab.l)
84
+ assert_in_tolerance(0.0031199, lab.a)
85
+ assert_in_tolerance(-0.000639, lab.b)
86
+ assert_equal(Color::CIELAB.from_values(0, 0, 0), Color::Grayscale.from_percentage(0).to_lab)
62
87
  end
63
88
 
64
89
  def test_to_rgb
@@ -67,6 +92,16 @@ module TestColor
67
92
  assert_in_tolerance(0.33, rgb.r)
68
93
  assert_in_tolerance(0.33, rgb.g)
69
94
  assert_in_tolerance(0.33, rgb.b)
95
+ assert_equal(Color::RGB.from_values(0, 0, 0), Color::Grayscale.from_percentage(0).to_rgb)
96
+ end
97
+
98
+ def test_to_xyz
99
+ xyz = @gs.to_xyz
100
+ assert_kind_of(Color::XYZ, xyz)
101
+ assert_in_tolerance(0.08457, xyz.x)
102
+ assert_in_tolerance(0.08898, xyz.y)
103
+ assert_in_tolerance(0.09688, xyz.z)
104
+ assert_equal(Color::XYZ.from_values(0, 0, 0), Color::Grayscale.from_percentage(0).to_xyz)
70
105
  end
71
106
 
72
107
  def test_to_yiq
@@ -75,10 +110,11 @@ module TestColor
75
110
  assert_in_tolerance(0.33, yiq.y)
76
111
  assert_in_tolerance(0.0, yiq.i)
77
112
  assert_in_tolerance(0.0, yiq.q)
113
+ assert_equal(Color::YIQ.from_values(0, 0, 0), Color::Grayscale.from_percentage(0).to_yiq)
78
114
  end
79
115
 
80
- def test_inspect
81
- assert_equal("Grayscale [33.00%]", @gs.inspect)
116
+ def test_to_internal
117
+ assert_equal([0.0], Color::Grayscale.from_percentage(0).to_internal)
82
118
  end
83
119
  end
84
120
  end