Refactor: use coerceAtLeast instead of an if expression

Also makes it clear that it's the device resolution that matters
for the crash, rather than the device density
This commit is contained in:
Cactric 2025-11-30 21:33:50 +00:00 committed by Julien Papasian
parent e69d68d41d
commit cdfc099891

View File

@ -73,10 +73,9 @@ class SnowImplementor(
-radius
}
val bound = (2 * speedY).toInt()
// Fix bound to at least two to prevent crashes on small screens (where bound would be 0) and provide
// some variation on medium screens (where bound would always be 1 and the RNG would only give 0)
speedX = r.nextInt(if (bound >= 2) bound else 2) - speedY
// Fix input to nextInt to at least two to prevent crashes on low res screens (where bound would be 0)
// and provide some variation on medium-res screens (where bound would always be 1)
speedX = r.nextInt((2 * speedY).toInt().coerceAtLeast(2)) - speedY
computeCenterPosition()
}