import { combineRGBComponents , SimpleEase , Color } from './ParticleUtils' ; import { PropertyNode } from './PropertyNode' ; function intValueSimple ( this , lerp ) { if ( this . ease ) lerp = this . ease ( lerp ) ; return ( ( this . first . next . value - this . first . value ) * lerp ) + this . first . value ; } function intColorSimple ( this , lerp ) { if ( this . ease ) lerp = this . ease ( lerp ) ; const curVal = this . first . value ; const nextVal = this . first . next . value ; const r = ( ( nextVal . r - curVal . r ) * lerp ) + curVal . r ; const g = ( ( nextVal . g - curVal . g ) * lerp ) + curVal . g ; const b = ( ( nextVal . b - curVal . b ) * lerp ) + curVal . b ; return combineRGBComponents ( r , g , b ) ; } function intValueComplex ( this , lerp ) { if ( this . ease ) lerp = this . ease ( lerp ) ; let current = this . first ; let next = current . next ; while ( lerp > next . time ) { current = next ; next = next . next ; } lerp = ( lerp - current . time ) / ( next . time - current . time ) ; return ( ( next . value - current . value ) * lerp ) + current . value ; } function intColorComplex ( this , lerp ) { if ( this . ease ) lerp = this . ease ( lerp ) ; let current = this . first ; let next = current . next ; while ( lerp > next . time ) { current = next ; next = next . next ; } lerp = ( lerp - current . time ) / ( next . time - current . time ) ; const curVal = current . value ; const nextVal = next . value ; const r = ( ( nextVal . r - curVal . r ) * lerp ) + curVal . r ; const g = ( ( nextVal . g - curVal . g ) * lerp ) + curVal . g ; const b = ( ( nextVal . b - curVal . b ) * lerp ) + curVal . b ; return combineRGBComponents ( r , g , b ) ; } function intValueStepped ( this , lerp ) { if ( this . ease ) lerp = this . ease ( lerp ) ; let current = this . first ; while ( current . next && lerp > current . next . time ) { current = current . next ; } return current . value ; } function intColorStepped ( this , lerp ) { if ( this . ease ) lerp = this . ease ( lerp ) ; let current = this . first ; while ( current . next && lerp > current . next . time ) { current = current . next ; } const curVal = current . value ; return combineRGBComponents ( curVal . r , curVal . g , curVal . b ) ; } /**
 * Singly linked list container for keeping track of interpolated properties for particles.
 * Each Particle will have one of these for each interpolated property.
 */ export class PropertyList < V > { /**
     * The first property node in the linked list.
     */ public first : PropertyNode < V > ; param lerp return public interpolate : ( lerp : number ) => number ; param lerp return public ease : SimpleEase ; /**
     * If this list manages colors, which requires a different method for interpolation.
     */ private isColor : boolean ; param isColor constructor ( isColor = false ) { this . first = null ; this . isColor = ! ! isColor ; this . interpolate = null ; this . ease = null ; } param first param first . isStepped public reset ( first ) { this . first = first ; const isSimple = first . next && first . next . time >= 1 ; if ( isSimple ) { this . interpolate = this . isColor ? intColorSimple : intValueSimple ; } else if ( first . isStepped ) { this . interpolate = this . isColor ? intColorStepped : intValueStepped ; } else { this . interpolate = this . isColor ? intColorComplex : intValueComplex ; } this . ease = this . first . ease ; } }