SourceModule emath
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§
Modules§
| align | One- and two-dimensional alignment ( |
Classes§
| Pos2 | A position on screen. |
| Rangef | Inclusive range of floats, i.e. |
| Rect | A rectangular region of space. |
| RectAlign | |
| RectTransform | Linearly transforms positions from one |
| TSTransform | Linearly transforms positions via a translation, then a scaling. |
| Vec2 | A vector has a direction and length.
A |
| Vec2b | Two bools, one for each axis (X and Y). |
Functions§
| lerp | Linear interpolation. |
| pos2 |
|
| remap | Linearly remap a value from one range to another,
so that when |
| remap_clamp | Like |
| vec2 |
|
SourceFunction lerp§
from egui import lerpdef lerp(min: float, max: float, t: float) -> floatLinear interpolation.
SourceFunction pos2§
from egui import pos2def pos2(x: float, y: float) -> Pos2pos2(x, y) == Pos2.new(x, y)
SourceFunction remap§
from egui import remapdef remap(x: float, from_min: float, from_max: float, to_min: float, to_max: float) -> floatLinearly remap a value from one range to another,
so that when x == from.start() returns to.start()
and when x == from.end() returns to.end().
SourceFunction remap_clamp§
from egui import remap_clampdef remap_clamp(x: float, from_min: float, from_max: float, to_min: float, to_max: float) -> floatLike remap, but also clamps the value so that the returned value is always in the to range.
SourceFunction vec2§
from egui import vec2def vec2(x: float, y: float) -> Vec2vec2(x, y) == Vec2.new(x, y)