type TypedArray = Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array ; param texture param width param height param u param v export function sampleBilinear ( texture , width , height , u , v ) { const maxXIndex = width - 1 ; const maxYIndex = height - 1 ; const xIndex = u * maxXIndex ; const xIndexFloor = Math . floor ( xIndex ) ; const yIndex = v * maxYIndex ; const yIndexFloor = Math . floor ( yIndex ) ; const swIndex = yIndexFloor * width + xIndexFloor ; const seIndex = xIndexFloor < maxXIndex ? swIndex + 1 : swIndex ; const nwIndex = yIndexFloor < maxYIndex ? swIndex + width : swIndex ; const neIndex = xIndexFloor < maxXIndex ? nwIndex + 1 : nwIndex ; const swElevation = texture [ swIndex ] ; const seElevation = texture [ seIndex ] ; const nwElevation = texture [ nwIndex ] ; const neElevation = texture [ neIndex ] ; const xFrac = Number . isInteger ( xIndex ) ? 0 : xIndex - xIndexFloor ; const xFracInverse = 1 - xFrac ; const yFrac = Number . isInteger ( yIndex ) ? 0 : yIndex - yIndexFloor ; const yFracInverse = 1 - yFrac ; const result = swElevation * xFracInverse * yFracInverse + seElevation * xFrac * yFracInverse + nwElevation * xFracInverse * yFrac + neElevation * xFrac * yFrac ; return result ; }