Crate emath

source ·
Expand description

Opinionated 2D math library for building GUIs.

Includes vectors, positions, rectangles etc.

Conventions (unless otherwise specified):

  • All angles are in radians
  • X+ is right and Y+ is down.
  • (0,0) is left top.
  • Dimension order is always x y

§Integrating with other math libraries.

emath does not strive to become a general purpose or all-powerful math library.

For that, use something else (glam, nalgebra, …) and enable the mint feature flag in emath to enable implicit conversion to/from emath.

§Feature flags

  • extra_debug_asserts — Enable additional checks if debug assertions are enabled (debug builds).
  • extra_asserts — Always enable additional checks.

§Optional dependencies

  • bytemuckbytemuck enables you to cast emath types to &[u8].
  • document-features — Enable this when generating docs.
  • mintmint enables interoperability with other math libraries such as glam and nalgebra.
  • serde — Allow serialization using serde.

Re-exports§

Modules§

Macros§

  • An assert that is only active when emath is compiled with the extra_asserts feature or with the extra_debug_asserts feature in debug builds.

Structs§

  • This struct tracks recent values of some time series.
  • A position on screen.
  • Inclusive range of floats, i.e. min..=max, but more ergonomic than RangeInclusive.
  • A rectangular region of space.
  • Linearly transforms positions from one Rect to another.
  • Represents a rotation in the 2D plane. A rotation of 𝞃/4 = 90° rotates the X axis to the Y axis. Normally a Rot2 is normalized (unit-length). If not, it will also scale vectors.
  • Linearly transforms positions via a translation, then a scaling.
  • A vector has a direction and length. A Vec2 is often used to represent a size.
  • Two bools, one for each axis (X and Y).

Traits§

  • Extends f32, Vec2 etc with at_least and at_most as aliases for max and min.
  • Implemented for all builtin numeric types
  • Helper trait to implement lerp and remap.
  • Helper trait to implement lerp and remap.

Functions§