From 86f1e4a08f5129a1f0497ac6b91e2df7e82e23ca Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Wed, 26 Aug 2026 17:08:20 -0400 Subject: [PATCH] detekt: sector indices as a table, not a when MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MagicNumber's ignore list is -1/0/1/2, so the `3 ->` and `4 ->` branch labels were findings. A lookup table has no literals to flag, and it is the form colors.ts already uses — the two now read as the same function rather than as two people's idea of it. Co-Authored-By: Claude Opus 5 --- .../fabledsword/thoughtsync/ui/DerivedTint.kt | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/android/app/src/main/java/com/fabledsword/thoughtsync/ui/DerivedTint.kt b/android/app/src/main/java/com/fabledsword/thoughtsync/ui/DerivedTint.kt index 44eeed5..fbe904d 100644 --- a/android/app/src/main/java/com/fabledsword/thoughtsync/ui/DerivedTint.kt +++ b/android/app/src/main/java/com/fabledsword/thoughtsync/ui/DerivedTint.kt @@ -261,15 +261,19 @@ private fun hslToArgb( val sector = hue / HUE_SECTOR_DEGREES val second = chroma * (1.0 - abs(sector % TWO - 1.0)) val match = lightness - chroma / TWO - val (red, green, blue) = - when (sector.toInt()) { - 0 -> Triple(chroma, second, 0.0) - 1 -> Triple(second, chroma, 0.0) - 2 -> Triple(0.0, chroma, second) - 3 -> Triple(0.0, second, chroma) - 4 -> Triple(second, 0.0, chroma) - else -> Triple(chroma, 0.0, second) - } + // The six hue sectors, as a table rather than a `when` — which is also the form + // colors.ts uses, so the two read as the same function rather than as two people's + // idea of it. `sector` is in [0, 6) because the hue it came from is in [0, 360). + val ramps = + listOf( + Triple(chroma, second, 0.0), + Triple(second, chroma, 0.0), + Triple(0.0, chroma, second), + Triple(0.0, second, chroma), + Triple(second, 0.0, chroma), + Triple(chroma, 0.0, second), + ) + val (red, green, blue) = ramps[sector.toInt()] return (ALPHA_OPAQUE shl ALPHA_BIT_SHIFT) or (channelByte(red + match) shl RED_BIT_SHIFT) or (channelByte(green + match) shl GREEN_BIT_SHIFT) or