Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace 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 PATH_SEPARATOR

PATH_SEPARATOR: "/" = '/'

Path separator used for path related functions such as dirname and basename.

Const RAD2DEG

RAD2DEG: 57.29577951308232 = 57.295779513082320

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

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
  • Queries window.location.search, or, if not present, window.location.search of the window's top frame.

    Returns string

Let assert

  • assert(statement: boolean, message: string): void

assertions

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

    Parameters

    • Optional enable: boolean

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

    Returns boolean

    whether assertions are enabled

basename

  • basename(path: string): string
  • Returns the base name of a given file path. If no path separator is found, the input path is returned.

    Parameters

    • path: string

      Path string the file/base name should be returned of.

    Returns string

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

dirname

  • dirname(path: string): string
  • Returns the directory name of a given (file) path. If no path separator is found, an empty dir name is returned.

    Parameters

    • path: string

      Path string the directory name should be returned of.

    Returns string

isPowerOfTwo

  • isPowerOfTwo(x: number): boolean
  • Tests with binary operations if the number is power of two.

    Parameters

    • x: number

      The number to test.

    Returns boolean

log

  • log(verbosity: LogLevel, ...message: any[]): 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.

    • Rest ...message: any[]

      Message to be passed to the log (if verbosity high enough).

    Returns void

logIf

  • logIf(statement: boolean, verbosity: LogLevel, ...message: any[]): 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.

    • Rest ...message: any[]

      Message to be passed to the log (if thrown and verbosity high enough).

    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.

    • 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.

    • measureIndent: number = 0

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

    Returns void

logVerbosity

  • logVerbosity(verbosity?: 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: 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

    • min: number = 0.0

      Minimum random value possible.

    • max: number = 1.0

      Maximum random value possible.

    Returns number

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

upperPowerOfTwo

  • upperPowerOfTwo(x: number): number