class Colors::XYZ
Constants
- EPSILON
- KAPPA
Attributes
x[R]
y[R]
z[R]
Public Class Methods
new(x, y, z)
click to toggle source
# File lib/colors/xyz.rb, line 9 def initialize(x, y, z) @x, @y, @z = canonicalize(x, y, z) end
Public Instance Methods
==(other)
click to toggle source
Calls superclass method
# 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()
click to toggle source
# File lib/colors/xyz.rb, line 15 def components [x, y, z] end
luv_components(wp)
click to toggle source
# 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()
click to toggle source
# File lib/colors/xyz.rb, line 32 def rgb_components Convert.xyz_to_rgb(x, y, z) end
to_rgb()
click to toggle source
# File lib/colors/xyz.rb, line 28 def to_rgb RGB.new(*rgb_components) end
uv_values()
click to toggle source
# 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
Private Instance Methods
canonicalize(x, y, z)
click to toggle source
# File lib/colors/xyz.rb, line 62 def canonicalize(x, y, z) [ Rational(x), Rational(y), Rational(z) ] end