stdlib.geom¶
2D/3D Geometry Library (vectors, matrices, quaternions, primitives)
Generated from
v0.60.1. 14 source files, 460 documented symbols.
collision.xi¶
type CollisionAabb¶
Axis-aligned bounding box defined by min and max corners.
| Field | Type |
|---|---|
min |
Vec[Float64] |
max |
Vec[Float64] |
type CollisionSphere¶
CollisionSphere primitive defined by centre point and radius.
| Field | Type |
|---|---|
center |
Vec[Float64] |
radius |
Float64 |
type CollisionRay¶
CollisionRay primitive: infinite line from origin along dir.
| Field | Type |
|---|---|
origin |
Vec[Float64] |
dir |
Vec[Float64] |
fn aabb_new(min: &Vec[Float64], max: &Vec[Float64]) -> CollisionAabb¶
Construct an AABB from min and max corners (3 components each). O(1).
fn aabb_contains(a: CollisionAabb, p: &Vec[Float64]) -> Bool¶
True iff p lies inside the AABB (inclusive). A point with fewer than 3 components is not inside. O(1).
fn aabb_intersects(a: CollisionAabb, b: CollisionAabb) -> Bool¶
True iff the two AABBs overlap or touch. O(1).
fn sphere_new(center: &Vec[Float64], radius: Float64) -> CollisionSphere¶
Construct a sphere from center and radius. O(1).
fn sphere_contains(s: CollisionSphere, p: &Vec[Float64]) -> Bool¶
True iff p lies inside the sphere (inclusive). O(1).
fn sphere_intersects(a: CollisionSphere, b: CollisionSphere) -> Bool¶
True iff the two spheres overlap or touch. O(1).
fn ray_new(origin: &Vec[Float64], dir: &Vec[Float64]) -> CollisionRay¶
Construct a ray from origin and direction. O(1).
fn ray_sphere_intersect(r: CollisionRay, s: CollisionSphere) -> Option[Float64]¶
CollisionRay-sphere intersection: nearest positive t; None on miss. O(1).
fn ray_aabb_intersect(r: CollisionRay, a: CollisionAabb) -> Option[Float64]¶
CollisionRay-AABB intersection via the slab method: nearest positive t; None on miss. O(1).
fn ray_plane_intersect(r: CollisionRay, plane: &Vec[Float64]) -> Option[Float64]¶
CollisionRay-plane intersection against the plane (n, d) given as the 4-element vector [nx, ny, nz, d] with n.p = d. None when parallel or behind. O(1).
fn point_in_triangle(p: &Vec[Float64], a: &Vec[Float64], b: &Vec[Float64], c: &Vec[Float64]) -> Bool¶
True iff p is inside (or on) the triangle (a, b, c) using same-side tests on the 2D-projected coordinate with the dominant axis removed. O(1).
fn segment_intersect(p1: &Vec[Float64], p2: &Vec[Float64], p3: &Vec[Float64], p4: &Vec[Float64]) -> Option[Vec[Float64]]¶
Intersection point of segments p1p2 and p3p4; None if disjoint or parallel. The result is a 3-component point. O(1).
curves.xi¶
fn bezier_quad(p0: &Vec[Float64], p1: &Vec[Float64], p2: &Vec[Float64], t: Float64) -> Vec[Float64]¶
Point on a quadratic Bezier curve at parameter t. O(1).
fn bezier_cubic(p0: &Vec[Float64], p1: &Vec[Float64], p2: &Vec[Float64], p3: &Vec[Float64], t: Float64) -> Vec[Float64]¶
Point on a cubic Bezier curve at parameter t. O(1).
fn bezier_derivative(points: &Vec[Vec[Float64]], t: Float64) -> Vec[Float64]¶
Tangent vector of a Bezier curve at t: the derivative of the de Casteljau ladder. O(k^2).
fn catmull_rom(p0: &Vec[Float64], p1: &Vec[Float64], p2: &Vec[Float64], p3: &Vec[Float64], t: Float64) -> Vec[Float64]¶
Catmull-Rom spline point over [p1, p2] at parameter t in [0, 1]. O(1).
fn b_spline(points: &Vec[Vec[Float64]], t: Float64) -> Vec[Float64]¶
Uniform cubic B-spline point at parameter t in [0, 1] over the four control points. O(1).
fn hermite_curve(p0: &Vec[Float64], t0: &Vec[Float64], p1: &Vec[Float64], t1: &Vec[Float64], t: Float64) -> Vec[Float64]¶
Hermite interpolation with endpoint tangents t0 and t1. O(1).
fn curve_length(samples: fn(Float64) -> Vec[Float64], a: Float64, b: Float64, n: Int) -> Float64¶
Arc length of a sampled curve over [a, b] by piecewise-linear integration with n segments. O(n * cost(f)).
geom.xi¶
type Vec2¶
2-component vector (x, y) -- used for 2D positions, directions, UVs.
| Field | Type |
|---|---|
x |
Float64 |
y |
Float64 |
type Vec3¶
3-component vector (x, y, z) -- core 3D math type.
| Field | Type |
|---|---|
x |
Float64 |
y |
Float64 |
z |
Float64 |
type Vec4¶
4-component vector (x, y, z, w) -- homogeneous coords, RGBA colours.
| Field | Type |
|---|---|
x |
Float64 |
y |
Float64 |
z |
Float64 |
w |
Float64 |
type Quaternion¶
Quaternion (x, y, z, w) -- rotation representation; w is the scalar part.
| Field | Type |
|---|---|
x |
Float64 |
y |
Float64 |
z |
Float64 |
w |
Float64 |
type Mat2¶
2x2 column-major matrix.
| Field | Type |
|---|---|
m00 |
Float64 |
m01 |
Float64 |
m10 |
Float64 |
m11 |
Float64 |
type Mat3¶
3x3 column-major matrix.
| Field | Type |
|---|---|
m00 |
Float64 |
m01 |
Float64 |
m02 |
Float64 |
m10 |
Float64 |
m11 |
Float64 |
m12 |
Float64 |
m20 |
Float64 |
m21 |
Float64 |
m22 |
Float64 |
type Mat4¶
4x4 column-major matrix -- core 3D transform type.
| Field | Type |
|---|---|
m00 |
Float64 |
m01 |
Float64 |
m02 |
Float64 |
m03 |
Float64 |
m10 |
Float64 |
m11 |
Float64 |
m12 |
Float64 |
m13 |
Float64 |
m20 |
Float64 |
m21 |
Float64 |
m22 |
Float64 |
m23 |
Float64 |
m30 |
Float64 |
m31 |
Float64 |
m32 |
Float64 |
m33 |
Float64 |
type Aabb¶
Axis-aligned bounding box defined by min and max corners.
| Field | Type |
|---|---|
min |
Vec3 |
max |
Vec3 |
type Sphere¶
Sphere primitive defined by centre point and radius.
| Field | Type |
|---|---|
center |
Vec3 |
radius |
Float64 |
type Ray¶
Ray primitive: infinite line from origin along dir. dir should be normalised for consistent t values.
| Field | Type |
|---|---|
origin |
Vec3 |
dir |
Vec3 |
fn vec2_new(x: Float64, y: Float64) -> Vec2¶
Create a new 2D vector.
fn vec2_add(a: Vec2, b: Vec2) -> Vec2¶
Add two 2D vectors component-wise. O(1).
- Postcondition:
result.x == a.x + b.x && result.y == a.y + b.y
fn vec2_sub(a: Vec2, b: Vec2) -> Vec2¶
Subtract b from a component-wise. O(1).
- Postcondition:
result.x == a.x - b.x && result.y == a.y - b.y
fn vec2_mul(a: Vec2, b: Vec2) -> Vec2¶
Multiply two 2D vectors component-wise. O(1).
- Postcondition:
result.x == a.x * b.x && result.y == a.y * b.y
fn vec2_div(a: Vec2, b: Vec2) -> Vec2¶
Divide a by b component-wise. O(1).
- Postcondition:
result.x == a.x / b.x && result.y == a.y / b.y
fn vec2_add_scalar(v: Vec2, s: Float64) -> Vec2¶
Add scalar s to each component of v. O(1).
- Postcondition:
result.x == v.x + s && result.y == v.y + s
fn vec2_sub_scalar(v: Vec2, s: Float64) -> Vec2¶
Subtract scalar s from each component of v. O(1).
- Postcondition:
result.x == v.x - s && result.y == v.y - s
fn vec2_mul_scalar(v: Vec2, s: Float64) -> Vec2¶
Multiply each component of v by scalar s. O(1).
- Postcondition:
result.x == v.x * s && result.y == v.y * s
fn vec2_div_scalar(v: Vec2, s: Float64) -> Vec2¶
Divide each component of v by scalar s. O(1).
- Postcondition:
result.x == v.x / s && result.y == v.y / s
fn vec2_dot(a: Vec2, b: Vec2) -> Float64¶
Dot product of two 2D vectors. O(1).
- Postcondition:
result == a.x * b.x + a.y * b.y
fn vec2_cross(a: Vec2, b: Vec2) -> Float64¶
2D cross product (scalar): a.x * b.y - a.y * b.x. O(1). This is the signed area of the parallelogram spanned by a and b.
- Postcondition:
result == a.x * b.y - a.y * b.x
fn vec2_length(v: Vec2) -> Float64¶
Euclidean length (magnitude) of v. O(1).
- Postcondition:
result >= 0
fn vec2_normalize(v: Vec2) -> Vec2¶
Normalise v to unit length. Returns zero vector if length is zero. O(1).
fn vec2_distance(a: Vec2, b: Vec2) -> Float64¶
Euclidean distance between two 2D points. O(1).
- Postcondition:
result >= 0
fn vec2_lerp(a: Vec2, b: Vec2, t: Float64) -> Float64¶
Linearly interpolate between a and b by t. t=0 -> a, t=1 -> b. O(1).
- Postcondition:
result == math.lerp(a.x, b.x, t)
fn vec3_new(x: Float64, y: Float64, z: Float64) -> Vec3¶
Create a new 3D vector.
fn vec3_add(a: Vec3, b: Vec3) -> Vec3¶
Add two 3D vectors component-wise. O(1).
- Postcondition:
result.x == a.x + b.x && result.y == a.y + b.y && result.z == a.z + b.z
fn vec3_sub(a: Vec3, b: Vec3) -> Vec3¶
Subtract b from a component-wise. O(1).
- Postcondition:
result.x == a.x - b.x && result.y == a.y - b.y && result.z == a.z - b.z
fn vec3_mul(a: Vec3, b: Vec3) -> Vec3¶
Multiply two 3D vectors component-wise (Hadamard product). O(1).
- Postcondition:
result.x == a.x * b.x && result.y == a.y * b.y && result.z == a.z * b.z
fn vec3_div(a: Vec3, b: Vec3) -> Vec3¶
Divide a by b component-wise. O(1).
- Postcondition:
result.x == a.x / b.x && result.y == a.y / b.y && result.z == a.z / b.z
fn vec3_add_scalar(v: Vec3, s: Float64) -> Vec3¶
Add scalar s to each component of v. O(1).
- Postcondition:
result.x == v.x + s && result.y == v.y + s && result.z == v.z + s
fn vec3_sub_scalar(v: Vec3, s: Float64) -> Vec3¶
Subtract scalar s from each component of v. O(1).
- Postcondition:
result.x == v.x - s && result.y == v.y - s && result.z == v.z - s
fn vec3_mul_scalar(v: Vec3, s: Float64) -> Vec3¶
Multiply each component of v by scalar s. O(1).
- Postcondition:
result.x == v.x * s && result.y == v.y * s && result.z == v.z * s
fn vec3_div_scalar(v: Vec3, s: Float64) -> Vec3¶
Divide each component of v by scalar s. O(1).
- Postcondition:
result.x == v.x / s && result.y == v.y / s && result.z == v.z / s
fn vec3_dot(a: Vec3, b: Vec3) -> Float64¶
Dot product of two 3D vectors. O(1).
- Postcondition:
result == a.x * b.x + a.y * b.y + a.z * b.z
fn vec3_cross(a: Vec3, b: Vec3) -> Vec3¶
3D cross product: a x b (right-handed). O(1).
- Postcondition:
result.x == a.y * b.z - a.z * b.y && result.y == a.z * b.x - a.x * b.z && result.z == a.x * b.y - a.y * b.x
fn vec3_length(v: Vec3) -> Float64¶
Euclidean length (magnitude) of v. O(1).
- Postcondition:
result >= 0
fn vec3_normalize(v: Vec3) -> Vec3¶
Normalise v to unit length. Returns zero vector if length is zero. O(1).
fn vec3_distance(a: Vec3, b: Vec3) -> Float64¶
Euclidean distance between two 3D points. O(1).
- Postcondition:
result >= 0
fn vec3_lerp(a: Vec3, b: Vec3, t: Float64) -> Vec3¶
Linearly interpolate each component between a and b by t. O(1).
fn vec4_new(x: Float64, y: Float64, z: Float64, w: Float64) -> Vec4¶
Create a new 4D vector.
fn quat_identity() -> Quaternion¶
Identity quaternion (no rotation). O(1).
fn quat_new(axis: Vec3, angle: Float64) -> Quaternion¶
Create a quaternion from an axis (must be normalised) and an angle (radians). Rotation is right-handed around the axis. O(1).
fn quat_mul(a: Quaternion, b: Quaternion) -> Quaternion¶
Multiply two quaternions q1 * q2 (compose rotations, q2 applied first). O(1). Hamilton product: (w1w2 - v1-v2, w1v2 + w2v1 + v1xv2)
fn quat_normalize(q: Quaternion) -> Quaternion¶
Normalise a quaternion to unit length. If length is zero, returns identity. O(1).
fn quat_conjugate(q: Quaternion) -> Quaternion¶
Conjugate of a quaternion. For unit quaternions this is the inverse. O(1).
fn quat_rotate_vec3(q: Quaternion, v: Vec3) -> Vec3¶
Rotate a 3D vector by quaternion q (q must be normalised). O(1). Returns: v + 2.0 * q.xyz x (q.xyz x v + q.w * v)
fn quat_from_euler(yaw: Float64, pitch: Float64, roll: Float64) -> Quaternion¶
Create a quaternion from Euler angles (ZYX intrinsic = yaw-pitch-roll in radians). yaw: rotation around Z, pitch: around Y, roll: around X.
fn mat4_identity() -> Mat4¶
4x4 identity matrix. O(1).
fn mat4_mul(a: Mat4, b: Mat4) -> Mat4¶
Multiply two 4x4 matrices: a * b. Row x column dot products. O(64 ops).
fn mat4_translate(tx: Float64, ty: Float64, tz: Float64) -> Mat4¶
Translation matrix. O(1).
fn mat4_scale(sx: Float64, sy: Float64, sz: Float64) -> Mat4¶
Scale matrix (non-uniform). O(1).
fn mat4_rotate_x(angle: Float64) -> Mat4¶
Rotation around X axis by angle radians (right-handed). O(1).
fn mat4_rotate_y(angle: Float64) -> Mat4¶
Rotation around Y axis by angle radians (right-handed). O(1).
fn mat4_rotate_z(angle: Float64) -> Mat4¶
Rotation around Z axis by angle radians (right-handed). O(1).
fn mat4_perspective(fov: Float64, aspect: Float64, near: Float64, far: Float64) -> Mat4¶
Perspective projection matrix (right-handed, reverse Z [-1,1] NDC). fov: vertical field of view in radians, aspect: width/height, near/far: clipping planes. O(1).
fn mat4_look_at(eye: Vec3, target: Vec3, up: Vec3) -> Mat4¶
Look-at view matrix: camera at eye, looking at target, with up vector. Right-handed coordinate system. O(1).
fn mat4_transform_vec3(m: Mat4, v: Vec3) -> Vec3¶
Transform a Vec3 point by a 4x4 matrix (x,y,z,1 homogeneous). O(16 ops).
fn mat3_identity() -> Mat3¶
3x3 identity matrix. O(1).
fn mat3_mul(a: Mat3, b: Mat3) -> Mat3¶
Multiply two 3x3 matrices: a * b. O(27 ops).
fn aabb_new(min: Vec3, max: Vec3) -> Aabb¶
Create an AABB from min and max corners.
fn aabb_contains_point(box: Aabb, point: Vec3) -> Bool¶
Test whether a point is inside the AABB (inclusive). O(1).
fn aabb_intersects_aabb(a: Aabb, b: Aabb) -> Bool¶
Test whether two AABBs intersect. O(1).
fn sphere_new(center: Vec3, radius: Float64) -> Sphere¶
Create a sphere from centre and radius.
fn sphere_contains_point(s: Sphere, point: Vec3) -> Bool¶
Test whether a point is inside the sphere (inclusive). O(1).
fn ray_new(origin: Vec3, dir: Vec3) -> Ray¶
Create a ray from origin and direction.
fn ray_intersect_sphere(r: Ray, s: Sphere) -> Option[Float64]¶
Ray-sphere intersection. Returns Some(t) for the nearest hit, or None. t is the distance from origin along dir to the intersection point. Uses quadratic formula; only returns the smaller positive t. O(1).
fn ray_intersect_aabb(r: Ray, box: Aabb) -> Option[Float64]¶
Ray-AABB intersection (slab method). Returns Some(t_near) for intersection, or None if the ray misses the box. O(1). See: "An Efficient and Robust Ray-Box Intersection Algorithm" by Williams et al.
fn vec2_neg(v: Vec2) -> Vec2¶
Negate a 2D vector (component-wise -v). O(1).
- Postcondition:
result.x == -v.x && result.y == -v.y
fn vec2_reflect(incident: Vec2, normal: Vec2) -> Vec2¶
Reflect a 2D incident vector about a surface normal (normal must be unit). Formula: i - 2 * dot(i, n) * n. Degenerate (zero) normal returns incident. O(1).
fn vec2_refract(incident: Vec2, normal: Vec2, eta: Float64) -> Option[Vec2]¶
Refract a 2D vector across an interface with relative index eta. Returns None on total internal reflection (k < 0). Both vectors should be unit length. Formula: etai - (etadot(i,n) + sqrt(k)) * n, k = 1 - eta2(1 - dot2). O(1).
fn vec2_project(a: Vec2, b: Vec2) -> Vec2¶
Project a onto b: b * dot(a,b) / dot(b,b). Returns zero if b is degenerate. O(1).
fn vec2_reject(a: Vec2, b: Vec2) -> Vec2¶
Reject a from b: a - project(a,b), the component of a perpendicular to b. O(1).
fn vec2_angle_between(a: Vec2, b: Vec2) -> Float64¶
Angle (radians) between two 2D vectors in [0, PI]. Returns 0 if either is zero. Uses acos of the clamped dot product of the normalised vectors. O(1).
fn vec2_distance_squared(a: Vec2, b: Vec2) -> Float64¶
Squared Euclidean distance between two 2D points (avoids sqrt). O(1).
- Postcondition:
result >= 0
fn vec2_lerp_unclamped(a: Vec2, b: Vec2, t: Float64) -> Vec2¶
Unclamped linear interpolation between a and b by t (t may leave [0,1]). O(1).
- Postcondition:
result.x == a.x + (b.x - a.x) * t && result.y == a.y + (b.y - a.y) * t
fn vec2_nlerp(a: Vec2, b: Vec2, t: Float64) -> Vec2¶
Normalised linear interpolation (nlerp): lerp then normalise the result. O(1). Cheaper than slerp; not constant angular velocity.
fn vec2_rotate(v: Vec2, angle: Float64) -> Vec2¶
Rotate a 2D vector counter-clockwise by angle (radians) about the origin. Formula: (xcos - ysin, xsin + ycos). O(1).
fn vec2_rotate_around(v: Vec2, center: Vec2, angle: Float64) -> Vec2¶
Rotate v around an arbitrary center point by angle (radians). O(1). Translates to the origin, rotates, then translates back.
fn vec2_perpendicular(v: Vec2) -> Vec2¶
Return a vector perpendicular to v: (-y, x). This is v rotated by +90 degrees. O(1).
fn vec2_from_angle(angle: Float64) -> Vec2¶
Unit vector from an angle (radians): (cos(angle), sin(angle)). O(1).
fn vec2_is_unit(v: Vec2, epsilon: Float64) -> Bool¶
True if the length of v is within epsilon of 1.0. O(1).
fn vec2_is_zero(v: Vec2) -> Bool¶
True if every component of v is exactly zero. O(1).
fn vec2_approx_eq(a: Vec2, b: Vec2, epsilon: Float64) -> Bool¶
True if every corresponding component of a and b differs by at most epsilon. O(1).
fn vec2_min_component(v: Vec2) -> Float64¶
Smallest component of a 2D vector. O(1).
- Postcondition:
result <= v.x && result <= v.y
fn vec2_max_component(v: Vec2) -> Float64¶
Largest component of a 2D vector. O(1).
- Postcondition:
result >= v.x && result >= v.y
fn vec2_abs(v: Vec2) -> Vec2¶
Component-wise absolute value of a 2D vector. O(1).
- Postcondition:
result.x >= 0 && result.y >= 0
fn vec2_clamp_length(v: Vec2, max_len: Float64) -> Vec2¶
Clamp the length of v to max_len. Vectors shorter than max_len are unchanged. If max_len <= 0 the zero vector is returned. O(1).
fn vec3_neg(v: Vec3) -> Vec3¶
Negate a 3D vector (component-wise -v). O(1).
- Postcondition:
result.x == -v.x && result.y == -v.y && result.z == -v.z
fn vec3_reflect(incident: Vec3, normal: Vec3) -> Vec3¶
Reflect a 3D incident vector about a surface normal (normal must be unit). Formula: i - 2 * dot(i, n) * n. Degenerate (zero) normal returns incident. O(1).
fn vec3_refract(incident: Vec3, normal: Vec3, eta: Float64) -> Option[Vec3]¶
Refract a 3D vector across an interface with relative index eta. Returns None on total internal reflection (k < 0). Both vectors should be unit length. Formula: etai - (etadot(i,n) + sqrt(k)) * n, k = 1 - eta2(1 - dot2). O(1).
fn vec3_project(a: Vec3, b: Vec3) -> Vec3¶
Project a onto b: b * dot(a,b) / dot(b,b). Returns zero if b is degenerate. O(1).
fn vec3_reject(a: Vec3, b: Vec3) -> Vec3¶
Reject a from b: a - project(a,b), the component of a perpendicular to b. O(1).
fn vec3_angle_between(a: Vec3, b: Vec3) -> Float64¶
Angle (radians) between two 3D vectors in [0, PI]. Returns 0 if either is zero. Uses acos of the clamped dot product of the normalised vectors. O(1).
fn vec3_distance_squared(a: Vec3, b: Vec3) -> Float64¶
Squared Euclidean distance between two 3D points (avoids sqrt). O(1).
- Postcondition:
result >= 0
fn vec3_lerp_unclamped(a: Vec3, b: Vec3, t: Float64) -> Vec3¶
Unclamped linear interpolation between a and b by t (t may leave [0,1]). O(1). Contrast with vec3_lerp which clamps t into [0,1].
- Postcondition:
result.x == a.x + (b.x - a.x) * t && result.y == a.y + (b.y - a.y) * t && result.z == a.z + (b.z - a.z) * t
fn vec3_nlerp(a: Vec3, b: Vec3, t: Float64) -> Vec3¶
Normalised linear interpolation (nlerp): lerp then normalise the result. O(1). Cheaper than slerp; not constant angular velocity.
fn vec3_orthogonal(v: Vec3) -> Vec3¶
Return any vector perpendicular to v (unit length), using the smallest-absolute-component zero method to avoid cancellation. Returns the zero vector when v is zero. O(1).
fn vec3_is_unit(v: Vec3, epsilon: Float64) -> Bool¶
True if the length of v is within epsilon of 1.0. O(1).
fn vec3_is_zero(v: Vec3) -> Bool¶
True if every component of v is exactly zero. O(1).
fn vec3_approx_eq(a: Vec3, b: Vec3, epsilon: Float64) -> Bool¶
True if every corresponding component of a and b differs by at most epsilon. O(1).
fn vec3_min_component(v: Vec3) -> Float64¶
Smallest component of a 3D vector. O(1).
- Postcondition:
result <= v.x && result <= v.y && result <= v.z
fn vec3_max_component(v: Vec3) -> Float64¶
Largest component of a 3D vector. O(1).
- Postcondition:
result >= v.x && result >= v.y && result >= v.z
fn vec3_abs(v: Vec3) -> Vec3¶
Component-wise absolute value of a 3D vector. O(1).
- Postcondition:
result.x >= 0 && result.y >= 0 && result.z >= 0
fn vec3_clamp_length(v: Vec3, max_len: Float64) -> Vec3¶
Clamp the length of v to max_len. Vectors shorter than max_len are unchanged. If max_len <= 0 the zero vector is returned. O(1).
fn vec4_mul_component(a: Vec4, b: Vec4) -> Vec4¶
Multiply two 4D vectors component-wise (Hadamard product). O(1).
- Postcondition:
result.x == a.x * b.x && result.y == a.y * b.y && result.z == a.z * b.z && result.w == a.w * b.w
fn vec4_div_component(a: Vec4, b: Vec4) -> Vec4¶
Divide a by b component-wise. O(1).
- Postcondition:
result.x == a.x / b.x && result.y == a.y / b.y && result.z == a.z / b.z && result.w == a.w / b.w
fn vec4_scale(v: Vec4, s: Float64) -> Vec4¶
Multiply each component of v by scalar s. O(1).
- Postcondition:
result.x == v.x * s && result.y == v.y * s && result.z == v.z * s && result.w == v.w * s
fn vec4_neg(v: Vec4) -> Vec4¶
Negate a 4D vector (component-wise -v). O(1).
- Postcondition:
result.x == -v.x && result.y == -v.y && result.z == -v.z && result.w == -v.w
fn vec4_approx_eq(a: Vec4, b: Vec4, epsilon: Float64) -> Bool¶
True if every corresponding component of a and b differs by at most epsilon. O(1).
fn vec4_min_component(v: Vec4) -> Float64¶
Smallest component of a 4D vector. O(1).
- Postcondition:
result <= v.x && result <= v.y && result <= v.z && result <= v.w
fn vec4_max_component(v: Vec4) -> Float64¶
Largest component of a 4D vector. O(1).
- Postcondition:
result >= v.x && result >= v.y && result >= v.z && result >= v.w
fn vec4_abs(v: Vec4) -> Vec4¶
Component-wise absolute value of a 4D vector. O(1).
- Postcondition:
result.x >= 0 && result.y >= 0 && result.z >= 0 && result.w >= 0
fn vec3_from_vec4(v: Vec4) -> Vec3¶
Drop the w component of a 4D vector to produce a 3D vector. O(1).
fn vec4_from_vec3(v: Vec3, w: Float64) -> Vec4¶
Build a 4D vector from a 3D vector plus an explicit w component. O(1).
fn mat2_identity() -> Mat2¶
2x2 identity matrix. O(1).
fn mat2_mul(a: Mat2, b: Mat2) -> Mat2¶
Multiply two 2x2 matrices: a * b. O(8 ops).
fn mat2_transpose(m: Mat2) -> Mat2¶
Transpose a 2x2 matrix in place. O(1).
fn mat2_determinant(m: Mat2) -> Float64¶
Determinant of a 2x2 matrix: m00m11 - m01m10. O(1).
fn mat2_inverse(m: Mat2) -> Option[Mat2]¶
Inverse of a 2x2 matrix via the adjugate / determinant formula. Returns None when the determinant is (near) zero, so the matrix is singular. O(1).
fn mat2_scale(s: Float64) -> Mat2¶
Uniform 2x2 scale matrix with factor s. O(1).
fn mat2_rotation(angle: Float64) -> Mat2¶
2x2 rotation matrix by angle radians (counter-clockwise). O(1).
fn mat2_transform_vec2(m: Mat2, v: Vec2) -> Vec2¶
Transform a 2D vector by a 2x2 matrix: M * v. O(4 ops).
fn mat3_transpose(m: Mat3) -> Mat3¶
Transpose a 3x3 matrix. O(1).
fn mat3_determinant(m: Mat3) -> Float64¶
Determinant of a 3x3 matrix by cofactor expansion along the first row. O(9 ops).
fn mat3_inverse(m: Mat3) -> Option[Mat3]¶
Inverse of a 3x3 matrix via the adjugate / determinant formula. Returns None when the determinant is (near) zero, so the matrix is singular. O(27 ops).
fn mat3_transform_vec3(m: Mat3, v: Vec3) -> Vec3¶
Transform a 3D vector by a 3x3 matrix: M * v. O(9 ops).
fn mat3_scale(s: Float64) -> Mat3¶
Uniform 3x3 scale matrix with factor s. O(1).
fn mat3_scale_xyz(x: Float64, y: Float64, z: Float64) -> Mat3¶
Non-uniform 3x3 scale matrix with per-axis factors. O(1).
fn mat3_rotation_x(angle: Float64) -> Mat3¶
3x3 rotation around the X axis by angle radians (right-handed). O(1).
fn mat3_rotation_y(angle: Float64) -> Mat3¶
3x3 rotation around the Y axis by angle radians (right-handed). O(1).
fn mat3_rotation_z(angle: Float64) -> Mat3¶
3x3 rotation around the Z axis by angle radians (right-handed). O(1).
fn mat3_from_quat(q: Quaternion) -> Mat3¶
Rotation matrix from a (unit) quaternion. The quaternion is normalised first. Formula: the standard 3x3 rotation matrix derived from q. O(27 ops).
fn mat4_transpose(m: Mat4) -> Mat4¶
Transpose a 4x4 matrix. O(1).
fn mat4_determinant(m: Mat4) -> Float64¶
Determinant of a 4x4 matrix by cofactor expansion along the first row. O(48 ops). Uses 3x3 sub-determinants of the three lower rows.
fn mat4_inverse(m: Mat4) -> Option[Mat4]¶
Inverse of a 4x4 matrix via the adjugate method (cofactor transpose / det). Returns None when |det| < 1e-12, so the matrix is singular. O(150 ops).
fn mat4_transform_vec4(m: Mat4, v: Vec4) -> Vec4¶
Transform a Vec4 (homogeneous) by a 4x4 matrix: M * v, no perspective divide. O(16 ops).
fn mat4_transform_point(m: Mat4, p: Vec3) -> Vec3¶
Transform a point (w=1) by a 4x4 matrix, including perspective divide. If the transformed w is zero, returns the zero vector. O(16 ops).
fn mat4_transform_direction(m: Mat4, d: Vec3) -> Vec3¶
Transform a direction (w=0) by a 4x4 matrix: rotation/scale only, translation is ignored and no perspective divide is applied. O(9 ops).
fn mat4_from_scale(x: Float64, y: Float64, z: Float64) -> Mat4¶
Scale matrix (non-uniform) from three axis factors. Same as mat4_scale. O(1).
fn mat4_from_translation(t: Vec3) -> Mat4¶
Translation matrix from a Vec3 offset. O(1).
fn mat4_translation_xyz(x: Float64, y: Float64, z: Float64) -> Mat4¶
Translation matrix from three components. Same as mat4_translate. O(1).
fn mat4_from_rotation_x(angle: Float64) -> Mat4¶
Rotation around the X axis. Same as mat4_rotate_x. O(1).
fn mat4_from_rotation_y(angle: Float64) -> Mat4¶
Rotation around the Y axis. Same as mat4_rotate_y. O(1).
fn mat4_from_rotation_z(angle: Float64) -> Mat4¶
Rotation around the Z axis. Same as mat4_rotate_z. O(1).
fn mat4_from_quat(q: Quaternion) -> Mat4¶
Rotation matrix from a (unit) quaternion. The quaternion is normalised first. Formula: the standard 4x4 rotation matrix derived from q. O(27 ops).
fn mat4_rotation_axis_angle(axis: Vec3, angle: Float64) -> Mat4¶
Rotation matrix about an arbitrary axis (unit length) by angle radians. Uses the Rodrigues formula. The axis is normalised first. O(30 ops).
fn mat4_orthographic(l: Float64, r: Float64, b: Float64, t: Float64, n: Float64, f: Float64) -> Mat4¶
Orthographic projection matrix (right-handed, standard OpenGL mapping). Maps [l,r]x[b,t]x[n,f] to NDC [-1,1]^3. l != r, b != t, n != f required. O(1).
fn mat4_is_identity(m: Mat4, eps: Float64) -> Bool¶
True if every element of m is within epsilon of the identity matrix. O(16 ops).
fn mat4_approx_eq(a: Mat4, b: Mat4, eps: Float64) -> Bool¶
True if every corresponding element of a and b differs by at most epsilon. O(16 ops).
fn quat_from_axis_angle(axis: Vec3, angle: Float64) -> Quaternion¶
Create a quaternion from an axis and angle (radians). The axis is normalised first, so any (non-zero) axis is accepted. Rotation is right-handed. O(1).
fn quat_mul_vec3(q: Quaternion, v: Vec3) -> Vec3¶
Rotate a 3D vector by a quaternion: q * v * q^-1 (q must be unit length). Same as quat_rotate_vec3, provided under the mul_vec3 name. O(1).
fn quat_inverse(q: Quaternion) -> Quaternion¶
Inverse of a quaternion: the conjugate of the normalised quaternion. For a unit quaternion the conjugate is exactly the inverse. O(1).
fn quat_dot(a: Quaternion, b: Quaternion) -> Float64¶
Dot product of two quaternions (4-vector dot). O(4 ops).
fn quat_length(q: Quaternion) -> Float64¶
Length (magnitude) of a quaternion. O(4 ops + sqrt).
fn quat_is_unit(q: Quaternion, eps: Float64) -> Bool¶
True if the length of q is within epsilon of 1.0. O(1).
fn quat_slerp(a: Quaternion, b: Quaternion, t: Float64) -> Quaternion¶
Spherical linear interpolation between two quaternions by t in [0,1]. Handles the shortest path by negating b when dot(a,b) < 0, clamps the dot to [-1,1], and falls back to nlerp when a and b are nearly parallel. O(1).
fn quat_nlerp(a: Quaternion, b: Quaternion, t: Float64) -> Quaternion¶
Normalised linear interpolation between two quaternions (fast, not constant angular velocity). t is clamped into [0,1]. O(1).
fn quat_from_mat4(m: &Mat4) -> Quaternion¶
Extract the quaternion from a rotation matrix using the standard trace method. Handles all three largest-diagonal cases to avoid degenerate sqrt. O(1).
fn quat_to_mat4(q: Quaternion) -> Mat4¶
4x4 rotation matrix from a quaternion. Same result as mat4_from_quat. O(1).
fn quat_to_mat3(q: Quaternion) -> Mat3¶
3x3 rotation matrix from a quaternion. Same result as mat3_from_quat. O(1).
fn quat_roll(q: Quaternion) -> Float64¶
Roll (rotation around X, radians) extracted from a quaternion. Conventions match quat_from_euler (ZYX intrinsic). O(1).
fn quat_pitch(q: Quaternion) -> Float64¶
Pitch (rotation around Y, radians) extracted from a quaternion. Conventions match quat_from_euler (ZYX intrinsic). Input to asin is clamped. O(1).
fn quat_yaw(q: Quaternion) -> Float64¶
Yaw (rotation around Z, radians) extracted from a quaternion. Conventions match quat_from_euler (ZYX intrinsic). O(1).
fn quat_angle_between(a: Quaternion, b: Quaternion) -> Float64¶
Angle (radians) between two rotation quaternions in [0, 2PI]. Returns 2acos(clamped dot) over the shortest arc. O(1).
fn aabb_from_min_max(min: Vec3, max: Vec3) -> Aabb¶
Create an AABB from min and max corners. Same as aabb_new. O(1).
fn aabb_center(box: Aabb) -> Vec3¶
Centre point of an AABB: (min + max) / 2. O(1).
fn aabb_size(box: Aabb) -> Vec3¶
Size (extent per axis) of an AABB: max - min. O(1).
fn aabb_half_extents(box: Aabb) -> Vec3¶
Half-extents of an AABB: size / 2. O(1).
fn aabb_intersects_sphere(box: Aabb, s: Sphere) -> Bool¶
True if the sphere intersects the AABB. Uses the closest-point test: the squared distance from the sphere centre to the box must not exceed r2. O(1).
fn aabb_closest_point(box: Aabb, p: Vec3) -> Vec3¶
Closest point on (or inside) the AABB to p: p clamped into [min, max]. O(1).
fn aabb_surface_area(box: Aabb) -> Float64¶
Surface area of an AABB: 2(wh + hd + wd). O(1).
fn aabb_volume(box: Aabb) -> Float64¶
Volume of an AABB: whd. O(1).
fn aabb_expand(box: Aabb, p: Vec3) -> Aabb¶
Expand the AABB to include point p (grow min/max component-wise). O(1).
fn aabb_union(a: Aabb, b: Aabb) -> Aabb¶
Smallest AABB that contains both a and b (component-wise min/max). O(1).
fn aabb_intersection(a: Aabb, b: Aabb) -> Option[Aabb]¶
Overlap of two AABBs. Returns None when the boxes do not intersect. The result is the intersection volume between them. O(1).
fn sphere_intersects_sphere(a: Sphere, b: Sphere) -> Bool¶
True if two spheres intersect (or touch): distance <= r_a + r_b. O(1).
fn sphere_intersects_aabb(s: Sphere, box: Aabb) -> Bool¶
True if a sphere intersects an AABB. Delegates to aabb_intersects_sphere. O(1).
fn sphere_closest_point(s: Sphere, p: Vec3) -> Vec3¶
Closest point on the sphere surface to p. If p equals the centre, the centre (an arbitrary surface direction) is returned. O(1).
fn sphere_surface_area(s: Sphere) -> Float64¶
Surface area of a sphere: 4PIr2. O(1).
fn sphere_volume(s: Sphere) -> Float64¶
Volume of a sphere: (4/3)PIr3. O(1).
fn sphere_expand(s: Sphere, p: Vec3) -> Sphere¶
Expand the sphere so it contains point p. If p is already inside, the sphere is returned unchanged. O(1).
fn ray_at(r: Ray, t: Float64) -> Vec3¶
Point on the ray at parameter t: origin + dir * t. O(1).
fn ray_origin(r: Ray) -> Vec3¶
Origin of the ray. O(1).
fn ray_dir(r: Ray) -> Vec3¶
Direction of the ray. O(1).
fn ray_intersect_plane(r: Ray, plane_point: Vec3, plane_normal: Vec3) -> Option[Float64]¶
Ray-plane intersection. Returns Some(t) where t is the ray parameter of the hit, or None if the ray is parallel to the plane or the hit lies behind the origin. plane_normal need not be unit. O(1).
fn ray_distance_to_point(r: Ray, p: Vec3) -> Float64¶
Distance from a point p to the ray line (not the segment). Uses the 3D cross-product formula |(p - o) x d| / |d|. Returns 0 if the direction is degenerate. O(1).
type Plane¶
Plane defined by a point on the plane and its normal direction. The normal need not be unit length; signed distances then scale accordingly.
| Field | Type |
|---|---|
point |
Vec3 |
normal |
Vec3 |
fn plane_new(point: Vec3, normal: Vec3) -> Plane¶
Create a plane from a point on it and a normal direction. O(1).
fn plane_signed_distance(p: &Plane, pt: Vec3) -> Float64¶
Signed distance from a point to the plane (positive on the normal side). Assumes the plane normal is unit length. O(1).
fn plane_distance_to_point(p: &Plane, pt: Vec3) -> Float64¶
Absolute distance from a point to the plane. Assumes a unit normal. O(1).
fn plane_intersect_ray(p: &Plane, r: Ray) -> Option[Float64]¶
Ray-plane intersection against a Plane. Returns Some(t) or None. This is an alias of ray_intersect_plane using the plane's fields. O(1).
fn f64_approx_eq(a: Float64, b: Float64, eps: Float64) -> Bool¶
True if |a - b| <= eps. The canonical epsilon comparison. O(1).
fn f64_deg_to_rad(d: Float64) -> Float64¶
Convert degrees to radians: d * PI / 180. O(1).
fn f64_rad_to_deg(r: Float64) -> Float64¶
Convert radians to degrees: r * 180 / PI. O(1).
fn f32_deg_to_rad(d: Float64) -> Float64¶
Convert degrees to radians (Float32 API: same formula, Float64 arithmetic). O(1).
fn f32_rad_to_deg(r: Float64) -> Float64¶
Convert radians to degrees (Float32 API: same formula, Float64 arithmetic). O(1).
geometry_2d.xi¶
type Point2¶
2D point.
| Field | Type |
|---|---|
x |
Float64 |
y |
Float64 |
type Line2¶
Infinite line ax + by + c = 0.
| Field | Type |
|---|---|
a |
Float64 |
b |
Float64 |
c |
Float64 |
type Ray2¶
Ray: origin and (not necessarily unit) direction.
| Field | Type |
|---|---|
origin |
Point2 |
dir |
Vec2 |
type Segment2¶
Segment between two points.
| Field | Type |
|---|---|
a |
Point2 |
b |
Point2 |
type Circle¶
Circle with center and radius.
| Field | Type |
|---|---|
center |
Point2 |
radius |
Float64 |
type Rect¶
Axis-aligned rectangle defined by min and max corners.
| Field | Type |
|---|---|
min |
Point2 |
max |
Point2 |
type Triangle2¶
Triangle with three vertices.
| Field | Type |
|---|---|
a |
Point2 |
b |
Point2 |
c |
Point2 |
type Polygon2¶
Polygon: vertex list in boundary order.
| Field | Type |
|---|---|
vertices |
Vec[Point2] |
fn point_distance(a: Point2, b: Point2) -> Float64¶
Euclidean distance between two points. O(1).
fn point_in_circle(p: Point2, c: Circle) -> Bool¶
True if p lies inside (or on) the circle. O(1).
fn point_in_rect(p: Point2, r: Rect) -> Bool¶
True if p lies inside (or on) the axis-aligned rectangle. O(1).
fn point_in_triangle(p: Point2, t: Triangle2) -> Bool¶
True if p lies inside (or on) the triangle (same-side test). O(1).
fn point_in_polygon(p: Point2, poly: Polygon2) -> Bool¶
True if p lies inside the polygon (ray-casting test; boundary counts as inside). O(n).
fn line_intersection(l1: Line2, l2: Line2) -> Option[Point2]¶
Intersection of two infinite lines; None when they are parallel. O(1).
fn segment_intersection(s1: Segment2, s2: Segment2) -> Option[Point2]¶
Intersection of two segments; None when they do not meet. O(1).
fn segment_point_distance(s: Segment2, p: Point2) -> Float64¶
Shortest distance from p to the segment s. O(1).
fn line_point_distance(l: Line2, p: Point2) -> Float64¶
Perpendicular distance from p to the infinite line l. O(1).
fn circle_intersection(c: Circle, l: Line2) -> Option[Vec[Point2]]¶
Intersection points of the circle and the line; None when they do not meet or the line is degenerate. O(1).
fn circle_line_intersection(c: Circle, l: Line2) -> Option[Vec[Point2]]¶
Alias of circle_intersection. O(1).
fn circle_circle_intersection(c1: Circle, c2: Circle) -> Option[Vec[Point2]]¶
Intersection points of two circles; None when they do not intersect (or are concentric). O(1).
fn area_triangle(t: Triangle2) -> Float64¶
Signed area of the triangle (positive for counter-clockwise vertices). O(1).
fn area_polygon(poly: Polygon2) -> Float64¶
Signed area of the polygon via the shoelace formula. O(n).
fn centroid(poly: Polygon2) -> Point2¶
Area centroid of the polygon. Returns the zero point for a degenerate polygon. O(n).
fn convex_hull(points: &Vec[Point2]) -> Polygon2¶
Convex hull of the points via the monotone chain algorithm (Andrew). The hull is counter-clockwise without a duplicated closing vertex. O(n log n).
fn is_convex(poly: Polygon2) -> Bool¶
True if every interior angle of the polygon is at most 180 degrees (collinear edges allowed). O(n).
fn polygon_contains(poly: Polygon2, p: Point2) -> Bool¶
Containment test for p in poly. Same as point_in_polygon. O(n).
fn polygon_intersection(a: Polygon2, b: Polygon2) -> Option[Polygon2]¶
Intersection polygon of a and b via Sutherland-Hodgman clipping of a against the edges of b (exact when b is convex). None when the result is empty. O(n*m).
fn polygon_union(a: Polygon2, b: Polygon2) -> Option[Polygon2]¶
Boolean union polygon of a and b. Implemented as the convex hull of both vertex sets: exact when the union is convex (e.g. overlapping convex polygons), otherwise an enclosing convex approximation (documented). O(n log n).
fn polygon_difference(a: Polygon2, b: Polygon2) -> Option[Polygon2]¶
Boolean difference a minus b. Implemented by clipping a against the outside of b (Sutherland-Hodgman with an inverted inside test): exact when b lies fully inside a, otherwise a conservative approximation (documented). None when the result is empty. O(n*m).
fn polygon_circumference(poly: Polygon2) -> Float64¶
Perimeter of the polygon. O(n).
geometry_3d.xi¶
type Point3¶
3D point.
| Field | Type |
|---|---|
x |
Float64 |
y |
Float64 |
z |
Float64 |
type Line3¶
Infinite line: point plus direction.
| Field | Type |
|---|---|
point |
Point3 |
dir |
Vec3 |
type Ray3¶
Ray: origin plus (not necessarily unit) direction.
| Field | Type |
|---|---|
origin |
Point3 |
dir |
Vec3 |
type Segment3¶
Segment between two points.
| Field | Type |
|---|---|
a |
Point3 |
b |
Point3 |
type Plane3d¶
Plane3d normal . p = d.
| Field | Type |
|---|---|
normal |
Vec3 |
d |
Float64 |
type Sphere3d¶
Sphere3d with center and radius.
| Field | Type |
|---|---|
center |
Point3 |
radius |
Float64 |
type Capsule¶
Capsule: segment (a, b) with radius.
| Field | Type |
|---|---|
a |
Point3 |
b |
Point3 |
radius |
Float64 |
type Cylinder¶
Cylinder: axis segment plus radius.
| Field | Type |
|---|---|
axis |
Segment3 |
radius |
Float64 |
type Cone¶
Cone: apex, axis direction, and half angle in radians.
| Field | Type |
|---|---|
apex |
Point3 |
axis |
Vec3 |
half_angle |
Float64 |
type Box¶
Axis-aligned box defined by min and max corners.
| Field | Type |
|---|---|
min |
Point3 |
max |
Point3 |
type OBB¶
Oriented box: center, orthonormal axes, half extents.
| Field | Type |
|---|---|
center |
Point3 |
axes |
Vec[Vec3] |
half_extents |
Vec[Float64] |
type Triangle3¶
Triangle with three vertices.
| Field | Type |
|---|---|
a |
Point3 |
b |
Point3 |
c |
Point3 |
type Polygon3¶
Polygon: vertex list in boundary order.
| Field | Type |
|---|---|
vertices |
Vec[Point3] |
type Mesh¶
Triangle mesh: vertices plus triangle index list (3 indices per triangle).
| Field | Type |
|---|---|
vertices |
Vec[Point3] |
indices |
Vec[Int] |
fn point_distance(a: Point3, b: Point3) -> Float64¶
Euclidean distance between two points. O(1).
fn point_sphere_distance(p: Point3, s: Sphere3d) -> Float64¶
Distance from p to the sphere surface (0 when p is inside). O(1).
fn point_plane_distance(p: Point3, pl: Plane3d) -> Float64¶
Signed distance from p to the plane (positive on the normal side). O(1).
fn plane_point_distance(pl: Plane3d, p: Point3) -> Float64¶
Absolute distance from p to the plane. Alias of point_plane_distance. O(1).
fn line_point_distance(l: Line3, p: Point3) -> Float64¶
Shortest distance from p to the infinite line l. O(1).
fn segment_point_distance(s: Segment3, p: Point3) -> Float64¶
Shortest distance from p to the segment s. O(1).
fn ray_plane_intersection(r: Ray3, pl: Plane3d) -> Option[Float64]¶
Ray-plane intersection: parameter t along the ray; None when parallel or behind the origin. O(1).
fn ray_triangle_intersection(r: Ray3, t: Triangle3) -> Option[Float64]¶
Ray-triangle intersection via the Moller-Trumbore algorithm. Returns the nearest positive t; None on miss or behind the origin. O(1).
fn ray_sphere_intersection(r: Ray3, s: Sphere3d) -> Option[Float64]¶
Ray-sphere intersection: nearest positive t; None on miss. O(1).
fn ray_box_intersection(r: Ray3, b: Box) -> Option[Float64]¶
Ray-box intersection via the slab method: nearest positive t; None on miss. O(1).
fn plane_plane_intersection(p1: Plane3d, p2: Plane3d) -> Option[Line3]¶
Line of intersection of two planes; None when parallel. O(1).
fn sphere_sphere_intersection(a: Sphere3d, b: Sphere3d) -> Bool¶
True if the two spheres overlap or touch. O(1).
fn aabb_intersection(a: Box, b: Box) -> Bool¶
True if the two axis-aligned boxes overlap or touch. O(1).
fn aabb_contains(b: Box, p: Point3) -> Bool¶
True if p lies inside (or on) the box. O(1).
fn closest_point_on_segment(s: Segment3, p: Point3) -> Point3¶
Closest point on the segment s to p. O(1).
fn closest_point_on_plane(pl: Plane3d, p: Point3) -> Point3¶
Orthogonal projection of p onto the plane. O(1).
fn triangle_normal(t: Triangle3) -> Vec3¶
Unit normal of the triangle (right-handed, b-a cross c-a). Returns the zero vector for a degenerate triangle. O(1).
fn mesh_volume(m: Mesh) -> Float64¶
Signed volume of a closed mesh via the divergence theorem (sum of signed tetrahedron volumes about the origin). O(n).
fn mesh_surface_area(m: Mesh) -> Float64¶
Total surface area of a mesh (sum of triangle areas). O(n).
fn mesh_centroid(m: Mesh) -> Point3¶
Volume-weighted centroid of a closed mesh. Returns the zero point for a degenerate mesh. O(n).
fn convex_hull_3d(points: &Vec[Point3]) -> Mesh¶
Convex hull of a point cloud as a triangle mesh. Every oriented face is a triangle (i, j, k) such that all other points lie on (or behind) the plane of that triangle. O(n^4); exact for small point sets.
geometry_extended.xi¶
fn voronoi(sites: &Vec[Point2], bounds: Rect) -> Vec[Polygon2]¶
Bounded Voronoi diagram of sites clipped to bounds: one cell per site, each cell the intersection of the half-planes defined by the perpendicular bisectors with every other site. O(k^2 * n).
fn delaunay(points: &Vec[Point2]) -> Vec[Triangle2]¶
Delaunay triangulation of points via the Bowyer-Watson algorithm (bounded by a super-triangle). Returns a non-empty triangle list for >= 3 points. O(n^2) typical.
fn bezier_curve(controls: &Vec[Vec2], t: Float64) -> Vec2¶
Point on a Bezier curve with de Casteljau's algorithm. O(k^2).
fn b_spline(controls: &Vec[Vec2], knots: &Vec[Float64], t: Float64) -> Vec2¶
Uniform open (clamped) quadratic B-spline evaluation with de Boor's algorithm. Knots must satisfy knots.len() == controls.len() + 3 and be clamped (non-decreasing, endpoints repeated); t is clamped to [0, 1]. Returns the zero vector on inconsistent input. O(1).
fn nurbs(controls: &Vec[Vec2], weights: &Vec[Float64], knots: &Vec[Float64], t: Float64) -> Vec2¶
NURBS evaluation: weighted rational B-spline with de Boor's algorithm. weights.len() must equal controls.len() and knots must satisfy the clamped B-spline sizing. O(1).
fn subdivision(mesh: Mesh, iterations: Int) -> Mesh¶
Midpoint subdivision surface refinement: every triangle is split into four by inserting edge midpoints (no shared-edge deduplication). The triangle count quadruples per iteration. O(iterations * n).
fn mesh_processing(mesh: Mesh) -> Mesh¶
Mesh cleanup pipeline: removes duplicate vertices (exact position match) and rewrites the index list accordingly. Returns the cleaned mesh. O(n^2).
fn projective_geometry(points: &Vec[Vec3]) -> Vec[Vec3]¶
Apply a projective transform to the points: each point (x, y, z) is mapped to (x/w, y/w, z/w) with the perspective weight w = 1 + x + y + z. Points whose weight is zero are left unchanged. O(n).
fn hyperbolic_geometry(a: &Vec[Float64], b: &Vec[Float64]) -> Float64¶
Hyperbolic distance in the Poincare ball model: 2 * atanh(|a - b| / |1 - a.b|). Returns 0 for identical points. O(1).
fn elliptic_geometry(a: &Vec[Float64], b: &Vec[Float64]) -> Float64¶
Elliptic (spherical) distance between two unit vectors: acos(a.b) in [0, PI]. Returns 0 for identical unit vectors. O(n).
fn non_euclidean(a: &Vec[Float64], b: &Vec[Float64]) -> Float64¶
Generic non-Euclidean metric: the Poincare hyperbolic distance (see hyperbolic_geometry). O(n).
fn incidence_geometry(points: &Vec[Point2], lines: &Vec[Line2]) -> Bool¶
Incidence predicate: true iff every point lies on at least one of the lines. O(p * l).
fn convex_geometry(points: &Vec[Vec2]) -> Polygon2¶
Convex decomposition/combination of a point set: returns the convex hull of the points as a Polygon2. O(n log n).
fn computational_geometry(points: &Vec[Vec2]) -> Vec[Polygon2]¶
General computational geometry entry point: returns the convex hull of the points as a single-cell polygon list. O(n log n).
linear.xi¶
fn gram_schmidt(vectors: &Vec[Vec[Float64]]) -> Vec[Vec[Float64]]¶
Orthonormalise a set of vectors (each row is a vector) via the modified Gram-Schmidt process. Linearly dependent vectors collapse to the zero vector. O(k^2 * n).
fn orthogonalize(vectors: &Vec[Vec[Float64]]) -> Vec[Vec[Float64]]¶
Orthogonalise a set of vectors (each row is a vector) without normalising the output. Linearly dependent vectors collapse to the zero vector. O(k^2 * n).
fn normalize_columns(m: &Vec[Vec[Float64]]) -> Vec[Vec[Float64]]¶
Normalise every column of m to unit length. Columns with zero length are left as-is. Empty matrix for a ragged input. O(n*m).
fn normalize_rows(m: &Vec[Vec[Float64]]) -> Vec[Vec[Float64]]¶
Normalise every row of m to unit length. Rows with zero length are left as-is. Empty matrix for a ragged input. O(n*m).
fn is_orthogonal(m: &Vec[Vec[Float64]]) -> Bool¶
True iff m is orthogonal: m * m^T is the identity (within 1e-9). Empty or non-square matrices are false. O(n^3).
fn is_symmetric(m: &Vec[Vec[Float64]]) -> Bool¶
True iff m equals its transpose (exact component equality). O(n^2).
fn is_skew_symmetric(m: &Vec[Vec[Float64]]) -> Bool¶
True iff m equals minus its transpose (exact component equality, diagonal must be zero). O(n^2).
fn is_positive_definite(m: &Vec[Vec[Float64]]) -> Bool¶
True iff m is symmetric positive definite: symmetric and every leading principal minor is positive (checked via a Cholesky-style sweep). O(n^2).
fn is_diagonal_dominant(m: &Vec[Vec[Float64]]) -> Bool¶
True iff m is diagonally dominant: |m[i][i]| >= sum of the absolute values of the off-diagonal entries in the same row, for every row. O(n^2).
fn matrix_exponential(m: &Vec[Vec[Float64]]) -> Vec[Vec[Float64]]¶
Matrix exponential of m via the Taylor series exp(M) = sum M^k / k!, iterated until the added term is negligible (or 60 terms). Empty matrix on non-square input. O(n^3 * terms).
fn matrix_logarithm(m: &Vec[Vec[Float64]]) -> Vec[Vec[Float64]]¶
Principal matrix logarithm of m via the series log(M) = sum (-1)^(k+1) (M-I)^k / k, which converges when M is close to the identity. Returns the zero matrix for the identity and an empty matrix for non-square input. O(n^3 * terms).
fn matrix_sqrt(m: &Vec[Vec[Float64]]) -> Vec[Vec[Float64]]¶
Principal matrix square root of m via Newton iteration X_{k+1} = (X_k + M * X_k^-1) / 2 (converges for well-conditioned SPD-like inputs). Empty matrix on non-square input. O(n^3 * iterations).
fn matrix_power(m: &Vec[Vec[Float64]], p: Int) -> Vec[Vec[Float64]]¶
Integer matrix power m^p. p == 0 yields the identity, p < 0 inverts first, and repeated squaring keeps it to O(log |p|) multiplications. Empty matrix on non-square or singular input. O(n^3 * log |p|).
fn vec_to_skew(v: &Vec[Float64]) -> Vec[Vec[Float64]]¶
Skew-symmetric matrix [v]_x of a 3-vector v. Empty matrix unless v has exactly 3 elements. O(1).
fn skew_to_vec(m: &Vec[Vec[Float64]]) -> Vec[Float64]¶
The 3-vector v such that vec_to_skew(v) == m, extracted from a skew-symmetric matrix. Empty vector unless m is 3x3. O(1).
mat.xi¶
fn mat_identity(n: Int) -> Vec[Vec[Float64]]¶
n x n identity matrix. O(n^2).
fn mat_mul(a: &Vec[Vec[Float64]], b: &Vec[Vec[Float64]]) -> Vec[Vec[Float64]]¶
Matrix product a * b. Returns an empty matrix when the inner dimensions do not match. O(n^3).
fn mat_det(m: &Vec[Vec[Float64]]) -> Float64¶
Determinant of a square matrix via Gaussian elimination with partial pivoting. Returns NaN for a non-square matrix and 0 for a singular one. O(n^3).
fn mat_inv(m: &Vec[Vec[Float64]]) -> Option[Vec[Vec[Float64]]]¶
Inverse of a square matrix via Gauss-Jordan elimination with partial pivoting. None when the matrix is singular or non-square. O(n^3).
fn mat_transpose(m: &Vec[Vec[Float64]]) -> Vec[Vec[Float64]]¶
Transpose of a matrix. Empty matrix for a ragged input. O(n*m).
fn mat_translate(m: &Vec[Vec[Float64]], x: Float64, y: Float64, z: Float64) -> Vec[Vec[Float64]]¶
Compose the 4x4 matrix m with a translation (x, y, z): returns T * m where T is the translation matrix, so the translation is applied after m. Empty matrix unless m is 4x4. O(64).
fn mat_rotate(m: &Vec[Vec[Float64]], angle: Float64, axis: &Vec[Float64]) -> Vec[Vec[Float64]]¶
Compose the 4x4 matrix m with a rotation of angle (radians) about the axis direction: returns R * m where R is the Rodrigues rotation matrix (the axis is normalised first). Empty matrix unless m is 4x4. O(64).
fn mat_scale(m: &Vec[Vec[Float64]], x: Float64, y: Float64, z: Float64) -> Vec[Vec[Float64]]¶
Compose the 4x4 matrix m with a scale (x, y, z): returns S * m where S is the scale matrix, applied after m. Empty matrix unless m is 4x4. O(64).
fn mat_look_at(eye: &Vec[Float64], target: &Vec[Float64], up: &Vec[Float64]) -> Vec[Vec[Float64]]¶
Right-handed look-at view matrix: camera at eye looking at target with up direction. Column-major 4x4. O(1).
fn mat_perspective(fovy: Float64, aspect: Float64, near: Float64, far: Float64) -> Vec[Vec[Float64]]¶
Perspective projection matrix (right-handed, standard OpenGL mapping). fovy is the vertical field of view in radians; near/far must differ. 4x4. O(1).
fn mat_ortho(left: Float64, right: Float64, bottom: Float64, top: Float64, near: Float64, far: Float64) -> Vec[Vec[Float64]]¶
Orthographic projection matrix mapping [left,right] x [bottom,top] x [near,far] to NDC [-1,1]^3. 4x4. O(1).
fn mat_transform_point(m: &Vec[Vec[Float64]], p: &Vec[Float64]) -> Vec[Float64]¶
Transform the point p (3 or 4 components, w defaults to 1) by the 4x4 matrix m including the perspective divide. Returns the zero vector when the transformed w is zero. Empty vector for a non-4x4 matrix. O(16).
matrix.xi¶
type Mat2¶
2x2 column-major matrix.
| Field | Type |
|---|---|
m00 |
Float64 |
m01 |
Float64 |
m10 |
Float64 |
m11 |
Float64 |
type Mat3¶
3x3 column-major matrix.
| Field | Type |
|---|---|
m00 |
Float64 |
m01 |
Float64 |
m02 |
Float64 |
m10 |
Float64 |
m11 |
Float64 |
m12 |
Float64 |
m20 |
Float64 |
m21 |
Float64 |
m22 |
Float64 |
type Mat4¶
4x4 column-major matrix.
| Field | Type |
|---|---|
m00 |
Float64 |
m01 |
Float64 |
m02 |
Float64 |
m03 |
Float64 |
m10 |
Float64 |
m11 |
Float64 |
m12 |
Float64 |
m13 |
Float64 |
m20 |
Float64 |
m21 |
Float64 |
m22 |
Float64 |
m23 |
Float64 |
m30 |
Float64 |
m31 |
Float64 |
m32 |
Float64 |
m33 |
Float64 |
type MatMN¶
Dynamic m x n matrix stored row-major.
| Field | Type |
|---|---|
rows |
Int |
cols |
Int |
data |
Vec[Float64] |
fn mat2_new(a: Float64, b: Float64, c: Float64, d: Float64) -> Mat2¶
Construct a 2x2 matrix. O(1).
fn mat3_new(a: Float64, b: Float64, c: Float64, d: Float64, e: Float64, f: Float64, g: Float64, h: Float64, i: Float64) -> Mat3¶
Construct a 3x3 matrix. O(1).
fn mat4_new(a: Float64, b: Float64, c: Float64, d: Float64, e: Float64, f: Float64, g: Float64, h: Float64, i: Float64, j: Float64, k: Float64, l: Float64, m: Float64, n: Float64, o: Float64, p: Float64) -> Mat4¶
Construct a 4x4 matrix. O(1).
fn identity(n: Int) -> Vec[Vec[Float64]]¶
n x n identity matrix. O(n^2).
fn zero(rows: Int, cols: Int) -> Vec[Vec[Float64]]¶
rows x cols zero matrix. O(n*m).
fn one(rows: Int, cols: Int) -> Vec[Vec[Float64]]¶
rows x cols all-ones matrix. O(n*m).
fn add(a: &Vec[Vec[Float64]], b: &Vec[Vec[Float64]]) -> Vec[Vec[Float64]]¶
Element-wise addition of two same-shape matrices. Empty matrix on shape mismatch. O(n*m).
fn sub(a: &Vec[Vec[Float64]], b: &Vec[Vec[Float64]]) -> Vec[Vec[Float64]]¶
Element-wise subtraction of two same-shape matrices. Empty matrix on shape mismatch. O(n*m).
fn mul(a: &Vec[Vec[Float64]], b: &Vec[Vec[Float64]]) -> Vec[Vec[Float64]]¶
Matrix product a * b. Empty matrix on inner-dimension mismatch. O(n^3).
fn scalar_mul(a: &Vec[Vec[Float64]], s: Float64) -> Vec[Vec[Float64]]¶
Scale every element of a by s. O(n*m).
fn transpose(a: &Vec[Vec[Float64]]) -> Vec[Vec[Float64]]¶
Matrix transpose. Empty matrix for a ragged input. O(n*m).
fn det(a: &Vec[Vec[Float64]]) -> Float64¶
Determinant of a square matrix via Gaussian elimination with partial pivoting. NaN for non-square input. O(n^3).
fn inverse(a: &Vec[Vec[Float64]]) -> Option[Vec[Vec[Float64]]]¶
Inverse of a square matrix via Gauss-Jordan elimination with partial pivoting. None when singular or non-square. O(n^3).
fn minor(a: &Vec[Vec[Float64]], row: Int, col: Int) -> Float64¶
Determinant of the submatrix obtained by deleting row and col. NaN for non-square input or out-of-range indices. O(n^3).
fn cofactor(a: &Vec[Vec[Float64]], row: Int, col: Int) -> Float64¶
Signed minor (cofactor) at (row, col): (-1)^(row+col) * det of the deleted submatrix. NaN for non-square or out-of-range input. O(n^3).
fn adjugate(a: &Vec[Vec[Float64]]) -> Vec[Vec[Float64]]¶
Adjugate (classical) matrix: the transpose of the cofactor matrix. Empty matrix for non-square input. O(n^4).
fn trace(a: &Vec[Vec[Float64]]) -> Float64¶
Trace (sum of the main diagonal) of a square matrix. NaN for non-square. O(n).
fn rank(a: &Vec[Vec[Float64]]) -> Int¶
Rank of a matrix via Gaussian elimination with partial pivoting. O(n^3).
fn nullity(a: &Vec[Vec[Float64]]) -> Int¶
Nullity of a matrix: number of columns minus the rank. O(n^3).
fn eigenvalues(a: &Vec[Vec[Float64]]) -> Vec[Float64]¶
Eigenvalues of a square matrix. Implemented analytically for 2x2 matrices; returns the empty vector for any other size (documented). O(1).
fn eigenvectors(a: &Vec[Vec[Float64]]) -> Vec[Vec[Float64]]¶
Eigenvectors of a square matrix (each row is a unit eigenvector, in the same order as eigenvalues). Implemented analytically for 2x2 matrices; returns the empty matrix for any other size (documented). O(1).
fn diagonal(a: &Vec[Vec[Float64]]) -> Vec[Float64]¶
Main diagonal entries of a matrix. Empty vector for a ragged input. O(n).
fn diag_mul(a: &Vec[Vec[Float64]], d: &Vec[Float64]) -> Vec[Vec[Float64]]¶
Right-multiply a by the diagonal matrix diag(d): result[i][j] = a[i][j]d[j]. Empty matrix on size mismatch. O(nm).
fn hadamard(a: &Vec[Vec[Float64]], b: &Vec[Vec[Float64]]) -> Vec[Vec[Float64]]¶
Element-wise (Hadamard) product of two same-shape matrices. Empty matrix on shape mismatch. O(n*m).
fn kronecker(a: &Vec[Vec[Float64]], b: &Vec[Vec[Float64]]) -> Vec[Vec[Float64]]¶
Kronecker product of a (r x c) and b (p x q): an (rp) x (cq) matrix. Empty matrix for empty input. O(rpc*q).
fn lu_decompose(a: &Vec[Vec[Float64]]) -> (Vec[Vec[Float64]], Vec[Vec[Float64]])¶
LU factorization of a square matrix (Doolittle, no pivoting): (L, U) with L unit lower triangular and A = L*U. Returns empty matrices on failure (non-square or zero pivot). O(n^3).
fn qr_decompose(a: &Vec[Vec[Float64]]) -> (Vec[Vec[Float64]], Vec[Vec[Float64]])¶
QR factorization of a square matrix via Gram-Schmidt on the columns: (Q, R) with Q orthogonal and A = Q*R. Empty matrices on failure. O(n^3).
fn svd_decompose(a: &Vec[Vec[Float64]]) -> (Vec[Vec[Float64]], Vec[Float64], Vec[Vec[Float64]])¶
SVD of a 2x2 symmetric matrix (U, s, V) via its eigendecomposition with s holding the eigenvalues in descending order. Empty values for any other input (documented). O(1).
fn cholesky(a: &Vec[Vec[Float64]]) -> Option[Vec[Vec[Float64]]]¶
Cholesky factor L (lower triangular) of a symmetric positive definite matrix such that A = L*L^T. None when not SPD or non-square. O(n^3).
fn solve_linear(a: &Vec[Vec[Float64]], b: &Vec[Float64]) -> Vec[Float64]¶
Solve the square linear system A*x = b via Gauss-Jordan elimination with partial pivoting. Returns the empty vector when A is singular or the shapes do not match. O(n^3).
fn least_squares(a: &Vec[Vec[Float64]], b: &Vec[Float64]) -> Vec[Float64]¶
Least-squares solution of the overdetermined system Ax = b via the normal equations A^TAx = A^Tb. Returns the empty vector on shape mismatch or a singular normal matrix. O(m*n^2 + n^3).
fn condition_number(a: &Vec[Vec[Float64]]) -> Float64¶
Condition number of a 2x2 matrix: the ratio of the largest to the smallest singular value (singular values of A^T*A square-rooted). Returns NaN for non-2x2 input or a singular matrix (documented). O(1).
polyhedra.xi¶
fn cube_vertices(size: Float64) -> Vec[Vec[Float64]]¶
Vertices of a cube centered at the origin with the given side length. Returns 8 vertices, each (x, y, z). O(1).
fn cube_faces() -> Vec[Vec[Int]]¶
Face index list for cube_vertices: 12 triangles (3 indices each). O(1).
fn sphere_vertices(radius: Float64, slices: Int, stacks: Int) -> Vec[Vec[Float64]]¶
UV-sphere vertex grid: (slices + 1) x (stacks + 1) vertices of the form (x, y, z). O(slices * stacks).
fn icosahedron_vertices() -> Vec[Vec[Float64]]¶
Unit icosahedron vertices (12) in the standard layout: (+-1, +-phi, 0), (0, +-1, +-phi), (+-phi, 0, +-1). O(1).
fn icosahedron_faces() -> Vec[Vec[Int]]¶
Icosahedron faces: 20 triangles referencing icosahedron_vertices. O(1).
fn tetrahedron_vertices() -> Vec[Vec[Float64]]¶
Unit tetrahedron vertices (4). O(1).
fn octahedron_vertices() -> Vec[Vec[Float64]]¶
Unit octahedron vertices (6). O(1).
fn dodecahedron_vertices() -> Vec[Vec[Float64]]¶
Unit dodecahedron vertices (20). O(1).
fn convex_hull_2d(points: &Vec[Vec[Float64]]) -> Vec[Vec[Float64]]¶
Convex hull polygon of 2D points (monotone chain). The hull is returned without a duplicated closing vertex. O(n log n).
fn convex_hull_3d(points: &Vec[Vec[Float64]]) -> Vec[Vec[Float64]]¶
Convex hull vertices of a 3D point cloud. Every oriented triangle (i, j, k) with all other points on (or behind) its plane is emitted as a hull face. O(n^4); exact for small point sets.
quat.xi¶
type Quat¶
Quaternion (x, y, z, w); w is the scalar part.
| Field | Type |
|---|---|
x |
Float64 |
y |
Float64 |
z |
Float64 |
w |
Float64 |
fn quat_new(x: Float64, y: Float64, z: Float64, w: Float64) -> Quat¶
Construct a quaternion from components. Implemented locally (name collision with geom.quat_new which takes axis/angle). O(1).
fn quat_identity() -> Quat¶
Identity quaternion (no rotation). Implemented locally (name collision). O(1).
fn quat_mul(a: Quat, b: Quat) -> Quat¶
Hamilton product a * b (compose rotations; b applied first). Implemented locally (name collision with geom.quat_mul). O(1).
fn quat_conjugate(q: Quat) -> Quat¶
Conjugate of a quaternion: negate the vector part. Implemented locally (name collision with geom.quat_conjugate). O(1).
fn quat_inv(q: Quat) -> Quat¶
Inverse of a unit quaternion (the conjugate). Delegates to geom.quat_inverse through the canonical Quaternion type. O(1).
fn quat_norm(q: Quat) -> Float64¶
Euclidean length of a quaternion. Delegates to geom.quat_length. O(1).
fn quat_normalize(q: Quat) -> Quat¶
Unit quaternion; identity if the length is zero. Implemented locally (name collision with geom.quat_normalize). O(1).
fn quat_from_axis_angle(axis: &Vec[Float64], angle: Float64) -> Quat¶
Quaternion rotating angle (radians) about the (non-zero) axis direction. The axis is normalised first. Implemented locally (name collision). O(1).
fn quat_to_euler(q: Quat) -> (Float64, Float64, Float64)¶
Extract (yaw, pitch, roll) in radians, matching geom.quat_from_euler (ZYX intrinsic). Implemented locally: module-qualified results inside a tuple literal mis-type as Int in this compiler (BUG). O(1).
fn quat_slerp(a: Quat, b: Quat, t: Float64) -> Quat¶
Spherical linear interpolation between a and b by t in [0,1] along the shortest arc. Implemented locally (name collision with geom.quat_slerp). O(1).
fn quat_rotate(q: Quat, v: &Vec[Float64]) -> Vec[Float64]¶
Rotate the 3D vector v by quaternion q. Delegates to geom.quat_rotate_vec3 through the canonical types. O(1).
quaternion.xi¶
type Quat¶
Quaternion (x, y, z, w); w is the scalar part.
| Field | Type |
|---|---|
x |
Float64 |
y |
Float64 |
z |
Float64 |
w |
Float64 |
fn quat_new(x: Float64, y: Float64, z: Float64, w: Float64) -> Quat¶
Construct a quaternion from components. Implemented locally (name collision with geom.quat_new which takes axis/angle). O(1).
fn quat_identity() -> Quat¶
Identity quaternion (no rotation). Implemented locally (name collision). O(1).
fn quat_from_axis_angle(axis: &Vec[Float64], angle: Float64) -> Quat¶
Quaternion rotating angle (radians) about the (non-zero) axis direction. The axis is normalised first. Implemented locally (name collision). O(1).
fn quat_from_euler(yaw: Float64, pitch: Float64, roll: Float64) -> Quat¶
Quaternion from ZYX intrinsic Euler angles (yaw around Z, pitch around Y, roll around X), in radians. Implemented locally (name collision with geom.quat_from_euler). O(1).
fn quat_from_rotation_matrix(m: &Vec[Vec[Float64]]) -> Quat¶
Quaternion equivalent of a 3x3 rotation matrix (trace method). The matrix is copied locally before element access. Returns the identity quaternion for a non-3x3 input. O(1).
fn quat_to_matrix(q: Quat) -> Vec[Vec[Float64]]¶
3x3 rotation matrix (row-major Vec[Vec[Float64]]) from a quaternion. The quaternion is normalised first. O(1).
fn quat_to_euler(q: Quat) -> (Float64, Float64, Float64)¶
Extract (yaw, pitch, roll) in radians, matching quat_from_euler (ZYX intrinsic). Implemented locally: module-qualified results inside a tuple literal mis-type as Int in this compiler (BUG). O(1).
fn quat_mul(a: Quat, b: Quat) -> Quat¶
Hamilton product a * b (compose rotations; b applied first). Implemented locally (name collision with geom.quat_mul). O(1).
fn quat_conj(q: Quat) -> Quat¶
Conjugate of a quaternion: negate the vector part. Delegates to geom.quat_conjugate (name differs). O(1).
fn quat_inv(q: Quat) -> Quat¶
Inverse of a unit quaternion (the conjugate). Delegates to geom.quat_inverse (name differs). O(1).
fn quat_norm(q: Quat) -> Float64¶
Euclidean length of a quaternion. Delegates to geom.quat_length (name differs). O(1).
fn quat_normalize(q: Quat) -> Quat¶
Unit quaternion; identity if the length is zero. Implemented locally (name collision with geom.quat_normalize). O(1).
fn quat_rotate(q: Quat, v: &Vec[Float64]) -> Vec[Float64]¶
Rotate the 3D vector v by quaternion q. Delegates to geom.quat_rotate_vec3 through the canonical types. O(1).
fn quat_slerp(a: Quat, b: Quat, t: Float64) -> Quat¶
Spherical linear interpolation between a and b by t in [0,1] along the shortest arc. Implemented locally (name collision with geom.quat_slerp). O(1).
fn quat_nlerp(a: Quat, b: Quat, t: Float64) -> Quat¶
Normalised linear interpolation between a and b by t (t clamped to [0,1]). Implemented locally (name collision with geom.quat_nlerp). O(1).
fn quat_angle(q: Quat) -> Float64¶
Rotation angle of q in radians, in [0, PI]. 0 for the identity. O(1).
fn quat_axis(q: Quat) -> Vec[Float64]¶
Unit rotation axis of q (direction of the vector part). Returns the zero vector when q represents no rotation. O(1).
fn quat_look_at(eye: &Vec[Float64], target: &Vec[Float64], up: &Vec[Float64]) -> Quat¶
Orientation quaternion looking from eye towards target with the given up direction (right-handed). Returns the identity for a degenerate look. O(1).
fn quat_between(a: &Vec[Float64], b: &Vec[Float64]) -> Quat¶
Shortest rotation quaternion mapping the unit direction a onto the unit direction b. Returns the identity when a or b is degenerate. O(1).
vec.xi¶
fn vec2(x: Float64, y: Float64) -> Vec2¶
Construct a 2D vector. Delegates to geom.vec2_new. O(1).
fn vec2_add(a: Vec2, b: Vec2) -> Vec2¶
Add two 2D vectors component-wise. Implemented locally (same name as the canonical geom.vec2_add; same-name delegation is avoided). O(1).
fn vec2_sub(a: Vec2, b: Vec2) -> Vec2¶
Subtract b from a component-wise. Implemented locally (name collision). O(1).
fn vec2_scale(v: Vec2, s: Float64) -> Vec2¶
Multiply each component of v by scalar s. Delegates to geom.vec2_mul_scalar. O(1).
fn vec2_dot(a: Vec2, b: Vec2) -> Float64¶
Dot product of two 2D vectors. Implemented locally (name collision). O(1).
fn vec2_cross(a: Vec2, b: Vec2) -> Float64¶
2D cross product (scalar, signed area). Implemented locally (name collision). O(1).
fn vec2_len(v: Vec2) -> Float64¶
Euclidean length of a 2D vector. Delegates to geom.vec2_length. O(1).
fn vec2_norm(v: Vec2) -> Vec2¶
Unit vector of v; zero vector when the length is zero. Delegates to geom.vec2_normalize. O(1).
fn vec2_dist(a: Vec2, b: Vec2) -> Float64¶
Euclidean distance between two 2D points. Delegates to geom.vec2_distance. O(1).
fn vec2_lerp(a: Vec2, b: Vec2, t: Float64) -> Vec2¶
Linear interpolation between a and b by t (t outside [0,1] extrapolates). Implemented locally: the canonical geom.vec2_lerp returns a scalar, so a full Vec2 result requires a dedicated implementation. O(1).
fn vec3_new(x: Float64, y: Float64, z: Float64) -> Vec3¶
Construct a 3D vector. Implemented locally (name collision). O(1).
fn vec3_add(a: Vec3, b: Vec3) -> Vec3¶
Add two 3D vectors component-wise. Implemented locally (name collision). O(1).
fn vec3_sub(a: Vec3, b: Vec3) -> Vec3¶
Subtract b from a component-wise. Implemented locally (name collision). O(1).
fn vec3_scale(v: Vec3, s: Float64) -> Vec3¶
Multiply each component of v by scalar s. Delegates to geom.vec3_mul_scalar. O(1).
fn vec3_dot(a: Vec3, b: Vec3) -> Float64¶
Dot product of two 3D vectors. Implemented locally (name collision). O(1).
fn vec3_cross(a: Vec3, b: Vec3) -> Vec3¶
Right-handed cross product a x b. Implemented locally (name collision). O(1).
fn vec3_len(v: Vec3) -> Float64¶
Euclidean length of a 3D vector. Delegates to geom.vec3_length. O(1).
fn vec3_norm(v: Vec3) -> Vec3¶
Unit vector of v; zero vector when the length is zero. Delegates to geom.vec3_normalize. O(1).
fn vec3_dist(a: Vec3, b: Vec3) -> Float64¶
Euclidean distance between two 3D points. Delegates to geom.vec3_distance. O(1).
fn vec4_new(x: Float64, y: Float64, z: Float64, w: Float64) -> Vec4¶
Construct a 4D vector. Implemented locally (name collision). O(1).
fn vec4_add(a: Vec4, b: Vec4) -> Vec4¶
Add two 4D vectors component-wise. No canonical dynamic equivalent; local. O(1).
fn vec4_sub(a: Vec4, b: Vec4) -> Vec4¶
Subtract b from a component-wise. No canonical dynamic equivalent; local. O(1).
fn vec4_scale(v: Vec4, s: Float64) -> Vec4¶
Multiply each component of v by scalar s. Implemented locally (name collision). O(1).
fn vec4_dot(a: Vec4, b: Vec4) -> Float64¶
Dot product of two 4D vectors. No canonical equivalent; local. O(1).
fn vec4_len(v: Vec4) -> Float64¶
Euclidean length of a 4D vector. No canonical equivalent; local. O(4).
fn vec4_norm(v: Vec4) -> Vec4¶
Unit vector of v; zero vector when the length is zero. Local (no canonical equivalent for the vec4 length/normalise pair). O(4).
fn vec_reflect(v: &Vec[Float64], n: &Vec[Float64]) -> Vec[Float64]¶
Reflect the dynamic vector v about a surface normal n: v - 2dot(v,n)n. The normal is normalised first (any non-zero direction is accepted); a degenerate normal returns a copy of v. Dynamic-domain operation with no canonical Vec[Float64] equivalent in geom.xi. O(n).
fn vec_project(a: &Vec[Float64], b: &Vec[Float64]) -> Float64¶
Scalar projection of a onto b: dot(a, b) / |b|. Zero when b is degenerate. Dynamic-domain operation with no canonical Vec[Float64] equivalent. O(n).
fn vec_angle(a: &Vec[Float64], b: &Vec[Float64]) -> Float64¶
Angle in radians between two equal-length non-zero vectors, in [0, PI]. Returns 0 when either vector is degenerate. Dynamic-domain operation. O(n).
vector.xi¶
type Vec2¶
2-component vector (x, y).
| Field | Type |
|---|---|
x |
Float64 |
y |
Float64 |
type Vec3¶
3-component vector (x, y, z).
| Field | Type |
|---|---|
x |
Float64 |
y |
Float64 |
z |
Float64 |
type Vec4¶
4-component vector (x, y, z, w).
| Field | Type |
|---|---|
x |
Float64 |
y |
Float64 |
z |
Float64 |
w |
Float64 |
type VecN¶
Dynamic N-component vector.
| Field | Type |
|---|---|
data |
Vec[Float64] |
fn v2_new(x: Float64, y: Float64) -> Vec2¶
Construct a 2D vector. O(1).
fn v3_new(x: Float64, y: Float64, z: Float64) -> Vec3¶
Construct a 3D vector. O(1).
fn v4_new(x: Float64, y: Float64, z: Float64, w: Float64) -> Vec4¶
Construct a 4D vector. O(1).
fn dot(a: &Vec[Float64], b: &Vec[Float64]) -> Float64¶
Dot product of two equal-length dynamic vectors. Returns NaN (0.0/0.0) when the lengths differ or either is empty (documented; no silent garbage). O(n).
fn cross(a: &Vec[Float64], b: &Vec[Float64]) -> Vec[Float64]¶
3D cross product of two 3-element dynamic vectors. Returns an empty vector when either input is not exactly length 3 (documented). O(3).
fn cross2(a: Vec2, b: Vec2) -> Float64¶
2D cross product (signed area) of two 2D vectors. O(1).
fn outer(a: &Vec[Float64], b: &Vec[Float64]) -> Vec[Vec[Float64]]¶
Outer product matrix a (x) b: row i, col j holds a[i] * b[j]. O(n*m).
fn norm(v: &Vec[Float64]) -> Float64¶
Euclidean length of a dynamic vector. O(n).
fn norm_sq(v: &Vec[Float64]) -> Float64¶
Squared Euclidean length of a dynamic vector (avoids sqrt). O(n).
fn normalize(v: &Vec[Float64]) -> Vec[Float64]¶
Unit vector of v. Returns the zero vector when the length is zero (documented). O(n).
fn unit(v: &Vec[Float64]) -> Vec[Float64]¶
Alias of normalize. O(n).
fn distance(a: &Vec[Float64], b: &Vec[Float64]) -> Float64¶
Euclidean distance between two equal-length vectors. Returns NaN when the lengths differ (documented). O(n).
fn distance_sq(a: &Vec[Float64], b: &Vec[Float64]) -> Float64¶
Squared Euclidean distance between two equal-length vectors. Returns NaN when the lengths differ (documented). O(n).
fn angle(a: &Vec[Float64], b: &Vec[Float64]) -> Float64¶
Angle in radians between two equal-length non-zero vectors, in [0, PI]. Returns 0 when either vector is degenerate. O(n).
fn project(a: &Vec[Float64], b: &Vec[Float64]) -> Vec[Float64]¶
Projection of a onto b: b * dot(a,b) / dot(b,b). Returns the zero vector when b is degenerate. O(n).
fn reject(a: &Vec[Float64], b: &Vec[Float64]) -> Vec[Float64]¶
Reject a from b: a - project(a,b), the component of a perpendicular to b. Requires equal-length inputs; empty vector otherwise. O(n).
fn lerp(a: &Vec[Float64], b: &Vec[Float64], t: Float64) -> Vec[Float64]¶
Linear interpolation between a and b by t (t outside [0,1] extrapolates). Requires equal-length inputs; empty vector otherwise. O(n).
fn slerp(a: &Vec[Float64], b: &Vec[Float64], t: Float64) -> Vec[Float64]¶
Spherical linear interpolation between two equal-length non-zero vectors at parameter t in [0,1], with constant angular velocity. Falls back to lerp for near-parallel inputs; returns the empty vector for degenerate inputs. O(n).
fn reflect(v: &Vec[Float64], normal: &Vec[Float64]) -> Vec[Float64]¶
Reflect v about the (not necessarily unit) normal: v - 2dot(v,n)/dot(n,n)n. Empty vector when the normal is degenerate or lengths differ. O(n).
fn refract(v: &Vec[Float64], normal: &Vec[Float64], eta: Float64) -> Option[Vec[Float64]]¶
Refract v across an interface with relative index eta (both inputs unit). Returns None on total internal reflection (k < 0) or length mismatch. O(n).
fn clamp(v: &Vec[Float64], lo: Float64, hi: Float64) -> Vec[Float64]¶
Clamp each component of v into [lo, hi]. O(n).
fn component_min(v: &Vec[Float64]) -> Float64¶
Smallest component of v. Returns NaN for an empty vector (documented). O(n).
fn component_max(v: &Vec[Float64]) -> Float64¶
Largest component of v. Returns NaN for an empty vector (documented). O(n).
fn hadamard(a: &Vec[Float64], b: &Vec[Float64]) -> Vec[Float64]¶
Component-wise product (Hadamard) of two equal-length vectors. Empty vector on length mismatch (documented). O(n).