[][src]Crate euclid

A collection of strongly typed math tools for computer graphics with an inclination towards 2d graphics and layout.

All types are generic over the scalar type of their component (f32, i32, etc.), and tagged with a generic Unit parameter which is useful to prevent mixing values from different spaces. For example it should not be legal to translate a screen-space position by a world-space vector and this can be expressed using the generic Unit parameter.

This unit system is not mandatory and all structures have an alias with the default unit: UnknownUnit. for example default::Point2D<T> is equivalent to Point2D<T, UnknownUnit>. Client code typically creates a set of aliases for each type and doesn't need to deal with the specifics of typed units further. For example:

use euclid::*;
pub struct ScreenSpace;
pub type ScreenPoint = Point2D<f32, ScreenSpace>;
pub type ScreenSize = Size2D<f32, ScreenSpace>;
pub struct WorldSpace;
pub type WorldPoint = Point3D<f32, WorldSpace>;
pub type ProjectionMatrix = Transform3D<f32, WorldSpace, ScreenSpace>;
// etc...

All euclid types are marked #[repr(C)] in order to facilitate exposing them to foreign function interfaces (provided the underlying scalar type is also repr(C)).

Modules

approxeq
approxord

Utilities for testing approximate ordering - especially true for floating point types, where NaN's cannot be ordered.

default

A set of aliases for all types, tagged with the default unknown unit.

num

A one-dimensional length, tagged with its units.

Structs

Angle

An angle in radians

BoolVector2D

A 2d vector of booleans, useful for component-wise logic operations.

BoolVector3D

A 3d vector of booleans, useful for component-wise logic operations.

Box2D

An axis aligned rectangle represented by its minimum and maximum coordinates.

Box3D

An axis aligned 3D box represented by its minimum and maximum coordinates.

HomogeneousVector

Homogeneous vector in 3D space.

Length

A one-dimensional distance, with value represented by T and unit of measurement Unit.

NonEmpty
Point2D

A 2d Point tagged with a unit.

Point3D

A 3d Point tagged with a unit.

Rect

A 2d Rectangle optionally tagged with a unit.

RigidTransform3D

A rigid transformation. All lengths are preserved under such a transformation.

Rotation2D

A transform that can represent rotations in 2d, represented as an angle in radians.

Rotation3D

A transform that can represent rotations in 3d, represented as a quaternion.

Scale

A scaling factor between two different units of measurement.

SideOffsets2D

A group of 2D side offsets, which correspond to top/right/bottom/left for borders, padding, and margins in CSS, optionally tagged with a unit.

Size2D

A 2d size tagged with a unit.

Size3D

A 3d size tagged with a unit.

Transform2D

A 2d transform stored as a 3 by 2 matrix in row-major order in memory.

Transform3D

A 3d transform stored as a 4 by 4 matrix in row-major order in memory.

Translation2D

A 2d transformation from a space to another that can only express translations.

Translation3D

A 3d transformation from a space to another that can only express translations.

UnknownUnit

The default unit.

Vector2D

A 2d Vector tagged with a unit.

Vector3D

A 3d Vector tagged with a unit.

Traits

Trig

Trait for basic trigonometry functions, so they can be used on generic numeric types

Functions

box3d

Shorthand for Box3D::new(Point3D::new(x1, y1, z1), Point3D::new(x2, y2, z2)).

bvec2

Shorthand for BoolVector2D { x, y }.

bvec3

Shorthand for BoolVector3D { x, y, z }.

point2

Shorthand for Point2D::new(x, y).

point3

Shorthand for Point3D::new(x, y).

rect

Shorthand for Rect::new(Point2D::new(x, y), Size2D::new(w, h)).

size2

Shorthand for Size2D::new(w, h).

size3

Shorthand for Size3D::new(w, h, d).

vec2

Convenience constructor.

vec3

Convenience constructor.