(l1: LayoutItem, l2: LayoutItem)
| 17 | * @returns true if the items collide |
| 18 | */ |
| 19 | export function collides(l1: LayoutItem, l2: LayoutItem): boolean { |
| 20 | // Same element - can't collide with itself |
| 21 | if (l1.i === l2.i) return false; |
| 22 | |
| 23 | // Check if bounding boxes don't overlap (any gap means no collision) |
| 24 | if (l1.x + l1.w <= l2.x) return false; // l1 is completely left of l2 |
| 25 | if (l1.x >= l2.x + l2.w) return false; // l1 is completely right of l2 |
| 26 | if (l1.y + l1.h <= l2.y) return false; // l1 is completely above l2 |
| 27 | if (l1.y >= l2.y + l2.h) return false; // l1 is completely below l2 |
| 28 | |
| 29 | // Bounding boxes overlap |
| 30 | return true; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Find the first item in the layout that collides with the given item. |
no outgoing calls
no test coverage detected
searching dependent graphs…