Skip to content

Instantly share code, notes, and snippets.

@AndreVero
Last active April 15, 2024 07:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndreVero/7d592e4693b0bccd8ef1bdf6bcb189fa to your computer and use it in GitHub Desktop.
Save AndreVero/7d592e4693b0bccd8ef1bdf6bcb189fa to your computer and use it in GitHub Desktop.
Find the closest item
// 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