gizlang/geometry
import * as Geometry from "gizlang/geometry";Types
Point3
type Point3 = { x: f64; y: f64; z: f64; }Three coordinates, in a right-handed space.
x:f64y:f64z:f64
Point2
type Point2 = { x: f64; y: f64; }Two coordinates for mapping application content into a fitted canvas viewport.
x:f64y:f64
Viewport2D
type Viewport2D = { left: f64; top: f64; scale: f64; }A shared letterbox transform. Content and pointer input use these same offsets and scale.
left:f64top:f64scale:f64
Rotation
type Rotation = { x: f64; y: f64; z: f64; w: f64; }Quaternion in glTF order, x/y/z/w.
x:f64y:f64z:f64w:f64
Bounds3
type Bounds3 = { low: Point3; high: Point3; }An axis-aligned bound, derived from a mesh or transformed instances.
low:gizlang_geometry.Point3high:gizlang_geometry.Point3
Matrix4
type Matrix4 = { values: Vec<f64>; }A column-major 4 by 4 transform, compatible with WGSL and glTF.
values:Vec<f64>
Ray
type Ray = { origin: Point3; direction: Point3; }A normalized world-space picking ray from a camera's near plane.
origin:gizlang_geometry.Point3direction:gizlang_geometry.Point3
Functions
fitted2D
function fitted2D(width: f64, height: f64, logicalWidth: f64, logicalHeight: f64, pixelPerfect: bool = false): Viewport2D throws stringFits a logical 2D surface into physical pixels. Pixel-perfect minification uses whole source pixels per output pixel.
Effects: fail, alloc.
pixel2D
function pixel2D(viewport: Viewport2D, point: Point2): Point2Logical content to physical canvas pixels, shared by render extraction and non-game viewers.
logical2D
function logical2D(viewport: Viewport2D, point: Point2): Point2Physical canvas pixels to logical content; callers choose how to treat points outside the content.
identity
function identity(): Matrix4The identity matrix.
Effects: fail, alloc.
dot
function dot(a: Point3, b: Point3): f64A dot product.
cross
function cross(a: Point3, b: Point3): Point3A right-handed cross product.
normalized
function normalized(value: Point3): Point3 throws stringA unit direction; zero and non-finite vectors are refused.
Effects: fail.
multiply
function multiply(left: Matrix4, right: Matrix4): Matrix4LEFT * RIGHT: RIGHT is applied first.
Effects: fail, alloc.
inverse
function inverse(matrix: Matrix4): Matrix4 throws stringInverts a finite 4x4 matrix with partial pivoting. Singular camera/model transforms are explicit errors.
Effects: fail, alloc.
ray
function ray(viewProjection: Matrix4, point: Point2): Ray throws stringA normalized top-left-origin surface point to a world-space ray, using WebGPU's [0,1] depth convention.
Effects: fail, alloc.
plane
function plane(ray: Ray, normal: Point3, distance: f64): Point3 | undefinedForward ray intersection with dot(NORMAL, point)+DISTANCE=0. Parallel or behind-camera planes have no hit.
Effects: fail.
normalMatrix
function normalMatrix(matrix: Matrix4): Matrix4 throws stringThe inverse-transpose linear transform for vertex normals. Singular transforms are refused.
Effects: fail, alloc.
transformed
function transformed(matrix: Matrix4, point: Point3): Point3 throws stringApplies a homogeneous transform, including perspective division.
Effects: fail.
transform
function transform(position: Point3, rotation: Rotation, scale: Point3): Matrix4 throws stringTranslation, quaternion rotation and nonuniform scale. Normalizes the quaternion once.
Effects: fail, alloc.
perspective
function perspective(verticalRadians: f64, aspect: f64, near: f64, far: f64): Matrix4 throws stringRight-handed projection, camera toward -Z, WebGPU depth in [0,1]. FAR must exceed NEAR.
Effects: fail, alloc.
lookAt
function lookAt(eye: Point3, target: Point3, up: Point3 = { x: 0.0, y: 1.0, z: 0.0 }): Matrix4 throws stringA camera transform from EYE toward TARGET, with UP choosing its roll.
Effects: fail, alloc.
visible
function visible(bounds: Bounds3, viewProjection: Matrix4): boolConservative clip-space test of all eight bound corners, using WebGPU's six clip planes.
Effects: fail, alloc.
orthographic
function orthographic(left: f64, right: f64, bottom: f64, top: f64, near: f64, far: f64): Matrix4 throws stringRight-handed orthographic projection toward -Z, WebGPU depth in [0,1], as for a sun's shadow.
Effects: fail, alloc.
euler
function euler(yaw: f64, pitch: f64, roll: f64): RotationThe rotation of YAW about +Y, then PITCH about +X, then ROLL about +Z, in radians.
Effects: fail.