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 (
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:
default::Point2D<T> is equivalent to
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
A set of aliases for all types, tagged with the default unknown unit.
A one-dimensional length, tagged with its units.
An angle in radians
An axis aligned rectangle represented by its minimum and maximum coordinates.
An axis aligned 3D box represented by its minimum and maximum coordinates.
Homogeneous vector in 3D space.
A one-dimensional distance, with value represented by
A 2d Point tagged with a unit.
A 3d Point tagged with a unit.
A 2d Rectangle optionally tagged with a unit.
A rigid transformation. All lengths are preserved under such a transformation.
A transform that can represent rotations in 2d, represented as an angle in radians.
A transform that can represent rotations in 3d, represented as a quaternion.
A scaling factor between two different units of measurement.
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.
A 2d size tagged with a unit.
A 3d size tagged with a unit.
A 2d transform stored as a 3 by 2 matrix in row-major order in memory.
A 3d transform stored as a 4 by 4 matrix in row-major order in memory.
A 2d transformation from a space to another that can only express translations.
A 3d transformation from a space to another that can only express translations.
The default unit.
A 2d Vector tagged with a unit.
A 3d Vector tagged with a unit.
Trait for basic trigonometry functions, so they can be used on generic numeric types