import { RandomNumberGenerator } from './data_generator' ; internal export class Simple1DNoise { private maxVertices : number ; private maxVerticesMask : number ; private amplitude : number ; private scale : number ; private getRandomNumber : RandomNumberGenerator ; constructor ( randomNumberGenerator , maxVertices = 256 , amplitude = 5.1 , scale = 0.6 ) { this . getRandomNumber = randomNumberGenerator ; this . maxVerticesMask = maxVertices - 1 ; this . amplitude = amplitude ; this . scale = scale ; this . maxVertices = maxVertices ; } getValue ( x ) { const r = new Array ( this . maxVertices ) . fill ( 0 ) . map ( ( ) => this . getRandomNumber ( 0 , 1 , 5 , true ) ) ; const scaledX = x * this . scale ; const xFloor = Math . floor ( scaledX ) ; const t = scaledX - xFloor ; const tRemapSmoothstep = t * t * ( 3 - 2 * t ) ; const xMin = xFloor & this . maxVerticesMask ; const xMax = ( xMin + 1 ) & this . maxVerticesMask ; const y = this . lerp ( r [ xMin ] , r [ xMax ] , tRemapSmoothstep ) ; return y * this . amplitude ; } private lerp ( a , b , t ) { return a * ( 1 - t ) + b * t ; } }