std.math
f32 vectors, rects and scalar helpers for games; v2_/v3_ prefixes
pub PI :: 3.14159265f32constants
pub TAU :: 6.28318531f32DEG2RAD
Section titled “DEG2RAD”pub DEG2RAD :: 0.01745329f32RAD2DEG
Section titled “RAD2DEG”pub RAD2DEG :: 57.2957795f32pub lerp :: fn(a: f32, b: f32, t: f32) -> f32a at t=0, b at t=1
approach
Section titled “approach”pub approach :: fn(cur: f32, tgt: f32, step: f32) -> f32toward tgt by at most step; no overshoot
pub signf :: fn(x: f32) -> f32-1, 0 or +1
deg2rad
Section titled “deg2rad”pub deg2rad :: fn(deg: f32) -> f32rad2deg
Section titled “rad2deg”pub rad2deg :: fn(rad: f32) -> f32pub sin :: fn(x: f32) -> f32pub cos :: fn(x: f32) -> f32pub tan :: fn(x: f32) -> f32pub wrapf :: fn(x: f32, lo: f32, hi: f32) -> f32into [lo, hi)
pub Vec2 :: struct { x: f32, y: f32,}pub v2 :: fn(x: f32, y: f32) -> Vec2v2_zero
Section titled “v2_zero”pub v2_zero :: fn() -> Vec2v2_splat
Section titled “v2_splat”pub v2_splat :: fn(s: f32) -> Vec2v2_add
Section titled “v2_add”pub v2_add :: fn(a: Vec2, b: Vec2) -> Vec2v2_sub
Section titled “v2_sub”pub v2_sub :: fn(a: Vec2, b: Vec2) -> Vec2v2_mul
Section titled “v2_mul”pub v2_mul :: fn(a: Vec2, b: Vec2) -> Vec2v2_scale
Section titled “v2_scale”pub v2_scale :: fn(a: Vec2, s: f32) -> Vec2v2_neg
Section titled “v2_neg”pub v2_neg :: fn(a: Vec2) -> Vec2v2_dot
Section titled “v2_dot”pub v2_dot :: fn(a: Vec2, b: Vec2) -> f32v2_len2
Section titled “v2_len2”pub v2_len2 :: fn(a: Vec2) -> f32v2_len
Section titled “v2_len”pub v2_len :: fn(a: Vec2) -> f32v2_dist2
Section titled “v2_dist2”pub v2_dist2 :: fn(a: Vec2, b: Vec2) -> f32v2_dist
Section titled “v2_dist”pub v2_dist :: fn(a: Vec2, b: Vec2) -> f32v2_normalize
Section titled “v2_normalize”pub v2_normalize :: fn(a: Vec2) -> Vec2zero vector if a is ~zero
v2_lerp
Section titled “v2_lerp”pub v2_lerp :: fn(a: Vec2, b: Vec2, t: f32) -> Vec2v2_perp
Section titled “v2_perp”pub v2_perp :: fn(a: Vec2) -> Vec290 deg counter-clockwise
v2_rotate
Section titled “v2_rotate”pub v2_rotate :: fn(a: Vec2, rad: f32) -> Vec2by rad radians
v2_from_angle
Section titled “v2_from_angle”pub v2_from_angle :: fn(rad: f32) -> Vec2unit vector at rad; 0 = +x
pub Vec3 :: struct { x: f32, y: f32, z: f32,}pub v3 :: fn(x: f32, y: f32, z: f32) -> Vec3v3_add
Section titled “v3_add”pub v3_add :: fn(a: Vec3, b: Vec3) -> Vec3v3_sub
Section titled “v3_sub”pub v3_sub :: fn(a: Vec3, b: Vec3) -> Vec3v3_scale
Section titled “v3_scale”pub v3_scale :: fn(a: Vec3, s: f32) -> Vec3v3_dot
Section titled “v3_dot”pub v3_dot :: fn(a: Vec3, b: Vec3) -> f32v3_len
Section titled “v3_len”pub v3_len :: fn(a: Vec3) -> f32v3_cross
Section titled “v3_cross”pub v3_cross :: fn(a: Vec3, b: Vec3) -> Vec3v3_normalize
Section titled “v3_normalize”pub v3_normalize :: fn(a: Vec3) -> Vec3pub Rect :: struct { x: f32, y: f32, w: f32, h: f32,}axis-aligned rect for sprites, UI, collisions
pub rect :: fn(x: f32, y: f32, w: f32, h: f32) -> Rectrect_contains
Section titled “rect_contains”pub rect_contains :: fn(r: Rect, px: f32, py: f32) -> boolrect_overlaps
Section titled “rect_overlaps”pub rect_overlaps :: fn(a: Rect, b: Rect) -> boolAABB overlap
rect_center
Section titled “rect_center”pub rect_center :: fn(r: Rect) -> Vec2pub gcd :: fn(a: u64, b: u64) -> u64gcd(0, 0) is 0
pub lcm :: fn(a: u64, b: u64) -> ?u640 when either is 0; null on u64 overflow
pub ipow :: fn(base: u64, exp: u32) -> ?u64null on u64 overflow
pub isqrt :: fn(n: u64) -> u64floor(sqrt(n))
div_ceil
Section titled “div_ceil”pub div_ceil :: fn(a: u64, b: u64) -> u64rounds up; b != 0
align_up
Section titled “align_up”pub align_up :: fn(x: u64, align: u64) -> u64align must be a power of two
align_down
Section titled “align_down”pub align_down :: fn(x: u64, align: u64) -> u64align must be a power of two
log2_floor
Section titled “log2_floor”pub log2_floor :: fn(x: u64) -> u32floor(log2(x)); 0 for 0
next_power_of_two
Section titled “next_power_of_two”pub next_power_of_two :: fn(x: u64) -> ?u64smallest power of two >= x (1 for 0); null past 2^63
mod_floor
Section titled “mod_floor”pub mod_floor :: fn(a: i64, b: i64) -> i64remainder with the sign of b: mod_floor(-7, 3) == 2; b != 0