Class Common.Vector2D

2D Vector class.

Used for many pathfinding and many other operations that are treated as planar rather than 3d.

Fields

Common.Vector2D.x Vector x variable.
Common.Vector2D.y Vector y variable.

Methods

Common.Vector2D:Create (X[, Y]) Constructs a 2D vector.
Common.Vector2D:FromString (stringVector) Constructs a 2D vector from a string.
Common.Vector2D:Clone () Returns a clone of this vector.
Common.Vector2D:Length () Gets the length of this vector.
Common.Vector2D:Normalize () Returns the normalized form of this vector.
Common.Vector2D:Make3D () Returns the 3D form of this vector.
Common.Vector2D:ToString () Returns a string representation of this vector.
Common.Vector2D:DotProduct (v) Returns a dot product from 2 vectors.

Metamethods

Common.Vector2D.__index Base class.
Common.Vector2D.__tostring Returns a string representation of this vector.
Common.Vector2D:__unm () Returns a negated form of this vector.
Common.Vector2D:__eq (v) Compares this vector.
Common.Vector2D:__add (v) Returns a vector from addition of 2 vectors.
Common.Vector2D:__sub (v) Returns a vector from subtraction of 2 vectors.
Common.Vector2D:__mul (fl) Multiplies this vector with a number value.
Common.Vector2D:__div (fl) Divides this vector with a number value.


Fields

Common.Vector2D.x
Vector x variable.
  • x number (default 0)
Common.Vector2D.y
Vector y variable.
  • y number (default 0)

Methods

Common.Vector2D:Create (X[, Y])
Constructs a 2D vector.

Parameters:

  • X number or table The value of X. | The vector-compatible table.
  • Y number The value of Y (Ignored if X is table). (optional)

Returns:

    Common.Vector2D The new vector.

Usage:

    -- You can do this.
    vec = Common.Vector2D:Create( 1 , 2 )
    -- or do this.
    vec = Common.Vector2D:Create( { x = 1 , y = 2 } )
    -- or do this.
    vec = Common.Vector2D:Create( "1 2" )
Common.Vector2D:FromString (stringVector)
Constructs a 2D vector from a string. Format should be: x y

Parameters:

  • stringVector string The string vector.

Returns:

    Common.Vector2D The new vector.
Common.Vector2D:Clone ()
Returns a clone of this vector.

Returns:

    Common.Vector2D The new vector.
Common.Vector2D:Length ()
Gets the length of this vector.

Returns:

    number The length.
Common.Vector2D:Normalize ()
Returns the normalized form of this vector.

Returns:

    Common.Vector2D The normalized vector.
Common.Vector2D:Make3D ()
Returns the 3D form of this vector.

Returns:

    Common.Vector The new 3D vector.
Common.Vector2D:ToString ()
Returns a string representation of this vector.

Returns:

    string The string of integers.
Common.Vector2D:DotProduct (v)
Returns a dot product from 2 vectors.

Parameters:

Returns:

    number The dot product.

Metamethods

Common.Vector2D.__index
Base class.
Common.Vector2D.__tostring
Returns a string representation of this vector.
Common.Vector2D:__unm ()
Returns a negated form of this vector.

Returns:

    Common.Vector2D The new vector.

Usage:

    local vec = Common.Vector2D:Create( 1 , 2 );
    vec = -vec;
    print( vec:ToString() ); -- prints "-1 -2".
Common.Vector2D:__eq (v)
Compares this vector.

Parameters:

Returns:

    bool Returns true if equals.

Usage:

    local vec = Common.Vector2D:Create();
    print( vec == Common.vecZero ); -- prints "true".
Common.Vector2D:__add (v)
Returns a vector from addition of 2 vectors.

Parameters:

Returns:

    Common.Vector2D The new vector.

Usage:

    local vec = Common.Vector2D:Create( 2 , 3 );
    vec = vec + {x = 2 , y = 1};
    print( vec:ToString() ); -- prints "4 4".
Common.Vector2D:__sub (v)
Returns a vector from subtraction of 2 vectors.

Parameters:

Returns:

    Common.Vector2D The new vector.

Usage:

    local vec = Common.Vector2D:Create( 2 , 3 );
    vec = vec - {x = 2 , y = 1};
    print( vec:ToString() ); -- prints "0 2".
Common.Vector2D:__mul (fl)
Multiplies this vector with a number value.

Parameters:

  • fl number The modifier.

Returns:

    Common.Vector2D The new vector.

Usage:

    local vec = Common.Vector2D:Create( 2 , 3 );
    vec = vec * 2;
    print( vec:ToString() ); -- prints "4 6".
Common.Vector2D:__div (fl)
Divides this vector with a number value.

Parameters:

  • fl number The modifier.

Returns:

    Common.Vector2D The new vector.

Usage:

    local vec = Common.Vector2D:Create( 4 , 6 );
    vec = vec / 2;
    print( vec:ToString() ); -- prints "2 3".
generated by LDoc 1.4.6 Last updated 2020-06-15 21:15:36