Expand description
The app’s world coordinate system, owned outright: positions, vectors, rects,
ranges, alignment, the clamped-f32 newtype, the grid metric, and the grid’s
bridge to the document’s own integer geometry. No UI toolkit appears in this
crate’s dependency tree — normal, build or dev — so everything above it (the
router, the render path, the tools) is spelled in coordinates of our own.
The one crate below it is blockworx-doc: the bridge in grid converts
world pixels to and from the document’s GridPoint/GridRect/ScreenRect,
which is the whole point of a shared coordinate system.
The types are method-for-method the subset of
emath the app uses, and the
implementations are copied from it (© Rerun / emilk, dual-licensed MIT OR
Apache-2.0) wherever the semantics are load-bearing: Rect’s
union/intersection against NOTHING/EVERYTHING, Align2::anchor_size,
lerp/remap. The equivalence is held to by property tests, which live
with the conversions in the backend (blockworx_egui::convert) because
that is the only place allowed to name emath at all.
Modules§
- align 🔒
- angle 🔒
- A rotation, so a signature cannot take a bare number of radians.
- bounded 🔒
- A clamped
f32newtype, generic over its bounds.Bounded<B>can only hold values in[B::MIN, B::MAX]: the constructor clamps, every arithmetic op re-clamps, and NaN collapses toB::MIN— so the type is totally ordered andEq/Ordare sound. - grid
- The grid: the pitch, the snapping ladder, the screen-mapping constants every shape is measured against, and the bridge to the document’s own integer geometry.
- pos2 🔒
- range 🔒
- rect 🔒
- units 🔒
WorldPx, the newtype for world-space magnitudes — radii, hit margins, snap thresholds, the lengths that scale with zoom on screen. Non-negative: a length below zero clamps to zero.- vec2 🔒
Structs§
- Align2
- Two-dimensional alignment:
[x, y]. - Angle
- A rotation in radians, clockwise on a screen whose y axis points down — the sense every backend’s rotated text takes.
- Bounded
- OutOf
Bounds - A value outside a
Bounded’s interval, or NaN, offered where one is read rather than made — refused there instead of clamped, since it did not come from this type. - Pos2
- A point in space: world coordinates on the canvas, points on screen.
- Rangef
- An inclusive range of floats — one axis of a
Rect. - Rect
- An axis-aligned rectangle,
minits left-top corner andmaxits right-bottom one. - Vec2
- A direction-and-length, and the type a size is spelled in.
Enums§
- Align
- Left/center/right, or top/center/bottom.
Traits§
- Bounds
- The closed interval a
Boundedvalue lives in. Implemented by empty marker types (ProgressBounds,ZoomBounds, …).
Functions§
- lerp
- Linear interpolation from
range.0att == 0torange.1att == 1. Extrapolates outside0..=1. - midpoint 🔒
- The midpoint of
aandb. - pos2
pos2(x, y) == Pos2::new(x, y)- remap
- Map
xfrom thefromrange onto thetorange, linearly and without clamping. - remap_
clamp remapwith the result held insideto, and withfromaccepted in either order.- vec2
vec2(x, y) == Vec2::new(x, y)