tycho_math

    Tycho Math — zero-dependency pure-MoonBit fixed-dimension graphics & geometry math (glam/GLM-inspired, column-major, clip-space aware)

    math
    graphics
    linear-algebra
    geometry
    tycho
    Download zip
    Version
    0.10.0
    License
    Apache-2.0
    Last updated
    3 days ago
    Downloads
    35

    #laplaceliu/tycho_math

    Zero-dependency, pure-MoonBit fixed-dimension graphics and geometry math, in the spirit of Rust glam and C++ GLM / DirectXMath.

    #Highlights

    • Float by default: 32-bit values that map directly to GPU precision. A f64/ subpackage provides Double (DVec* / DMat* / DQuat) for large-world camera and shadow construction, with zero-cost to_vec3() / to_mat4() down-casts on upload.
    • Column-major everywhere: Mat4 stores four Vec4 columns, so the 16 floats are byte-identical to GLSL / Slang / WGSL / SPIR-V / Metal mat4 and can be uploaded to a UBO/SSBO without transposing.
    • Right-handed by default (+X right, +Y up, -Z forward), with explicit _lh variants for left-handed engines.
    • Clip space is an explicit parameter: ClipSpace::{Vulkan, ZeroToOne, NegOneToOne} plus reversed-Z and infinite-far projections. No global macro state.
    • Value types, no heap: every primitive is a #valtype struct; matrix math is allocation-free and ready for a future V128 kernel.
    • No C, no link flags: pure MoonBit, works on native, wasm, wasm-gc, and js.

    #Dependencies

    laplaceliu/tycho_math └── moonbitlang/core/math (scalar transcendentals only)

    The dependency arrow only points down: laplaceliu/tycho (RHI), laplaceliu/tycho_2d, and laplaceliu/tycho_ui consume this package, but tycho_math never imports them. That is what keeps it publishable on its own and usable from native / wasm / wasm-gc / js projects that have no GPU stack at all. check-math-layering.sh guards this contract.

    #Quick start

    let view = @tmath.look_to_rh(cam_pos, cam_forward, @tmath.Vec3::unit_y())
    let proj = @tmath.perspective_rh(
    @tmath.deg_to_rad(53.13),
    aspect,
    0.1,
    40.0,
    clip=@tmath.ClipSpace::Vulkan,
    )
    let vp = proj * view

    let writer = @tmath.GpuPackWriter::std140(48)
    writer.push_mat4(vp)
    let floats = writer.as_floats()
    // or, with no copy: upload_floats(writer.buffer(), count=writer.length())

    Downstream moon.pkg should alias the package as @tmath to avoid clashing with moonbitlang/core/math:

    import { "laplaceliu/tycho_math" @tmath, }

    #Module layout

    FileContents
    scalar.mbtConstants, clamp_f / lerp_f / smoothstep / fract, degrees↔radians, approx_eq_f, sin_cos
    vec2.mbt / vec3.mbt / vec4.mbtSingle-precision vectors
    ivec.mbtIVec2/3/4 (Int) and UVec2/3/4 (UInt)
    quat.mbtUnit quaternions, Euler orders, SLERP / NLERP
    mat2.mbt / mat3.mbt / mat4.mbtColumn-major matrices, inverse, normal matrix
    affine2.mbt / affine3.mbt / transform.mbt2D/3D affine transforms, TRS, VkTransformMatrixKHR 3x4 export (floats and bytes)
    projection.mbtClipSpace, perspective / orthographic, look_at, project / unproject
    geometry.mbtRay / Plane / Aabb2 / Aabb3 / Sphere / Frustum
    gpu_pack.mbtstd140 / std430 aligned writer
    batch.mbtContiguous-array batch kernels (accelerator seam for V128)
    f64/Double subpackage: DVec*, DMat*, DQuat, double-precision projections

    #Non-goals

    No dynamic arbitrary-dimension matrices, no scientific decompositions (LU/QR/SVD), no CUDA / OpenCL / OpenBLAS, and no C FFI for single-element operations.

    #Usage notes

    • Vec3::normalize returns the zero vector for zero input; use try_normalize when you need to detect degeneracy. The same "never emit NaN" rule applies to Mat4::inverse, Quat::slerp, and Plane::normalize.
    • Mat3::from_quat / Mat4::from_quat expect a unit quaternion; Quat::from_mat3 expects a pure rotation matrix.
    • Vec3::extend_w and Vec2::extend_z are the widening helpers (extend is a MoonBit keyword).
    • Ray directions are not normalized automatically; t values are in dir units. Use Ray::new_normalized when you want distances.
    • Frustum::from_view_proj accepts the same clip value that built the projection matrix.
    • Affine3::to_vk_transform_3x4() returns the 12 row-major floats of a VkTransformMatrixKHR (TLAS instance transform); to_vk_transform_3x4_bytes() returns the same data as 48 little-endian bytes for set_matrix.

    Aabb2

    pub(all) struct Aabb2 {
    min : Vec2
    max : Vec2
    } derive(Eq,
    Debug
    )

    Aabb2::center

    fn Aabb2::center(self : Aabb2) -> Vec2

    Aabb2::contains_point

    fn Aabb2::contains_point(self : Aabb2, p : Vec2) -> Bool

    Aabb2::expand

    fn Aabb2::expand(self : Aabb2, by : Vec2) -> Aabb2

    Aabb2::from_center_half_extents

    fn Aabb2::from_center_half_extents(center : Vec2, half_extents : Vec2) -> Aabb2

    Aabb2::intersects

    fn Aabb2::intersects(self : Aabb2, other : Aabb2) -> Bool

    Aabb2::new

    fn Aabb2::new(min : Vec2, max : Vec2) -> Aabb2

    Aabb2::size

    fn Aabb2::size(self : Aabb2) -> Vec2

    Aabb2::union

    fn Aabb2::union(self : Aabb2, other : Aabb2) -> Aabb2

    Aabb3

    pub(all) struct Aabb3 {
    min : Vec3
    max : Vec3
    } derive(Eq,
    Debug
    )

    Aabb3::center

    fn Aabb3::center(self : Aabb3) -> Vec3

    Aabb3::contains_aabb

    fn Aabb3::contains_aabb(self : Aabb3, other : Aabb3) -> Bool

    Aabb3::contains_point

    fn Aabb3::contains_point(self : Aabb3, p : Vec3) -> Bool

    Aabb3::corners

    fn Aabb3::corners(self : Aabb3) -> FixedArray[Vec3]

    Aabb3::expand

    fn Aabb3::expand(self : Aabb3, by : Vec3) -> Aabb3

    Aabb3::from_center_half_extents

    fn Aabb3::from_center_half_extents(center : Vec3, half_extents : Vec3) -> Aabb3

    Aabb3::from_points

    fn Aabb3::from_points(points : FixedArray[Vec3]) -> Aabb3

    Aabb3::half_extents

    fn Aabb3::half_extents(self : Aabb3) -> Vec3

    Aabb3::intersects

    fn Aabb3::intersects(self : Aabb3, other : Aabb3) -> Bool

    Aabb3::new

    fn Aabb3::new(min : Vec3, max : Vec3) -> Aabb3

    Aabb3::size

    fn Aabb3::size(self : Aabb3) -> Vec3

    Aabb3::transform

    fn Aabb3::transform(self : Aabb3, affine : Affine3) -> Aabb3

    Tight AABB of the eight transformed corners.

    Aabb3::transform_direction

    fn Aabb3::transform_direction(self : Aabb3, m : Mat3) -> Aabb3

    Transform as directions (ignores translation), e.g. for a normal-space box.

    Aabb3::union

    fn Aabb3::union(self : Aabb3, other : Aabb3) -> Aabb3

    Aabb3::volume

    fn Aabb3::volume(self : Aabb3) -> Float

    Affine2

    pub(all) struct Affine2 {
    x_axis : Vec2
    y_axis : Vec2
    translation : Vec2
    } derive(Eq,
    Debug
    )

    impl Mul for Affine2
    impl Show for Affine2

    Affine2::approx_eq

    fn Affine2::approx_eq(self : Affine2, other : Affine2, eps? : Float) -> Bool

    Affine2::determinant

    fn Affine2::determinant(self : Affine2) -> Float

    Affine2::from_angle

    fn Affine2::from_angle(radians : Float) -> Affine2

    Rotation by radians (counter-clockwise).

    Affine2::from_cols

    fn Affine2::from_cols(x_axis : Vec2, y_axis : Vec2, translation : Vec2) -> Affine2

    Affine2::from_scale

    fn Affine2::from_scale(s : Vec2) -> Affine2

    Affine2::from_scale_angle_translation

    fn Affine2::from_scale_angle_translation(s : Vec2, radians : Float, t : Vec2) -> Affine2

    Compose as T * R * S (scale applied first, then rotation, then translation).

    Affine2::from_scale_uniform

    fn Affine2::from_scale_uniform(s : Float) -> Affine2

    Affine2::from_translation

    fn Affine2::from_translation(t : Vec2) -> Affine2

    Affine2::identity

    fn Affine2::identity() -> Affine2

    Affine2::inverse

    fn Affine2::inverse(self : Affine2) -> Affine2?

    Inverse, or None when the linear part is singular.

    Affine2::is_axis_aligned

    fn Affine2::is_axis_aligned(self : Affine2, eps? : Float) -> Bool

    true when the transform is a pure axis-aligned scale + translation (no rotation or shear), which lets 2D rasterizers take a fast path.

    Affine2::is_identity

    fn Affine2::is_identity(self : Affine2, eps? : Float) -> Bool

    Affine2::is_pure_translation

    fn Affine2::is_pure_translation(self : Affine2, eps? : Float) -> Bool

    Affine2::to_cols_array

    fn Affine2::to_cols_array(self : Affine2) -> FixedArray[Float]

    The six floats of the 3x2 affine form, column-major ([a, b, c, d, tx, ty]).

    Affine2::to_mat3

    fn Affine2::to_mat3(self : Affine2) -> Mat3

    Affine2::to_mat4

    fn Affine2::to_mat4(self : Affine2) -> Mat4

    Promote to a 4x4 matrix for the 3D pipeline (z is untouched).

    Affine2::to_mat4_array

    fn Affine2::to_mat4_array(self : Affine2) -> FixedArray[Float]

    Affine2::transform_point2

    fn Affine2::transform_point2(self : Affine2, p : Vec2) -> Vec2

    Affine2::transform_vector2

    fn Affine2::transform_vector2(self : Affine2, v : Vec2) -> Vec2

    Affine3

    pub(all) struct Affine3 {
    matrix3 : Mat3
    translation : Vec3
    } derive(Eq,
    Debug
    )

    impl Mul for Affine3
    impl Show for Affine3

    Affine3::approx_eq

    fn Affine3::approx_eq(self : Affine3, other : Affine3, eps? : Float) -> Bool

    Affine3::determinant

    fn Affine3::determinant(self : Affine3) -> Float

    Affine3::from_cols

    fn Affine3::from_cols(matrix3 : Mat3, translation : Vec3) -> Affine3

    Affine3::from_mat4

    fn Affine3::from_mat4(m : Mat4) -> Affine3

    Extract an affine transform from a Mat4. The bottom row is assumed to be (0, 0, 0, 1); use Mat4::project_point3 for true projective matrices.

    Affine3::from_quat

    fn Affine3::from_quat(q : Quat) -> Affine3

    Affine3::from_scale

    fn Affine3::from_scale(s : Vec3) -> Affine3

    Affine3::from_scale_rotation_translation

    fn Affine3::from_scale_rotation_translation(scale : Vec3, rot : Quat, trans : Vec3) -> Affine3

    Affine3::from_translation

    fn Affine3::from_translation(t : Vec3) -> Affine3

    Affine3::identity

    fn Affine3::identity() -> Affine3

    Affine3::inverse

    fn Affine3::inverse(self : Affine3) -> Affine3?

    Inverse, or None when the linear part is singular.

    Affine3::normal_matrix

    fn Affine3::normal_matrix(self : Affine3) -> Mat3?

    Transform a normal with the inverse-transpose of the linear part, so that non-uniform scale is handled correctly. None when singular.

    Affine3::to_mat4

    fn Affine3::to_mat4(self : Affine3) -> Mat4

    Affine3::to_mat4_array

    fn Affine3::to_mat4_array(self : Affine3) -> FixedArray[Float]

    Affine3::to_vk_transform_3x4

    fn Affine3::to_vk_transform_3x4(self : Affine3) -> FixedArray[Float]

    12 floats in row-major 3x4 order, ready for VkTransformMatrixKHR (TLAS instance transform) and for GLTF/assimp-style APIs.

    Affine3::to_vk_transform_3x4_bytes

    fn Affine3::to_vk_transform_3x4_bytes(self : Affine3) -> Bytes

    48-byte little-endian encoding of the same 3x4 row-major matrix, ready for VkTransformMatrixKHR::set_matrix (TLAS instance transform) without any hand-assembled IEEE-754 byte literals at the call site.

    Affine3::transform_point3

    fn Affine3::transform_point3(self : Affine3, p : Vec3) -> Vec3

    Affine3::transform_vector3

    fn Affine3::transform_vector3(self : Affine3, v : Vec3) -> Vec3

    ClipSpace

    pub(all) enum ClipSpace {
    Vulkan
    ZeroToOne
    NegOneToOne
    } derive(Eq,
    Debug
    )

    Clip-space depth and Y conventions of the target graphics API.

    variantNDC YNDC Z
    Vulkandown (m11 < 0)[0, 1]
    ZeroToOne (Metal / DX12 / WebGPU)up (m11 > 0)[0, 1]
    NegOneToOne (OpenGL)up (m11 > 0)[-1, 1]

    ClipSpace::depth_zero_to_one

    fn ClipSpace::depth_zero_to_one(self : ClipSpace) -> Bool

    true when NDC depth spans [0, 1] (Vulkan / Metal / DX12 / WebGPU).

    ClipSpace::is_y_down

    fn ClipSpace::is_y_down(self : ClipSpace) -> Bool

    EulerOrder

    pub(all) enum EulerOrder {
    XYZ
    XZY
    YXZ
    YZX
    ZXY
    ZYX
    } derive(Eq,
    Debug
    )

    Order in which per-axis rotations are applied by Quat::from_euler. XYZ means q = qx * qy * qz, i.e. qz is applied to the vector first.

    Frustum

    pub(all) struct Frustum {
    planes : FixedArray[Plane]
    }

    Six normalized clipping planes (left, right, bottom, top, near, far). Not a #valtype because it owns a heap FixedArray.

    Frustum::contains_point

    fn Frustum::contains_point(self : Frustum, p : Vec3) -> Bool

    Frustum::from_view_proj

    fn Frustum::from_view_proj(view_proj : Mat4, clip? : ClipSpace) -> Frustum

    Extract the six clipping planes from a view-projection matrix (Gribb-Hartmann). The clip argument selects the depth range; the Y convention does not affect the result because both Y planes are kept.

    Frustum::intersects_aabb

    fn Frustum::intersects_aabb(self : Frustum, box : Aabb3) -> Bool

    true when the box is not fully outside any plane.

    Frustum::intersects_sphere

    fn Frustum::intersects_sphere(self : Frustum, s : Sphere) -> Bool

    GpuLayout

    pub(all) enum GpuLayout {
    Std140
    Std430
    } derive(Eq,
    Debug
    )

    Uniform/storage buffer layout rules.

    GpuPackWriter

    pub struct GpuPackWriter {
    buf : FixedArray[Float]
    len : Int
    layout : GpuLayout
    }

    GpuPackWriter::as_floats

    fn GpuPackWriter::as_floats(self : GpuPackWriter) -> FixedArray[Float]

    Copy of exactly the written floats (never the whole backing buffer).

    GpuPackWriter::buffer

    fn GpuPackWriter::buffer(self : GpuPackWriter) -> FixedArray[Float]

    Borrow the backing buffer without copying. Only the first length() floats are meaningful.

    GpuPackWriter::layout

    fn GpuPackWriter::layout(self : GpuPackWriter) -> GpuLayout

    GpuPackWriter::length

    fn GpuPackWriter::length(self : GpuPackWriter) -> Int

    Number of floats written so far.

    GpuPackWriter::new

    fn GpuPackWriter::new(float_capacity : Int) -> GpuPackWriter

    Create a std140 writer with room for float_capacity floats. The buffer grows automatically if more data is pushed.

    GpuPackWriter::push_affine_translation

    fn GpuPackWriter::push_affine_translation(self : GpuPackWriter, a : Affine3) -> Unit

    Push the translation column of an affine transform as a vec4 with w = 1.

    GpuPackWriter::push_float

    fn GpuPackWriter::push_float(self : GpuPackWriter, v : Float) -> Unit

    GpuPackWriter::push_mat2

    fn GpuPackWriter::push_mat2(self : GpuPackWriter, m : Mat2) -> Unit

    Push a mat2: 8 floats in std140 (columns padded to 16 bytes) or 4 floats in std430.

    GpuPackWriter::push_mat3

    fn GpuPackWriter::push_mat3(self : GpuPackWriter, m : Mat3) -> Unit

    Push a mat3: 12 floats (three columns each padded to 16 bytes), which is valid for both std140 and std430.

    GpuPackWriter::push_mat4

    fn GpuPackWriter::push_mat4(self : GpuPackWriter, m : Mat4) -> Unit

    Push a mat4 as 16 column-major floats (byte-identical to GPU mat4).

    GpuPackWriter::push_vec2

    fn GpuPackWriter::push_vec2(self : GpuPackWriter, v : Vec2) -> Unit

    GpuPackWriter::push_vec3

    fn GpuPackWriter::push_vec3(self : GpuPackWriter, v : Vec3) -> Unit

    Push a vec3: 4 floats (one explicit/implicit pad) in std140, 3 floats in std430. The next push_* realigns as needed.

    GpuPackWriter::push_vec3_padded

    fn GpuPackWriter::push_vec3_padded(self : GpuPackWriter, v : Vec3, pad? : Float) -> Unit

    Push a vec3 padded to 16 bytes regardless of layout.

    GpuPackWriter::push_vec4

    fn GpuPackWriter::push_vec4(self : GpuPackWriter, v : Vec4) -> Unit

    GpuPackWriter::reset

    fn GpuPackWriter::reset(self : GpuPackWriter) -> Unit

    Reset the write cursor; the underlying buffer is reused (no allocation).

    GpuPackWriter::std140

    fn GpuPackWriter::std140(float_capacity : Int) -> GpuPackWriter

    GpuPackWriter::std430

    fn GpuPackWriter::std430(float_capacity : Int) -> GpuPackWriter

    IVec2

    pub(all) struct IVec2 {
    x : Int
    y : Int
    } derive(Eq,
    Debug
    )

    impl Add for IVec2
    impl Div for IVec2
    impl Mul for IVec2
    impl Neg for IVec2
    impl Show for IVec2
    impl Sub for IVec2

    IVec2::as_uvec2

    fn IVec2::as_uvec2(self : IVec2) -> UVec2

    IVec2::as_vec2

    fn IVec2::as_vec2(self : IVec2) -> Vec2

    IVec2::dot

    fn IVec2::dot(self : IVec2, other : IVec2) -> Int

    IVec2::length_sq

    fn IVec2::length_sq(self : IVec2) -> Int

    IVec2::new

    fn IVec2::new(x : Int, y : Int) -> IVec2

    IVec2::one

    fn IVec2::one() -> IVec2

    IVec2::splat

    fn IVec2::splat(v : Int) -> IVec2

    IVec2::to_array

    fn IVec2::to_array(self : IVec2) -> FixedArray[Int]

    IVec2::zero

    fn IVec2::zero() -> IVec2

    IVec3

    pub(all) struct IVec3 {
    x : Int
    y : Int
    z : Int
    } derive(Eq,
    Debug
    )

    impl Add for IVec3
    impl Div for IVec3
    impl Mul for IVec3
    impl Neg for IVec3
    impl Show for IVec3
    impl Sub for IVec3

    IVec3::as_uvec3

    fn IVec3::as_uvec3(self : IVec3) -> UVec3

    IVec3::as_vec3

    fn IVec3::as_vec3(self : IVec3) -> Vec3

    IVec3::dot

    fn IVec3::dot(self : IVec3, other : IVec3) -> Int

    IVec3::length_sq

    fn IVec3::length_sq(self : IVec3) -> Int

    IVec3::new

    fn IVec3::new(x : Int, y : Int, z : Int) -> IVec3

    IVec3::one

    fn IVec3::one() -> IVec3

    IVec3::splat

    fn IVec3::splat(v : Int) -> IVec3

    IVec3::to_array

    fn IVec3::to_array(self : IVec3) -> FixedArray[Int]

    IVec3::zero

    fn IVec3::zero() -> IVec3

    IVec4

    pub(all) struct IVec4 {
    x : Int
    y : Int
    z : Int
    w : Int
    } derive(Eq,
    Debug
    )

    impl Add for IVec4
    impl Div for IVec4
    impl Mul for IVec4
    impl Neg for IVec4
    impl Show for IVec4
    impl Sub for IVec4

    IVec4::as_uvec4

    fn IVec4::as_uvec4(self : IVec4) -> UVec4

    IVec4::as_vec4

    fn IVec4::as_vec4(self : IVec4) -> Vec4

    IVec4::dot

    fn IVec4::dot(self : IVec4, other : IVec4) -> Int

    IVec4::length_sq

    fn IVec4::length_sq(self : IVec4) -> Int

    IVec4::new

    fn IVec4::new(x : Int, y : Int, z : Int, w : Int) -> IVec4

    IVec4::one

    fn IVec4::one() -> IVec4

    IVec4::splat

    fn IVec4::splat(v : Int) -> IVec4

    IVec4::zero

    fn IVec4::zero() -> IVec4

    Mat2

    pub(all) struct Mat2 {
    x_axis : Vec2
    y_axis : Vec2
    } derive(Eq,
    Debug
    )

    impl Add for Mat2
    impl Mul for Mat2
    impl Show for Mat2
    impl Sub for Mat2

    Mat2::approx_eq

    fn Mat2::approx_eq(self : Mat2, other : Mat2, eps? : Float) -> Bool

    Mat2::at

    fn Mat2::at(self : Mat2, row : Int, col : Int) -> Float

    Mat2::determinant

    fn Mat2::determinant(self : Mat2) -> Float

    Mat2::from_angle

    fn Mat2::from_angle(radians : Float) -> Mat2

    Rotation by radians (counter-clockwise).

    Mat2::from_cols

    fn Mat2::from_cols(x_axis : Vec2, y_axis : Vec2) -> Mat2

    Mat2::from_cols_array

    fn Mat2::from_cols_array(arr : FixedArray[Float]) -> Mat2

    Mat2::from_diagonal

    fn Mat2::from_diagonal(diag : Vec2) -> Mat2

    Mat2::from_scale

    fn Mat2::from_scale(sx : Float, sy : Float) -> Mat2

    Mat2::identity

    fn Mat2::identity() -> Mat2

    Mat2::inverse

    fn Mat2::inverse(self : Mat2) -> Mat2?

    Inverse, or None when the matrix is singular.

    Mat2::mul_vec2

    fn Mat2::mul_vec2(self : Mat2, v : Vec2) -> Vec2

    Mat2::row0

    fn Mat2::row0(self : Mat2) -> Vec2

    Mat2::row1

    fn Mat2::row1(self : Mat2) -> Vec2

    Mat2::scale

    fn Mat2::scale(self : Mat2, s : Float) -> Mat2

    Mat2::to_cols_array

    fn Mat2::to_cols_array(self : Mat2) -> FixedArray[Float]

    Mat2::to_mat3

    fn Mat2::to_mat3(self : Mat2) -> Mat3

    Mat2::to_mat4

    fn Mat2::to_mat4(self : Mat2) -> Mat4

    Mat2::transpose

    fn Mat2::transpose(self : Mat2) -> Mat2

    Mat2::write_to

    fn Mat2::write_to(self : Mat2, dst : FixedArray[Float], offset : Int) -> Unit

    Mat3

    pub(all) struct Mat3 {
    x_axis : Vec3
    y_axis : Vec3
    z_axis : Vec3
    } derive(Eq,
    Debug
    )

    impl Add for Mat3
    impl Mul for Mat3
    impl Show for Mat3
    impl Sub for Mat3

    Mat3::approx_eq

    fn Mat3::approx_eq(self : Mat3, other : Mat3, eps? : Float) -> Bool

    Mat3::at

    fn Mat3::at(self : Mat3, row : Int, col : Int) -> Float

    Element at (row, col); 0 for out-of-range indices.

    Mat3::determinant

    fn Mat3::determinant(self : Mat3) -> Float

    Mat3::from_cols

    fn Mat3::from_cols(x_axis : Vec3, y_axis : Vec3, z_axis : Vec3) -> Mat3

    Mat3::from_cols_array

    fn Mat3::from_cols_array(arr : FixedArray[Float]) -> Mat3

    Mat3::from_diagonal

    fn Mat3::from_diagonal(diag : Vec3) -> Mat3

    Mat3::from_quat

    fn Mat3::from_quat(q : Quat) -> Mat3

    Mat3::from_rotation_x

    fn Mat3::from_rotation_x(radians : Float) -> Mat3

    Mat3::from_rotation_y

    fn Mat3::from_rotation_y(radians : Float) -> Mat3

    Mat3::from_rotation_z

    fn Mat3::from_rotation_z(radians : Float) -> Mat3

    Mat3::from_scale

    fn Mat3::from_scale(s : Vec3) -> Mat3

    Mat3::identity

    fn Mat3::identity() -> Mat3

    Mat3::inverse

    fn Mat3::inverse(self : Mat3) -> Mat3?

    Inverse, or None when the matrix is singular.

    Mat3::inverse_transpose

    fn Mat3::inverse_transpose(self : Mat3) -> Mat3?

    transpose(inverse(self)) — the matrix that correctly transforms normals under non-uniform scale. None when singular.

    Mat3::mul_vec3

    fn Mat3::mul_vec3(self : Mat3, v : Vec3) -> Vec3

    Mat3::row0

    fn Mat3::row0(self : Mat3) -> Vec3

    Mat3::row1

    fn Mat3::row1(self : Mat3) -> Vec3

    Mat3::row2

    fn Mat3::row2(self : Mat3) -> Vec3

    Mat3::scale

    fn Mat3::scale(self : Mat3, s : Float) -> Mat3

    Mat3::to_cols_array

    fn Mat3::to_cols_array(self : Mat3) -> FixedArray[Float]

    Mat3::to_mat4

    fn Mat3::to_mat4(self : Mat3) -> Mat4

    Mat3::to_quat

    fn Mat3::to_quat(self : Mat3) -> Quat

    Mat3::transpose

    fn Mat3::transpose(self : Mat3) -> Mat3

    Mat3::write_to

    fn Mat3::write_to(self : Mat3, dst : FixedArray[Float], offset : Int) -> Unit

    Mat4

    pub(all) struct Mat4 {
    x_axis : Vec4
    y_axis : Vec4
    z_axis : Vec4
    w_axis : Vec4
    } derive(Eq,
    Debug
    )

    impl Add for Mat4
    impl Mul for Mat4
    impl Show for Mat4
    impl Sub for Mat4

    Mat4::approx_eq

    fn Mat4::approx_eq(self : Mat4, other : Mat4, eps? : Float) -> Bool

    Mat4::at

    fn Mat4::at(self : Mat4, row : Int, col : Int) -> Float

    Element at (row, col); out-of-range indices yield 0.

    Mat4::column

    fn Mat4::column(self : Mat4, i : Int) -> Vec4

    Mat4::determinant

    fn Mat4::determinant(self : Mat4) -> Float

    Mat4::from_axis_angle

    fn Mat4::from_axis_angle(axis : Vec3, angle : Float) -> Mat4

    Mat4::from_cols

    fn Mat4::from_cols(x_axis : Vec4, y_axis : Vec4, z_axis : Vec4, w_axis : Vec4) -> Mat4

    Mat4::from_cols_array

    fn Mat4::from_cols_array(arr : FixedArray[Float]) -> Mat4

    Mat4::from_diagonal

    fn Mat4::from_diagonal(diag : Vec4) -> Mat4

    Mat4::from_mat3

    fn Mat4::from_mat3(m : Mat3) -> Mat4

    Mat4::from_quat

    fn Mat4::from_quat(q : Quat) -> Mat4

    Mat4::from_rotation_x

    fn Mat4::from_rotation_x(radians : Float) -> Mat4

    Mat4::from_rotation_y

    fn Mat4::from_rotation_y(radians : Float) -> Mat4

    Mat4::from_rotation_z

    fn Mat4::from_rotation_z(radians : Float) -> Mat4

    Mat4::from_scale

    fn Mat4::from_scale(s : Vec3) -> Mat4

    Mat4::from_scale_rotation_translation

    fn Mat4::from_scale_rotation_translation(scale : Vec3, rot : Quat, trans : Vec3) -> Mat4

    T * R * S in that multiplication order (scale applied first).

    Mat4::from_scale_uniform

    fn Mat4::from_scale_uniform(s : Float) -> Mat4

    Mat4::from_translation

    fn Mat4::from_translation(t : Vec3) -> Mat4

    Mat4::identity

    fn Mat4::identity() -> Mat4

    Mat4::inverse

    fn Mat4::inverse(self : Mat4) -> Mat4?

    Full 4x4 inverse, or None for singular / non-finite matrices.

    Mat4::is_finite

    fn Mat4::is_finite(self : Mat4) -> Bool

    Mat4::mul_vec4

    fn Mat4::mul_vec4(self : Mat4, v : Vec4) -> Vec4

    Mat4::normal_matrix

    fn Mat4::normal_matrix(self : Mat4) -> Mat3?

    transpose(inverse(upper_left_3x3)), the correct normal transform under non-uniform scale. None when the linear part is singular.

    Mat4::project_point3

    fn Mat4::project_point3(self : Mat4, p : Vec3) -> Vec3

    Full projective transform including the perspective divide.

    Mat4::row0

    fn Mat4::row0(self : Mat4) -> Vec4

    Mat4::row1

    fn Mat4::row1(self : Mat4) -> Vec4

    Mat4::row2

    fn Mat4::row2(self : Mat4) -> Vec4

    Mat4::row3

    fn Mat4::row3(self : Mat4) -> Vec4

    Mat4::scale

    fn Mat4::scale(self : Mat4, s : Float) -> Mat4

    Multiply a matrix by a scalar.

    Mat4::to_cols_array

    fn Mat4::to_cols_array(self : Mat4) -> FixedArray[Float]

    Mat4::to_mat3

    fn Mat4::to_mat3(self : Mat4) -> Mat3

    Upper-left 3x3 block (rotation / scale).

    Mat4::transform_point3

    fn Mat4::transform_point3(self : Mat4, p : Vec3) -> Vec3

    Transform a point, assuming an affine matrix (w = 1, no perspective divide). For projective matrices use project_point3.

    Mat4::transform_vector3

    fn Mat4::transform_vector3(self : Mat4, v : Vec3) -> Vec3

    Transform a direction/vector (w = 0, ignores translation).

    Mat4::translation

    fn Mat4::translation(self : Mat4) -> Vec3

    Mat4::transpose

    fn Mat4::transpose(self : Mat4) -> Mat4

    Mat4::write_to

    fn Mat4::write_to(self : Mat4, dst : FixedArray[Float], offset : Int) -> Unit

    Write the 16 column-major floats into dst starting at offset.

    Plane

    pub(all) struct Plane {
    normal : Vec3
    d : Float
    } derive(Eq,
    Debug
    )

    Plane::from_point_normal

    fn Plane::from_point_normal(point : Vec3, normal : Vec3) -> Plane

    Plane through point with the given normal.

    Plane::new

    fn Plane::new(normal : Vec3, d : Float) -> Plane

    Plane equation: dot(normal, p) + d = 0.

    Plane::normalize

    fn Plane::normalize(self : Plane) -> Plane

    Plane::project_point

    fn Plane::project_point(self : Plane, point : Vec3) -> Vec3

    Orthogonal projection of point onto the plane.

    Plane::signed_distance

    fn Plane::signed_distance(self : Plane, point : Vec3) -> Float

    Positive on the side the normal points to.

    Quat

    pub(all) struct Quat {
    x : Float
    y : Float
    z : Float
    w : Float
    } derive(Eq,
    Debug
    )

    impl Add for Quat
    impl Mul for Quat
    impl Neg for Quat
    impl Show for Quat
    impl Sub for Quat

    Quat::approx_eq

    fn Quat::approx_eq(self : Quat, other : Quat, eps? : Float) -> Bool

    Quat::conjugate

    fn Quat::conjugate(self : Quat) -> Quat

    Quat::dot

    fn Quat::dot(self : Quat, other : Quat) -> Float

    Quat::from_axis_angle

    fn Quat::from_axis_angle(axis : Vec3, angle : Float) -> Quat

    Quat::from_euler

    fn Quat::from_euler(order : EulerOrder, a : Float, b : Float, c : Float) -> Quat

    Quat::from_mat3

    fn Quat::from_mat3(m : Mat3) -> Quat

    Extract the rotation from a pure rotation matrix (scale is not removed).

    Quat::from_rotation_arc

    fn Quat::from_rotation_arc(from : Vec3, to : Vec3) -> Quat

    Shortest-arc rotation taking direction from to direction to.

    Quat::from_rotation_x

    fn Quat::from_rotation_x(angle : Float) -> Quat

    Quat::from_rotation_y

    fn Quat::from_rotation_y(angle : Float) -> Quat

    Quat::from_rotation_z

    fn Quat::from_rotation_z(angle : Float) -> Quat

    Quat::from_xyzw

    fn Quat::from_xyzw(x : Float, y : Float, z : Float, w : Float) -> Quat

    Quat::identity

    fn Quat::identity() -> Quat

    Quat::inverse

    fn Quat::inverse(self : Quat) -> Quat

    Inverse rotation; for unit quaternions this equals the conjugate.

    Quat::is_normalized

    fn Quat::is_normalized(self : Quat, eps? : Float) -> Bool

    Quat::length

    fn Quat::length(self : Quat) -> Float

    Quat::length_sq

    fn Quat::length_sq(self : Quat) -> Float

    Quat::mul_vec3

    fn Quat::mul_vec3(self : Quat, v : Vec3) -> Vec3

    Rotate a 3D vector by this quaternion (assumed unit length).

    Quat::nlerp

    fn Quat::nlerp(self : Quat, other : Quat, t : Float) -> Quat

    Normalized linear interpolation (cheap, not constant angular velocity). Automatically takes the shortest arc.

    Quat::normalize

    fn Quat::normalize(self : Quat) -> Quat

    Quat::rotate_towards

    fn Quat::rotate_towards(self : Quat, other : Quat, max_angle : Float) -> Quat

    Interpolate towards other by at most max_angle radians (shortest arc).

    Quat::scale

    fn Quat::scale(self : Quat, s : Float) -> Quat

    Quat::slerp

    fn Quat::slerp(self : Quat, other : Quat, t : Float) -> Quat

    Spherical linear interpolation along the shortest arc.

    Quat::to_array

    fn Quat::to_array(self : Quat) -> FixedArray[Float]

    Quat::to_axis_angle

    fn Quat::to_axis_angle(self : Quat) -> (Vec3, Float)

    Decompose into (axis, angle) with a unit axis and angle in [0, PI].

    Quat::to_mat3

    fn Quat::to_mat3(self : Quat) -> Mat3

    Rotation matrix of this (assumed unit) quaternion.

    Quat::to_mat4

    fn Quat::to_mat4(self : Quat) -> Mat4

    Ray

    pub(all) struct Ray {
    origin : Vec3
    dir : Vec3
    } derive(Eq,
    Debug
    )

    Ray::at

    fn Ray::at(self : Ray, t : Float) -> Vec3

    Ray::intersect_aabb

    fn Ray::intersect_aabb(self : Ray, box : Aabb3) -> (Float, Float)?

    Slab test. Returns (t_enter, t_exit) along the ray, or None.

    Ray::intersect_plane

    fn Ray::intersect_plane(self : Ray, plane : Plane) -> Float?

    Ray/plane intersection distance, or None when parallel or behind.

    Ray::intersect_sphere

    fn Ray::intersect_sphere(self : Ray, center : Vec3, radius : Float) -> Float?

    Nearest forward hit distance against a sphere, or None.

    Ray::intersect_triangle

    fn Ray::intersect_triangle(self : Ray, v0 : Vec3, v1 : Vec3, v2 : Vec3) -> Float?

    Moller-Trumbore ray/triangle intersection; returns the forward distance.

    Ray::new

    fn Ray::new(origin : Vec3, dir : Vec3) -> Ray

    A ray direction does not have to be normalized; t values are expressed in dir units. Use Ray::new_normalized if you want distances.

    Ray::new_normalized

    fn Ray::new_normalized(origin : Vec3, dir : Vec3) -> Ray

    Sphere

    pub(all) struct Sphere {
    center : Vec3
    radius : Float
    } derive(Eq,
    Debug
    )

    Sphere::contains_point

    fn Sphere::contains_point(self : Sphere, p : Vec3) -> Bool

    Sphere::intersects_aabb

    fn Sphere::intersects_aabb(self : Sphere, box : Aabb3) -> Bool

    Conservative sphere/AABB overlap test.

    Sphere::intersects_sphere

    fn Sphere::intersects_sphere(self : Sphere, other : Sphere) -> Bool

    Sphere::new

    fn Sphere::new(center : Vec3, radius : Float) -> Sphere

    Transform

    pub(all) struct Transform {
    translation : Vec3
    rotation : Quat
    scale : Vec3
    } derive(Eq,
    Debug
    )

    impl Show for Transform

    Transform::approx_eq

    fn Transform::approx_eq(self : Transform, other : Transform, eps? : Float) -> Bool

    Transform::compose

    fn Transform::compose(self : Transform, other : Transform) -> Affine3

    Compose two TRS transforms into a general affine (self applied after other). The result may contain shear, hence Affine3.

    Transform::from_affine3

    fn Transform::from_affine3(a : Affine3) -> Transform?

    Decompose an affine matrix into TRS. Returns None when a scale axis is degenerate. A negative determinant is represented as a negative z scale.

    Transform::from_mat4

    fn Transform::from_mat4(m : Mat4) -> Transform?

    Transform::from_rotation

    fn Transform::from_rotation(q : Quat) -> Transform

    Transform::from_scale

    fn Transform::from_scale(s : Vec3) -> Transform

    Transform::from_translation

    fn Transform::from_translation(t : Vec3) -> Transform

    Transform::identity

    fn Transform::identity() -> Transform

    Transform::inverse

    fn Transform::inverse(self : Transform) -> Affine3?

    Inverse as an affine transform (general, may contain shear).

    Transform::lerp

    fn Transform::lerp(self : Transform, other : Transform, t : Float) -> Transform

    Interpolate translation and scale linearly, rotation via slerp.

    Transform::new

    fn Transform::new(translation : Vec3, rotation : Quat, scale : Vec3) -> Transform

    Transform::to_affine3

    fn Transform::to_affine3(self : Transform) -> Affine3

    Transform::to_mat4

    fn Transform::to_mat4(self : Transform) -> Mat4

    Transform::transform_point3

    fn Transform::transform_point3(self : Transform, p : Vec3) -> Vec3

    T * R * S applied to a point: scale, then rotate, then translate.

    Transform::transform_vector3

    fn Transform::transform_vector3(self : Transform, v : Vec3) -> Vec3

    UVec2

    pub(all) struct UVec2 {
    x : UInt
    y : UInt
    } derive(Eq,
    Debug
    )

    impl Add for UVec2
    impl Div for UVec2
    impl Mul for UVec2
    impl Show for UVec2
    impl Sub for UVec2

    UVec2::as_ivec2

    fn UVec2::as_ivec2(self : UVec2) -> IVec2

    UVec2::dot

    fn UVec2::dot(self : UVec2, other : UVec2) -> UInt

    UVec2::new

    fn UVec2::new(x : UInt, y : UInt) -> UVec2

    UVec2::one

    fn UVec2::one() -> UVec2

    UVec2::splat

    fn UVec2::splat(v : UInt) -> UVec2

    UVec2::to_vec2

    fn UVec2::to_vec2(self : UVec2) -> Vec2

    Integer size as (width, height) in pixels.

    UVec2::zero

    fn UVec2::zero() -> UVec2

    UVec3

    pub(all) struct UVec3 {
    x : UInt
    y : UInt
    z : UInt
    } derive(Eq,
    Debug
    )

    impl Add for UVec3
    impl Mul for UVec3
    impl Show for UVec3
    impl Sub for UVec3

    UVec3::dot

    fn UVec3::dot(self : UVec3, other : UVec3) -> UInt

    UVec3::new

    fn UVec3::new(x : UInt, y : UInt, z : UInt) -> UVec3

    UVec3::splat

    fn UVec3::splat(v : UInt) -> UVec3

    UVec3::zero

    fn UVec3::zero() -> UVec3

    UVec4

    pub(all) struct UVec4 {
    x : UInt
    y : UInt
    z : UInt
    w : UInt
    } derive(Eq,
    Debug
    )

    impl Add for UVec4
    impl Mul for UVec4
    impl Show for UVec4
    impl Sub for UVec4

    UVec4::dot

    fn UVec4::dot(self : UVec4, other : UVec4) -> UInt

    UVec4::from_vec4_rgba8

    fn UVec4::from_vec4_rgba8(v : Vec4) -> UVec4

    Convert a normalized Vec4 colour to 8-bit RGBA (rounds, then clamps).

    UVec4::new

    fn UVec4::new(x : UInt, y : UInt, z : UInt, w : UInt) -> UVec4

    UVec4::splat

    fn UVec4::splat(v : UInt) -> UVec4

    UVec4::zero

    fn UVec4::zero() -> UVec4

    Vec2

    pub(all) struct Vec2 {
    x : Float
    y : Float
    } derive(Eq,
    Debug
    )

    impl Add for Vec2
    impl Div for Vec2
    impl Mul for Vec2
    impl Neg for Vec2
    impl Show for Vec2
    impl Sub for Vec2

    Vec2::abs

    fn Vec2::abs(self : Vec2) -> Vec2

    Vec2::angle

    fn Vec2::angle(self : Vec2) -> Float

    Angle of the vector from +X, in radians, via atan2.

    Vec2::angle_to

    fn Vec2::angle_to(self : Vec2, other : Vec2) -> Float

    Angle from self to other, in [-PI, PI].

    Vec2::approx_eq

    fn Vec2::approx_eq(self : Vec2, other : Vec2, eps? : Float) -> Bool

    Vec2::clamp

    fn Vec2::clamp(self : Vec2, lo : Vec2, hi : Vec2) -> Vec2

    Vec2::cross

    fn Vec2::cross(self : Vec2, other : Vec2) -> Float

    2D cross product (perpendicular dot), i.e. the signed area of the parallelogram spanned by the two vectors.

    Vec2::distance

    fn Vec2::distance(self : Vec2, other : Vec2) -> Float

    Vec2::distance_sq

    fn Vec2::distance_sq(self : Vec2, other : Vec2) -> Float

    Vec2::dot

    fn Vec2::dot(self : Vec2, other : Vec2) -> Float

    Vec2::extend_z

    fn Vec2::extend_z(self : Vec2, z : Float) -> Vec3

    Widen to Vec3 with an explicit z (glam calls this extend).

    Vec2::from_array

    fn Vec2::from_array(arr : FixedArray[Float]) -> Vec2

    Vec2::is_finite

    fn Vec2::is_finite(self : Vec2) -> Bool

    Vec2::length

    fn Vec2::length(self : Vec2) -> Float

    Vec2::length_sq

    fn Vec2::length_sq(self : Vec2) -> Float

    Vec2::lerp

    fn Vec2::lerp(self : Vec2, other : Vec2, t : Float) -> Vec2

    Vec2::max

    fn Vec2::max(self : Vec2, other : Vec2) -> Vec2

    Vec2::min

    fn Vec2::min(self : Vec2, other : Vec2) -> Vec2

    Vec2::neg_x

    fn Vec2::neg_x() -> Vec2

    Vec2::neg_y

    fn Vec2::neg_y() -> Vec2

    Vec2::new

    fn Vec2::new(x : Float, y : Float) -> Vec2

    Vec2::normalize

    fn Vec2::normalize(self : Vec2) -> Vec2

    Normalize, returning the zero vector for zero-length input.

    Vec2::one

    fn Vec2::one() -> Vec2

    Vec2::perp

    fn Vec2::perp(self : Vec2) -> Vec2

    Rotate 90 degrees counter-clockwise: (-y, x).

    Vec2::project_onto

    fn Vec2::project_onto(self : Vec2, other : Vec2) -> Vec2

    Project self onto other.

    Vec2::reflect

    fn Vec2::reflect(self : Vec2, normal : Vec2) -> Vec2

    Mirror self about a (ideally normalized) normal.

    Vec2::rotate

    fn Vec2::rotate(self : Vec2, radians : Float) -> Vec2

    Rotate around the origin by radians (counter-clockwise).

    Vec2::scale

    fn Vec2::scale(self : Vec2, s : Float) -> Vec2

    Vec2::splat

    fn Vec2::splat(v : Float) -> Vec2

    Vec2::to_array

    fn Vec2::to_array(self : Vec2) -> FixedArray[Float]

    Vec2::try_normalize

    fn Vec2::try_normalize(self : Vec2) -> Vec2?

    Normalize, returning None when the vector is (near) zero length.

    Vec2::unit_x

    fn Vec2::unit_x() -> Vec2

    Vec2::unit_y

    fn Vec2::unit_y() -> Vec2

    Vec2::zero

    fn Vec2::zero() -> Vec2

    Vec3

    pub(all) struct Vec3 {
    x : Float
    y : Float
    z : Float
    } derive(Eq,
    Debug
    )

    impl Add for Vec3
    impl Div for Vec3
    impl Mul for Vec3
    impl Neg for Vec3
    impl Show for Vec3
    impl Sub for Vec3

    Vec3::abs

    fn Vec3::abs(self : Vec3) -> Vec3

    Vec3::any_orthonormal

    fn Vec3::any_orthonormal(self : Vec3) -> Vec3

    Any unit vector perpendicular to self; depends only on self, so two calls with the same input are reproducible (useful for building frames).

    Vec3::approx_eq

    fn Vec3::approx_eq(self : Vec3, other : Vec3, eps? : Float) -> Bool

    Vec3::clamp

    fn Vec3::clamp(self : Vec3, lo : Vec3, hi : Vec3) -> Vec3

    Vec3::cross

    fn Vec3::cross(self : Vec3, other : Vec3) -> Vec3

    Vec3::distance

    fn Vec3::distance(self : Vec3, other : Vec3) -> Float

    Vec3::distance_sq

    fn Vec3::distance_sq(self : Vec3, other : Vec3) -> Float

    Vec3::dot

    fn Vec3::dot(self : Vec3, other : Vec3) -> Float

    Vec3::extend_w

    fn Vec3::extend_w(self : Vec3, w : Float) -> Vec4

    Vec3::from_array

    fn Vec3::from_array(arr : FixedArray[Float]) -> Vec3

    Vec3::is_finite

    fn Vec3::is_finite(self : Vec3) -> Bool

    Vec3::length

    fn Vec3::length(self : Vec3) -> Float

    Vec3::length_sq

    fn Vec3::length_sq(self : Vec3) -> Float

    Vec3::lerp

    fn Vec3::lerp(self : Vec3, other : Vec3, t : Float) -> Vec3

    Vec3::max

    fn Vec3::max(self : Vec3, other : Vec3) -> Vec3

    Vec3::min

    fn Vec3::min(self : Vec3, other : Vec3) -> Vec3

    Vec3::neg_x

    fn Vec3::neg_x() -> Vec3

    Vec3::neg_y

    fn Vec3::neg_y() -> Vec3

    Vec3::neg_z

    fn Vec3::neg_z() -> Vec3

    Vec3::new

    fn Vec3::new(x : Float, y : Float, z : Float) -> Vec3

    Vec3::normalize

    fn Vec3::normalize(self : Vec3) -> Vec3

    Normalize, returning the zero vector for zero-length input (never NaN).

    Vec3::one

    fn Vec3::one() -> Vec3

    Vec3::project_onto

    fn Vec3::project_onto(self : Vec3, other : Vec3) -> Vec3

    Project self onto other.

    Vec3::reflect

    fn Vec3::reflect(self : Vec3, normal : Vec3) -> Vec3

    Mirror self about a (ideally normalized) normal.

    Vec3::refract

    fn Vec3::refract(self : Vec3, normal : Vec3, eta : Float) -> Vec3

    Refract self through a surface with (ideally normalized) normal and ratio eta of indices of refraction. Returns the zero vector on total internal reflection.

    Vec3::scale

    fn Vec3::scale(self : Vec3, s : Float) -> Vec3

    Vec3::sort

    fn Vec3::sort(self : Vec3) -> Vec3

    Sort the three components ascending (useful for AABB min/max folding).

    Vec3::splat

    fn Vec3::splat(v : Float) -> Vec3

    Vec3::to_array

    fn Vec3::to_array(self : Vec3) -> FixedArray[Float]

    Vec3::truncate

    fn Vec3::truncate(self : Vec3) -> Vec2

    Vec3::try_normalize

    fn Vec3::try_normalize(self : Vec3) -> Vec3?

    Normalize, returning None when the vector is (near) zero length.

    Vec3::unit_x

    fn Vec3::unit_x() -> Vec3

    Vec3::unit_y

    fn Vec3::unit_y() -> Vec3

    Vec3::unit_z

    fn Vec3::unit_z() -> Vec3

    Vec3::xy

    fn Vec3::xy(self : Vec3) -> Vec2

    Vec3::xz

    fn Vec3::xz(self : Vec3) -> Vec2

    Vec3::yz

    fn Vec3::yz(self : Vec3) -> Vec2

    Vec3::zero

    fn Vec3::zero() -> Vec3

    Vec4

    pub(all) struct Vec4 {
    x : Float
    y : Float
    z : Float
    w : Float
    } derive(Eq,
    Debug
    )

    impl Add for Vec4
    impl Div for Vec4
    impl Mul for Vec4
    impl Neg for Vec4
    impl Show for Vec4
    impl Sub for Vec4

    Vec4::abs

    fn Vec4::abs(self : Vec4) -> Vec4

    Vec4::approx_eq

    fn Vec4::approx_eq(self : Vec4, other : Vec4, eps? : Float) -> Bool

    Vec4::component

    fn Vec4::component(self : Vec4, i : Int) -> Float

    Component by index (0..=3); out-of-range indices yield 0.

    Vec4::dot

    fn Vec4::dot(self : Vec4, other : Vec4) -> Float

    Vec4::from_array

    fn Vec4::from_array(arr : FixedArray[Float]) -> Vec4

    Vec4::is_finite

    fn Vec4::is_finite(self : Vec4) -> Bool

    Vec4::length

    fn Vec4::length(self : Vec4) -> Float

    Vec4::length_sq

    fn Vec4::length_sq(self : Vec4) -> Float

    Vec4::lerp

    fn Vec4::lerp(self : Vec4, other : Vec4, t : Float) -> Vec4

    Vec4::max

    fn Vec4::max(self : Vec4, other : Vec4) -> Vec4

    Vec4::min

    fn Vec4::min(self : Vec4, other : Vec4) -> Vec4

    Vec4::new

    fn Vec4::new(x : Float, y : Float, z : Float, w : Float) -> Vec4

    Vec4::normalize

    fn Vec4::normalize(self : Vec4) -> Vec4

    Normalize, returning the zero vector for zero-length input (never NaN).

    Vec4::one

    fn Vec4::one() -> Vec4

    Vec4::perspective_divide

    fn Vec4::perspective_divide(self : Vec4) -> Vec4

    Perspective divide. Returns self unchanged when |w| <= EPSILON.

    Vec4::scale

    fn Vec4::scale(self : Vec4, s : Float) -> Vec4

    Vec4::splat

    fn Vec4::splat(v : Float) -> Vec4

    Vec4::to_array

    fn Vec4::to_array(self : Vec4) -> FixedArray[Float]

    Vec4::truncate

    fn Vec4::truncate(self : Vec4) -> Vec3

    Vec4::try_normalize

    fn Vec4::try_normalize(self : Vec4) -> Vec4?

    Vec4::unit_w

    fn Vec4::unit_w() -> Vec4

    Vec4::unit_x

    fn Vec4::unit_x() -> Vec4

    Vec4::unit_y

    fn Vec4::unit_y() -> Vec4

    Vec4::unit_z

    fn Vec4::unit_z() -> Vec4

    Vec4::xy

    fn Vec4::xy(self : Vec4) -> Vec2

    Vec4::xyz

    fn Vec4::xyz(self : Vec4) -> Vec3

    Vec4::zero

    fn Vec4::zero() -> Vec4

    DEG_TO_RAD

    let DEG_TO_RAD : Float

    EPSILON

    let EPSILON : Float

    Default absolute tolerance used by every approx_eq in this package.

    FRAC_PI_2

    let FRAC_PI_2 : Float

    FRAC_PI_3

    let FRAC_PI_3 : Float

    FRAC_PI_4

    let FRAC_PI_4 : Float

    FRAC_PI_6

    let FRAC_PI_6 : Float

    let PI : Float

    RAD_TO_DEG

    let RAD_TO_DEG : Float

    SQRT_1_2

    let SQRT_1_2 : Float

    SQRT_2

    let SQRT_2 : Float

    TAU

    let TAU : Float

    abs_f

    fn abs_f(v : Float) -> Float

    acos

    fn acos(v : Float) -> Float

    approx_eq_f

    fn approx_eq_f(a : Float, b : Float, eps? : Float) -> Bool

    Absolute-tolerance comparison. NaN never compares equal, even to itself.

    asin

    fn asin(v : Float) -> Float

    atan

    fn atan(v : Float) -> Float

    atan2

    fn atan2(y : Float, x : Float) -> Float

    batch_frustum_cull

    fn batch_frustum_cull(visible : FixedArray[Bool], frustum : Frustum, boxes : FixedArray[Aabb3], count : Int) -> Int

    Write true/false visibility flags and return how many boxes are visible.

    batch_mul_mat4

    fn batch_mul_mat4(dst : FixedArray[Mat4], a : FixedArray[Mat4], b : FixedArray[Mat4], count : Int) -> Unit

    dst[i] = a[i] * b[i] for the first count elements (clamped to the shortest array).

    batch_rotate_vec3

    fn batch_rotate_vec3(dst : FixedArray[Vec3], q : Quat, src : FixedArray[Vec3], count : Int) -> Unit

    dst[i] = q * src[i] for the first count vectors.

    batch_transform_points3

    fn batch_transform_points3(dst : FixedArray[Vec3], mat : Mat4, src : FixedArray[Vec3], count : Int) -> Unit

    dst[i] = mat * src[i] for the first count points.

    batch_transform_points3_affine

    fn batch_transform_points3_affine(dst : FixedArray[Vec3], affine : Affine3, src : FixedArray[Vec3], count : Int) -> Unit

    dst[i] = affine * src[i] for the first count points.

    clamp_f

    fn clamp_f(v : Float, lo : Float, hi : Float) -> Float

    Clamp v into [lo, hi]. If lo > hi the bounds are swapped so the function never returns a value outside the closed interval formed by them.

    cos

    fn cos(radians : Float) -> Float

    deg_to_rad

    fn deg_to_rad(deg : Float) -> Float

    exp

    fn exp(v : Float) -> Float

    fract

    fn fract(v : Float) -> Float

    Fractional part, always in [0, 1) for finite inputs.

    inv_lerp_f

    fn inv_lerp_f(a : Float, b : Float, v : Float) -> Float

    Inverse of lerp_f: returns where v lies between a and b. Returns 0 when a == b.

    invert_view_proj

    fn invert_view_proj(view_proj : Mat4) -> Mat4?

    Build an inverse view-projection matrix, or None when singular.

    is_finite

    fn is_finite(v : Float) -> Bool

    true when v is finite (not NaN, +inf, or -inf).

    is_nan

    fn is_nan(v : Float) -> Bool

    true when both values are NaN (handy for tests that must reject NaN).

    lerp_f

    fn lerp_f(a : Float, b : Float, t : Float) -> Float

    Linear interpolation, no clamping of t.
    fn ln(v : Float) -> Float

    look_at_lh

    fn look_at_lh(eye : Vec3, target : Vec3, up : Vec3) -> Mat4

    Left-handed view matrix looking at target.

    look_at_rh

    fn look_at_rh(eye : Vec3, target : Vec3, up : Vec3) -> Mat4

    Right-handed view matrix looking at target.

    look_to_lh

    fn look_to_lh(eye : Vec3, dir : Vec3, up : Vec3) -> Mat4

    Left-handed view matrix looking from eye along dir (+Z forward).

    look_to_rh

    fn look_to_rh(eye : Vec3, dir : Vec3, up : Vec3) -> Mat4

    Right-handed view matrix looking from eye along dir. dir does not need to be normalized; a zero dir yields identity.

    max_f

    fn max_f(a : Float, b : Float) -> Float

    min_f

    fn min_f(a : Float, b : Float) -> Float

    orthographic_lh

    fn orthographic_lh(left : Float, right : Float, bottom : Float, top : Float, z_near : Float, z_far : Float, clip? : ClipSpace) -> Mat4

    Left-handed orthographic projection.

    orthographic_rh

    fn orthographic_rh(left : Float, right : Float, bottom : Float, top : Float, z_near : Float, z_far : Float, clip? : ClipSpace) -> Mat4

    Right-handed orthographic projection.

    orthographic_rh_reverse

    fn orthographic_rh_reverse(left : Float, right : Float, bottom : Float, top : Float, z_near : Float, z_far : Float, clip? : ClipSpace) -> Mat4

    Reversed-Z right-handed orthographic projection (near maps to 1).

    perspective_infinite_reverse_rh

    fn perspective_infinite_reverse_rh(fov_y_rad : Float, aspect : Float, z_near : Float, clip? : ClipSpace) -> Mat4

    Infinite-far-plane reversed-Z right-handed perspective. z_near maps to 1 and the far plane to 0 (or -1 for NegOneToOne).

    perspective_lh

    fn perspective_lh(fov_y_rad : Float, aspect : Float, z_near : Float, z_far : Float, clip? : ClipSpace) -> Mat4

    Left-handed perspective projection (+Z forward).

    perspective_rh

    fn perspective_rh(fov_y_rad : Float, aspect : Float, z_near : Float, z_far : Float, clip? : ClipSpace) -> Mat4

    Right-handed perspective projection. z_near / z_far are positive distances along -Z.

    perspective_rh_reverse

    fn perspective_rh_reverse(fov_y_rad : Float, aspect : Float, z_near : Float, z_far : Float, clip? : ClipSpace) -> Mat4

    Reversed-Z right-handed perspective: near plane maps to 1, far plane to 0. Solves depth-precision banding in large scenes.

    pow

    fn pow(a : Float, b : Float) -> Float

    project

    fn project(view_proj : Mat4, world : Vec3) -> Vec3

    Transform a world-space point by view_proj and perform the perspective divide, returning normalized device coordinates.

    rad_to_deg

    fn rad_to_deg(rad : Float) -> Float

    saturate

    fn saturate(v : Float) -> Float

    Clamp v into [0, 1].

    sign_f

    fn sign_f(v : Float) -> Float

    Sign of v as -1, 0, or 1. NaN maps to 0.

    sin

    fn sin(radians : Float) -> Float

    sin_cos

    fn sin_cos(radians : Float) -> (Float, Float)

    (sin, cos) of an angle in radians, sharing one range reduction in the underlying libm when available.

    smoothstep

    fn smoothstep(edge0 : Float, edge1 : Float, x : Float) -> Float

    GLSL-style smoothstep: smooth Hermite interpolation between two edges, clamped to [0, 1]. Returns 0 when edge0 >= edge1.

    sqrt

    fn sqrt(v : Float) -> Float

    step

    fn step(edge : Float, x : Float) -> Float

    GLSL-style step: 0 when x < edge, otherwise 1.

    tan

    fn tan(radians : Float) -> Float

    unproject

    fn unproject(view_proj_inverse : Mat4, ndc : Vec3) -> Vec3

    Inverse of project: ndc is in the device range produced by the projection matrix that was used to build view_proj_inverse.