Skip to content

Commit d385a60

Browse files
committed
WIP
1 parent 132609e commit d385a60

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

lib/solvers/GapFillSolver.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ export class GapFillSolver extends BaseSolver {
308308
filledRect &&
309309
!this.overlapsExistingFill(filledRect) &&
310310
!this.overlapsInputRects(filledRect) &&
311+
!this.overlapsObstacles(filledRect) &&
311312
this.hasMinimumSize(filledRect)
312313
) {
313314
this.state.filledRects.push(filledRect)
@@ -375,6 +376,32 @@ export class GapFillSolver extends BaseSolver {
375376
return false
376377
}
377378

379+
private overlapsObstacles(candidate: Placed3D): boolean {
380+
for (const z of candidate.zLayers) {
381+
const obstacles = this.state.obstaclesByLayer[z] ?? []
382+
for (const obstacle of obstacles) {
383+
const overlapX =
384+
Math.max(candidate.rect.x, obstacle.x) <
385+
Math.min(
386+
candidate.rect.x + candidate.rect.width,
387+
obstacle.x + obstacle.width,
388+
)
389+
const overlapY =
390+
Math.max(candidate.rect.y, obstacle.y) <
391+
Math.min(
392+
candidate.rect.y + candidate.rect.height,
393+
obstacle.y + obstacle.height,
394+
)
395+
396+
if (overlapX && overlapY) {
397+
return true
398+
}
399+
}
400+
}
401+
402+
return false
403+
}
404+
378405
private hasMinimumSize(candidate: Placed3D): boolean {
379406
const minSize = 0.01
380407
return candidate.rect.width >= minSize && candidate.rect.height >= minSize

0 commit comments

Comments
 (0)