decolmor 1.1.2 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 391babdff79d7e079f2282aa45ad285323c2b58b87e518bb2d26ad8e1192a4e3
4
- data.tar.gz: 14aa6f29f76b05ab2e853e438e60b4e6705fb147a4ecebaccf1375778e88ad12
3
+ metadata.gz: 4394b870f83f01ebe74db59131475d1d9a72bd32d307e36b775f903fbfe95b67
4
+ data.tar.gz: e9aad1484b539e938e666de21bd5eb1a630118646b3391da4d40d95a473ea766
5
5
  SHA512:
6
- metadata.gz: ce61c17d0dbc5da49013777f8abc332354c681f566a03ee37ab959faa062176f48daa7e4495695580efa74d9b9383f4569be7b0f8fec63922a80730388bd267a
7
- data.tar.gz: 6fdd75e6224a79e587dacb66de5d74444196dfc3b4ebb3f592ab689df8435d67150d7bc0751f81289d253c9f1884468b14a94f59bb7f6a972e625d29809f540a
6
+ metadata.gz: 939483bfc049fefab624f9ed62e10b081684ce020a3b0d96189036eb20747386f9693c831221684eb1403eeb0af899e29382459798fd3bbbebdbf232f8976aec
7
+ data.tar.gz: 606d35831d04dea98b8405e176240d2cf4ceedd9f7684170b0c972fc9b7db97964ab2c5080de897d3308b900fd5d0b9aeaafb1f8ce5ad899147f320796d6a45a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.0 (September 21, 2021)
4
+
5
+ * `.hex_to_rgb` now support a returnable alpha in range `0..255`
6
+ `.rgb_to_hex` now support incoming alpha in range `0..255`
7
+ use the option: `alpha_255: true`
8
+ * refactor code for methods:
9
+ - hsl_to_rgb
10
+ - hsv_to_rgb
11
+ - hsb_to_rgb
12
+ - hsl_to_rgb_alt
13
+ - hsv_to_rgb_alt
14
+ - hsb_to_rgb_alt
15
+ Removed some inaccuracies in the math, which didn't affect the result.
16
+ Code in the _alt methods became clearer.
17
+ Improved performance, especially _alt methods
18
+ (but its still a bit slower than the main methods ~1.3X)
19
+
3
20
  ## 1.1.2 (September 16, 2021)
4
21
 
5
22
  * Migrate: Travis CI => Github Actions Workflow
@@ -15,11 +32,11 @@
15
32
 
16
33
  ## 1.1.0 (September 14, 2021)
17
34
 
18
- * ::hex_to_rgb
35
+ * .hex_to_rgb
19
36
  * change default rounding 5 => 3 for Alpha channel
20
37
  *reason: 3 digits is enough for a lossless conversion `0..255` -> `0..1` -> `0..255`*
21
38
  * for the Alpha channel now you can set rounding as the second argument:
22
- `Decolmor::hex_to_rgb(hex, 2)`
39
+ `Decolmor.hex_to_rgb(hex, 2)`
23
40
  * support short version of HEX
24
41
  e.g: `#CF3`, `0F9`, `#0F9F`
25
42
 
data/NEWS.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # News
2
2
 
3
+ ## 1.2.0 (September 21, 2021)
4
+
5
+ * `.hex_to_rgb` now support a returnable alpha in range `0..255`
6
+ `.rgb_to_hex` now support incoming alpha in range `0..255`
7
+ use the option: `alpha_255: true`
8
+ * Improved performance for HSL/HSV/HSB => RGB conversion
9
+
3
10
  ## 1.1.2 (September 16, 2021)
4
11
 
5
12
  * Migrate: Travis CI => Github Actions Workflow
@@ -11,7 +18,7 @@
11
18
 
12
19
  ## 1.1.0 (September 14, 2021)
13
20
 
14
- * `::hex_to_rgb` Now supports short version of HEX and rounding for the alpha channel
21
+ * `.hex_to_rgb` Now supports short version of HEX and rounding for the alpha channel
15
22
 
16
23
  ## 1.0.0 (September 13, 2021)
17
24
 
data/README.md CHANGED
@@ -8,6 +8,8 @@ Gem for converting color spaces from/to: HEX/RGB/HSL/HSV/HSB/CMYK
8
8
  The Alpha channel (transparency) is supported.
9
9
  There is also a simple RGB generator.
10
10
 
11
+ [News][news] | [Recent releases][releases] | [Changelog][changelog] | [Wiki][wiki]
12
+
11
13
  ## Install
12
14
  Add the following line to Gemfile:
13
15
 
@@ -46,6 +48,8 @@ SomeClass.rgb_to_hsb(rgb)
46
48
  ```
47
49
  Gem methods will be available as class methods.
48
50
 
51
+ See [WIKI](https://github.com/ChildrenofkoRn/decolmor/wiki/Examples) for more examples.
52
+
49
53
  ## Rounding for HSL/HSV/HSB/CMYK
50
54
  By default, rounding 1 is used to convert to HSL/HSV/HSB/CMYK.
51
55
  This is enough to loselessly convert RGB -> HSL/HSV/HSB/CMYK -> RGB:
@@ -80,9 +84,15 @@ If you need to get integers, use 0.
80
84
  When converting from HEX to RGBA Alpha channel is converted to a value from the range `0..1` with rounding 3:
81
85
  - 3 digits is enough for a lossless conversion `0..255` -> `0..1` -> `0..255`
82
86
  ```ruby
83
- Decolmor.hex_to_rgb('#19988BB8') # => [25, 152, 139, 0.722]
87
+ Decolmor.hex_to_rgb('#19988BB8') # => [25, 152, 139, 0.722]
88
+ Decolmor.hex_to_rgb([25, 152, 139, 0.722) # => "#19988BB8"
84
89
  ```
85
90
  Consequently, when converting to HEX from RGBA, Alpha from the range `0..1` is assumed.
91
+ But you can set range 0..255 for alpha channel:
92
+ ```ruby
93
+ Decolmor.hex_to_rgb('#19988BB8', alpha_255: true) # => [25, 152, 139, 184]
94
+ Decolmor.rgb_to_hex([25, 152, 139, 184], alpha_255: true) # => "#19988BB8"
95
+ ```
86
96
  You can also set rounding for Alpha channel as a second argument:
87
97
  ```ruby
88
98
  Decolmor.hex_to_rgb('#19988BB8', 2) # => [25, 152, 139, 0.72]
@@ -109,7 +119,7 @@ or
109
119
  - hsv_to_rgb_alt
110
120
  - hsb_to_rgb_alt
111
121
 
112
- The results of the two implementations are identical, but the alternative versions (postfix `_alt`) are ~1.6X slower.
122
+ The results of the two implementations are identical, but the alternative versions (postfix `_alt`) are ~1.35X slower.
113
123
 
114
124
  ## Attention for CMYK !
115
125
  Unfortunately, there is no simple formula for linear RGB to/from CMYK conversion.
@@ -117,7 +127,7 @@ This implementation is a simplified/dirty/simulation.
117
127
  CMYK is used for printing and the correct conversion will be non-linear, based on the color profile for the particular printing device.
118
128
  Therefore, the CMYK conversion results will not match Adobe products.
119
129
  **BUT:**
120
- Conversion to HEX/RGB/HSL/HSV/HSB is simple and is described by formulas.
130
+ Conversion from/to HEX/RGB/HSL/HSV/HSB is simple and is described by formulas.
121
131
  Read more: https://en.wikipedia.org/wiki/HSL_and_HSV
122
132
  The results when rounded to an integer will be the same as when using graphics editors, such as CorelDRAW or Adobe Photoshop.
123
133
 
@@ -137,7 +147,7 @@ The results when rounded to an integer will be the same as when using graphics e
137
147
  - hsl_to_rgb
138
148
  - hsv_to_rgb
139
149
  - hsb_to_rgb
140
- - Alternative implementation HSL/HSV/HSB to RGB(A) (~1.6X slower)
150
+ - Alternative implementation HSL/HSV/HSB to RGB(A) (a little slower)
141
151
  - hsl_to_rgb_alt
142
152
  - hsv_to_rgb_alt
143
153
  - hsb_to_rgb_alt
@@ -162,6 +172,12 @@ Copyright (c) 2021 ChildrenofkoRn
162
172
  [codecov]: https://codecov.io/gh/ChildrenofkoRn/decolmor "codecov"
163
173
  [badge-codecov]: https://codecov.io/gh/ChildrenofkoRn/decolmor/branch/main/graph/badge.svg?token=5P4OQUXC3N "codecov"
164
174
  [github-workflow]: https://github.com/ChildrenofkoRn/decolmor/actions/workflows/build.yml "build"
165
- [badge-build]: https://github.com/ChildrenofkoRn/decolmor/actions/workflows/build.yml/badge.svg "build status"
175
+ [badge-build]: https://img.shields.io/github/workflow/status/ChildrenofkoRn/decolmor/build/main "build status"
166
176
  [license]: https://github.com/ChildrenofkoRn/decolmor/blob/main/LICENSE "MIT"
167
177
  [badge-license]: https://img.shields.io/github/license/ChildrenofkoRn/decolmor?color=%23239393 "license"
178
+
179
+
180
+ [changelog]: https://github.com/ChildrenofkoRn/decolmor/blob/main/CHANGELOG.md "changelog"
181
+ [news]: https://github.com/ChildrenofkoRn/decolmor/blob/main/NEWS.md "news"
182
+ [releases]: https://github.com/ChildrenofkoRn/decolmor/releases "releases"
183
+ [wiki]: https://github.com/ChildrenofkoRn/decolmor/wiki "wiki"
data/lib/decolmor/main.rb CHANGED
@@ -5,7 +5,7 @@ module Decolmor
5
5
  end
6
6
 
7
7
  #========= Set default rounding for HSL/HSV/HSB/CMYK conversion ========
8
-
8
+
9
9
  # round 1 enough for lossless conversion RGB -> HSL/HSV/HSB -> RGB
10
10
  # for lossless conversion HSL <==> HSV (HSB) better to use round 2
11
11
  #
@@ -21,7 +21,7 @@ module Decolmor
21
21
 
22
22
  #========= HEX <==> RGB(A) =============================================
23
23
 
24
- def hex_to_rgb(hex, alpha_round = 3)
24
+ def hex_to_rgb(hex, alpha_round = 3, alpha_255: false)
25
25
  hex = hex.gsub('#','')
26
26
  hex = if [3, 4].include? hex.length
27
27
  hex.chars.map{ |char| char * 2 }
@@ -29,13 +29,20 @@ module Decolmor
29
29
  hex.scan(/../)
30
30
  end
31
31
  rgb = hex.map(&:hex)
32
- rgb.size == 4 ? rgb + [(rgb.delete_at(3) / 255.to_f).round(alpha_round)] : rgb
32
+ if rgb.size == 4
33
+ rgb[3] = (rgb[3] / 255.to_f).round(alpha_round) unless alpha_255
34
+ end
35
+
36
+ rgb
33
37
  end
34
38
 
35
- def rgb_to_hex(rgb)
36
- template = rgb.size == 3 ? "#%02X%02X%02X" : "#%02X%02X%02X%02X"
37
- rgb = rgb[0..2] + [(rgb[3] * 255).round] if rgb.size == 4
38
- template % rgb
39
+ def rgb_to_hex(rgb, alpha_255: false)
40
+ if rgb.size == 3
41
+ "#%02X%02X%02X" % rgb
42
+ else
43
+ rgb[3] = (rgb[3] * 255).round unless alpha_255
44
+ "#%02X%02X%02X%02X" % rgb
45
+ end
39
46
  end
40
47
 
41
48
  #=======================================================================
@@ -103,14 +110,14 @@ module Decolmor
103
110
 
104
111
  # calculation intermediate values
105
112
  a = saturation * [lightness, 1 - lightness].min
106
- converter = proc do |n|
107
- k = (n + hue / 30) % 12
108
- lightness - a * [-1, [k - 3, 9 - k, 1].min].max
109
- end
110
113
 
111
114
  # calculation rgb & scaling into range 0..255
112
115
  rgb = [0, 8, 4]
113
- rgb.map! { |channel| (converter.call(channel) * 255).round }
116
+ rgb.map! do |channel|
117
+ k = (channel + hue / 30) % 12
118
+ channel = lightness - a * [-1, [k - 3, 9 - k, 1].min].max
119
+ (channel * 255).round
120
+ end
114
121
  alpha.nil? ? rgb : rgb + [alpha]
115
122
  end
116
123
 
@@ -120,15 +127,13 @@ module Decolmor
120
127
  saturation /= 100
121
128
  value /= 100
122
129
 
123
- # calculation intermediate values
124
- converter = proc do |n|
125
- k = (n + hue / 60) % 6
126
- value - value * saturation * [0, [k, 4 - k, 1].min].max
127
- end
128
-
129
130
  # calculation rgb & scaling into range 0..255
130
131
  rgb = [5, 3, 1]
131
- rgb.map! { |channel| (converter.call(channel) * 255).round }
132
+ rgb.map! do |channel|
133
+ k = (channel + hue / 60) % 6
134
+ channel = value - value * saturation * [0, [k, 4 - k, 1].min].max
135
+ (channel * 255).round
136
+ end
132
137
  alpha.nil? ? rgb : rgb + [alpha]
133
138
  end
134
139
 
@@ -146,22 +151,11 @@ module Decolmor
146
151
  chroma = (1 - (2 * lightness - 1).abs) * saturation
147
152
  hue /= 60
148
153
  x = chroma * (1 - (hue % 2 - 1).abs)
149
-
150
- # possible RGB points
151
- points = [[chroma, x, 0],
152
- [x, chroma, 0],
153
- [0, chroma, x],
154
- [0, x, chroma],
155
- [x, 0, chroma],
156
- [chroma, 0, x]]
157
- # point selection based on entering HUE input in range
158
- point = points.each_with_index.detect { |rgb_, n| (n..n + 1).include? hue }&.first
159
- # if point == nil (hue undefined)
160
- rgb = point || [0, 0, 0]
154
+ point = get_rgb_point(hue, chroma, x)
161
155
 
162
156
  # calculation rgb & scaling into range 0..255
163
157
  m = lightness - chroma / 2
164
- rgb.map! { |channel| ((channel + m) * 255).round }
158
+ rgb = point.map { |channel| ((channel + m) * 255).round }
165
159
  alpha.nil? ? rgb : rgb + [alpha]
166
160
  end
167
161
 
@@ -175,22 +169,11 @@ module Decolmor
175
169
  chroma = value * saturation
176
170
  hue /= 60
177
171
  x = chroma * (1 - (hue % 2 - 1).abs)
178
-
179
- # possible RGB points
180
- points = [[chroma, x, 0],
181
- [x, chroma, 0],
182
- [0, chroma, x],
183
- [0, x, chroma],
184
- [x, 0, chroma],
185
- [chroma, 0, x]]
186
- # point selection based on entering HUE input in range
187
- point = points.each_with_index.detect { |rgb_, n| (n * (1 / 100.000)...n + 1).include? hue }&.first
188
- # if point == nil (hue undefined)
189
- rgb = point || [0, 0, 0]
172
+ point = get_rgb_point(hue, chroma, x)
190
173
 
191
174
  # calculation rgb & scaling into range 0..255
192
175
  m = value - chroma
193
- rgb.map! { |channel| ((channel + m) * 255).round }
176
+ rgb = point.map { |channel| ((channel + m) * 255).round }
194
177
  alpha.nil? ? rgb : rgb + [alpha]
195
178
  end
196
179
 
@@ -293,9 +276,25 @@ module Decolmor
293
276
  # blue is max
294
277
  (red - green) / chroma + 4
295
278
  end
296
- hue *= 60
297
- # make negative HUEs positive behind 360°
298
- 0 <= hue ? hue : hue + 360
279
+ hue * 60
280
+
281
+ # HUE will never leave the 0..360 range when RGB is within 0..255
282
+ # make negative HUEs positive
283
+ # 0 <= hue ? hue : hue + 360
284
+ end
285
+
286
+ # possible RGB points
287
+ # point selection based on entering HUE input in range
288
+ def get_rgb_point(hue, chroma, x)
289
+ case hue
290
+ when 0...1 then [chroma, x, 0]
291
+ when 1...2 then [x, chroma, 0]
292
+ when 2...3 then [0, chroma, x]
293
+ when 3...4 then [0, x, chroma]
294
+ when 4...5 then [x, 0, chroma]
295
+ when 5...6 then [chroma, 0, x]
296
+ else [0, 0, 0]
297
+ end
299
298
  end
300
299
  end
301
300
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Decolmor
4
- VERSION = '1.1.2'
4
+ VERSION = '1.2.0'
5
5
  end
@@ -68,6 +68,14 @@ RSpec.describe Decolmor do
68
68
  end
69
69
  end
70
70
 
71
+ it "set range 0..255 for alpha channel" do
72
+ color = colors.keys.sample
73
+ alphas.each_pair do |hex_alpha, alpha|
74
+ hex = format('%s%s', color, hex_alpha)
75
+ expect( Decolmor.hex_to_rgb(hex, alpha_255: true).last ).to eq alpha[:rgb_255]
76
+ end
77
+ end
78
+
71
79
  it "HEX w alpha channel and w/o prefix # to RGBA" do
72
80
  color = colors.keys.sample
73
81
 
@@ -100,12 +108,22 @@ RSpec.describe Decolmor do
100
108
  it "RGBA converts to HEX w alpha" do
101
109
  color = colors.keys.sample
102
110
 
103
- alphas.each_pair do |hex, alpha|
104
- hex = format('%s%s', color, hex)
111
+ alphas.each_pair do |hex_alpha, alpha|
112
+ hex = format('%s%s', color, hex_alpha)
105
113
  rgba = colors[color][:rgb] + [alpha[:rgb]]
106
114
  expect( Decolmor.rgb_to_hex(rgba) ).to eq hex
107
115
  end
108
116
  end
117
+
118
+ it "set range 0..255 for alpha channel" do
119
+ color = colors.keys.sample
120
+
121
+ alphas.each_pair do |hex_alpha, alpha|
122
+ hex = format('%s%s', color, hex_alpha)
123
+ rgba = colors[color][:rgb] + [alpha[:rgb_255]]
124
+ expect( Decolmor.rgb_to_hex(rgba, alpha_255: true) ).to eq hex
125
+ end
126
+ end
109
127
  end
110
128
  end
111
129
 
@@ -145,7 +163,7 @@ RSpec.describe Decolmor do
145
163
 
146
164
  it "alpha channel pass to HSL unchanged" do
147
165
  color = colors.keys.sample
148
- alphas.each_pair do |hex_, alpha|
166
+ alphas.each_pair do |_hex_alpha, alpha|
149
167
  rgba = colors[color][:rgb] + [alpha[:rgb]]
150
168
  expect( Decolmor.rgb_to_hsl(rgba).last ).to eq alpha[:rgb]
151
169
  end
@@ -160,7 +178,7 @@ RSpec.describe Decolmor do
160
178
 
161
179
  it "setting rounding doesn't affect alpha channel" do
162
180
  color = colors.keys.sample
163
- alphas.each_pair do |hex_, alpha|
181
+ alphas.each_pair do |_hex_alpha, alpha|
164
182
  rgba = colors[color][:rgb] + [alpha[:rgb]]
165
183
  # alpha shouldn't be rounded because its range is 0..1
166
184
  # if that did happen, we would get 0 or 1 instead of the normal value
@@ -182,7 +200,7 @@ RSpec.describe Decolmor do
182
200
 
183
201
  it "alpha channel pass to HSV unchanged" do
184
202
  color = colors.keys.sample
185
- alphas.each_pair do |hex_, alpha|
203
+ alphas.each_pair do |_hex_alpha, alpha|
186
204
  rgba = colors[color][:rgb] + [alpha[:rgb]]
187
205
  expect( Decolmor.rgb_to_hsv(rgba).last ).to eq alpha[:rgb]
188
206
  end
@@ -196,7 +214,7 @@ RSpec.describe Decolmor do
196
214
 
197
215
  it "setting rounding doesn't affect alpha channel" do
198
216
  color = colors.keys.sample
199
- alphas.each_pair do |hex_, alpha|
217
+ alphas.each_pair do |_hex_alpha, alpha|
200
218
  rgba = colors[color][:rgb] + [alpha[:rgb]]
201
219
  expect( Decolmor.rgb_to_hsv(rgba, 0).last ).to eq alpha[:rgb]
202
220
  end
@@ -217,14 +235,14 @@ RSpec.describe Decolmor do
217
235
  let(:alphas) { FactoryBot.build(:alpha) }
218
236
 
219
237
  it "HSL converts to RGB" do
220
- colors.each_pair do |hex, values|
238
+ colors.each_pair do |_hex, values|
221
239
  expect( Decolmor.hsl_to_rgb(values[:hsl]) ).to eq values[:rgb]
222
240
  end
223
241
  end
224
242
 
225
243
  it "alpha channel pass to RGB unchanged" do
226
244
  color = colors.keys.sample
227
- alphas.each_pair do |hex_, values|
245
+ alphas.each_pair do |_hex_alpha, values|
228
246
  hsla = colors[color][:hsl] + [values[:rgb]]
229
247
  expect( Decolmor.hsl_to_rgb(hsla).last ).to eq values[:rgb]
230
248
  end
@@ -236,14 +254,14 @@ RSpec.describe Decolmor do
236
254
  let(:alphas) { FactoryBot.build(:alpha) }
237
255
 
238
256
  it "HSV converts to RGB" do
239
- colors.each_pair do |hex, values|
257
+ colors.each_pair do |_hex, values|
240
258
  expect( Decolmor.hsv_to_rgb(values[:hsv]) ).to eq values[:rgb]
241
259
  end
242
260
  end
243
261
 
244
262
  it "alpha channel pass to RGB unchanged" do
245
263
  color = colors.keys.sample
246
- alphas.each_pair do |hex_, values|
264
+ alphas.each_pair do |_hex_alpha, values|
247
265
  hsva = colors[color][:hsv] + [values[:rgb]]
248
266
  expect( Decolmor.hsv_to_rgb(hsva).last ).to eq values[:rgb]
249
267
  end
@@ -264,18 +282,26 @@ RSpec.describe Decolmor do
264
282
  let(:alphas) { FactoryBot.build(:alpha) }
265
283
 
266
284
  it "HSL converts to RGB" do
267
- colors.each_pair do |hex, values|
285
+ colors.each_pair do |_hex, values|
268
286
  expect( Decolmor.hsl_to_rgb_alt(values[:hsl]) ).to eq values[:rgb]
269
287
  end
270
288
  end
271
289
 
272
290
  it "alpha channel pass to RGB unchanged" do
273
291
  color = colors.keys.sample
274
- alphas.each_pair do |hex_, values|
292
+ alphas.each_pair do |_hex_alpha, values|
275
293
  hsla = colors[color][:hsl] + [values[:rgb]]
276
294
  expect( Decolmor.hsl_to_rgb_alt(hsla).last ).to eq values[:rgb]
277
295
  end
278
296
  end
297
+
298
+ it "if hue not a range member 0..360 return identical RGB values (colorless)" do
299
+ colors.each_pair do |hex, values|
300
+ hsl = values[:hsl]
301
+ hsl[0] += 360
302
+ expect( Decolmor.hsl_to_rgb_alt(hsl).uniq.size ).to eq 1
303
+ end
304
+ end
279
305
  end
280
306
 
281
307
  describe ".hsv_to_rgb_alt" do
@@ -283,18 +309,26 @@ RSpec.describe Decolmor do
283
309
  let(:alphas) { FactoryBot.build(:alpha) }
284
310
 
285
311
  it "HSV converts to RGB" do
286
- colors.each_pair do |hex, values|
312
+ colors.each_pair do |_hex, values|
287
313
  expect( Decolmor.hsv_to_rgb_alt(values[:hsv]) ).to eq values[:rgb]
288
314
  end
289
315
  end
290
316
 
291
317
  it "alpha channel pass to RGB unchanged" do
292
318
  color = colors.keys.sample
293
- alphas.each_pair do |hex_, values|
319
+ alphas.each_pair do |_hex_alpha, values|
294
320
  hsva = colors[color][:hsv] + [values[:rgb]]
295
321
  expect( Decolmor.hsv_to_rgb_alt(hsva).last ).to eq values[:rgb]
296
322
  end
297
323
  end
324
+
325
+ it "if hue not a range member 0..360 return identical RGB values (colorless)" do
326
+ colors.each_pair do |_hex, values|
327
+ hsl = values[:hsl]
328
+ hsl[0] -= 360
329
+ expect( Decolmor.hsl_to_rgb_alt(hsl).uniq.size ).to eq 1
330
+ end
331
+ end
298
332
  end
299
333
 
300
334
  describe ".hsb_to_rgb_alt" do
@@ -320,21 +354,21 @@ RSpec.describe Decolmor do
320
354
 
321
355
  it "alpha channel pass to HSV unchanged" do
322
356
  color = colors.keys.sample
323
- alphas.each_pair do |hex_, alpha|
357
+ alphas.each_pair do |_hex_alpha, alpha|
324
358
  hsla = colors[color][:hsl] + [alpha[:rgb]]
325
359
  expect( Decolmor.hsl_to_hsv(hsla).last ).to eq alpha[:rgb]
326
360
  end
327
361
  end
328
362
 
329
363
  it "you can set rounding for resulting HSV values (default = 1)" do
330
- colors.each_pair do |hex, values|
364
+ colors.each_pair do |_hex, values|
331
365
  expect( Decolmor.hsl_to_hsv(values[:hsl], 0) ).to eq values[:hsv].map(&:round)
332
366
  end
333
367
  end
334
368
 
335
369
  it "setting rounding doesn't affect alpha channel" do
336
370
  color = colors.keys.sample
337
- alphas.each_pair do |hex_, alpha|
371
+ alphas.each_pair do |_hex_alpha, alpha|
338
372
  hsla = colors[color][:hsl] + [alpha[:rgb]]
339
373
  expect( Decolmor.hsl_to_hsv(hsla, 0).last ).to eq alpha[:rgb]
340
374
  end
@@ -353,7 +387,7 @@ RSpec.describe Decolmor do
353
387
  let(:alphas) { FactoryBot.build(:alpha) }
354
388
 
355
389
  it "HSV converts to HSL" do
356
- colors.each_pair do |hex_, values|
390
+ colors.each_pair do |_hex, values|
357
391
  hsl = values[:hsl].map { |value| value.round(1) }
358
392
  expect( Decolmor.hsv_to_hsl(values[:hsv]) ).to eq hsl
359
393
  end
@@ -361,21 +395,21 @@ RSpec.describe Decolmor do
361
395
 
362
396
  it "alpha channel pass to HSL unchanged" do
363
397
  color = colors.keys.sample
364
- alphas.each_pair do |hex_, alpha|
398
+ alphas.each_pair do |_hex_alpha, alpha|
365
399
  hsva = colors[color][:hsv] + [alpha[:rgb]]
366
400
  expect( Decolmor.hsv_to_hsl(hsva).last ).to eq alpha[:rgb]
367
401
  end
368
402
  end
369
403
 
370
404
  it "you can set rounding for resulting HSL values (default = 1)" do
371
- colors.each_pair do |hex, values|
405
+ colors.each_pair do |_hex, values|
372
406
  expect( Decolmor.hsv_to_hsl(values[:hsv], 0) ).to eq values[:hsl].map(&:round)
373
407
  end
374
408
  end
375
409
 
376
410
  it "setting rounding doesn't affect alpha channel" do
377
411
  color = colors.keys.sample
378
- alphas.each_pair do |hex_, alpha|
412
+ alphas.each_pair do |_hex, alpha|
379
413
  hsva = colors[color][:hsv] + [alpha[:rgb]]
380
414
  expect( Decolmor.hsv_to_hsl(hsva, 0).last ).to eq alpha[:rgb]
381
415
  end
@@ -405,7 +439,7 @@ RSpec.describe Decolmor do
405
439
 
406
440
  it "alpha channel pass to HSL unchanged" do
407
441
  color = colors.keys.sample
408
- alphas.each_pair do |hex_, alpha|
442
+ alphas.each_pair do |_hex_alpha, alpha|
409
443
  rgba = colors[color][:rgb] + [alpha[:rgb]]
410
444
  expect( Decolmor.rgb_to_cmyk(rgba).last ).to eq alpha[:rgb]
411
445
  end
@@ -419,7 +453,7 @@ RSpec.describe Decolmor do
419
453
 
420
454
  it "setting rounding doesn't affect alpha channel" do
421
455
  color = colors.keys.sample
422
- alphas.each_pair do |hex_, alpha|
456
+ alphas.each_pair do |_hex_alpha, alpha|
423
457
  rgba = colors[color][:rgb] + [alpha[:rgb]]
424
458
  expect( Decolmor.rgb_to_cmyk(rgba, 0).last ).to eq alpha[:rgb]
425
459
  end
@@ -438,7 +472,7 @@ RSpec.describe Decolmor do
438
472
 
439
473
  it "alpha channel pass to RGB unchanged" do
440
474
  color = colors.keys.sample
441
- alphas.each_pair do |hex_, values|
475
+ alphas.each_pair do |_hex_alpha, values|
442
476
  cmyka = colors[color][:cmyk] + [values[:rgb]]
443
477
  expect( Decolmor.cmyk_to_rgb(cmyka).last ).to eq values[:rgb]
444
478
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decolmor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ChildrenofkoRn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-16 00:00:00.000000000 Z
11
+ date: 2021-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler