(t: number, side: number)
| 103 | const others = [...blockers, ...placed]; |
| 104 | let best: { t: number; side: number; rect: ScreenRect; overlap: number } | undefined; |
| 105 | const tryAt = (t: number, side: number) => { |
| 106 | const offset = side * step; |
| 107 | const x = from.x + (to.x - from.x) * t + normal.x * offset, y = from.y + (to.y - from.y) * t + normal.y * offset; |
| 108 | const rect = { left: x - size.width / 2, right: x + size.width / 2, top: y - size.height / 2, bottom: y + size.height / 2 }; |
| 109 | const overlap = others.reduce((sum, other) => sum + overlapArea(rect, other), 0); |
| 110 | if (!best || overlap < best.overlap) best = { t, side, rect, overlap }; |
| 111 | return overlap === 0; |
| 112 | }; |
| 113 | for (const side of SIDES.filter((value) => Math.abs(value) <= maxSide)) { |
| 114 | for (const t of LABEL_STEPS) if (tryAt(t, side)) return best!; |
| 115 | } |
no test coverage detected