Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "gvec"

Index

Variables

Const PROPS

PROPS: Set<string | number | symbol> = new Set<PropertyKey>([SYM_B,SYM_C,SYM_CV,SYM_EMPTY,SYM_EQD,SYM_L,SYM_O,SYM_S,SYM_STR,Symbol.iterator,])

Const SYM_B

SYM_B: "buf" = "buf"

Const SYM_C

SYM_C: "copy" = "copy"

Const SYM_CV

SYM_CV: "copyView" = "copyView"

Const SYM_EMPTY

SYM_EMPTY: "empty" = "empty"

Const SYM_EQD

SYM_EQD: "eqDelta" = "eqDelta"

Const SYM_L

SYM_L: "length" = "length"

Const SYM_O

SYM_O: "offset" = "offset"

Const SYM_S

SYM_S: "stride" = "stride"

Const SYM_STR

SYM_STR: "toString" = "toString"

Const keys

keys: (x: A) => B = memoize1<number, PropertyKey[]>((size: number) => [...map(String, range(size)),...PROPS,])

Type declaration

    • (x: A): B
    • Parameters

      • x: A

      Returns B

Functions

Const gvec

  • gvec(buf: Vec, size: number, offset?: number, stride?: number): IVector<any>
  • Wrapper for strided, arbitrary length vectors.

    remarks

    Wraps given buffer in ES6 Proxy with custom property getters/setters and implements the following interfaces:

    • Iterable (ES6)
    • {@link @thi.ng/api#ICopy}
    • {@link @thi.ng/api#IEmpty}
    • {@link @thi.ng/api#IEqualsDelta}
    • IVector
    • Object.toString()

    Read/write access for the following properties:

    • array indices in the [0 .. size) interval
    • offset - start index
    • stride - component stride
    • buf - backing buffer (readonly)
    • length - vector size

    Array index access uses bounds checking against the [0 .. size) interval, but, for performance reasons, not against the actual wrapped buffer.

    Note: ES6 proxies are ~10x slower than standard array accesses. If several computations are to be performed on such vectors it will be much more efficient to first copy them to compact arrays and then copy result back if needed.

    example
    // 3D vector w/ stride length of 4
    a = gvec([1,0,0,0,2,0,0,0,3,0,0,0], 3, 0, 4);
    a[0] // 1
    a[1] // 2
    a[2] // 3
    
    a.stride
    // 4
    
    [...a]
    // [1, 2, 3]
    
    a.toString()
    // "[1,2,3]"
    
    add([], a, a)
    // [2, 4, 6]
    
    copy(a)
    // [1, 2, 3]
    
    a.copyView()
    // Proxy [ [ 1, 0, 2, 0, 3, 0 ], ... }
    
    eqDelta(a, [1, 2, 3])
    // true

    Parameters

    • buf: Vec

      backing buffer

    • size: number

      vector size / num components

    • Default value offset: number = 0

      start index

    • Default value stride: number = 1

      component stride

    Returns IVector<any>

Generated using TypeDoc