Skip to content

Commit c6a26fa

Browse files
jamesarichCopilot
andcommitted
fix(car): resolve detekt failure in node colors
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 225b44c commit c6a26fa

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

  • core/model/src/commonMain/kotlin/org/meshtastic/core/model

core/model/src/commonMain/kotlin/org/meshtastic/core/model/NodeColors.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,23 @@ private const val GREEN_WEIGHT = 0.587
2121
private const val BLUE_WEIGHT = 0.114
2222
private const val BRIGHTNESS_THRESHOLD = 0.5
2323
private const val MAX_CHANNEL = 255
24+
private const val RED_MASK = 0xFF0000
25+
private const val GREEN_MASK = 0x00FF00
26+
private const val BLUE_MASK = 0x0000FF
27+
private const val ALPHA_MASK = 0xFF
28+
private const val RED_SHIFT = 16
29+
private const val GREEN_SHIFT = 8
30+
private const val ALPHA_SHIFT = 24
31+
private const val BLACK = 0xFF000000.toInt()
32+
private const val WHITE = 0xFFFFFFFF.toInt()
2433

2534
/** Derives a unique color pair from a node number. Returns (foreground, background) as @ColorInt. */
2635
fun nodeColorsFromNum(nodeNum: Int): Pair<Int, Int> {
27-
val r = (nodeNum and 0xFF0000) shr 16
28-
val g = (nodeNum and 0x00FF00) shr 8
29-
val b = nodeNum and 0x0000FF
36+
val r = (nodeNum and RED_MASK) shr RED_SHIFT
37+
val g = (nodeNum and GREEN_MASK) shr GREEN_SHIFT
38+
val b = nodeNum and BLUE_MASK
3039
val brightness = ((r * RED_WEIGHT) + (g * GREEN_WEIGHT) + (b * BLUE_WEIGHT)) / MAX_CHANNEL
31-
val foreground = if (brightness > BRIGHTNESS_THRESHOLD) 0xFF000000.toInt() else 0xFFFFFFFF.toInt()
32-
val background = (0xFF shl 24) or (r shl 16) or (g shl 8) or b
40+
val foreground = if (brightness > BRIGHTNESS_THRESHOLD) BLACK else WHITE
41+
val background = (ALPHA_MASK shl ALPHA_SHIFT) or (r shl RED_SHIFT) or (g shl GREEN_SHIFT) or b
3342
return foreground to background
3443
}

0 commit comments

Comments
 (0)