Function setDefaultType

  • Sets the type this library creates for a Vec2

    Parameters

    • ctor: (new (n) => Vec2)

      the constructor for the type. Either Float32Array, Float64Array, or Array

        • new (n): Vec2
        • Parameters

          • n: number

          Returns Vec2

    Returns (new (n) => Vec2)

    previous constructor for Vec2

      • new (n): Vec2
      • Vec2 math functions.

        Almost all functions take an optional dst argument. If it is not passed in the functions will create a new Vec2. In other words you can do this

        const v = vec2.cross(v1, v2);  // Creates a new Vec2 with the cross product of v1 x v2.
        

        or

        const v = vec2.create();
        vec2.cross(v1, v2, v); // Puts the cross product of v1 x v2 in v

        The first style is often easier but depending on where it's used it generates garbage where as there is almost never allocation with the second style.

        It is always safe to pass any vector as the destination. So for example

        vec2.cross(v1, v2, v1);  // Puts the cross product of v1 x v2 in v1
        

        Parameters

        • n: number

        Returns Vec2