Skip to main content

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:

ParameterTypeDescription
vecVec2The other vector to calculate the distance to.

Returns:

Return TypeDescription
numberThe 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:

ParameterTypeDescription
vecVec2The other vector to calculate the squared distance to.

Returns:

Return TypeDescription
numberThe 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 TypeDescription
Vec2The normalized vector.

perp

Type: Function.

Description:

  Gets the perpendicular vector of this vector.

Signature:

perp: function(self: Vec2): Vec2

Returns:

Return TypeDescription
Vec2The 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:

ParameterTypeDescription
fromVec2The lower bound of the range.
toVec2The upper bound of the range.

Returns:

Return TypeDescription
Vec2The clamped vector.

dot

Type: Function.

Description:

  Gets the dot product of two vectors.

Signature:

dot: function(self: Vec2, other: Vec2): number

Parameters:

ParameterTypeDescription
otherVec2The other vector to calculate the dot product with.

Returns:

Return TypeDescription
numberThe dot product of the two vectors.

add

Type: Function.

Description:

  Adds two vectors together.

Signature:

add: function(self: Vec2, other: Vec2): Vec2

Parameters:

ParameterTypeDescription
otherVec2The other vector to add.

Returns:

Return TypeDescription
Vec2The sum of the two vectors.

sub

Type: Function.

Description:

  Subtracts one vector from another.

Signature:

sub: function(self: Vec2, other: Vec2): Vec2

Parameters:

ParameterTypeDescription
otherVec2The vector to subtract.

Returns:

Return TypeDescription
Vec2The difference between the two vectors.

mul

Type: Function.

Description:

  Multiplies two vectors component-wise.

Signature:

mul: function(self: Vec2, other: Vec2): Vec2

Parameters:

ParameterTypeDescription
otherVec2The other vector to multiply by.

Returns:

Return TypeDescription
Vec2The 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:

ParameterTypeDescription
otherVec2The scalar to multiply by, represented by a number.

Returns:

Return TypeDescription
Vec2The 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:

ParameterTypeDescription
otherSizeThe Size object to multiply by.

Returns:

Return TypeDescription
Vec2The 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:

ParameterTypeDescription
othernumberThe scalar to divide by, represented by a number.

Returns:

Return TypeDescription
Vec2The 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:

ParameterTypeDescription
otherVec2The other vector to compare to.

Returns:

Return TypeDescription
booleanWhether 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:

ParameterTypeDescription
otherVec2The other vector to add.

Returns:

Return TypeDescription
Vec2The sum of the two vectors.

__sub

Type: Metamethod.

Description:

  Subtracts one vector from another.

Signature:

metamethod __sub: function(self: Vec2, other: Vec2): Vec2

Parameters:

ParameterTypeDescription
otherVec2The vector to subtract.

Returns:

Return TypeDescription
Vec2The difference between the two vectors.

__mul

Type: Metamethod.

Description:

  Multiplies two vectors component-wise.

Signature:

metamethod __mul: function(self: Vec2, other: Vec2): Vec2

Parameters:

ParameterTypeDescription
otherVec2The other vector to multiply by.

Returns:

Return TypeDescription
Vec2The 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:

ParameterTypeDescription
otherVec2The scalar to multiply by, represented by a number.

Returns:

Return TypeDescription
Vec2The 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:

ParameterTypeDescription
otherSizeThe Size object to multiply by.

Returns:

Return TypeDescription
Vec2The 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:

ParameterTypeDescription
othernumberThe scalar to divide by, represented by a number.

Returns:

Return TypeDescription
Vec2The 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:

ParameterTypeDescription
otherVec2The other vector to compare to.

Returns:

Return TypeDescription
booleanWhether or not the two vectors are equal.