[][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 Typed* structures have an alias with the default unit: UnknownUnit. for example Point2D<T> is equivalent to TypedPoint2D<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 = TypedPoint2D<f32, ScreenSpace>;
pub type ScreenSize = TypedSize2D<f32, ScreenSpace>;
pub struct WorldSpace;
pub type WorldPoint = TypedPoint3D<f32, WorldSpace>;
pub type ProjectionMatrix = TypedTransform3D<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)).

Components are accessed in their scalar form by default for convenience, and most types additionally implement strongly typed accessors which return typed Length wrappers. For example:

let p = WorldPoint::new(0.0, 1.0, 1.0);
// p.x is an f32.
println!("p.x = {:?} ", p.x);
// p.x is a Length<f32, WorldSpace>.
println!("p.x_typed() = {:?} ", p.x_typed());
// Length::get returns the scalar value (f32).
assert_eq!(p.x, p.x_typed().get());

Modules

approxeq
approxord
num

A one-dimensional length, tagged with its units.

Structs

Angle

An angle in radians

BoolVector2D
BoolVector3D
HomogeneousVector

Homogeneous vector in 3D space.

Length

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

Radians

An angle in radians

TypedBox2D

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

TypedBox3D

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

TypedPoint2D

A 2d Point tagged with a unit.

TypedPoint3D

A 3d Point tagged with a unit.

TypedRect

A 2d Rectangle optionally tagged with a unit.

TypedRigidTransform3D

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

TypedRotation2D

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

TypedRotation3D

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

TypedScale

A scaling factor between two different units of measurement.

TypedSideOffsets2D

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

TypedSize2D

A 2d size tagged with a unit.

TypedTransform2D

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

TypedTransform3D

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

TypedTranslation2D

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

TypedTranslation3D

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

TypedVector2D

A 2d Vector tagged with a unit.

TypedVector3D

A 3d Vector tagged with a unit.

UnknownUnit

The default unit.

Traits

Trig

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

Functions

box3d

Shorthand for TypedBox3D::new(TypedPoint3D::new(x1, y1, z1), TypedPoint3D::new(x2, y2, z2)).

bvec2
bvec3
point2
point3
rect

Shorthand for TypedRect::new(TypedPoint2D::new(x, y), TypedSize2D::new(w, h)).

size2

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

vec2

Convenience constructor.

vec3

Convenience constructor.

Type Definitions

Box2D

The default box 2d type with no unit.

Box3D

The default box 3d type with no unit.

Matrix2DDeprecated

Temporary alias to facilitate the transition to the new naming scheme

Matrix4DDeprecated

Temporary alias to facilitate the transition to the new naming scheme

Point2D

Default 2d point type with no unit.

Point3D

Default 3d point type with no unit.

Rect

The default rectangle type with no unit.

RigidTransform3D
Rotation2D

The default 2d rotation type with no units.

Rotation3D

The default 3d rotation type with no units.

ScaleFactorDeprecated

Temporary alias to facilitate the transition to the new naming scheme

SideOffsets2D

The default 2D side offset type with no unit.

Size2D

Default 2d size type with no unit.

Transform2D

The default 2d transform type with no units.

Transform3D

The default 3d transform type with no units.

TypedMatrix2DDeprecated

Temporary alias to facilitate the transition to the new naming scheme

TypedMatrix4DDeprecated

Temporary alias to facilitate the transition to the new naming scheme

Vector2D

Default 2d vector type with no unit.

Vector3D

Default 3d vector type with no unit.