Class Common.Vector2D
2D Vector class.
Used for many pathfinding and many other operations
that are treated as planar rather than 3d.
-
Common.Vector2D.x
-
Vector x variable.
-
Common.Vector2D.y
-
Vector y variable.
-
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:
vec = Common.Vector2D:Create( 1 , 2 )
vec = Common.Vector2D:Create( { x = 1 , y = 2 } )
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.
-
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() );
-
Common.Vector2D:__eq (v)
-
Compares this vector.
Parameters:
Returns:
bool
Returns true if equals.
Usage:
local vec = Common.Vector2D:Create();
print( vec == Common.vecZero );
-
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() );
-
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() );
-
Common.Vector2D:__mul (fl)
-
Multiplies this vector with a number value.
Parameters:
Returns:
Common.Vector2D
The new vector.
Usage:
local vec = Common.Vector2D:Create( 2 , 3 );
vec = vec * 2;
print( vec:ToString() );
-
Common.Vector2D:__div (fl)
-
Divides this vector with a number value.
Parameters:
Returns:
Common.Vector2D
The new vector.
Usage:
local vec = Common.Vector2D:Create( 4 , 6 );
vec = vec / 2;
print( vec:ToString() );