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
Integrating with other math libraries.
emath does not strive to become a general purpose or all-powerful math library.
For that, use something else (
and enable the
mint feature flag in
emath to enable implicit conversion to/from
extra_debug_asserts— Enable additional checks if debug assertions are enabled (debug builds).
extra_asserts— Always enable additional checks.
One- and two-dimensional alignment (
Find “simple” numbers is some range. Used by sliders.
An assert that is only active when
emathis compiled with the
extra_assertsfeature or with the
extra_debug_assertsfeature in debug builds.
This struct tracks recent values of some time series.
A position on screen.
A rectangular region of space.
Linearly transforms positions from one
Represents a rotation in the 2D plane. A rotation of 𝞃/4 = 90° rotates the X axis to the Y axis. Normally a
Rot2is normalized (unit-length). If not, it will also scale vectors.
Implemented for all builtin numeric types
Return true when arguments are the same within some rounding error.
Calculate a lerp-factor for exponential smoothing using a time step.
Where in the range is this value? Returns 0-1 if within the range.
Wrap angle to
pos2(x, y) == Pos2::new(x, y)
Linearly remap a value from one range to another, so that when
x == from.start()returns
x == from.end()returns
remap, but also clamps the value so that the returned value is always in the
Round a value to the given number of decimal places.
vec2(x, y) == Vec2::new(x, y)