docs: clarify formula derivation and dev-only state

Three documentation/marker additions surfaced by an engineer-v1 audit:

- ChatWallpaper.kt: the per-mode/per-element constants used by the theme
  color formula were a wall of magic numbers. Add a header explaining
  what each parameter controls and where the values came from
  (empirically tuned via the dev UI in Appearance.kt).
- Appearance.kt: surround the module-level FormulaDevTools state
  (formulaSavedParams, patternScaleDragging) with a prominent banner
  marking it dev-only. The dev UI is shipped in the current build but
  must be removed before reaching end users; the search-tag makes that
  trivial later.
- Color.kt: solveCubic had no docstring; the 1e-10f thresholds looked
  like magic. Document Cardano's method, the maxChromaForMatrix caller
  context, and the numerical-stability rationale for the thresholds.

Pure comment additions; no behavior change.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
another-simple-pixel
2026-05-13 13:36:33 -07:00
parent bd9d31c5f4
commit 19318576f3
3 changed files with 26 additions and 5 deletions
@@ -148,6 +148,12 @@ private fun allChannelsInGamut(C: Float, p: FloatArray, q: FloatArray, matrix: A
return true
}
/** Real roots of ax³+bx²+cx+d = 0 (Cardano's method).
* Used by [maxChromaForMatrix] to find the gamut-boundary chroma at a given
* (L, H) — the largest C such that oklch(L, C, H) is still inside the target
* RGB cube. The 1e-10f thresholds detect near-zero leading coefficients to
* avoid amplifying floating-point noise (degree drops from cubic to quadratic
* to linear as coefficients vanish). */
private fun solveCubic(a: Float, b: Float, c: Float, d: Float): FloatArray {
if (abs(a) < 1e-10f) {
if (abs(b) < 1e-10f) {
@@ -300,9 +300,16 @@ fun wallpaperBackgrounds(
)
// ===== Theme color formula =====
// L = mode.lBase + mode.lSpread * elem.lOffset
// C = mode.cFactor * elem.cFactor * theme.cScale
// H = theme.hue
// Each preset's per-mode bubble/tint colors are derived from the preset's hue
// and chroma scale, the mode's anchor (lBase) + range (lSpread) + chroma factor,
// and the element's lightness offset + chroma factor. Constants below were tuned
// empirically via the FormulaDevTools UI (see Appearance.kt) and locked in once
// every preset/mode combination satisfied the design contrast targets.
//
// Formula:
// L = mode.lBase + mode.lSpread * elem.lOffset
// C = mode.cFactor * elem.cFactor * theme.cScale
// H = theme.hue
private data class ModeParams(val lBase: Float, val lSpread: Float, val cFactor: Float)
private data class ElemParams(val lOffset: Float, val cFactor: Float)
@@ -56,11 +56,19 @@ import kotlin.math.*
@Composable
expect fun AppearanceView(m: ChatModel)
// Formula slider values — survives navigation, cleared on app restart
// ─── DEV-ONLY: theme-formula tuning UI ─────────────────────────────────────
// Module-level state below backs the FormulaDevTools panel that the founder
// uses to live-tune wallpaper color formulas. It is NOT part of the user-facing
// settings flow and MUST be removed (along with FormulaDevTools, FormulaSlider,
// buildCodeOutput, formulaSavedParams, patternScaleDragging) before this PR's
// dev affordances ship to end users. Search-tag: REMOVE-DEV-FORMULA.
// Formula slider values — survives navigation, cleared on app restart.
private val formulaSavedParams = mutableStateMapOf<String, Float>()
// Desktop: use fast scaling during slider drag, SCALE_SMOOTH on release
// Desktop: use fast scaling during slider drag, SCALE_SMOOTH on release.
private var patternScaleDragging by mutableStateOf(false)
// ───────────────────────────────────────────────────────────────────────────
object AppearanceScope {
@Composable