appdimens-dynamic

//AppDimens SDP, HDP, WDP: Scalable Width and Height Dimensions/com.appdimens.dynamic.code.power/calculatePowerDp

calculatePowerDp

internal fun calculatePowerDp(baseValue: Float, configuration: Configuration, qualifier: DpQualifier, inverter: Inverter, ignoreMultiWindows: Boolean, applyAspectRatio: Boolean, customSensitivityK: Float?, context: Context? = null): Float

EN Shared pure-math scaling kernel used by toDynamicPowerPx and toDynamicPowerDp.

Algorithm summary:

Applies Inverter rules to swap the effective DpQualifier based on screen orientation.

If ignoreMultiWindows is true, detects split-screen mode via layout flags; if active, returns baseValue unchanged so the UI does not over-scale inside a small window.

For the common path (SMALL_WIDTH + DEFAULT inverter + no custom sensitivity), delegates to DimenCache.calculateRawScaling which reads pre-computed factors from DimenCache.ScreenFactors — a single float multiply, zero extra allocations.

For other qualifiers or a custom sensitivity constant, reads the screen dimension from android.content.res.Configuration and performs the scaling formula inline.

Performance: Simple paths without Aspect Ratio complete in ~2 ns (single multiply). Paths with Aspect Ratio require ~41 ns on Snapdragon 888 (includes ln() fallback). Results are memoized by the DimenCache shared across code and compose packages.

Note: Both code/ and compose/ packages intentionally maintain separate copies of this function because the code/ variant operates on android.content.res.Configuration directly (no Compose runtime), while compose/ reads it from androidx.compose.ui.platform.LocalConfiguration. The math is identical; only the Context acquisition path differs.

PT Núcleo de escalonamento puro compartilhado por toDynamicPowerPx e toDynamicPowerDp.

Resumo do algoritmo:

Aplica as regras de Inverter para trocar o DpQualifier efetivo conforme a orientação.

Se ignoreMultiWindows for true, detecta split-screen via flags de layout; se ativo, retorna baseValue sem escalar.

Para o caminho comum (SMALL_WIDTH + DEFAULT + sem sensibilidade customizada), delega para DimenCache.calculateRawScaling com os fatores pré-calculados.

Para outros qualificadores ou sensibilidade customizada, lê a dimensão da tela da android.content.res.Configuration e executa a fórmula de escalonamento inline.

Nota: Os pacotes code/ e compose/ mantêm cópias separadas intencionalmente. A versão code/ opera sobre android.content.res.Configuration diretamente, enquanto a versão compose/ usa androidx.compose.ui.platform.LocalConfiguration. A matemática é idêntica; apenas a obtenção do contexto difere.

Scaled Dp value as a raw Float.

Raw Dp value to scale (e.g. 16f for 16 dp).

Current android.content.res.Configuration from the context.

Original screen qualifier before inversion.

Orientation-swap rule.

Whether to suppress scaling in multi-window mode.

Whether to apply the AR multiplier.

Custom AR sensitivity constant, or null for the library default.