src/utils.js
/**
 * Ensures an array of rgba floats contains exactly 4 numbers. If an alpha
 * channel value is missing, then it is assumed to be '1'.
 * ensureRGBA(color: Array<...Number>) -> Array<Number, Number, Number, Number>>
 */
Ensures an array of rgba floats contains exactly 4 numbers. If an alpha
channel value is missing, then it is assumed to be '1'.
Ensures an array of rgba floats contains exactly 4 numbers . If an alpha channel value is missing then it is assumed to be ' 1 ' .
function ensureRGBA(color) {
  color = [...(color || [])]
  for (let i = 0; i < 3; ++i) {
    if ('number' != typeof color[i]) { color[i] = 0 }
    else { color[i] = clamp(color[i], 0, 1) }
  }
  if ('number' != typeof color[3]) { color[3] = 1 }
  else { color[3] = clamp(color[3], 0, 1) }
  return [...color].slice(0, 4)
}
function ensureRGBA ( color ) { color = [ ... ( color || [ ] ) ] for ( let i = 0 ; i < 3 ; ++ i ) { if ( 'number' != typeof color [ i ] ) { color [ i ] = 0 } else { color [ i ] = clamp ( color [ i ] , 0 , 1 ) } } if ( 'number' != typeof color [ 3 ] ) { color [ 3 ] = 1 } else { color [ 3 ] = clamp ( color [ 3 ] , 0 , 1 ) } return [ ... color ] . slice ( 0 , 4 ) }
Ensures an array of rgba floats contains exactly 4 numbers.
Ensures an array of rgba floats contains exactly 4 numbers .