export function clamp ( val , min , max ) { return Math . min ( max , Math . max ( min , val ) ) ; } export function modAbs ( val , length ) { let newVal = val ; if ( newVal < 0 ) { newVal = length + ( newVal % length ) ; } if ( newVal >= length ) { return newVal % length ; } return newVal ; }