This commit is contained in:
Jens Cornelsen
2024-12-09 19:54:28 +01:00
parent 286fa429a5
commit 06c39ec060

View File

@@ -169,11 +169,22 @@ import Layout from "#layouts/layoutCAD.astro";
const endX = snapToGrid(e.offsetX);
const endY = snapToGrid(e.offsetY);
// Draw a point if the start and end are the same
// Check if the end point is valid:
// - Must not be the same as the start point
// - Must be a valid grid point or the start point of the first line
const isValidEndPoint =
(endX !== startX || endY !== startY) &&
((endX === firstStartPoint?.x && endY === firstStartPoint?.y) || true);
if (!isValidEndPoint) {
return;
}
// If it's a point, draw a point
if (startX === endX && startY === endY) {
drawPoint(startX, startY);
} else {
// Draw the line
// Otherwise, draw the line
drawLine(startX, startY, endX, endY);
}