Class Vector2

Hierarchy

  • Vector2

Constructors

  • Constructs a new Vector2 with the given components.

    Parameters

    • x: number = 0

      X component

    • y: number = 0

      Y component

    Returns Vector2

Properties

x: number

X component of vector.

Property

y: number

Y component of vector.

Property

Accessors

Methods

  • Adds given Vector2 or X, Y to this Vector2 components.

    Method

    Returns

    This reference

    Example

    vector2.add(exampleVector);
    vector2.add(x, y);

    Parameters

    • x: number | Vector2

      The Vector2 or X-coordinate

    • Optional y: number

      The Y-coordinate (if x isn't Vector2)

    Returns Vector2

  • Returns distance between Vector2 or X, Y coordinate.

    Method

    Returns

    The distance between vectors

    Example

    vector2.distance(exampleVector);
    vector2.distance(0, 0);

    Parameters

    • x: number | Vector2

      The Vector2 or X-coordinate

    • Optional y: number

      The Y-coordinate (if x isn't Vector2)

    Returns number

  • Divides component by scalar or Vector2.

    Method

    Returns

    This reference

    Example

    vector2.divide(exampleVector);
    vector2.divide(scalar);

    Parameters

    • x: number | Vector2

      The Vector2 or scalar

    Returns Vector2

  • Returns true if two vectors are equal.

    Method

    Returns

    are vectors equal

    Example

    const vector1 = new JSGL.Vector2(2, 4);
    const vector2 = new JSGL.Vector2(2, 4);
    vector1.equal(vector2);

    Parameters

    • Optional v: Vector2

      The second Vector2

    Returns boolean

  • Multiplies component by scalar or Vector2.

    Method

    Returns

    This reference

    Example

    vector2.multiply(exampleVector);
    vector2.multiply(scalar);

    Parameters

    • x: number | Vector2

      The Vector2 or scalar

    Returns Vector2

  • Sets components to given Vector2 or X, Y.

    Method

    Returns

    This reference

    Example

    vector2.set(exampleVector);
    vector2.set(x, y);

    Parameters

    • x: number | Vector2

      The Vector2 or X-coordinate

    • Optional y: number

      The Y-coordinate (if x isn't Vector2)

    Returns Vector2

  • Substracts given Vector2 or X, Y to this Vector2 components.

    Method

    Returns

    This reference

    Example

    vector2.subtract(exampleVector);
    vector2.subtract(x, y);

    Parameters

    • x: number | Vector2

      The Vector2 or X-coordinate

    • Optional y: number

      The Y-coordinate (if x isn't Vector2)

    Returns Vector2

  • Returns true if two vectors are equal.

    Method

    Returns

    are vectors equal

    Example

    const vector1 = new JSGL.Vector2(2, 4);
    const vector2 = new JSGL.Vector2(2, 4);
    JSGL.Vector2.Equal(vector1, vector2);

    Parameters

    • Optional v: Vector2

      The first Vector2

    • Optional v2: Vector2

      The second Vector2

    Returns boolean

  • Returns is point between given 2D range.

    Method

    Returns

    is point between range.

    Example

    const min = new JSGL.Vector2(5, 5);
    const max = new JSGL.Vector2(7, 7);
    JSGL.Vector2.IsPointIn(min, max, new JSGL.Vector2(6, 5));

    Parameters

    Returns boolean

  • Performs Linear Interpolation on Vectors2 with given decimal midpoint

    Method

    Returns

    Vector2 after Linear Interpolation.

    Example

    const a = new JSGL.Vector2(3, 9);
    const b = new JSGL.Vector2(5, 2);
    JSGL.Vector2.Lerp(a, b, 0); // (3, 9)
    JSGL.Vector2.Lerp(a, b, 0.5); // (4, 5.5)
    JSGL.Vector2.Lerp(a, b, 1); // (5, 2)

    Parameters

    • a: Vector2

      The first Vector2

    • b: Vector2

      The second Vector2

    • c: number = 0

      The decimal midpoint

    Returns Vector2

  • Returns the new Vector2 with maximum X and Y coordinates from first and second Vector2

    Method

    Returns

    The new Vector2 with maximum X and Y

    Example

    const a = new JSGL.Vector2(3, 9);
    const b = new JSGL.Vector2(5, 2);
    const max = JSGL.Vector2.Max(a, b); // (5, 9)

    Parameters

    Returns Vector2

  • Returns the new Vector2 with minimum X and Y coordinates from first and second Vector2

    Method

    Returns

    The new Vector2 with minimum X and Y

    Example

    const a = new JSGL.Vector2(3, 9);
    const b = new JSGL.Vector2(5, 2);
    const min = JSGL.Vector2.Min(a, b); // (3, 2)

    Parameters

    Returns Vector2