reference monoe.vec2

Lua API Reference

Properties

NameTypeDescription
xnumber-- X component
ynumber-- Y component

monoe.vec2.new

Creates a new 2D vector. If no values are provided, defaults to (0, 0).

Parameters

NameTypeDescription
xnumber|nil
ynumber|nil

Returns


monoe.vec2.zero

Returns a zero vector (0, 0).

Returns


monoe.vec2:add

Adds another vector to this one.

Parameters

NameTypeDescription
vmonoe.vec2

Returns


monoe.vec2:sub

Subtracts another vector from this one.

Parameters

NameTypeDescription
vmonoe.vec2

Returns


monoe.vec2:mul

Multiplies this vector by a scalar.

Parameters

NameTypeDescription
snumber

Returns


monoe.vec2:div

Divides this vector by a scalar.

Parameters

NameTypeDescription
snumber

Returns


monoe.vec2:length_sq

Returns the squared length of the vector. Useful when you want distance comparisons without sqrt().

Returns


monoe.vec2:length

Returns the length (magnitude) of the vector.

Returns


monoe.vec2:distance

Returns the distance between this vector and another one.

Parameters

NameTypeDescription
vmonoe.vec2

Returns


monoe.vec2:normalized

Returns a normalized (unit) vector and the original length. If the vector is zero, returns (0,0) and length 0.

Returns


monoe.vec2:dot

Returns the dot product between this vector and another. Useful for angles, projections, and direction checks.

Parameters

NameTypeDescription
vmonoe.vec2

Returns


monoe.vec2:lerp

Linearly interpolates between this vector and another. t = 0 → this vector t = 1 → target vector

Parameters

NameTypeDescription
vmonoe.vec2
tnumber

Returns


monoe.vec2:clamp_length

Clamps the vector length so it does not exceed max_len. Keeps direction the same.

Parameters

NameTypeDescription
max_lennumber

Returns


monoe.vec2:unpack

Returns x and y as separate values. Useful for APIs that expect unpacked numbers.

Returns


monoe.vec2:set

Sets the vector components directly.

Parameters

NameTypeDescription
xnumber
ynumber

Returns


monoe.vec2:inside_aabb

Checks if this vector (point) is inside an axis-aligned bounding box. `min` is bottom-left, `max` is top-right.

Parameters

NameTypeDescription
minmonoe.vec2
maxmonoe.vec2

Returns