import { clamp } from './gl-matrix-extensions' ; /**
 * If true, assertions immediately return on invocation (variable can be set via webpack define plugin).
 */ declare let DISABLE_ASSERTIONS ; /**
 * If defined, logs of equal or higher verbosity level are skipped (variable can be set via webpack define plugin).
 */ declare let LOG_VERBOSITY_THRESHOLD ; /** Namespace that comprises various utils (also cleans up documentation). */ namespace auxiliaries { let logVerbosityThreshold = typeof LOG_VERBOSITY_THRESHOLD !== 'undefined' ? LOG_VERBOSITY_THRESHOLD : 3 ; param verbosity returns export function logVerbosity ( verbosity ? ) { if ( verbosity !== undefined ) { logVerbosityThreshold = Math . max ( - 1 , verbosity ) ; } return logVerbosityThreshold ; } /**
     * Log verbosity levels.
     */ export enum LogLevel { Debug = 3 , Info = 2 , Warning = 1 , Error = 0 } param statement param message const assertImpl = ( statement , message ) : void => { if ( statement ) { return ; } throw new EvalError ( message ) ; } ; const assertEmpty = ( statement , message ) : void => { } ; export let assert = assertImpl ; if ( typeof DISABLE_ASSERTIONS !== 'undefined' && DISABLE_ASSERTIONS ) { assert = assertEmpty ; } param enable returns export function assertions ( enable ? ) { if ( enable !== undefined ) { assert = enable ? assertImpl : assertEmpty ; } return assert !== assertEmpty ; } param statement param verbosity param message export function log ( verbosity , ... message ) { if ( verbosity > logVerbosityThreshold ) { return ; } console . log ( `[${ verbosity }]` , ... message ) ; } param statement param verbosity param message export function logIf ( statement , verbosity , ... message ) { if ( ! statement ) { return ; } log ( verbosity , ... message ) ; } param mark export function logPerformanceStart ( mark ) { const start = `${ mark }-start` ; assert ( performance . getEntriesByName ( mark ) . length === 0 , `expected mark identifier to not already exists, given ${ mark }` ) ; assert ( performance . getEntriesByName ( start ) . length === 0 , `expected mark identifier to not already exists, given ${ start }` ) ; performance . mark ( start ) ; } param statement param mark see logPerformanceStart .
      export function logPerformanceStartIf ( statement , mark ) { if ( ! statement ) { return ; } logPerformanceStart ( mark ) ; } param mark param message param measureIndent export function logPerformanceStop ( mark , message , measureIndent = 0 ) { const start = `${ mark }-start` ; const end = `${ mark }-end` ; assert ( performance . getEntriesByName ( mark ) . length === 0 , `expected mark identifier to not already exists, given ${ mark }` ) ; assert ( performance . getEntriesByName ( end ) . length === 0 , `expected mark identifier to not already exists, given ${ end }` ) ; performance . mark ( end ) ; performance . measure ( mark , start , end ) ; const measures = performance . getEntriesByName ( mark ) ; const measure = measures [ 0 ] ; performance . clearMarks ( start ) ; performance . clearMarks ( end ) ; performance . clearMeasures ( mark ) ; const minIndent = message === undefined || message ! . length === 0 ? 0 : 2 ; const indent = Math . max ( minIndent , measureIndent - mark . length - ( message ? message ! . length : 0 ) - 1 ) ; const prettyMeasure = prettyPrintMilliseconds ( measure . duration ) ; log ( LogLevel . Debug , `${ mark }${ ' ' . repeat ( indent ) }${ message ? message : '' } | ${ prettyMeasure }` ) ; } param statement param mark see logPerformanceStart .
     *  param message see logPerformanceStart .
     *  param measureIndent see logPerformanceStart .
      export function logPerformanceStopIf ( statement , mark , message , measureIndent = 0 ) { if ( ! statement ) { return ; } logPerformanceStop ( mark , message , measureIndent ) ; } param min param max returns export function rand ( min = 0.0 , max = 1.0 ) { return Math . random ( ) * ( max - min ) + min ; } param x export function isPowerOfTwo ( x ) { return Number . isInteger ( x ) && Number . isInteger ( Math . log2 ( x ) ) ; } /**
     * Computes the next upper power of two for the given number. Math is based on
     *  https .
     *  param x export function upperPowerOfTwo ( x ) { -- x ; x |= x >> 1 ; x |= x >> 2 ; x |= x >> 4 ; x |= x >> 8 ; x |= x >> 16 ; return ++ x ; } /**
     * Byte suffixes based on ISO/IEC 80000 used for pretty printing of bytes.
     */ const byteSuffixes = [ '' , 'Ki' , 'Mi' , 'Gi' , 'Ti' , 'Pi' , 'Ei' , 'Zi' , 'Yi' ] ; param bytes export function prettyPrintBytes ( bytes ) { const prefix = bytes > 0 ? Math . floor ( Math . log ( bytes ) / Math . log ( 1024 ) ) : 0 ; const value = bytes / Math . pow ( 1024 , prefix ) ; return `${ prefix > 0 ? value . toFixed ( 3 ) : value }${ byteSuffixes [ prefix ] }B` ; } /**
     * Suffixes used for pretty printing of time values in milliseconds.
     */ const msSuffixes = [ 'ms' , 'ns' , 'μs' , 'ms' , 's' ] ; /**
     * Scales used for pretty printing of time values in milliseconds.
     */ const msScales = [ 0 , 1e+6 , 1e+3 , 1e+0 , 1e-3 ] ; param milliseconds export function prettyPrintMilliseconds ( milliseconds ) { let prefix = milliseconds > 0 ? Math . max ( 1 , Math . floor ( Math . log ( milliseconds * 10 ) / Math . log ( 1e+3 ) ) + 3 ) : 0 ; prefix = clamp ( prefix , 0 , 4 ) ; const value = milliseconds * msScales [ prefix ] ; return `${ value . toFixed ( 3 ) }${ msSuffixes [ prefix ] }` ; } /**
     * Tests if specific bits are set in a given bitfield and returns true if so, false otherwise.
     */ export function bitInBitfield ( flags , flag ) { if ( flag === undefined ) { return false ; } return ( flags & flag ) === flag ; } /**
     * Conversion multiplier for radians to degrees conversion (180 / PI).
     */ export const RAD2DEG = 57.295779513082320 ; /**
     * Conversion multiplier for degrees to radians conversion (PI / 180).
     */ export const DEG2RAD = 0.017453292519943295 ; /**
     * Queries window.location.search, or, if not present, window.location.search of the window's top frame.
     */ export function GETsearch ( ) { let search = window . location . search ; if ( ! search ) { search = window . top . location . search ; } return search ; } param parameter export function GETparameter ( parameter ) { const re = new RegExp ( `${ parameter }=([^&]+)` ) ; let match = window . location . search . match ( re ) ; if ( ! match ) { match = window . top . location . search . match ( re ) ; } if ( ! match ) { return undefined ; } return match [ 1 ] ; } /**
     * Path separator used for path related functions such as dirname and basename.
     */ export const PATH_SEPARATOR = '/' ; param path export function dirname ( path ) { if ( path . includes ( PATH_SEPARATOR ) === false ) { return '' ; } return path . substr ( 0 , path . lastIndexOf ( PATH_SEPARATOR ) ) . trimLeft ( ) ; } param path export function basename ( path ) { if ( path . includes ( PATH_SEPARATOR ) === false ) { return path ; } return path . substr ( path . lastIndexOf ( PATH_SEPARATOR ) + 1 ) . trimRight ( ) ; } } export = auxiliaries ;