| 163 | * Sektion, ob sie ihn nun auch im Baum enthaelt oder nicht. |
| 164 | */ |
| 165 | export function avoidFrameOf(anchor: HintRect, protect: readonly HintRect[]): HintRect { |
| 166 | let left = anchor.x; |
| 167 | let top = anchor.y; |
| 168 | let right = anchor.x + anchor.width; |
| 169 | let bottom = anchor.y + anchor.height; |
| 170 | for (const rect of protect) { |
| 171 | const holds = rect.x <= anchor.x + 1 |
| 172 | && rect.y <= anchor.y + 1 |
| 173 | && rect.x + rect.width >= anchor.x + anchor.width - 1 |
| 174 | && rect.y + rect.height >= anchor.y + anchor.height - 1; |
| 175 | if (!holds) { |
| 176 | continue; |
| 177 | } |
| 178 | left = Math.min(left, rect.x); |
| 179 | top = Math.min(top, rect.y); |
| 180 | right = Math.max(right, rect.x + rect.width); |
| 181 | bottom = Math.max(bottom, rect.y + rect.height); |
| 182 | } |
| 183 | return { x: left, y: top, width: right - left, height: bottom - top }; |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Den Kasten aus dem Weg schieben, wenn keine der zwoelf Lagen frei ist. |