 # CIE L*a*b* constants
 lab_e = 0.008856
 lab_k = 903.3
+
+# Clip to fit the 0..1 range
+clip = (i) ->
+  i = 0 if i < 0
+  i = 1 if i > 1
+  return i
 
 # Functions for converting between CIE XYZ and other color spaces
 # Most of these taken directly from Wikipedia

if jQuery?
  jQuery.colorspaces = root 


          12.92 * c
        else
          1.055 * Math.pow(c, 1 / 2.4) - 0.055
      _R = clip from_linear dot_product m[0], tuple
      _G = clip from_linear dot_product m[1], tuple
      _B = clip from_linear dot_product m[2], tuple
      [_R, _G, _B]
    to_CIExyY: (_X, _Y, _Z) ->
      sum = _X + _Y + _Z
