(x: number, y: number, radius: number)
| 39 | let left = Infinity, right = -Infinity, top = Infinity, bottom = -Infinity; |
| 40 | |
| 41 | const collisions = (x: number, y: number, radius: number): Disk[] => { |
| 42 | const found: Disk[] = []; |
| 43 | for (const level of levels.values()) { |
| 44 | const cx = Math.floor(x / level.width), cy = Math.floor(y / level.width); |
| 45 | for (let ix = cx - 1; ix <= cx + 1; ix++) { |
| 46 | const column = level.columns.get(ix); if (!column) continue; |
| 47 | for (let iy = cy - 1; iy <= cy + 1; iy++) { |
| 48 | const bucket = column.get(iy); if (!bucket) continue; |
| 49 | for (const other of bucket) { |
| 50 | const dx = x - other.x, dy = y - other.y, distance = radius + other.radius; |
| 51 | if (dx * dx + dy * dy < distance * distance) found.push(other); |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | return found; |
| 57 | }; |
| 58 | |
| 59 | const insert = (disk: Disk, scale = disk.radius) => { |
| 60 | left = Math.min(left, disk.x - disk.radius); right = Math.max(right, disk.x + disk.radius); |
no test coverage detected