Options
All
  • Public
  • Public/Protected
  • All
Menu

Module auxiliaries

Namespace that comprises various utils (also cleans up documentation).

Index

Variables

Const DEG2RAD

DEG2RAD: 0.017453292519943295 = 0.017453292519943295

Conversion multiplier for degrees to radians conversion (PI / 180).

Const RAD2DEG

RAD2DEG: 57.29577951308232 = 57.29577951308232

Conversion multiplier for radians to degrees conversion (180 / PI).

Let assert

assert: assertImpl = assertImpl

Const byteSuffixes

byteSuffixes: Array<string> = ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi']

Byte suffixes based on ISO/IEC 80000 used for pretty printing of bytes.

Let logVerbosityThreshold

logVerbosityThreshold: number = typeof LOG_VERBOSITY_THRESHOLD !== 'undefined' ? LOG_VERBOSITY_THRESHOLD : 3

Const msScales

msScales: Array<number> = [0, 1e+6, 1e+3, 1e+0, 1e-3]

Scales used for pretty printing of time values in milliseconds.

Const msSuffixes

msSuffixes: Array<string> = ['ms', 'ns', 'μs', 'ms', 's']

Suffixes used for pretty printing of time values in milliseconds.

Functions

GETparameter

  • GETparameter(parameter: string): string | undefined
  • Queries the value of a GET parameter.

    Parameters

    • parameter: string

      Name/identifier of the parameter to query for.

    Returns string | undefined

GETsearch

  • GETsearch(): string

Const assertEmpty

  • assertEmpty(statement: boolean, message: string): void
  • Parameters

    • statement: boolean
    • message: string

    Returns void

Const assertImpl

  • assertImpl(statement: boolean, message: string): void
  • Evaluates the provided statement and throws an evaluation error if false.

    assert(foo <= threshold, `value of foo ${foo} exceeds threshold of ${threshold}`);

    Parameters

    • statement: boolean

      Result of an statement expected to be true.

    • message: string

      Message to be passed to the error (if thrown).

    Returns void

assertions

  • assertions(enable?: undefined | false | true): boolean
  • Allows to specify whether or not assertions should be enabled or disabled/ignored.

    Parameters

    • Optional enable: undefined | false | true

      If true, assertions will be evaluated and might throw errors.

    Returns boolean

bitInBitfield

  • bitInBitfield(flags: GLbitfield, flag: GLbitfield | undefined): boolean
  • Tests if specific bits are set in a given bitfield and returns true if so, false otherwise.

    Parameters

    • flags: GLbitfield
    • flag: GLbitfield | undefined

    Returns boolean

log

  • log(verbosity: LogLevel, message: string): void
  • Writes a warning to the console when the evaluated statement is false.

    log(,`scale changed to ${scale}, given ${this._scale}`);

    Parameters

    • verbosity: LogLevel

      Verbosity of log level: user, developer, or module developer.

    • message: string

      Message to be passed to the error (if thrown).

    Returns void

logIf

  • logIf(statement: boolean, verbosity: LogLevel, message: string): void
  • Writes a lo message to the console when the evaluated statement is false.

    logIf(!vec2.equals(this._scale, scale), LogLevel.Info, `scale changed to ${scale}, given ${this._scale}`);

    Parameters

    • statement: boolean

      Result of an statement expected to be true.

    • verbosity: LogLevel

      Verbosity of log level: debug, info, warning, or error.

    • message: string

      Message to be passed to the error (if thrown).

    Returns void

logPerformanceStart

  • logPerformanceStart(mark: string): void
  • Starts performance measure using the performance API. This call initiates a performance mark and should be followed by a logPerformanceStop call later on. Furthermore, the measurement can be tracked using, e.g., the Chrome built-in performance profiler. Example:

    gloperate.auxiliaries.logPerformanceStart('initialization');
    ...
    gloperate.auxiliaries.logPerformanceStop('initialization');

    The example above should output something like: [3] initialization | 5.635s.

    Parameters

    • mark: string

      Name for the performance measure and base name for the start mark (<mark>-start).

    Returns void

logPerformanceStartIf

  • logPerformanceStartIf(statement: boolean, mark: string): void
  • Invokes logPerformanceStart iff the statement resolves successfully.

    Parameters

    • statement: boolean

      Result of an statement expected to be true in order to invoke logPerformanceStart.

    • mark: string

      Name for the performance measure mark ... @see logPerformanceStart.

    Returns void

logPerformanceStop

  • logPerformanceStop(mark: string, message: string | undefined, measureIndent?: number): void
  • This creates a second, end mark for the given mark name, then creates a performance measure between the start and end mark (<mark>-start and <mark>-end), resolves the duration for logging and, finally, removes/cleans both marks and the measure. The duration is pretty printed ranging from nanoseconds to seconds. Example:

    gloperate.auxiliaries.logPerformanceStart('initialization');
    ...
    gloperate.auxiliaries.logPerformanceStop('initialization', '#items processed: ' + items.length , 48);

    The example above should output something like: [3] initialization #items processed: 4096 | 7.172ms.

    Parameters

    • mark: string

      Name for the performance measure and base name for the end mark (<mark>-end).

    • message: string | undefined

      Optional message to provide to the debug-log output.

    • Default value measureIndent: number = 0

      Optional indentation of the measure (useful if multiple measurements shall be aligned).

    Returns void

logPerformanceStopIf

  • logPerformanceStopIf(statement: boolean, mark: string, message: string | undefined, measureIndent?: number): void
  • Invokes logPerformanceStop under the condition that the statement is true.

    Parameters

    • statement: boolean

      Result of an expression expected to be true in order to invoke logPerformanceStop.

    • mark: string

      Name for the performance measure mark ... @see logPerformanceStart.

    • message: string | undefined

      Optional message to provide to the debug-log output ... @see logPerformanceStart.

    • Default value measureIndent: number = 0

      Optional indentation of the measure ... @see logPerformanceStart.

    Returns void

logVerbosity

  • logVerbosity(verbosity?: undefined | number): number
  • Allows to specify the log verbosity. The default verbosity depends on the bundle type, e.g., a production bundle might use a verbosity of 1, a local development bundle might favor a verbosity of 2. Even though verbosity levels can be used arbitrarily, a verbosity of 0 is intended for user info only, 1 for developers, and 2 for developers of this module. However, this semantic breaks when reusing this logging mechanism in other modules as well...

    Parameters

    • Optional verbosity: undefined | number

      Log level threshold, -1:disabled, 0:user, 1:developer, and 2:module developer.

    Returns number

    • The current log verbosity.

prettyPrintBytes

  • prettyPrintBytes(bytes: number): string
  • Prints bytes using ISO/IEC 80000 postfixes for bytes and fixed number of decimal places (3 decimal places if bytes >= KiB).

    prettyPrintBytes(27738900); // returns '26.454MiB'

    Parameters

    • bytes: number

      Number of bytes in plain bytes.

    Returns string

prettyPrintMilliseconds

  • prettyPrintMilliseconds(milliseconds: number): string
  • Prints given milliseconds in an appropriate seconds-based time unit and fixed number of decimal places.

    prettyPrintMilliseconds(0.03277); // returns '32.770μs'

    Parameters

    • milliseconds: number

      Number of milliseconds as floating point number.

    Returns string

rand

  • rand(min?: number, max?: number): number
  • Generates a random value within a given range [min,max].

    Parameters

    • Default value min: number = 0

      Minimum random value possible.

    • Default value max: number = 1

      Maximum random value possible.

    Returns number

    • Random number in the range [min,max].