DatumHueEnterprise v0.0.24datumhue.com
Contents

handle40 methods, 2 fields, 6 operators

Vec2

A 2D vector (Y-up, center-origin). Construct with datumhue.math.vec2(x, y). #v is v:length(), not a component count.

Obtained from
datumhue.math.vec2, datumhue.time.tween (in its callback), datumhue.input.mouse_position, datumhue.input.app_mouse_position, datumhue.input.mouse_delta, datumhue.input.scroll_delta, datumhue.input.touches, datumhue.input.app_touch_position and 38 more
Accepted by
datumhue.time.tween, datumhue.audio.synth, datumhue.audio.sfx, datumhue.audio.play, datumhue.physics.point_query, datumhue.debug.input.gamepad_stick, Scene:sprite, SceneNode:deform and 53 more
Operators
Vec2 + Vec2 -> Vec2 Component-wise addition.
Vec2 - Vec2 -> Vec2 Component-wise subtraction.
Vec2 * Vec2 | number -> Vec2 Vector or scalar multiplication.
Vec2 / Vec2 | number -> Vec2 Vector or scalar division.
-Vec2 -> Vec2 Negation.
#Vec2 -> number Magnitude (the # operator).

Fields 2

FieldTypeAccessDescription
xnumberread-onlyX component.
ynumberread-onlyY component.

Methods 40

Vec2:length

method
Vec2:length() -> number

Magnitude.

Vec2:length_squared

method
Vec2:length_squared() -> number

Squared magnitude (no sqrt).

Vec2:to_angle

method
Vec2:to_angle() -> number

Angle in radians from the +X axis.

Example
-- Radians counterclockwise from +X, from -pi to pi.
local up = datumhue.math.vec2(0, 1)
local down = datumhue.math.vec2(0, -1)
print(string.format("%.4f", up:to_angle())) --> 1.5708
print(string.format("%.4f", down:to_angle())) --> -1.5708

Vec2:min_element

method
Vec2:min_element() -> number

Smallest component.

Vec2:max_element

method
Vec2:max_element() -> number

Largest component.

Vec2:normalize

method
Vec2:normalize() -> Vec2

Unit vector. Raises if v is zero-length / non-finite; use normalize_or or try_normalize for a fallback.

Vec2:normalize_or

method
Vec2:normalize_or(fallback: Vec2) -> Vec2

Unit vector, or fallback if v is zero-length / non-finite.

Vec2:try_normalize

method
Vec2:try_normalize() -> Vec2?

Unit vector, or nil if v is zero-length / non-finite.

Vec2:distance_squared

method
Vec2:distance_squared(o: Vec2) -> number

Squared Euclidean distance to o (no sqrt).

Vec2:signum

method
Vec2:signum() -> Vec2

Component-wise sign (-1, 0, or +1).

Vec2:fract

method
Vec2:fract() -> Vec2

Component-wise fractional part (self - self.trunc()).

Vec2:recip

method
Vec2:recip() -> Vec2

Component-wise reciprocal (1/x).

Vec2:element_sum

method
Vec2:element_sum() -> number

Sum of the components.

Vec2:element_product

method
Vec2:element_product() -> number

Product of the components.

Vec2:to_array

method
Vec2:to_array() -> number[]

Components as a {x, y} array.

Vec2:perp

method
Vec2:perp() -> Vec2

Perpendicular vector (90 deg CCW).

Example
-- A quarter turn counterclockwise.
print(datumhue.math.vec2(3, 4):perp()) --> vec2(-4.0, 3.0)

Vec2:abs

method
Vec2:abs() -> Vec2

Component-wise absolute value.

Vec2:floor

method
Vec2:floor() -> Vec2

Component-wise floor.

Vec2:ceil

method
Vec2:ceil() -> Vec2

Component-wise ceil.

Vec2:round

method
Vec2:round() -> Vec2

Component-wise round.

Vec2:dot

method
Vec2:dot(o: Vec2) -> number

Dot product.

Vec2:distance

method
Vec2:distance(o: Vec2) -> number

Euclidean distance to o.

Vec2:perp_dot

method
Vec2:perp_dot(o: Vec2) -> number

Perpendicular dot (2D cross).

Vec2:angle_to

method
Vec2:angle_to(o: Vec2) -> number

Signed angle to o in radians.

Example
-- Signed radians: positive turns counterclockwise.
local east = datumhue.math.vec2(1, 0)
local north = datumhue.math.vec2(0, 1)
print(string.format("%.4f", east:angle_to(north))) --> 1.5708
print(string.format("%.4f", north:angle_to(east))) --> -1.5708

Vec2:rotate

method
Vec2:rotate(o: Vec2) -> Vec2

Rotate v by the rotation o represents.

Example
-- A rotation is a unit vector at its angle: (0, 1) is a quarter
-- turn counterclockwise.
local v = datumhue.math.vec2(3, 4)
print(v:rotate(datumhue.math.vec2(0, 1))) --> vec2(-4.0, 3.0)
local turn = datumhue.math.vec2.from_angle(math.pi / 2)
print(v:rotate(turn):round()) --> vec2(-4.0, 3.0)

Vec2:midpoint

method
Vec2:midpoint(o: Vec2) -> Vec2

Midpoint between v and o.

Vec2:reflect

method
Vec2:reflect(o: Vec2) -> Vec2

Reflect v about the normal o.

Vec2:min

method
Vec2:min(o: Vec2) -> Vec2

Component-wise minimum.

Vec2:max

method
Vec2:max(o: Vec2) -> Vec2

Component-wise maximum.

Vec2:project_onto

method
Vec2:project_onto(o: Vec2) -> Vec2

Projection of v onto o. Errors if o is zero-length.

Vec2:reject_from

method
Vec2:reject_from(o: Vec2) -> Vec2

Rejection of v from o. Errors if o is zero-length.

Vec2:lerp

method
Vec2:lerp(o: Vec2, t: number) -> Vec2

Linear interpolation toward o by t; t outside 0..1 extrapolates past the endpoints (not clamped).

Example
local a = datumhue.math.vec2(0, 0)
local b = datumhue.math.vec2(10, 20)
print(a:lerp(b, 0.25)) --> vec2(2.5, 5.0)
-- t past 1 keeps going.
print(a:lerp(b, 1.5)) --> vec2(15.0, 30.0)

Vec2:move_towards

method
Vec2:move_towards(o: Vec2, d: number) -> Vec2

Move toward o by at most distance d.

Vec2:clamp

method
Vec2:clamp(lo: Vec2, hi: Vec2) -> Vec2

Component-wise clamp to [lo, hi].

Vec2:clamp_length

method
Vec2:clamp_length(lo: number, hi: number) -> Vec2

Clamp magnitude to [lo, hi].

Vec2:is_normalized

method
Vec2:is_normalized() -> boolean

Whether the vector is unit length.

Vec2:extend

method
Vec2:extend(z: number) -> Vec3

Extend to a Vec3 with the given z.

Vec2:with_x

method
Vec2:with_x(x: number) -> Vec2

Copy with x replaced.

Vec2:with_y

method
Vec2:with_y(y: number) -> Vec2

Copy with y replaced.

Vec2:unpack

method
Vec2:unpack() -> number, number

Return the x and y components as two values.

Example
local x, y = datumhue.math.vec2(3, 4):unpack()
print(x, y) --> 3.0 4.0

datumhue.com

(c) 2026 Shuusei AB. Quote excerpts of this manual, with attribution to DatumHue, in your own documentation, tutorials, course materials, reviews, and other writing or video. Republishing it in whole or in substantial part needs written permission: support@datumhue.com.

Victor Mono is licensed under the SIL Open Font License 1.1
Copyright (c) 2024, Rune Bjørnerås (https://github.com/rubjo)

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL


-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.

"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are
not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

Try

    ↑↓ selectEnter openTab filter

    Settings

    Theme
    Text
    Print

    Keyboard shortcuts

    / or Ctrl KSearch
    ↑ ↓ EnterPick a result
    TabNext result filter
    j kNext or previous entry
    [ ]Previous or next page
    yCopy a link to the current entry
    ?These shortcuts
    EscClose

    On this page