detekt: sector indices as a table, not a when
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 <noreply@anthropic.com>
This commit is contained in:
@@ -261,15 +261,19 @@ private fun hslToArgb(
|
|||||||
val sector = hue / HUE_SECTOR_DEGREES
|
val sector = hue / HUE_SECTOR_DEGREES
|
||||||
val second = chroma * (1.0 - abs(sector % TWO - 1.0))
|
val second = chroma * (1.0 - abs(sector % TWO - 1.0))
|
||||||
val match = lightness - chroma / TWO
|
val match = lightness - chroma / TWO
|
||||||
val (red, green, blue) =
|
// The six hue sectors, as a table rather than a `when` — which is also the form
|
||||||
when (sector.toInt()) {
|
// colors.ts uses, so the two read as the same function rather than as two people's
|
||||||
0 -> Triple(chroma, second, 0.0)
|
// idea of it. `sector` is in [0, 6) because the hue it came from is in [0, 360).
|
||||||
1 -> Triple(second, chroma, 0.0)
|
val ramps =
|
||||||
2 -> Triple(0.0, chroma, second)
|
listOf(
|
||||||
3 -> Triple(0.0, second, chroma)
|
Triple(chroma, second, 0.0),
|
||||||
4 -> Triple(second, 0.0, chroma)
|
Triple(second, chroma, 0.0),
|
||||||
else -> Triple(chroma, 0.0, second)
|
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
|
return (ALPHA_OPAQUE shl ALPHA_BIT_SHIFT) or
|
||||||
(channelByte(red + match) shl RED_BIT_SHIFT) or
|
(channelByte(red + match) shl RED_BIT_SHIFT) or
|
||||||
(channelByte(green + match) shl GREEN_BIT_SHIFT) or
|
(channelByte(green + match) shl GREEN_BIT_SHIFT) or
|
||||||
|
|||||||
Reference in New Issue
Block a user