Expand description
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§
- angle π
- Utilities for testing approximate ordering - especially true for floating point types, where NaNβs cannot be ordered.
- box2d π
- box3d π
- A set of aliases for all types, tagged with the default unknown unit.
- homogen π
- length πA one-dimensional length, tagged with its units.
- macros π
- A one-dimensional length, tagged with its units.
- point π
- rect π
- rigid πAll matrix multiplication in this module is in row-vector notation, i.e. a vector
v
is transformed withv * T
, and if you want to applyT1
beforeT2
you useT1 * T2
- rotation π
- scale πA type-checked scaling factor between units.
- side_offsets πA group of side offsets, which correspond to top/left/bottom/right for borders, padding, and margins in CSS.
- size π
- transform2d π
- transform3d π
- translation π
- trig π
- vector π
Structs§
- An angle in radians
- A 2d vector of booleans, useful for component-wise logic operations.
- A 3d vector of booleans, useful for component-wise logic operations.
- A 2d 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
T
and unit of measurementUnit
. - 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/right/bottom/left 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 represented by a column-major 3 by 3 matrix, compressed down to 3 by 2.
- A 3d transform stored as a column-major 4 by 4 matrix.
- 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.
Traits§
- Trait for basic trigonometry functions, so they can be used on generic numeric types
Functions§
- Shorthand for
Box3D::new(Point3D::new(x1, y1, z1), Point3D::new(x2, y2, z2))
. - Shorthand for
BoolVector2D { x, y }
. - Shorthand for
BoolVector3D { x, y, z }
. - Shorthand for
Point2D::new(x, y)
. - Shorthand for
Point3D::new(x, y)
. - Shorthand for
Rect::new(Point2D::new(x, y), Size2D::new(w, h))
. - Shorthand for
Size2D::new(w, h)
. - Shorthand for
Size3D::new(w, h, d)
. - Convenience constructor.
- Convenience constructor.