Types

Vectors and colors

Vector, Vec2, Color and Rect, with their operators and methods.

Vector (also vector, QAngle), Vec2 and Color are fast FFI structs; Rect holds two Vec2. Anywhere a color is expected you may also pass a {r, g, b, a} table or a "#rrggbb" string.

local v = Vector(1, 2, 3)
v.x, v.y, v.z
v + v, v - v, v * 2, v / 2, -v, v == v
v:length()  v:length_2d()  v:dist(other)  v:dot(other)  v:cross(other)
v:normalized()  v:lerp(other, 0.5)  v:to_screen()
local angles = Vector(0, 90, 0)
angles.pitch, angles.yaw, angles.roll
angles:forward()  angles:angle_vectors()
local dir = Vector(1, 0, 0)
dir:vector_angles()

local p = Vec2(10, 20)
p:len()  p:dist(other)  p:floor()  p:round()

local c = Color(255, 128, 0, 200)
Color("#ff8800")  Color.White()  Color.hsv(120, 1, 1)  Color.rainbow(0.2)  Color.accent()
c.r, c.g, c.b, c.a
c:alpha(0.5)  c:darken(0.2)  c:lighten(0.2)  c:lerp(other, 0.5)  c:to_hex()

local r = Rect(10, 10, 110, 60)
r.mins, r.maxs
r:width()  r:height()  r:center()  r:contains(Vec2(20, 20))  r:shrink(4)  r:translate(Vec2(5, 5))

math.clamp(v, lo, hi)  math.lerp(a, b, t)  math.round(v, digits)  math.angle_normalize(a)
math.angle_diff(a, b)  math.calc_angle(from, to)  math.fov(view, from, to)  math.world_to_screen(v)