Return size 0 for NULL array, correct for min/max in spatial grid

This commit is contained in:
2024-02-10 10:51:38 +01:00
parent aa0fea49e9
commit 0e6e1d5a2d
2 changed files with 12 additions and 0 deletions

View File

@@ -28,6 +28,7 @@ void _bzArrayClear(void *arr) {
} }
i32 _bzArraySize(void *arr) { i32 _bzArraySize(void *arr) {
if (arr == NULL) return 0;
return ARRAY_HEAD(arr)->size; return ARRAY_HEAD(arr)->size;
} }
i32 _bzArrayCapacity(void *arr) { i32 _bzArrayCapacity(void *arr) {

View File

@@ -104,6 +104,17 @@ static BzSpatialGridIndex calculateGridIndex(BzSpatialGrid *grid, f32 posX, f32
if (index.minY < 0) index.minY = 0; if (index.minY < 0) index.minY = 0;
if (index.maxX >= grid->width) index.maxX = grid->width - 1; if (index.maxX >= grid->width) index.maxX = grid->width - 1;
if (index.maxY >= grid->height) index.maxY = grid->height - 1; if (index.maxY >= grid->height) index.maxY = grid->height - 1;
if (index.minX > index.maxX) {
i32 tmp = index.minX;
index.minX = index.maxX;
index.maxX = tmp;
}
if (index.minY > index.maxY) {
i32 tmp = index.minY;
index.minY = index.maxY;
index.maxX = tmp;
}
return index; return index;
} }