Spatial’s units system replaces rawDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/danielitoCode/Spatial/llms.txt
Use this file to discover all available pages before exploring further.
Float values in transform APIs with two inline value classes — Distance and Angle — that carry explicit semantic meaning. Instead of passing an ambiguous 5f to a position call and hoping it means meters, or supplying 0.785f to a rotation and hoping it means radians, you write 5f.meters and 45f.deg. The compiler rejects any attempt to mix types, so a Distance can never silently end up where an Angle is expected and vice versa. This makes 3D scenes both easier to read and structurally safer to refactor.
Distance
Distance is a Kotlin inline value class that wraps a single Float internally stored in meters. Because it is marked private constructor, you can only create Distance values through the provided extension properties or companion factory methods — never by constructing the class directly.
Extension properties
Thespatial-units module exposes four extension properties on Int and Float so you can write literal distances inline:
.cm properties divide the value by 100f before storing it, so 50.cm and 0.5f.meters are identical at runtime.
Arithmetic operators
Distance supports addition and subtraction, returning a new Distance:
Factory methods
When you need to create aDistance from a computed Float rather than a literal, use the companion object factories:
Angle
Angle is an inline value class that wraps a Float stored internally in radians. Like Distance, its constructor is private — all creation goes through extension properties or companion factories.
Extension properties
.deg properties convert the degree value to radians at construction time using value × π / 180. The stored radians property then gives you the internal representation if you need it downstream (for example, when passing to OpenGL matrix math).
Factory methods
Angle.radians() when you already have a radian value from a math library; use Angle.degrees() (or the .deg extension) for everything you type by hand.
Usage in Modifier3D
Modifier3D accepts Distance and Angle throughout its transform API — there are no raw-float overloads for rotation, and the typed position / size overloads require Distance. Here is a complete transform chain using the units system:
@Composable:
Modifier3D methods that consume units:
Why typed units?
| Concern | Raw Float | Typed units |
|---|---|---|
| Readability | position(0f, 0f, -5f) — what scale? | position(0f.meters, 0f.meters, (-5f).meters) — unambiguous |
| Mixing degrees / radians | Silently accepted, wrong at runtime | Compile error — Angle ≠ Float |
| Mixing meters / centimeters | Easy to forget a /100 | .cm converts automatically |
| Refactoring | All raw floats look alike | IDE can track Distance vs Angle references |
| Scene scale consistency | Each author decides their scale | One scale: meters, always |
1.5f.meters is a distance and 30f.deg is a rotation without reading surrounding context.
Negative values
Kotlin’s extension properties bind tightly to the receiver literal. Writing-5f.meters is parsed as -(5f.meters), which would attempt to negate a Distance using the unary minus — an operator that Distance does not currently define. To express a negative distance literal, wrap the negative float in parentheses first:
Angle: