module Webglimpse { export var GL = WebGLRenderingContext ; export function hasval ( value ) { return ( value != null ) ; } export function isNumber ( value ) { return typeof ( value ) === 'number' ; } export function isString ( value ) { return typeof ( value ) === 'string' ; } export function isEmpty ( array ) { return ( array . length === 0 ) ; } export function notEmpty ( array ) { return ( array . length > 0 ) ; } export function alwaysTrue ( ) { return true ; } export function alwaysFalse ( ) { return false ; } export function constantFn < V > ( value ) { return function ( ) : V { return value ; } ; } export function log10 ( x ) { return Math . log ( x ) * ( 1.0 / Math . LN10 ) ; } export function order ( x ) { return Math . floor ( log10 ( x ) + 1e-12 ) ; } export function clamp ( xMin , xMax , x ) { return Math . max ( xMin , Math . min ( xMax , x ) ) ; } export function copyArray < T > ( values ) { return values . slice ( 0 ) ; } export function ensureCapacityFloat32 ( buffer , minNewCapacity ) { if ( ! minNewCapacity || buffer . length >= minNewCapacity ) { return buffer ; } else { var newCapacity = Math . max ( minNewCapacity , 2 * buffer . length ) ; return new Float32Array ( newCapacity ) ; } } export function ensureCapacityUint32 ( buffer , minNewCapacity ) { if ( ! minNewCapacity || buffer . length >= minNewCapacity ) { return buffer ; } else { var newCapacity = Math . max ( minNewCapacity , 2 * buffer . length ) ; return new Uint32Array ( newCapacity ) ; } } export function ensureCapacityUint16 ( buffer , minNewCapacity ) { if ( ! minNewCapacity || buffer . length >= minNewCapacity ) { return buffer ; } else { var newCapacity = Math . max ( minNewCapacity , 2 * buffer . length ) ; return new Uint16Array ( newCapacity ) ; } } export interface StringMap < V > { [ key ] : V ; } export interface IdFunction < V > { ( value ) : string ; } export var getObjectId = ( function ( ) { var keyName = 'webglimpse_ObjectId' ; var nextValue = 0 ; return function ( obj ) : string { var value = obj [ keyName ] ; if ( ! hasval ( value ) ) { value = ( nextValue ++ ) . toString ( ) ; obj [ keyName ] = value ; } return value ; } ; } ) ( ) ; export function concatLines ( ... lines ) { return lines . join ( '\n' ) ; } /**
     * Parses a timestamp from the format 'YYYY-MM-DDTHH:mm:ss[.SSS]ZZ' into posix-milliseconds.
     *
     * Format examples:
     *   - '2014-01-01T00:00:00Z'
     *   - '2014-01-01T00:00:00.000+00:00'
     *
     * Use of a colon in numeric timezones is optional. However, it is strongly encouraged, for
     * compatibility with Date in major browsers.
     *
     * Parsing is strict, and will throw an error if the input string does not match the expected
     * format. A notable example is that the seconds field must not have more than three decimal
     * places.
     *
     */ export function parseTime_PMILLIS ( time_ISO8601 ) { var m = moment ( time_ISO8601 , 'YYYY-MM-DDTHH:mm:ssZZ' , true ) ; if ( m . isValid ( ) ) return m . valueOf ( ) ; var m = moment ( time_ISO8601 , 'YYYY-MM-DDTHH:mm:ss.SSSZZ' , true ) ; if ( m . isValid ( ) ) return m . valueOf ( ) ; var m = moment ( time_ISO8601 , 'YYYY-MM-DDTHH:mm:ss.SSZZ' , true ) ; if ( m . isValid ( ) ) return m . valueOf ( ) ; var m = moment ( time_ISO8601 , 'YYYY-MM-DDTHH:mm:ss.SZZ' , true ) ; if ( m . isValid ( ) ) return m . valueOf ( ) ; throw new Error ( 'Failed to parse time-string: \'' + time_ISO8601 + '\'' ) ; } /**
     * Formats a timestamp from posix-millis into the format 'YYYY-MM-DDThh:mm:ss.SSSZZ' (for
     * example '2014-01-01T00:00:00.000Z').
     *
     * The input value is effectively truncated (not rounded!) to milliseconds. So for example,
     * formatTime_ISO8601(12345.999) will return '1970-01-01T00:00:12.345Z' -- exactly the same
     * as for an input of 12345.
     *
     */ export function formatTime_ISO8601 ( time_PMILLIS ) { return moment ( time_PMILLIS ) . toISOString ( ) ; } }