### 66 releases

0.19.5 | Jan 12, 2019 |
---|---|

0.19.4 | Dec 7, 2018 |

0.19.3 | Nov 16, 2018 |

0.19.0 | Jul 20, 2018 |

0.1.5 | Jul 23, 2015 |

#**7** in Math

**16,060** downloads per month

Used in **72** crates (22 directly)

**MIT/Apache**

258KB

6K
SLoC

# euclid

This is a small library for geometric types with a focus on 2d graphics and layout.

###
`lib.rs`

:

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`

, 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.`i32`

This unit system is not mandatory and all Typed* structures have an alias
with the default unit:

.
for example `UnknownUnit`

is equivalent to `Point2D <T>`

`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

in order to facilitate exposing them to
foreign function interfaces (provided the underlying scalar type is also `#``[``repr``(``C``)``]`

).`repr``(`C`)`

Components are accessed in their scalar form by default for convenience, and most
types additionally implement strongly typed accessors which return typed

wrappers.
For example:`Length`

`#` `use` `euclid``::``*``;`
`#` `pub` `struct` `WorldSpace``;`
`#` `pub` `type` `WorldPoint` `=` `TypedPoint3D``<``f32`, WorldSpace`>``;`
`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``(``)``)``;`

#### Dependencies

~1MB

~21K SLoC