Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5ebb0fdc authored by James O'Leary's avatar James O'Leary
Browse files

[CP] If there are > 4 colors, maximize difference

Bug: 199389755
Test: atest ColorSchemeTest
Change-Id: I4c2d76c9c92e96ca8259a4fc991e9e52b9e97ba9
parent 0789a7d6
Loading
Loading
Loading
Loading
+21 −13
Original line number Diff line number Diff line
@@ -168,26 +168,34 @@ public class ColorScheme(@ColorInt seed: Int, val darkTheme: Boolean) {
                        (totalPopulationMeaningless || proportion > 0.01)
            }
            // Sort the colors by score, from high to low.
            val seeds = mutableListOf<Int>()
            val intToScoreIntermediate = filteredIntToCam.mapValues {
                score(it.value, intToHueProportion[it.key]!!)
            }
            val intToScore = intToScoreIntermediate.entries.toMutableList()
            intToScore.sortByDescending { it.value }

            // Go through the colors, from high score to low score. If there isn't already a seed
            // color with a hue close to color being examined, add the color being examined to the
            // seed colors.
            // Go through the colors, from high score to low score.
            // If the color is distinct in hue from colors picked so far, pick the color.
            // Iteratively decrease the amount of hue distinctness required, thus ensuring we
            // maximize difference between colors.
            val minimumHueDistance = 15
            val seeds = mutableListOf<Int>()
            maximizeHueDistance@ for (i in 90 downTo minimumHueDistance step 1) {
                seeds.clear()
                for (entry in intToScore) {
                    val int = entry.key
                    val existingSeedNearby = seeds.find {
                        val hueA = intToCam[int]!!.hue
                        val hueB = intToCam[it]!!.hue
                    hueDiff(hueA, hueB) < 15 } != null
                        hueDiff(hueA, hueB) < i } != null
                    if (existingSeedNearby) {
                        continue
                    }
                    seeds.add(int)
                    if (seeds.size >= 4) {
                        break@maximizeHueDistance
                    }
                }
            }

            if (seeds.isEmpty()) {