Nano WebGPU API - v0.11.0
    Preparing search index...

    Class Vec2

    2D vector representation containing x and y components. Used for positional and texture coordinate calculations.

    Index

    Accessors

    Constructors

    • Create a new Vec2

      Parameters

      • Optionalx: number = 0

        X component

      • Optionaly: number = 0

        Y component

      Returns Vec2

    Methods

    • Adds another vector to this one (in-place)

      Parameters

      • v: Vec2

        The vector to add

      Returns this

      The current vector (for chaining)

    • Adds a scaled vector to this one (in-place) without allocating temporary objects. Computes: this += v * s

      Parameters

      • v: Vec2

        The vector to scale and add

      • s: number

        The scalar factor

      Returns this

      The current vector (for chaining)

    • Clone this vector into a new Vec2

      Returns Vec2

      A new vector with the same x and y values

    • Copy the values of another vector into this vector

      Parameters

      • v: Vec2

        The vector to copy from

      Returns this

      The current vector (for chaining)

    • Calculates the distance to another vector

      Parameters

      • v: Vec2

        The other vector

      Returns number

      The distance

    • Calculates the squared distance to another vector

      Parameters

      • v: Vec2

        The other vector

      Returns number

      The squared distance

    • Calculates the dot product of this vector and another

      Parameters

      • v: Vec2

        The other vector

      Returns number

      The dot product

    • Checks for strict equality with another vector

      Parameters

      • v: Vec2

        The vector to compare with

      Returns boolean

      True if the components are exactly equal

    • Calculates the length of this vector

      Returns number

      The length

    • Calculates the squared length of this vector

      Returns number

      The squared length

    • Linearly interpolate to a target vector (in-place)

      Parameters

      • target: Vec2

        The target vector to interpolate towards

      • t: number

        Interpolation factor

      Returns this

      The current vector (for chaining)

    • Multiplies this vector by another vector (in-place)

      Parameters

      • v: Vec2

        The vector to multiply by

      Returns this

      The current vector (for chaining)

    • Normalizes this vector (in-place)

      Returns this

      The current vector (for chaining)

    • Scales this vector by a scalar value (in-place)

      Parameters

      • n: number

        The scalar value

      Returns this

      The current vector (for chaining)

    • Set the x and y components of this vector

      Parameters

      • x: number

        The new x value

      • y: number

        The new y value

      Returns this

      The current vector (for chaining)

    • Subtracts another vector from this one (in-place)

      Parameters

      • v: Vec2

        The vector to subtract

      Returns this

      The current vector (for chaining)

    • Get the vector as a Float32Array or fill an existing array

      Parameters

      • Optionalout: Float32Array<ArrayBufferLike>

        Optional Float32Array to fill

      • Optionaloffset: number = 0

        Optional offset in the array

      Returns Float32Array

      The filled array

    • Linearly interpolate between two vectors into a new vector

      Parameters

      • v1: Vec2

        Start vector

      • v2: Vec2

        End vector

      • t: number

        Interpolation factor

      • Optionalout: Vec2 = ...

        Optional vector to store the result

      Returns Vec2

      The interpolated vector

    Properties

    x: number

    X component

    y: number

    Y component