pigment 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dda5e6ade89b5949326fcb411e9aa8d99065fa511d3baeebb08e1cfb6199e84e
4
- data.tar.gz: '058d8b2c5e47edfe74d716688ab99e33b99b51c46773dd0600c43c4755010b2e'
3
+ metadata.gz: 79ec5aef1ab5b45b400c11d9b56cd5dda30e191962bff97a91bfa9ba461d28ed
4
+ data.tar.gz: f684c0abf44be4e7d466f9acdbb4317510bd3b334004b8168c440dda089c50db
5
5
  SHA512:
6
- metadata.gz: 409765f525e55b3b63fd2ce3fe1e54af1fb070600c4f049a7992d984bd20b0b7f08bbdedb08f5702d6a9f53b50f035c4e25cff4013d741175f5615f889b1febd
7
- data.tar.gz: ab38122e3bbd72c5af6f78a451ae885b52673ec3583a05d346af1bd9c81bd8d844d0dea757fb8e5a5eb7a111452815a192cfebd079304707128a35b45ced28d6
6
+ metadata.gz: aab005b7c4e84a23a9f1c515d27314f2f994a57c2f7bad76be1dbecc89285b3fe6793244fc414bf8786745212d6292e807a27062ace6be41c637dcc7a161a0be
7
+ data.tar.gz: 868457b116af47ae1c7601c5c541d43926cc5002e109823654ea67c7fb167660132c0fbad6f34ac55e1b0db0f52798f3eef727d27322df5117c3e60df36e658b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # 0.3.1
2
+ - Fixes creating colors with approximation errors:
3
+ ```ruby
4
+ # before 0.3.1
5
+ BrilliantLavender.analogous
6
+ # Invalid Format [0.8063725490196079, 1.0000000000000004, 0.8666666666666667, 1.0]
7
+
8
+ # after 0.3.1
9
+ BrilliantLavender.analogous
10
+ # RGB Color(red: 0.8063725490196079, green: 1.0, blue: 0.8666666666666667, alpha: 1.0)
11
+ ```
12
+
1
13
  # 0.3.0
2
14
  - New classes per Color Format
3
15
  - Pigment::Color::RGB
data/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright © 2020 Pedro Miranda
3
+ Copyright © 2021 Pedro Miranda
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
@@ -53,10 +53,14 @@ module Pigment
53
53
  # @param [#to_f] saturation between 0.0 and 1.0
54
54
  # @param [#to_f] lightness between 0.0 and 1.0
55
55
  # @param [#to_f] alpha between 0.0 and 1.0
56
- # @raise [InvalidColorFormatError]
57
56
  # @return [Pigment::Color::HSL]
57
+ # @raise [InvalidColorFormatError]
58
58
  def initialize(hue, saturation, lightness, alpha = 1.0)
59
- @hue, @saturation, @lightness, @alpha = hue % 1.0, saturation.to_f, lightness.to_f, alpha.to_f
59
+ @hue = hue % 1.0
60
+ @saturation = saturation.to_f.snap
61
+ @lightness = lightness.to_f.snap
62
+ @alpha = alpha.to_f.snap
63
+
60
64
  color = to_f(with_alpha: true)
61
65
  raise InvalidColorFormatError, color unless color.all? { |c| c.between?(0.0, 1.0) }
62
66
  end
@@ -12,8 +12,8 @@ module Pigment
12
12
  class << self
13
13
  # Converts a color into RGB format from any possible format
14
14
  # @param [Pigment::Color] color
15
- # @raise [InvalidColorFormatError]
16
15
  # @return [Pigment::Color]
16
+ # @raise [InvalidColorFormatError]
17
17
  def convert(color)
18
18
  case color
19
19
  when RGB then color
@@ -23,9 +23,9 @@ module Pigment
23
23
  end
24
24
 
25
25
  # Creates a Pigment::Color::RGB from an HTML Hex code String
26
- # @param [String, Integer] hex
27
- # @raise [InvalidColorFormatError]
26
+ # @param [String, Integer, Float] hex
28
27
  # @return [Pigment::Color::RGB]
28
+ # @raise [InvalidColorFormatError]
29
29
  def from_hex(hex)
30
30
  case hex
31
31
  when String then from_hex_string(hex)
@@ -40,8 +40,8 @@ module Pigment
40
40
  # @param [Integer] green
41
41
  # @param [Integer] blue
42
42
  # @param [Integer] alpha
43
- # @raise [InvalidColorFormatError]
44
43
  # @return [Pigment::Color::RGB]
44
+ # @raise [InvalidColorFormatError]
45
45
  def from_rgba_integers(red, green, blue, alpha = 255)
46
46
  color = [red, green, blue, alpha]
47
47
  raise InvalidColorFormatError, color unless color.all? do |c|
@@ -126,18 +126,22 @@ module Pigment
126
126
  # @param [Float, Integer] green between 0.0 and 1.0
127
127
  # @param [Float, Integer] blue between 0.0 and 1.0
128
128
  # @param [Float, Integer] alpha between 0.0 and 1.0
129
- # @raise [InvalidColorFormatError]
130
129
  # @return [Pigment::Color::RGB]
130
+ # @raise [InvalidColorFormatError]
131
131
  def initialize(red, green, blue, alpha = 1.0)
132
- @red, @green, @blue, @alpha = red.to_f, green.to_f, blue.to_f, alpha.to_f
132
+ @red = red.to_f.snap
133
+ @green = green.to_f.snap
134
+ @blue = blue.to_f.snap
135
+ @alpha = alpha.to_f
136
+
133
137
  color = to_floats(with_alpha: true)
134
138
  raise InvalidColorFormatError, color unless color.all? { |c| c.between?(0.0, 1.0) }
135
139
  end
136
140
 
137
141
  # Sums all the two colors components. If any component gets out of the 0 to 1.0 range it gets suppressed.
138
142
  # @param [Pigment::Color] color
139
- # @raise [InvalidColorFormatError]
140
143
  # @return [Pigment::Color::RGB]
144
+ # @raise [InvalidColorFormatError]
141
145
  def +(color)
142
146
  raise InvalidColorFormatError, color unless color.is_a?(Pigment::Color)
143
147
  color = color.into(self.class)
@@ -153,8 +157,8 @@ module Pigment
153
157
  # Subtracts all the two color components. If any component gets out of the 0 to 1.0 range it gets suppressed.
154
158
  # Tone component will be 0 if it gets lower than 0
155
159
  # @param [Pigment::Color] color
156
- # @raise [InvalidColorFormatError]
157
160
  # @return [Pigment::Color::RGB]
161
+ # @raise [InvalidColorFormatError]
158
162
  def -(color)
159
163
  raise InvalidColorFormatError, color unless color.is_a?(Pigment::Color)
160
164
  color = color.into(self.class)
@@ -209,8 +213,8 @@ module Pigment
209
213
  # Interpolates two colors. Amount must be an float between -1.0 and 1.0
210
214
  # @param [Pigment::Color] color
211
215
  # @param [Float] amount
212
- # @raise [InvalidColorFormatError]
213
216
  # @return [Pigment::Color::RGB]
217
+ # @raise [InvalidColorFormatError]
214
218
  def interpolate(color, amount = 0.5)
215
219
  raise InvalidColorFormatError, color unless color.is_a?(Pigment::Color)
216
220
  raise ArgumentError, "Amount must be an float between -1.0 and 1.0, got #{amount}" unless (-1.0..1.0).include?(amount)
@@ -7,7 +7,7 @@ module Pigment
7
7
 
8
8
  refine Float do
9
9
  def snap
10
- ceil(Pigment::FloatSnap.snap_digits)
10
+ round(Pigment::FloatSnap.snap_digits)
11
11
  end
12
12
  end
13
13
  end
@@ -36,6 +36,7 @@ module Pigment
36
36
  # @param [Array] names
37
37
  # @param [Pigment::Color] color
38
38
  # @return [Pigment::Color]
39
+ # @raise ArgumentError
39
40
  def []=(*names, color)
40
41
  raise ArgumentError, "Expects Pigment::Color but got #{color.inspect}" unless color.is_a? Pigment::Color
41
42
  names.each { |name| @colors[name] = color }
@@ -1,3 +1,3 @@
1
1
  module Pigment
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pigment
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - P3t3rU5
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-09-20 00:00:00.000000000 Z
12
+ date: 2021-08-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -45,14 +45,14 @@ dependencies:
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '0.19'
48
+ version: '0'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '0.19'
55
+ version: '0'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rake
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -106,20 +106,16 @@ homepage: https://github.com/P3t3rU5/pigment
106
106
  licenses:
107
107
  - MIT
108
108
  metadata: {}
109
- post_install_message: |
110
- +----------------------------------------------------------------------------+
111
- Thanks for choosing Pigment.
112
- --------------------------------------------------------------------------
113
- # 0.3.0
114
- - New classes per Color Format
115
- - Pigment::Color::RGB
116
- - Pigment::Color::HSL
117
- - Base module for Color Formats Pigment::Color
118
- - Palette class to handle a collection of colors
119
- --------------------------------------------------------------------------
120
- If you find any bugs, please report them on
121
- https://github.com/P3t3rU5/pigment/issues
122
- +----------------------------------------------------------------------------+
109
+ post_install_message: "+----------------------------------------------------------------------------+\n
110
+ \ Thanks for choosing Pigment.\n --------------------------------------------------------------------------\n#
111
+ 0.3.1\n- Fixes creating colors with approximation errors:\n```ruby\n# before 0.3.1\nBrilliantLavender.analogous\n#
112
+ Invalid Format [0.8063725490196079, 1.0000000000000004, 0.8666666666666667, 1.0]\n\n#
113
+ after 0.3.1 \nBrilliantLavender.analogous\n# RGB Color(red: 0.8063725490196079,
114
+ green: 1.0, blue: 0.8666666666666667, alpha: 1.0)\n```\n\n# 0.3.0\n- New classes
115
+ per Color Format\n - Pigment::Color::RGB\n - Pigment::Color::HSL\n- Base module
116
+ for Color Formats Pigment::Color\n- Palette class to handle a collection of colors\n
117
+ \ --------------------------------------------------------------------------\n If
118
+ you find any bugs, please report them on\n https://github.com/P3t3rU5/pigment/issues\n+----------------------------------------------------------------------------+\n"
123
119
  rdoc_options: []
124
120
  require_paths:
125
121
  - lib
@@ -134,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
130
  - !ruby/object:Gem::Version
135
131
  version: '0'
136
132
  requirements: []
137
- rubygems_version: 3.1.4
133
+ rubygems_version: 3.2.25
138
134
  signing_key:
139
135
  specification_version: 4
140
136
  summary: A rgb color gem, with a list of 750 different colors.