I make a grid like this:
let columns = Math.floor(width / new Boid().perceptionRadius)
let rows = Math.floor(height / new Boid().perceptionRadius)
let grid = {
grid: Array(rows).fill(Array(columns).fill([])),
dimensions: {
width: (width / rows),
height: (height / columns)
}
}
and then I push items to the array like this:
flock.forEach((boid)=>{
let column = Math.floor(this.position.y / grid.dimensions.height),
row = Math.floor(this.position.x / grid.dimensions.width);
grid.grid[row][column].push(this)
})
console.log(grid.grid)
When I look in the output, every tiem in both row and column contains flock.length
items, why?