mirror of
https://github.com/SimpleMobileTools/Simple-Launcher.git
synced 2025-02-18 04:20:36 +01:00
further improving some collision checks
This commit is contained in:
parent
abc838f307
commit
dccad9ef90
@ -136,11 +136,13 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
|
||||
|
||||
val closestCellX = roundToClosestMultiplyOfNumber(wantedLeft - sideMargins.left, cellWidth) / cellWidth
|
||||
var areAllCellsFree = true
|
||||
for (xCell in closestCellX until cellsRect.right) {
|
||||
for (yCell in cellsRect.top until cellsRect.bottom) {
|
||||
if (occupiedCells.contains(Pair(closestCellX, yCell))) {
|
||||
if (occupiedCells.contains(Pair(xCell, yCell))) {
|
||||
areAllCellsFree = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (areAllCellsFree && cellsRect.left != closestCellX) {
|
||||
cellsRect.left = closestCellX
|
||||
@ -160,10 +162,12 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
|
||||
val closestCellY = roundToClosestMultiplyOfNumber(wantedTop - sideMargins.top, cellHeight) / cellHeight
|
||||
var areAllCellsFree = true
|
||||
for (xCell in cellsRect.left until cellsRect.right) {
|
||||
if (occupiedCells.contains(Pair(xCell, closestCellY))) {
|
||||
for (yCell in closestCellY until cellsRect.bottom) {
|
||||
if (occupiedCells.contains(Pair(xCell, yCell))) {
|
||||
areAllCellsFree = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (areAllCellsFree && cellsRect.top != closestCellY) {
|
||||
cellsRect.top = closestCellY
|
||||
@ -182,11 +186,13 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
|
||||
|
||||
val closestCellX = roundToClosestMultiplyOfNumber(wantedRight - sideMargins.left, cellWidth) / cellWidth - 1
|
||||
var areAllCellsFree = true
|
||||
for (xCell in cellsRect.left until closestCellX + 1) {
|
||||
for (yCell in cellsRect.top until cellsRect.bottom) {
|
||||
if (occupiedCells.contains(Pair(closestCellX, yCell))) {
|
||||
if (occupiedCells.contains(Pair(xCell, yCell))) {
|
||||
areAllCellsFree = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (areAllCellsFree && cellsRect.right != closestCellX) {
|
||||
cellsRect.right = closestCellX
|
||||
@ -221,11 +227,13 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
|
||||
val wantedLeft = roundToClosestMultiplyOfNumber(frameRect.left - sideMargins.left, cellWidth)
|
||||
val wantedLeftCellX = wantedLeft / cellWidth
|
||||
var areAllCellsFree = true
|
||||
for (xCell in wantedLeftCellX until cellsRect.right) {
|
||||
for (yCell in cellsRect.top until cellsRect.bottom) {
|
||||
if (occupiedCells.contains(Pair(wantedLeftCellX, yCell))) {
|
||||
if (occupiedCells.contains(Pair(xCell, yCell))) {
|
||||
areAllCellsFree = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (areAllCellsFree) {
|
||||
frameRect.left = wantedLeft + sideMargins.left
|
||||
@ -239,10 +247,12 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
|
||||
val wantedTopCellY = wantedTop / cellHeight
|
||||
var areAllCellsFree = true
|
||||
for (xCell in cellsRect.left until cellsRect.right) {
|
||||
if (occupiedCells.contains(Pair(xCell, wantedTopCellY))) {
|
||||
for (yCell in wantedTopCellY until cellsRect.bottom) {
|
||||
if (occupiedCells.contains(Pair(xCell, yCell))) {
|
||||
areAllCellsFree = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (areAllCellsFree) {
|
||||
frameRect.top = wantedTop + sideMargins.top
|
||||
@ -255,11 +265,13 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
|
||||
val wantedRight = roundToClosestMultiplyOfNumber(frameRect.right - sideMargins.left, cellWidth)
|
||||
val wantedRightCellX = wantedRight / cellWidth - 1
|
||||
var areAllCellsFree = true
|
||||
for (xCell in cellsRect.left until wantedRightCellX + 1) {
|
||||
for (yCell in cellsRect.top until cellsRect.bottom) {
|
||||
if (occupiedCells.contains(Pair(wantedRightCellX, yCell))) {
|
||||
if (occupiedCells.contains(Pair(xCell, yCell))) {
|
||||
areAllCellsFree = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (areAllCellsFree) {
|
||||
frameRect.right = wantedRight + sideMargins.left
|
||||
|
Loading…
x
Reference in New Issue
Block a user