Class: Colors::XYZ
- Inherits:
-
AbstractColor
- Object
- AbstractColor
- Colors::XYZ
- Includes:
- Helper
- Defined in:
- lib/colors/xyz.rb
Constant Summary collapse
- EPSILON =
(6/29r)**3
- KAPPA =
(29/3r)**3
Instance Attribute Summary collapse
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
-
#z ⇒ Object
readonly
Returns the value of attribute z.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #components ⇒ Object
-
#initialize(x, y, z) ⇒ XYZ
constructor
A new instance of XYZ.
- #luv_components(wp) ⇒ Object
- #rgb_components ⇒ Object
- #to_rgb ⇒ Object
- #uv_values ⇒ Object
Methods inherited from AbstractColor
Constructor Details
#initialize(x, y, z) ⇒ XYZ
Returns a new instance of XYZ.
9 10 11 |
# File 'lib/colors/xyz.rb', line 9 def initialize(x, y, z) @x, @y, @z = canonicalize(x, y, z) end |
Instance Attribute Details
#x ⇒ Object (readonly)
Returns the value of attribute x.
13 14 15 |
# File 'lib/colors/xyz.rb', line 13 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
13 14 15 |
# File 'lib/colors/xyz.rb', line 13 def y @y end |
#z ⇒ Object (readonly)
Returns the value of attribute z.
13 14 15 |
# File 'lib/colors/xyz.rb', line 13 def z @z end |
Instance Method Details
#==(other) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/colors/xyz.rb', line 19 def ==(other) case other when XYZ x == other.x && y == other.y && z == other.z else super end end |
#components ⇒ Object
15 16 17 |
# File 'lib/colors/xyz.rb', line 15 def components [x, y, z] end |
#luv_components(wp) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/colors/xyz.rb', line 36 def luv_components(wp) yy = y/wp.y uu, vv = uv_values l = if yy <= EPSILON KAPPA * yy else 116 * Math.cbrt(yy).to_r - 16 end if l <= 1e-8 u = v = 0r else wp_u, wp_v = wp.uv_values u = 13*l*(uu - wp_u) v = 13*l*(vv - wp_v) end [l, u, v] end |
#rgb_components ⇒ Object
32 33 34 |
# File 'lib/colors/xyz.rb', line 32 def rgb_components Convert.xyz_to_rgb(x, y, z) end |
#to_rgb ⇒ Object
28 29 30 |
# File 'lib/colors/xyz.rb', line 28 def to_rgb RGB.new(*rgb_components) end |
#uv_values ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/colors/xyz.rb', line 54 def uv_values d = x + 15*y + 3*z return [0r, 0r] if d == 0 u = 4*x / d v = 9*y / d [u, v] end |