# [−][src]Crate cgmath

A low-dimensional linear algebra library, targeted at computer graphics.

# Trait overview

In order to make a clean, composable API, we divide operations into traits that are roughly based on mathematical properties. The main ones that we concern ourselves with are listed below:

- `VectorSpace`: Specifies the main operators for vectors, quaternions, and matrices.
- `MetricSpace`: For types that have a distance function implemented.
- `InnerSpace`: For types that have a dot (or inner) product - ie. vectors or quaternions. This also allows for the definition of operations that are based on the dot product, like finding the magnitude or normalizing.
- `EuclideanSpace`: Points in euclidean space, with an associated space of displacement vectors.
- `Matrix`: Common operations for matrices of arbitrary dimensions.
- `SquareMatrix`: A special trait for matrices where the number of columns equal the number of rows.

Other traits are included for practical convenience, for example:

- `Array`: For contiguous, indexable arrays of elements, specifically vectors.
- `ElementWise`: For element-wise addition, subtraction, multiplication, division, and remainder operations.

# The prelude

Importing each trait individually can become a chore, so we provide a `prelude` module to allow you to import the main trait all at once. For example:

    use cgmath::prelude::*;

## Re-exports

`pub extern crate num_traits;`

## Modules

conv | Constrained conversion functions for assisting in situations where type inference is difficult.
prelude | This module contains the most common traits used in `cgmath`. By glob-importing this module, you can avoid the need to import each trait individually, while still being selective about what types you import.

## Macros

abs_diff_eq | Approximate equality of using the absolute difference.
abs_diff_ne | Approximate inequality of using the absolute difference.
assert_abs_diff_eq | An assertion that delegates to `abs_diff_eq!`, and panics with a helpful error on failure.
assert_abs_diff_ne | An assertion that delegates to `abs_diff_ne!`, and panics with a helpful error on failure.
assert_relative_eq | An assertion that delegates to `relative_eq!`, and panics with a helpful error on failure.
assert_relative_ne | An assertion that delegates to `relative_ne!`, and panics with a helpful error on failure.
assert_ulps_eq | An assertion that delegates to `ulps_eq!`, and panics with a helpful error on failure.
assert_ulps_ne | An assertion that delegates to `ulps_ne!`, and panics with a helpful error on failure.
relative_eq | Approximate equality using both the absolute difference and relative based comparisons.
relative_ne | Approximate inequality using both the absolute difference and relative based comparisons.
ulps_eq | Approximate equality using both the absolute difference and ULPs (Units in Last Place).
ulps_ne | Approximate inequality using both the absolute difference and ULPs (Units in Last Place).

## Structs

AbsDiff | The requisite parameters for testing for approximate equality using a absolute difference based comparison.
Basis2 | A two-dimensional rotation matrix.
Basis3 | A three-dimensional rotation matrix.
Decomposed | A generic transformation consisting of a rotation, displacement vector and scale amount.
Deg | An angle, in degrees.
Euler | A set of Euler angles representing a rotation in three-dimensional space.
Matrix2 | A 2 x 2, column major matrix
Matrix3 | A 3 x 3, column major matrix
Matrix4 | A 4 x 4, column major matrix
Ortho | An orthographic projection with arbitrary left/right/bottom/top distances
Perspective | A perspective projection with arbitrary left/right/bottom/top distances
PerspectiveFov | A perspective projection based on a vertical field-of-view angle.
Point1 | A point in 1-dimensional space.
Point2 | A point in 2-dimensional space.
Point3 | A point in 3-dimensional space.
Quaternion | A quaternion in scalar/vector form.
Rad | An angle, in radians.
Relative | The requisite parameters for testing for approximate equality using a relative based comparison.
Ulps | The requisite parameters for testing for approximate equality using an ULPs based comparison.
Vector1 | A 1-dimensional vector.
Vector2 | A 2-dimensional vector.
Vector3 | A 3-dimensional vector.
Vector4 | A 4-dimensional vector.

## Traits

AbsDiffEq | Equality that is defined using the absolute difference of two numbers.
Angle | Angles and their associated trigonometric functions.
Array | An array containing elements of type `Element`
BaseFloat | Base floating point types
BaseNum | Base numeric types with partial ordering
Bounded | Numbers which have upper and lower bounds
ElementWise | Element-wise arithmetic operations. These are supplied for pragmatic reasons, but will usually fall outside of traditional algebraic properties.
EuclideanSpace | Points in a Euclidean space with an associated space of displacement vectors.
InnerSpace | Vectors that also have a dot (or inner) product.
Matrix | A column-major matrix of arbitrary dimensions.
MetricSpace | A type with a distance function between values.
One | Defines a multiplicative identity element for `Self`.
RelativeEq | Equality comparisons between two numbers using both the absolute difference and relative based comparisons.
Rotation | A trait for a generic rotation. A rotation is a transformation that creates a circular motion, and preserves at least one point in the space.
Rotation2 | A two-dimensional rotation.
Rotation3 | A three-dimensional rotation.
SquareMatrix | A column-major major matrix where the rows and column vectors are of the same dimensions.
Transform | A trait representing an affine transformation that can be applied to points or vectors. An affine transformation is one which
Transform2 |
Transform3 |
UlpsEq | Equality comparisons between two numbers using both the absolute difference and ULPs (Units in Last Place) based comparisons.
VectorSpace | Vectors that can be added together and multiplied by scalars.
Zero | Defines an additive identity element for `Self`.

## Functions

dot | Dot product of two vectors.
frustum | Create a perspective matrix from a view frustum.
ortho | Create an orthographic projection matrix.
perspective | Create a perspective projection matrix.
vec1 | The short constructor.
vec2 | The short constructor.
vec3 | The short constructor.
vec4 | The short constructor.

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g., `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)