logo
Expand description

Generic 2D-3D math swiss army knife for game engines, with SIMD support and focus on convenience.

See the wiki for an overview, FAQ, guides, and other info.

Issues and bug reports are very welcome!

Cargo features

  • vec8, vec16, vec32, vec64, rgba, rgb, uvw, uv Enable these types. Other types are always enabled for the sake of doc-tests.
  • repr_simd enables Nightly Rust’s repr_simd and simd_ffi features, and unlock SIMD versions of all appropriate types (though repr_simd modules). On Stable, this feature has no effect.
  • serde makes vectors and matrices derive Serialize and Deserialize.
  • image makes color vectors implement the Pixel trait from the image crate.
  • mint enables conversion to the mint crate’s types. mint is an interoperability layer for math libraries.

#![no_std]

This crate is #![no_std].

Modules

A crate that provides facilities for testing the approximate equality of floating-point based types, using either relative difference, or units in the last place (ULPs) comparisons.

Low-order (quadratic and cubic) Bézier curves.

Common and trivial geometric primitives.

Matrix types.

Integer trait and functions.

Numeric traits for generic mathematics

Operations defined by this crate, such as MulAdd, Lerp, Clamp, and Wrap.

Quaternions are a convenient representation for rotations in 3D spaces.

Serde

SIMD traits; they are useful when the features “repr_simd” and “platform_intrinsics” are enabled.

A convenient position + orientation + scale container, backed by two Vec3 and a Quaternion.

Convenience structures for representing a transition from one value to another.

Vector types.

Structs

Axis-aligned Bounding Box (3D), represented by min and max points.

Axis-aligned Bounding Rectangle (2D), represented by min and max points.

A 2D Bézier curve with two control points.

A 3D Bézier curve with two control points.

Disk (2D), represented by center and radius.

Ellipsis (2D), represented by center and radius in both axii.

Vector type suited for 2D extents (width and height).

Vector type suited for 3D extents (width, height and depth).

Data that represents distance offsets of frustum planes from an origin.

A pass-through functor that returns progress values directly as LERP factors.

2D Line segment, represented by two points, start and end.

3D Line segment, represented by two points, start and end.

2x2 matrix.

3x3 matrix.

4x4 matrix.

Nobody can possibly use this ???

A function pointer container that can map a progress value to a LERP factor.

A 2D Bézier curve with one control point.

A 3D Bézier curve with one control point.

Quaternions are a convenient representation for rotations in 3D spaces.

3D ray, represented by a starting point and a normalized direction vector.

2D rectangle, represented by a bottom-left position, and 2D extents.

A Rect extended to 3D.

Vector type suited for RGB color data.

Vector type suited for RGBA color data.

Opaque type wrapping a hardware-preferred shuffle mask format for 4D vectors.

Sphere (3D), represented by center and radius.

A convenient position + orientation + scale container, backed by two Vec3 and a Quaternion.

A convenience structure for storing a progression from one value to another.

Vector type suited for 2D spatial coordinates.

Vector type suited for 3D spatial coordinates.

Vector type suited for homogeneous 3D spatial coordinates.

Traits

A scalar or vector that can be constrained to be between two values (inclusive).

A scalar or vector that can be constrained to be between 0 and 1 (inclusive).

A scalar or vector that can be constrained to be between -1 and 1 (inclusive).

Trait for types that are suitable for representing a color component value.

A value that can tell whether or not it is between two bounds (inclusive).

A value that can tell whether or not it is between 0 and 1 (inclusive).

A value that can be linearly interpolated.

Fused multiply-add. Computes (self * a) + b with only one rounding error, yielding a more accurate result than an unfused multiply-add.

A functor that maps a progress value to a LERP factor.

This trait should be implemented by scalar types, vectors of which are supported by SIMD intrinsics. For instance, i16 and f32 can implement this trait, as well as #[repr(transparent)] wrappers of these, but not hand-built numeric types.

Implemented by unsigned integer types that can represent the result of SIMD comparison elements: semantically, these are booleans, but in their representation, zero is false and any other value is true. Typically, SIMD comparison of two vectors will yield a vector of mask elements, on which you can call reduce_and() or reduce_or().

A value that can be Spherically Linearly interpolated.

A value that can wrap itself around given bounds.

Functions

mul_addDeprecated

Returns (val * mul) + add.

Compares and returns the maximum of two values, using partial ordering.

Compares and returns the minimum of two values, using partial ordering.

Type Definitions

A convenience structure for storing a linear progression from one value to another.