rapid-render
    Preparing search index...

    Class MatrixStore

    A highly optimized store for a collection of 2D 3x3 matrices (stored as 6 elements: a, b, c, d, tx, ty). Matrices are stored flat in a dynamic Float32Array to improve memory locality and cache performance.

    Index

    Constructors

    • Creates a new MatrixStore.

      Parameters

      • capacity: number = 10

        The initial capacity of the matrix store (default is 10).

      Returns MatrixStore

    Properties

    The dynamic buffer used to hold matrix data.

    data: Float32Array

    The raw floating-point data of all matrices.

    matrixCount: number = 0

    Total number of matrices currently allocated in the store.

    Methods

    • Allocates a new matrix and initializes it to the identity matrix.

      Returns number

      The index of the newly allocated matrix.

    • Allocates a new matrix without initializing its elements.

      Returns number

      The index of the newly allocated matrix.

    • Copies the elements from the source matrix to the destination matrix.

      Parameters

      • dst: number

        The index of the destination matrix.

      • src: number

        The index of the source matrix.

      Returns void

    • Extracts the global position (translation) from the matrix at the given index.

      Parameters

      • index: number

        The index of the matrix.

      Returns { x: number; y: number }

      An object containing x and y global coordinates.

    • Extracts the global rotation (in radians) from the matrix at the given index.

      Parameters

      • index: number

        The index of the matrix.

      Returns number

      The global rotation in radians.

    • Extracts the global scale from the matrix at the given index.

      Parameters

      • index: number

        The index of the matrix.

      Returns { x: number; y: number }

      An object containing x and y global scale factors.

    • Sets the matrix at the given index to the identity matrix.

      Parameters

      • index: number

        The index of the matrix to modify.

      Returns void

    • Inverts the matrix at the given index. If the matrix is not invertible, it defaults to the identity matrix.

      Parameters

      • index: number

        The index of the matrix to invert.

      Returns void

    • Transforms a point from local coordinates to world coordinates.

      Parameters

      • index: number

        The index of the local transformation matrix.

      • x: number

        Local x coordinate.

      • y: number

        Local y coordinate.

      Returns { x: number; y: number }

      The transformed point in world coordinates.

    • Multiplies the destination matrix by the source matrix and stores the result in the destination.

      Parameters

      • dst: number

        The index of the destination matrix.

      • src: number

        The index of the source matrix.

      Returns void

    • Multiplies matrix A by matrix B and stores the result in the output matrix.

      Parameters

      • out: number

        The index of the output matrix.

      • aIdx: number

        The index of matrix A.

      • bIdx: number

        The index of matrix B.

      Returns void

    • Resets the store, clearing all allocated matrices.

      Returns void

    • Rotates the matrix at the given index by the specified radians.

      Parameters

      • index: number

        The index of the matrix to modify.

      • radians: number

        The rotation angle in radians.

      Returns void

    • Rotates the matrix at the given index around a local offset point (pivot).

      This is equivalent to:

      1. Translating by (offsetX, offsetY) to move the pivot to the origin.
      2. Rotating by radians.
      3. Translating back by (-offsetX, -offsetY).

      Useful for rotating a sprite around a point other than its own origin, e.g. a character's limb rotating around its joint.

      Parameters

      • index: number

        The index of the matrix to modify.

      • radians: number

        The rotation angle in radians.

      • offsetX: number

        The x component of the pivot point in local space.

      • offsetY: number

        The y component of the pivot point in local space.

      Returns void

    • Scales the matrix at the given index by scaleX and scaleY.

      Parameters

      • index: number

        The index of the matrix to modify.

      • scaleX: number

        The scale factor along the x-axis.

      • scaleY: number

        The scale factor along the y-axis.

      Returns void

    • Converts the matrix at the given index to a CSS matrix string.

      Parameters

      • index: number

        The index of the matrix.

      Returns string

      A CSS matrix string.

    • Transforms a point by the matrix at the given index.

      Parameters

      • index: number

        The index of the transformation matrix.

      • x: number

        The x coordinate of the point.

      • y: number

        The y coordinate of the point.

      Returns { x: number; y: number }

      The transformed point {x, y}.

    • Translates the matrix at the given index by x and y.

      Parameters

      • index: number

        The index of the matrix to modify.

      • x: number

        The x translation.

      • y: number

        The y translation.

      Returns void

    • Transforms a point from world coordinates to local coordinates using the matrix at the specified index. Useful for hit testing against objects placed in world space.

      Parameters

      • index: number

        The index of the world transformation matrix.

      • x: number

        World x coordinate.

      • y: number

        World y coordinate.

      Returns { x: number; y: number }

      The transformed point in local coordinates.