Wowpedia

We have moved to Warcraft Wiki. Click here for information and the new URL.

READ MORE

Wowpedia
m (Reverting API pages back to 9.0.1 (the patch number change only applies to content).)
Tags: WoW API docs Undo
Tag: WoW API docs
(19 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{{wowapitype}}
 
{{wowapitype}}
Defined in <code>FrameXML/[https://www.townlong-yak.com/framexml/live/Vector2D.lua Vector2D.lua]</code>, the Vector2DMixin interface represents a math vector with X and Y coordinates.
+
<font size="3">Source: [https://www.townlong-yak.com/framexml/live/Vector2D.lua SharedXML\Vector2D.lua]</font>
   
== Construction ==
+
==API==
  +
: [[File:Wowpedia_icon_stamp.png|12px|link=API_CreateVector2D]] [https://www.townlong-yak.com/framexml/live/go/CreateVector2D CreateVector2D](<span style="font-size:smaller; color:#ecbc2a">x, y</span>) : <span style="font-size:smaller; color:#4ec9b0">vector</span> - Creates a new vector.
* {{api|CreateVector2D(x, y)}} - Creates a new vector with the given coordinates.
 
  +
: [[File:Wowpedia_icon_stamp.png|12px|link=API_AreVector2DEqual]] [https://www.townlong-yak.com/framexml/live/go/AreVector2DEqual AreVector2DEqual](<span style="font-size:smaller; color:#ecbc2a">left, right</span>) : <span style="font-size:smaller; color:#4ec9b0">''boolean''</span> - Compares if vectors are equal.
* {{api|Vector2DMixin:Clone()}} - Creates a new vector with identical coordinates.
 
   
== Methods ==
+
===Methods===
  +
: [[File:Wowpedia_icon_stamp.png|12px|link=API_Vector2DMixin_IsEqualTo]] [https://www.townlong-yak.com/framexml/live/go/Vector2DMixin:IsEqualTo Vector2DMixin:IsEqualTo](<span style="font-size:smaller; color:#ecbc2a">vector</span>) : <span style="font-size:smaller; color:#4ec9b0">''boolean''</span>
; Fundamental
 
  +
: [[File:Wowpedia_icon_stamp.png|12px|link=API_Vector2DMixin_GetXY]] [https://www.townlong-yak.com/framexml/live/go/Vector2DMixin:GetXY Vector2DMixin:GetXY](<span style="font-size:smaller; color:#ecbc2a"></span>) : <span style="font-size:smaller; color:#4ec9b0">x, y</span>
* {{api|Vector2DMixin:GetXY()}} - Returns the X and Y coordinates.
 
  +
: [[File:Wowpedia_icon_stamp.png|12px|link=API_Vector2DMixin_SetXY]] [https://www.townlong-yak.com/framexml/live/go/Vector2DMixin:SetXY Vector2DMixin:SetXY](<span style="font-size:smaller; color:#ecbc2a">x, y</span>)
* {{api|Vector2DMixin:SetXY(number, number)}} - Defines the X and Y coordinates.
 
  +
: [[File:Wowpedia_icon_stamp.png|12px|link=API_Vector2DMixin_ScaleBy]] [https://www.townlong-yak.com/framexml/live/go/Vector2DMixin:ScaleBy Vector2DMixin:ScaleBy](<span style="font-size:smaller; color:#ecbc2a">scalar</span>)
  +
: [[File:Wowpedia_icon_stamp.png|12px|link=API_Vector2DMixin_DivideBy]] [https://www.townlong-yak.com/framexml/live/go/Vector2DMixin:DivideBy Vector2DMixin:DivideBy](<span style="font-size:smaller; color:#ecbc2a">scalar</span>)
  +
: [[File:Wowpedia_icon_stamp.png|12px|link=API_Vector2DMixin_Add]] [https://www.townlong-yak.com/framexml/live/go/Vector2DMixin:Add Vector2DMixin:Add](<span style="font-size:smaller; color:#ecbc2a">vector</span>)
  +
: [[File:Wowpedia_icon_stamp.png|12px|link=API_Vector2DMixin_Subtract]] [https://www.townlong-yak.com/framexml/live/go/Vector2DMixin:Subtract Vector2DMixin:Subtract](<span style="font-size:smaller; color:#ecbc2a">vector</span>)
  +
: [[File:Wowpedia_icon_stamp.png|12px|link=API_Vector2DMixin_Cross]] [https://www.townlong-yak.com/framexml/live/go/Vector2DMixin:Cross Vector2DMixin:Cross](<span style="font-size:smaller; color:#ecbc2a">vector</span>)
  +
: [[File:Wowpedia_icon_stamp.png|12px|link=API_Vector2DMixin_Dot]] [https://www.townlong-yak.com/framexml/live/go/Vector2DMixin:Dot Vector2DMixin:Dot](<span style="font-size:smaller; color:#ecbc2a">vector</span>) : <span style="font-size:smaller; color:#4ec9b0">dot</span>
  +
: [[File:Wowpedia_icon_stamp.png|12px|link=API_Vector2DMixin_IsZero]] [https://www.townlong-yak.com/framexml/live/go/Vector2DMixin:IsZero Vector2DMixin:IsZero](<span style="font-size:smaller; color:#ecbc2a"></span>) : <span style="font-size:smaller; color:#4ec9b0">''boolean''</span>
  +
: [[File:Wowpedia_icon_stamp.png|12px|link=API_Vector2DMixin_GetLengthSquared]] [https://www.townlong-yak.com/framexml/live/go/Vector2DMixin:GetLengthSquared Vector2DMixin:GetLengthSquared](<span style="font-size:smaller; color:#ecbc2a"></span>) : <span style="font-size:smaller; color:#4ec9b0">lengthSquared</span>
  +
: [[File:Wowpedia_icon_stamp.png|12px|link=API_Vector2DMixin_GetLength]] [https://www.townlong-yak.com/framexml/live/go/Vector2DMixin:GetLength Vector2DMixin:GetLength](<span style="font-size:smaller; color:#ecbc2a"></span>) : <span style="font-size:smaller; color:#4ec9b0">length</span>
  +
: [[File:Wowpedia_icon_stamp.png|12px|link=API_Vector2DMixin_Normalize]] [https://www.townlong-yak.com/framexml/live/go/Vector2DMixin:Normalize Vector2DMixin:Normalize](<span style="font-size:smaller; color:#ecbc2a"></span>)
  +
: [[File:Wowpedia_icon_stamp.png|12px|link=API_Vector2DMixin_RotateDirection]] [https://www.townlong-yak.com/framexml/live/go/Vector2DMixin:RotateDirection Vector2DMixin:RotateDirection](<span style="font-size:smaller; color:#ecbc2a">rotationRadians</span>)
  +
: [[File:Wowpedia_icon_stamp.png|12px|link=API_Vector2DMixin_Clone]] [https://www.townlong-yak.com/framexml/live/go/Vector2DMixin:Clone Vector2DMixin:Clone](<span style="font-size:smaller; color:#ecbc2a"></span>) : <span style="font-size:smaller; color:#4ec9b0">vector</span>
   
 
==Example==
; Manipulation
 
  +
<syntaxhighlight lang="lua">
* {{api|Vector2DMixin:ScaleBy(number)}} - Multiplies each coordinate by a scalar.
 
 
local foo = CreateVector2D(12, 5)
* {{api|Vector2DMixin:DivideBy(number)}} - Divides each coordinate by a scalar.
 
 
local bar = CreateVector2D(2, 3)
* {{api|Vector2DMixin:Add(Vector2DMixin)}} - Translates the vector by another.
 
* {{api|Vector2DMixin:Subtract(Vector2DMixin)}} - Translates the vector by the opposite of another.
 
* {{api|Vector2DMixin:Cross(Vector2DMixin)}} - Mimics a 3D cross product, computing its magnitude and then applying this value to the X coordinate.
 
* {{api|Vector2DMixin:Normalize()}} - Divides each coordinate by the vector's total length, producing a unit vector in the same direction.
 
* {{api|Vector2DMixin:RotateDirection(number)}} - Rotates the vector counter-clockwise by a number of radians.
 
   
 
foo:Add(bar)
; Calcuation
 
 
print(foo:GetXY()) -- 14, 8
* {{api|Vector2DMixin:IsEqualTo(Vector2DMixin)}} - Returns true if both vectors have equal coordinates.
 
  +
</syntaxhighlight>
* {{api|Vector2DMixin:IsZero()}} - Returns true for the vector (0,0).
 
* {{api|Vector2DMixin:GetLength()}} - Returns the vector's total length or magnitude, independent of direction.
 
* {{api|Vector2DMixin:GetLengthSquared()}} - Returns the dot product of the vector with itself.
 
* {{api|Vector2DMixin:Dot(Vector2DMixin)}} - Returns the dot product of the vector with another.
 
   
  +
It's also valid to only pass the <code>x</code> and <code>y</code> fields for API functions that would take a Vector2DMixin object.
== Example ==
 
  +
<syntaxhighlight lang="lua">
local foo = CreateVector2D(14, 10)
 
  +
/dump C_Map.GetWorldPosFromMapPos(37, {x=0.5, y=1})
print(foo:GetXY()) <font color="#ecbc2a">-- 14, 10</font>
 
  +
</syntaxhighlight>
 
local bar = CreateVector2D(2, 3)
 
foo:Add(bar)
 
print(foo:GetXY()) <font color="#ecbc2a">-- 16, 13</font>
 
   
== Patch changes ==
+
==Patch changes==
 
* {{Patch 9.0.1|note=Added IsZero() method.<ref>{{ref FrameXML|Vector2D.lua|9.0.1|34714|109|20200608}}</ref>}}
 
* {{Patch 9.0.1|note=Added IsZero() method.<ref>{{ref FrameXML|Vector2D.lua|9.0.1|34714|109|20200608}}</ref>}}
 
* {{Patch 8.0.1|note=Added RotateDirection() method.<ref>{{ref FrameXML|Vector2D.lua|8.0.1|27101|122|20180716}}</ref>}}
 
* {{Patch 8.0.1|note=Added RotateDirection() method.<ref>{{ref FrameXML|Vector2D.lua|8.0.1|27101|122|20180716}}</ref>}}
Line 44: Line 46:
 
* [[Vector3DMixin]]
 
* [[Vector3DMixin]]
   
== External Links ==
+
== External links ==
 
<!-- Please read https://wow.gamepedia.com/Wowpedia:External_links_policy before adding new links. -->
 
<!-- Please read https://wow.gamepedia.com/Wowpedia:External_links_policy before adding new links. -->
{{Elinks-api}}
+
{{Elinks-api|t=a|name=CreateVector2D}}
   
 
== References ==
 
== References ==

Revision as of 20:15, 10 June 2021

Source: SharedXML\Vector2D.lua

API

Wowpedia icon stamp CreateVector2D(x, y) : vector - Creates a new vector.
Wowpedia icon stamp AreVector2DEqual(left, right) : boolean - Compares if vectors are equal.

Methods

Wowpedia icon stamp Vector2DMixin:IsEqualTo(vector) : boolean
Wowpedia icon stamp Vector2DMixin:GetXY() : x, y
Wowpedia icon stamp Vector2DMixin:SetXY(x, y)
Wowpedia icon stamp Vector2DMixin:ScaleBy(scalar)
Wowpedia icon stamp Vector2DMixin:DivideBy(scalar)
Wowpedia icon stamp Vector2DMixin:Add(vector)
Wowpedia icon stamp Vector2DMixin:Subtract(vector)
Wowpedia icon stamp Vector2DMixin:Cross(vector)
Wowpedia icon stamp Vector2DMixin:Dot(vector) : dot
Wowpedia icon stamp Vector2DMixin:IsZero() : boolean
Wowpedia icon stamp Vector2DMixin:GetLengthSquared() : lengthSquared
Wowpedia icon stamp Vector2DMixin:GetLength() : length
Wowpedia icon stamp Vector2DMixin:Normalize()
Wowpedia icon stamp Vector2DMixin:RotateDirection(rotationRadians)
Wowpedia icon stamp Vector2DMixin:Clone() : vector

Example

local foo = CreateVector2D(12, 5)
local bar = CreateVector2D(2, 3)

foo:Add(bar)
print(foo:GetXY()) -- 14, 8

It's also valid to only pass the x and y fields for API functions that would take a Vector2DMixin object.

/dump C_Map.GetWorldPosFromMapPos(37, {x=0.5, y=1})

Patch changes

See also

External links

References

 
  1. ^ 2020-06-08, Vector2D.lua, version 9.0.1.34714, near line 109, archived at Townlong-Yak
  2. ^ 2018-07-16, Vector2D.lua, version 8.0.1.27101, near line 122, archived at Townlong-Yak
  3. ^ 2017-03-28, Vector2D.lua, version 7.2.0.23835, near line 41, archived at Townlong-Yak
  4. ^ 2016-10-25, Vector2D.lua, version 7.1.0.22908, archived at Townlong-Yak