Source: FrameXML/Vector2D.lua
API
- CreateVector2D(x, y) - Creates a new vector.
- AreVector2DEqual(left, right) - Compares if vectors are equal.
Methods
- Vector2DMixin:Add(Vector2DMixin) - Translates the vector by another.
- Vector2DMixin:Clone() - Copies a vector.
- Vector2DMixin:Cross(Vector2DMixin) - Mimics a 3D cross product, computing its magnitude and then applying this value to the X coordinate.
- Vector2DMixin:DivideBy(scalar)- Divides each coordinate by a scalar.
- Vector2DMixin:Dot(Vector2DMixin) - Returns the dot product of the vector with another.
- Vector2DMixin:GetLength() - Returns the vector's total length or magnitude, independent of direction.
- Vector2DMixin:GetLengthSquared() - Returns the dot product of the vector with itself.
- Vector2DMixin:GetXY() - Returns the X and Y coordinates.
- Vector2DMixin:IsEqualTo(Vector2DMixin) - Compares if a vector is equal.
- Vector2DMixin:IsZero() - Returns true for the vector (0,0).
- Vector2DMixin:Normalize() - Divides each coordinate by the vector's total length, producing a unit vector in the same direction.
- Vector2DMixin:RotateDirection(rotationRadians) - Rotates the vector counter-clockwise by a number of radians.
- Vector2DMixin:ScaleBy(scalar) - Multiplies each coordinate by a scalar.
- Vector2DMixin:SetXY(x, y) - Sets the X and Y coordinates.
- Vector2DMixin:Subtract(Vector2DMixin) - Translates the vector by the opposite of another.
Example
local foo = CreateVector2D(12, 5)
local bar = CreateVector2D(2, 3)
foo:Add(bar)
print(foo:GetXY()) -- 14, 8
Patch changes
- Patch 9.0.1 (2020-10-13): Added IsZero() method.[1]
- Patch 8.0.1 (2018-07-17): Added RotateDirection() method.[2]
- Patch 7.2.0 (2017-03-28): Added.[3]
- Patch 7.1.0 (2016-10-25): Vector2D.lua introduced, but without Vector2DMixin.[4]
See also
External links
- Globe "wut?" Tool, Townlong-Yak
- GitHub FrameXML, Gethe
References
- ^ 2020-06-08, Vector2D.lua, version 9.0.1.34714, near line 109, archived at Townlong-Yak
- ^ 2018-07-16, Vector2D.lua, version 8.0.1.27101, near line 122, archived at Townlong-Yak
- ^ 2017-03-28, Vector2D.lua, version 7.2.0.23835, near line 41, archived at Townlong-Yak
- ^ 2016-10-25, Vector2D.lua, version 7.1.0.22908, archived at Townlong-Yak