Perimeter strategy (compose.perimeter / code.perimeter)
August 30, 2026 · View on GitHub
Artifact: io.github.bodenberg:appdimens-kmp-perimeter:3.2.0 (:library-perimeter)
See MODULES.md · README installation
Same API surface as scaled with prefixes prsdp / prhdp / prwdp / prssp / … — see COMPOSE-API-CONVENTIONS.md §3.
What it is
Perimeter scales by the normalized screen perimeter: sum of shorter and longer side in dp, divided by reference 833 dp (perimeter reference aligned with 300 + 533 in DesignScaleConstants). It reflects “width + height” together, unlike diagonal or a single axis.
Calculation used
Mathematically:
scale = (shorter + longer) / BASE_PERIMETER_DPwithBASE_PERIMETER_DP = 833(DesignScaleConstants, aligned with 300 + 533).out = base × scale
Implementation note: scale is derived from the immutable per-window snapshot (DimenCache.currentMetrics) at resolution time — no process-global pre-computation. The formula matches (shorter + longer) / 833; the default path does not re-sum sides on every call.
- With
a: multiply by the pre-computed aspect-ratio factor (DimenCache.currentAspectRatioMul); custom sensitivity uses .
Implementation: calculatePerimeterDpCompose in DimenPerimeterDp.kt.
How to use
import com.appdimens.kmp.compose.perimeter.prsdp
Modifier.size(72.prsdp)
Prefixes: prsdp, prhdp, prwdp (+ Sp, px, variants).
Code: com.appdimens.kmp.code.perimeter.
Why use it
When width and height together should drive size (frame-like cards, grids that represent total area).
When to use it
- Layouts that think in total area but want a linear formula on the sum of sides (vs the square root in diagonal).
- A perceptual alternative to diagonal when you want different weighting across dimensions.
Advantages and trade-offs
- Pros: simple; folds both axes into one scalar.
- Cons: two screens with similar diagonal can differ from diagonal-only metrics — align with design on which metric is source of truth.
Recommended usage strategy
Use on card / thumbnail families; avoid mixing at the same hierarchy level with diagonal without a clear guideline, or scales may clash.