Skip to content

Commit

Permalink
Update script.js
Browse files Browse the repository at this point in the history
generateshapes is shapevalid feature improved?
  • Loading branch information
Demothedread authored Apr 15, 2024
1 parent 0271825 commit 34c645e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,20 @@ function isShapeValid(newShape, existingShapes, lines) {
return false; // Overlap detected with a line
}
}

return true; // No overlaps

// Check mandatory line presence on edges
const hasVerticalLine = lines.some(line => line.orientation === 'vertical' &&
(newShape.x === line.x || newShape.x + newShape.width === line.x));
const hasHorizontalLine = lines.some(line => line.orientation === 'horizontal' &&
(newShape.y === line.y || newShape.y + newShape.height === line.y));

if (!hasVerticalLine || !hasHorizontalLine) {
console.log("Required line on edge missing", newShape);
return false;
}

return true;
}


Expand Down

0 comments on commit 34c645e

Please sign in to comment.