Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add better collision logic for trash #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import androidx.compose.ui.unit.dp
import xyz.tberghuis.floatingtimer.TRASH_SIZE_DP
import xyz.tberghuis.floatingtimer.composables.LocalFloatingService
import xyz.tberghuis.floatingtimer.logd
import kotlin.math.pow
import kotlin.math.sqrt

@Composable
fun TrashOverlay() {
Expand Down Expand Up @@ -104,11 +106,10 @@ fun calcTimerIsHoverTrash(
if (bubble == null) {
return false
}
val halfTimerSize = bubble.bubbleSizePx / 2f
val timerCenterX = bubblePosition.x + halfTimerSize
val timerCenterY = bubblePosition.y + halfTimerSize
return !(timerCenterX < trashRect.left ||
timerCenterX > trashRect.right ||
timerCenterY < trashRect.top ||
timerCenterY > trashRect.bottom)
}
val timerCenterX = bubblePosition.x + (bubble.bubbleSizePx / 2)
val timerCenterY = bubblePosition.y + (bubble.bubbleSizePx / 2)
val trashCenterX = trashRect.center.x
val trashCenterY = trashRect.center.y
// circle collision test
return sqrt((timerCenterX - trashCenterX).pow(2F) + (timerCenterY - trashCenterY).pow(2F)) < (bubble.bubbleSizePx / 2) + (trashRect.size.width / 2)
}