Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions lib/solvers/RectDiffGridSolverPipeline/buildObstacleIndexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,16 @@ export const buildObstacleIndexesByLayer = (params: {
const rect = obstacleToXYRect(obstacle as any)
if (!rect) continue
const zLayers = obstacleZs(obstacle as any, zIndexByName)
const invalidZs = zLayers.filter((z) => z < 0 || z >= layerCount)
if (invalidZs.length) {
throw new Error(
`RectDiff: obstacle uses z-layer indices ${invalidZs.join(",")} outside 0-${layerCount - 1}`,
)
}
// Filter out z-layers outside the valid range instead of throwing an error
const validZLayers = zLayers.filter((z) => z >= 0 && z < layerCount)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Yes, I think it's better too; throwing an error is too harsh when the program can fix it.

if (validZLayers.length === 0) continue
if (
(!obstacle.zLayers || obstacle.zLayers.length === 0) &&
zLayers.length
validZLayers.length
) {
obstacle.zLayers = zLayers
obstacle.zLayers = validZLayers
}
for (const z of zLayers) insertObstacle(rect, z)
for (const z of validZLayers) insertObstacle(rect, z)
}

return { obstacleIndexByLayer }
Expand Down