import { IClone } from "./IClone" ; import { MathUtil } from "./MathUtil" ; /**
 * Describes a color in the from of RGBA (in order: R, G, B, A).
 */ export class Color implements IClone { param value returns static gammaToLinearSpace ( value ) { if ( value <= 0.0 ) return 0.0 ; else if ( value <= 0.04045 ) return value / 12.92 ; else if ( value < 1.0 ) return Math . pow ( ( value + 0.055 ) / 1.055 , 2.4 ) ; else return Math . pow ( value , 2.4 ) ; } param value returns static linearToGammaSpace ( value ) { if ( value <= 0.0 ) return 0.0 ; else if ( value < 0.0031308 ) return 12.92 * value ; else if ( value < 1.0 ) return 1.055 * Math . pow ( value , 0.41666 ) - 0.055 ; else return Math . pow ( value , 0.41666 ) ; } param left param right returns static equals ( left , right ) { return ( MathUtil . equals ( left . r , right . r ) && MathUtil . equals ( left . g , right . g ) && MathUtil . equals ( left . b , right . b ) && MathUtil . equals ( left . a , right . a ) ) ; } param left param right param out returns static add ( left , right , out ) { out . r = left . r + right . r ; out . g = left . g + right . g ; out . b = left . b + right . b ; out . a = left . a + right . a ; return out ; } param left param s param out returns static scale ( left , s , out ) { out . r = left . r * s ; out . g = left . g * s ; out . b = left . b * s ; out . a = left . a * s ; return out ; } /** The red component of the color, 0~1. */ public r : number ; /** The green component of the color, 0~1. */ public g : number ; /** The blue component of the color, 0~1. */ public b : number ; /** The alpha component of the color, 0~1. */ public a : number ; param r param g param b param a constructor ( r = 1 , g = 1 , b = 1 , a = 1 ) { this . r = r ; this . g = g ; this . b = b ; this . a = a ; } param r param g param b param a returns setValue ( r , g , b , a ) { this . r = r ; this . g = g ; this . b = b ; this . a = a ; return this ; } param color returns add ( color ) { this . r += color . r ; this . g += color . g ; this . b += color . b ; this . a += color . a ; return this ; } param s returns scale ( s ) { this . r *= s ; this . g *= s ; this . b *= s ; this . a *= s ; return this ; } returns clone ( ) { const ret = new Color ( this . r , this . g , this . b , this . a ) ; return ret ; } param out returns cloneTo ( out ) { out . r = this . r ; out . g = this . g ; out . b = this . b ; out . a = this . a ; return out ; } param out returns toLinear ( out ) { out . r = Color . gammaToLinearSpace ( this . r ) ; out . g = Color . gammaToLinearSpace ( this . g ) ; out . b = Color . gammaToLinearSpace ( this . b ) ; return out ; } param out returns toGamma ( out ) { out . r = Color . linearToGammaSpace ( this . r ) ; out . g = Color . linearToGammaSpace ( this . g ) ; out . b = Color . linearToGammaSpace ( this . b ) ; return out ; } }