import { Item } from "../types/Item" ; import { collision } from "./collision" ; import { outOfBounds } from "./outOfBounds" ; export function findSpot ( item , page , height , width ) { let col = 0 ; let row = 0 ; while ( row < height && col < width ) { const target = { ... item , row , column : col } ; if ( ! outOfBounds ( target , height , width ) && ! page . some ( ( existing ) => collision ( target , existing ) ) ) { return [ col , row ] ; } row ++ ; if ( row >= height ) { row = 0 ; col ++ ; } } }