Vec2
Description:
A record representing a 2D vector with an x and y component.
Class Object: Vec2 Class.
Inherits from: ContainerItem.
x
Type: Readonly Field.
Description:
The x-component of the vector.
Signature:
const x: number
y
Type: Readonly Field.
Description:
The y-component of the vector.
Signature:
const y: number
length
Type: Readonly Field.
Description:
The length of the vector.
Signature:
const length: number
lengthSquared
Type: Readonly Field.
Description:
The squared length of the vector.
Signature:
const lengthSquared: number
angle
Type: Readonly Field.
Description:
The angle between the vector and the x-axis.
Signature:
const angle: number
distance
Type: Function.
Description:
Calculates the distance between two vectors.
Signature:
distance: function(self: Vec2, vec: Vec2): number
Parameters:
Parameter | Type | Description |
---|---|---|
vec | Vec2 | The other vector to calculate the distance to. |
Returns:
Return Type | Description |
---|---|
number | The distance between the two vectors. |
distanceSquared
Type: Function.
Description:
Calculates the squared distance between two vectors.
Signature:
distanceSquared: function(self: Vec2, vec: Vec2): number
Parameters:
Parameter | Type | Description |
---|---|---|
vec | Vec2 | The other vector to calculate the squared distance to. |
Returns:
Return Type | Description |
---|---|
number | The squared distance between the two vectors. |
normalize
Type: Function.
Description:
Normalizes the vector to have a length of 1.
Signature:
normalize: function(self: Vec2): Vec2
Returns:
Return Type | Description |
---|---|
Vec2 | The normalized vector. |
perp
Type: Function.
Description:
Gets the perpendicular vector of this vector.
Signature:
perp: function(self: Vec2): Vec2
Returns:
Return Type | Description |
---|---|
Vec2 | The perpendicular vector. |
clamp
Type: Function.
Description:
Clamps the vector to a range between two other vectors.
Signature:
clamp: function(self: Vec2, from: Vec2, to: Vec2): Vec2
Parameters:
Parameter | Type | Description |
---|---|---|
from | Vec2 | The lower bound of the range. |
to | Vec2 | The upper bound of the range. |
Returns:
Return Type | Description |
---|---|
Vec2 | The clamped vector. |
dot
Type: Function.
Description:
Gets the dot product of two vectors.
Signature:
dot: function(self: Vec2, other: Vec2): number
Parameters:
Parameter | Type | Description |
---|---|---|
other | Vec2 | The other vector to calculate the dot product with. |
Returns:
Return Type | Description |
---|---|
number | The dot product of the two vectors. |
add
Type: Function.
Description:
Adds two vectors together.
Signature:
add: function(self: Vec2, other: Vec2): Vec2
Parameters:
Parameter | Type | Description |
---|---|---|
other | Vec2 | The other vector to add. |
Returns:
Return Type | Description |
---|---|
Vec2 | The sum of the two vectors. |
sub
Type: Function.
Description:
Subtracts one vector from another.
Signature:
sub: function(self: Vec2, other: Vec2): Vec2
Parameters:
Parameter | Type | Description |
---|---|---|
other | Vec2 | The vector to subtract. |
Returns:
Return Type | Description |
---|---|
Vec2 | The difference between the two vectors. |
mul
Type: Function.
Description:
Multiplies two vectors component-wise.
Signature:
mul: function(self: Vec2, other: Vec2): Vec2
Parameters:
Parameter | Type | Description |
---|---|---|
other | Vec2 | The other vector to multiply by. |
Returns:
Return Type | Description |
---|---|
Vec2 | The result of multiplying the two vectors component-wise. |
mul
Type: Function.
Description:
Multiplies a vector by a scalar.
Signature:
mul: function(self: Vec2, other: number): Vec2
Parameters:
Parameter | Type | Description |
---|---|---|
other | Vec2 | The scalar to multiply by, represented by a number. |
Returns:
Return Type | Description |
---|---|
Vec2 | The result of multiplying the vector by the scalar. |
mul
Type: Function.
Description:
Multiplies a vector by a Size object.
Signature:
mul: function(self: Vec2, other: Dora.Size.Type): Vec2
Usage:
local halfVec = vec * Size(0.5, 0.5)
Parameters:
Parameter | Type | Description |
---|---|---|
other | Size | The Size object to multiply by. |
Returns:
Return Type | Description |
---|---|
Vec2 | The result of multiplying the vector by the Size object. |
div
Type: Function.
Description:
Divide a vector by a scalar.
Signature:
div: function(self: Vec2, other: number): Vec2
Parameters:
Parameter | Type | Description |
---|---|---|
other | number | The scalar to divide by, represented by a number. |
Returns:
Return Type | Description |
---|---|
Vec2 | The result of dividing the vector by the scalar. |
equals
Type: Function.
Description:
Compare two vectors for equality.
Signature:
equals: function(self: Vec2, other: Vec2): boolean
Parameters:
Parameter | Type | Description |
---|---|---|
other | Vec2 | The other vector to compare to. |
Returns:
Return Type | Description |
---|---|
boolean | Whether or not the two vectors are equal. |
__add
Type: Metamethod.
Description:
Adds two vectors together.
Signature:
metamethod __add: function(self: Vec2, other: Vec2): Vec2
Parameters:
Parameter | Type | Description |
---|---|---|
other | Vec2 | The other vector to add. |
Returns:
Return Type | Description |
---|---|
Vec2 | The sum of the two vectors. |
__sub
Type: Metamethod.
Description:
Subtracts one vector from another.
Signature:
metamethod __sub: function(self: Vec2, other: Vec2): Vec2
Parameters:
Parameter | Type | Description |
---|---|---|
other | Vec2 | The vector to subtract. |
Returns:
Return Type | Description |
---|---|
Vec2 | The difference between the two vectors. |
__mul
Type: Metamethod.
Description:
Multiplies two vectors component-wise.
Signature:
metamethod __mul: function(self: Vec2, other: Vec2): Vec2
Parameters:
Parameter | Type | Description |
---|---|---|
other | Vec2 | The other vector to multiply by. |
Returns:
Return Type | Description |
---|---|
Vec2 | The result of multiplying the two vectors component-wise. |
__mul
Type: Metamethod.
Description:
Multiplies a vector by a scalar.
Signature:
metamethod __mul: function(self: Vec2, other: number): Vec2
Parameters:
Parameter | Type | Description |
---|---|---|
other | Vec2 | The scalar to multiply by, represented by a number. |
Returns:
Return Type | Description |
---|---|
Vec2 | The result of multiplying the vector by the scalar. |
__mul
Type: Metamethod.
Description:
Multiplies a vector by a Size object.
Signature:
metamethod __mul: function(self: Vec2, other: Dora.Size.Type): Vec2
Usage:
local halfVec = vec * Size(0.5, 0.5)
Parameters:
Parameter | Type | Description |
---|---|---|
other | Size | The Size object to multiply by. |
Returns:
Return Type | Description |
---|---|
Vec2 | The result of multiplying the vector by the Size object. |
__div
Type: Metamethod.
Description:
Divide a vector by a scalar.
Signature:
metamethod __div: function(self: Vec2, other: number): Vec2
Parameters:
Parameter | Type | Description |
---|---|---|
other | number | The scalar to divide by, represented by a number. |
Returns:
Return Type | Description |
---|---|
Vec2 | The result of dividing the vector by the scalar. |
__eq
Type: Metamethod.
Description:
Compare two vectors for equality.
Signature:
metamethod __eq: function(self: Vec2, other: Vec2): boolean
Parameters:
Parameter | Type | Description |
---|---|---|
other | Vec2 | The other vector to compare to. |
Returns:
Return Type | Description |
---|---|
boolean | Whether or not the two vectors are equal. |