Note
Version: 1.0.1 — modules: MODULES.md
Related: PDR · Mathematics · API Conventions
AppDimens Dynamic is a mathematical scaling engine for Kotlin Multiplatform (com.appdimens.kmp). Its purpose is to map generic UI dimensions (developed against a 300dp or equivalent reference) to physical window parameters—scaling elegantly across phones, tablets, desktop windows, and unpredictable foldables, on Android, JVM, iOS, macOS, the web (Kotlin/JS + wasmJs), Linux and Windows.
It encapsulates scaling strategies (curves) shipped as Maven modules, alongside an autonomous Resize/Constraint subsystem that finds the largest fitting size via binary search.
Static dp measurements fall apart as device variety increases. A 300dp horizontal card fits perfectly on a classic phone but becomes aggressively small on high-density tablets or wide-screen foldables.
- Mathematical Consistency: Provide reproducible scaling curves (Linear, Logarithmic, Power).
- Unified Surface APIs: Symmetrical integration rules for Compose Multiplatform (
compose.*) and non-Compose code (code.*, with a platform-neutralAppDimensContextwindow handle). - High-Frequency Performance: Accommodate zero-allocation hot paths using lock-free architecture for smooth
60FPSand120FPSrendering algorithms. - Hardware Awareness: Adapt directly to
Configuration, Display aspect ratios, Multi-Window flags, and Context DPI. - Modular APK control: Developers include only the strategy artifacts they need; the principal artifact must not pull all strategies.
mindmap
root((AppDimens Dynamic))
Mathematical Engine
Linear & Scaled Defaults
Logarithmic Deterioration
Exponential / Power Curves
Diagonal Vector Paths
Resize Subsystem
Binary Constraint Search
Max Area Fits Predicate
Zero-GC Floating Arrays
Consumer Platforms
Compose Multiplatform (Android/Desktop/iOS/macOS/Web) · `code` API also on Linux/Windows native
Non-Compose code API (AppDimensContext)
Pure Kotlin Math Core
Thread Safe Cache Layer
Snapshot-partitioned Cache
Multi-Window Detection
Atomic Reference Entries
- FR-0.1 (Module Separation): Each strategy must exist as an independent computational node.
compose.percentcannot importcompose.power. - FR-0.2 (Telemetry & Reading): Raw dimensions must derive from the platform window configuration — on Android from
android.content.res.Configuration, on desktop/web/iOS/macOS from the live window/viewport snapshot exposed asScreenConfiguration, and on Linux/Windows native from aScreenConfigurationyou build (no windowing API in the Kotlin/Native stdlib —defaultPlatformContext()returnsnullthere). - FR-0.3 (Platform Parity): All Compose API nodes (
*DpExtensions) must explicitly feature symmetriccodeequivalents for legacy migration.
Tip
The Scaled default curve remains optimal for generic UI development, specifically supporting aspect-ratio injection (sdpa, sdpi) for anti-distortion tuning.
| Strategy Class | Mathematical Goal | Expected Consumer Use Case |
|---|---|---|
| Scaled (Default) | Linear geometry translation from basic 300dp scale. |
Baseline paddings, Standard containers. |
| Logarithmic | Fast early growth curve with heavy downstream damping. | Text geometries on massive tablets. |
| Fluid | Breakpoint-based linear interpolation ([320..768]). | Responsive Web-like UI adjustments. |
| Percent / Space | Absolute device fractional limits (( % \times sw )). | Fixed grid splits, Nav bars. |
| Interpolated | Blend between base and linear scale (50%). | Softer growth than pure linear. |
- FR-2.1 (Memory Integrity): Generates constraint step buffers via static pre-allocated
FloatArray. No auto-boxing allowed. - FR-2.2 (Processing): Operates on an asymptotic (\mathcal{O}(\log N)) binary search protocol to match element sizing to physical screen limits.
- FR-2.3 (Bounds & Safety): Respect hardware metrics with
ResizeBound.resolveToPxusing strictrequire(density > 0)contracts.
- NFR-1 (Performance Benchmarking):
shouldBypassCacheskips snapshot-cache I/O for multiply-only types (PERCENT,SCALED,DENSITY,DIAGONAL,INTERPOLATED,PERIMETER) and forPOWER/LOGARITHMICon the default SW path — including default aspect ratio when applicable. See library/PERFORMANCE.md. - NFR-2 (Lock-Free Threading): Lock-free, snapshot-partitioned cache. Each window/configuration snapshot (
DimenMetrics) owns a fixed-size partition whose entries are published as a single immutableCacheEntry(key + value bits) throughAtomicReferenceArray, so concurrent readers never observe another key’s value; no disk persistence. - NFR-3 (Minimum Environment):
minSdk = 24, Java 17 requirements, enforcing direct Proguard shipping viaconsumer-rules.pro. - NFR-4 (Runtime Diagnostics): Engine observability functions remain conditionally gated (
diagnosticsEnabled) to eliminate tracing overhead in production applications.
- Integration on both Compose/XML environments without memory/GC stuttering.
- Binary scale operations taking
< 15nsmedian time. - Successful scaling to multi-window split structures automatically.