Skip to main content

Module transform

Module transform 

Source
Expand description

Mapping user space onto clip space.

Three coordinate systems meet here, and confusing any two of them produces output that is mirrored or off by a scale factor rather than obviously broken:

  • Path space — whatever units a path was authored in.
  • Device space — pixels on the target. Origin top-left, X right, Y down, which is the convention 2D UI works in.
  • Clip space — what the vertex shader emits. Both axes in [-1, 1], and Y runs up, following the WGSL convention that shader translation normalizes to. This is the axis that flips.

Tolerance is a device-space quantity, so flattening a path that will be scaled up has to happen more finely in path space. max_scale is what that adjustment is computed from.

Structs§

Transform2D
A transform of the plane that may carry perspective.

Functions§

invert_to_local
Invert a paint’s placement into the form a shader’s to_local takes.
max_scale
The largest factor by which a transform can stretch a direction.
preserves_axis_alignment
Whether a transform maps axis-aligned rectangles to axis-aligned rectangles.
to_local_columns
The same packing, for a mapping already stated in the direction the shader reads it.
transform_points
Apply a transform to every point in place.
transformed_bounds
The bounds of a rectangle’s corners after a transform, if there are any.
unbounded
Bounds standing in for “anywhere”, where a mapping gives none.
viewport_projection
Map device pixels onto clip space for a target of the given size.