Module math

Module math 

Source
Expand description

Linear algebra and other useful mathematics.

Includes vectors, matrices, colors, angles, Bezier splines and pseudo-random numbers, as well as support for custom varying types and utilities such as approximate equality comparisons.

This library is more strongly typed than many other similar math libraries. It aims to diagnose at compile time many errors that might otherwise only manifest as graphical glitches, runtime panics, or even – particularly in languages that are unsafe-by-default – undefined behavior.

In particular, vectors and colors are tagged with a type that represents the space they’re embedded in, and values in different spaces cannot be mixed without explicit conversion (transformation). Matrices, similarly, are tagged by both source and destination space, and can only be applied to matching vectors. Angles are strongly typed as well, to allow working with different angular units without confusion.

Re-exports§

pub use angle::Angle;
pub use angle::PolarVec;
pub use angle::SphericalVec;
pub use angle::degs;
pub use angle::polar;
pub use angle::rads;
pub use angle::spherical;
pub use angle::turns;
pub use approx::ApproxEq;
pub use color::Color;
pub use color::Color3;
pub use color::Color3f;
pub use color::Color4;
pub use color::Color4f;
pub use color::rgb;
pub use color::rgba;
pub use mat::Apply;
pub use mat::Mat2x2;
pub use mat::Mat3x3;
pub use mat::Mat4x4;
pub use mat::Matrix;
pub use mat::orthographic;
pub use mat::perspective;
pub use mat::scale;
pub use mat::scale3;
pub use mat::translate;
pub use mat::translate3;
pub use mat::viewport;
pub use param::Parametric;
pub use point::Point;
pub use point::Point2;
pub use point::Point2u;
pub use point::Point3;
pub use point::pt2;
pub use point::pt3;
pub use space::Affine;
pub use space::Linear;
pub use spline::BezierSpline;
pub use spline::CubicBezier;
pub use spline::smootherstep;
pub use spline::smoothstep;
pub use vary::Vary;
pub use vec::Vec2;
pub use vec::Vec2i;
pub use vec::Vec3;
pub use vec::Vec3i;
pub use vec::Vector;
pub use vec::splat;
pub use vec::vec2;
pub use vec::vec3;
pub use angle::acos;
pub use angle::asin;
pub use angle::atan2;
pub use mat::orient_y;
pub use mat::orient_z;
pub use mat::rotate;
pub use mat::rotate_x;
pub use mat::rotate_y;
pub use mat::rotate_z;
pub use mat::rotate2;

Modules§

angle
Angular quantities, including scalar angles and angular vectors.
approx
Testing and asserting approximate equality.
color
Colors and color spaces.
float
Floating-point compatibility API.
mat
Matrices and linear and affine transforms.
param
point
rand
Pseudo-random number generation and distributions.
space
Linear (vector) spaces and affine spaces.
spline
Bézier curves and splines.
vary
Types that can be interpolated across a face when rendering.
vec
Real and projective vectors.

Traits§

Lerp
Trait for linear interpolation between two values.

Functions§

inv_lerp
Returns the relative position of t between min and max.
lerp
Linearly interpolates between two values.