S or /

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 (Align.Center, Align2.LEFT_TOP etc).

Classes§

Pos2

A position on screen.

Rangef

Inclusive range of floats, i.e. min..=max, but more ergonomic than RangeInclusive.

Rect

A rectangular region of space.

RectAlign
RectTransform

Linearly transforms positions from one Rect to another.

TSTransform

Linearly transforms positions via a translation, then a scaling.

Vec2

A vector has a direction and length. A Vec2 is often used to represent a size.

Vec2b

Two bools, one for each axis (X and Y).

Functions§

lerp

Linear interpolation.

pos2

pos2(x, y) == Pos2.new(x, y)

remap

Linearly 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().

remap_clamp

Like remap, but also clamps the value so that the returned value is always in the to range.

vec2

vec2(x, y) == Vec2.new(x, y)

SourceFunction lerp§

from egui import lerp
def lerp(min: float, max: float, t: float) -> float

Linear interpolation.

SourceFunction pos2§

from egui import pos2
def pos2(x: float, y: float) -> Pos2

pos2(x, y) == Pos2.new(x, y)

SourceFunction remap§

from egui import remap
def remap(x: float, from_min: float, from_max: float, to_min: float, to_max: float) -> float

Linearly 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_clamp
def remap_clamp(x: float, from_min: float, from_max: float, to_min: float, to_max: float) -> float

Like remap, but also clamps the value so that the returned value is always in the to range.

SourceFunction vec2§

from egui import vec2
def vec2(x: float, y: float) -> Vec2

vec2(x, y) == Vec2.new(x, y)

Constants§

Re-exports§