Skip to main content

Crate blockworx_geom

Crate blockworx_geom 

Source
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 f32 newtype, 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 to B::MIN — so the type is totally ordered and Eq/Ord are 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
OutOfBounds
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, min its left-top corner and max its 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 Bounded value lives in. Implemented by empty marker types (ProgressBounds, ZoomBounds, …).

Functions§

lerp
Linear interpolation from range.0 at t == 0 to range.1 at t == 1. Extrapolates outside 0..=1.
midpoint 🔒
The midpoint of a and b.
pos2
pos2(x, y) == Pos2::new(x, y)
remap
Map x from the from range onto the to range, linearly and without clamping.
remap_clamp
remap with the result held inside to, and with from accepted in either order.
vec2
vec2(x, y) == Vec2::new(x, y)

Type Aliases§

WorldPx