Last active
April 15, 2024 07:26
-
-
Save AndreVero/7d592e4693b0bccd8ef1bdf6bcb189fa to your computer and use it in GitHub Desktop.
Find the closest item
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Convert angles to degrees | |
val itemAngleDegrees = (itemAngle * (180f / PI.toFloat())).toFloat() | |
// Get the distance from the top position to the current item | |
val distanceToSelectedItem = itemAngleDegrees.mod(360f) - SELECTED_ANGLE_DEGREES | |
// Find the closest item | |
if (abs(distanceToSelectedItem) < abs(state.selectedItem.angle)) { | |
state.selectedItem = SelectedItem(distanceToSelectedItem, items[index]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment