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