cvmath 0.1.3

Computer Graphics Vector Math Library
Documentation

Computer Vector Graphics Math Library

MIT License crates.io docs.rs Build status

Because reinventing the wheel is half the fun.

Path Tracing Example
A path tracing scene using cvmath. See pathtracing.rs.

What is this?

cvmath is a lightweight, graphics-oriented math library written in Rust. It focuses on vector math and geometric primitives commonly used in computer graphics. It is not a general-purpose numerical library.

If you're building 2D/3D renderers, ray tracers, or similar tools and want something compact and to the point, this might be a good fit.

The API is lean, clear, and practical.

Features Overview

All types are available at the crate root.

General Types

  • Vec2<T>, Vec3<T>, Vec4<T> — 2D, 3D, and 4D vectors
  • Bool2, Bool3, Bool4 — Boolean vector masks
  • Angle<T>, Complex<T>, Polar<T>, Quat<T>, RotationVector<T> — Angles and rotations

Matrices and Transformations

  • Mat2<T>, Mat3<T>, Mat4<T> — General-purpose matrices
  • Transform2<T>, Transform3<T> — Affine transformations

Shapes and Geometry

Shapes are available in 2D and 3D variants.

  • Point2<T>, Point3<T> — 2D and 3D points
  • Bounds2<T>, Bounds3<T> — Axis-aligned bounding boxes
  • Plane2<T>, Plane3<T> — Infinite planes
  • Circle<T>, Sphere<T> — Defined by a center point and radius
  • Capsule2<T>, Capsule3<T> — Swept spheres/rounded line segments
  • Line2<T>, Line3<T> — Line segments defined by two points
  • Triangle2<T>, Triangle3<T> — Triangles defined by three points
  • Shape2<T>, Shape3<T> — Generic shape enums for flexible composition

Ray Tracing

Types involved in ray casting and intersection:

  • Ray2<T>, Ray3<T> — Rays defined by origin, direction, and max distance
  • Hit2<T>, Hit3<T> — Intersection results (distance, normal, index)
  • Trace2<T>, Trace3<T> — Traits for types that support ray tracing
  • Bvh2<T>, Bvh3<T> — Bounding Volume Hierarchies for efficient ray tracing

Debugger Visualizers

On Windows MSVC targets, Natvis visualizers make common math types easier to inspect in the debugger.

Optional Dependencies

  • dataview — Implements dataview::Pod for all types, allowing zero-copy views into raw byte buffers.
  • serde — Enables serialization and deserialization of all types.
  • urandom — Provides random number generation for types that support it (e.g., Vec3::random()).

License

Licensed under the MIT License, see license.txt for details.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, shall be licensed as above, without any additional terms or conditions.