further improving some collision checks

This commit is contained in:
tibbi 2022-10-04 20:00:45 +02:00
parent abc838f307
commit dccad9ef90
1 changed files with 28 additions and 16 deletions

View File

@ -136,9 +136,11 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
val closestCellX = roundToClosestMultiplyOfNumber(wantedLeft - sideMargins.left, cellWidth) / cellWidth val closestCellX = roundToClosestMultiplyOfNumber(wantedLeft - sideMargins.left, cellWidth) / cellWidth
var areAllCellsFree = true var areAllCellsFree = true
for (yCell in cellsRect.top until cellsRect.bottom) { for (xCell in closestCellX until cellsRect.right) {
if (occupiedCells.contains(Pair(closestCellX, yCell))) { for (yCell in cellsRect.top until cellsRect.bottom) {
areAllCellsFree = false if (occupiedCells.contains(Pair(xCell, yCell))) {
areAllCellsFree = false
}
} }
} }
@ -160,8 +162,10 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
val closestCellY = roundToClosestMultiplyOfNumber(wantedTop - sideMargins.top, cellHeight) / cellHeight val closestCellY = roundToClosestMultiplyOfNumber(wantedTop - sideMargins.top, cellHeight) / cellHeight
var areAllCellsFree = true var areAllCellsFree = true
for (xCell in cellsRect.left until cellsRect.right) { for (xCell in cellsRect.left until cellsRect.right) {
if (occupiedCells.contains(Pair(xCell, closestCellY))) { for (yCell in closestCellY until cellsRect.bottom) {
areAllCellsFree = false if (occupiedCells.contains(Pair(xCell, yCell))) {
areAllCellsFree = false
}
} }
} }
@ -182,9 +186,11 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
val closestCellX = roundToClosestMultiplyOfNumber(wantedRight - sideMargins.left, cellWidth) / cellWidth - 1 val closestCellX = roundToClosestMultiplyOfNumber(wantedRight - sideMargins.left, cellWidth) / cellWidth - 1
var areAllCellsFree = true var areAllCellsFree = true
for (yCell in cellsRect.top until cellsRect.bottom) { for (xCell in cellsRect.left until closestCellX + 1) {
if (occupiedCells.contains(Pair(closestCellX, yCell))) { for (yCell in cellsRect.top until cellsRect.bottom) {
areAllCellsFree = false if (occupiedCells.contains(Pair(xCell, yCell))) {
areAllCellsFree = false
}
} }
} }
@ -221,9 +227,11 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
val wantedLeft = roundToClosestMultiplyOfNumber(frameRect.left - sideMargins.left, cellWidth) val wantedLeft = roundToClosestMultiplyOfNumber(frameRect.left - sideMargins.left, cellWidth)
val wantedLeftCellX = wantedLeft / cellWidth val wantedLeftCellX = wantedLeft / cellWidth
var areAllCellsFree = true var areAllCellsFree = true
for (yCell in cellsRect.top until cellsRect.bottom) { for (xCell in wantedLeftCellX until cellsRect.right) {
if (occupiedCells.contains(Pair(wantedLeftCellX, yCell))) { for (yCell in cellsRect.top until cellsRect.bottom) {
areAllCellsFree = false if (occupiedCells.contains(Pair(xCell, yCell))) {
areAllCellsFree = false
}
} }
} }
@ -239,8 +247,10 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
val wantedTopCellY = wantedTop / cellHeight val wantedTopCellY = wantedTop / cellHeight
var areAllCellsFree = true var areAllCellsFree = true
for (xCell in cellsRect.left until cellsRect.right) { for (xCell in cellsRect.left until cellsRect.right) {
if (occupiedCells.contains(Pair(xCell, wantedTopCellY))) { for (yCell in wantedTopCellY until cellsRect.bottom) {
areAllCellsFree = false if (occupiedCells.contains(Pair(xCell, yCell))) {
areAllCellsFree = false
}
} }
} }
@ -255,9 +265,11 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
val wantedRight = roundToClosestMultiplyOfNumber(frameRect.right - sideMargins.left, cellWidth) val wantedRight = roundToClosestMultiplyOfNumber(frameRect.right - sideMargins.left, cellWidth)
val wantedRightCellX = wantedRight / cellWidth - 1 val wantedRightCellX = wantedRight / cellWidth - 1
var areAllCellsFree = true var areAllCellsFree = true
for (yCell in cellsRect.top until cellsRect.bottom) { for (xCell in cellsRect.left until wantedRightCellX + 1) {
if (occupiedCells.contains(Pair(wantedRightCellX, yCell))) { for (yCell in cellsRect.top until cellsRect.bottom) {
areAllCellsFree = false if (occupiedCells.contains(Pair(xCell, yCell))) {
areAllCellsFree = false
}
} }
} }