diff --git a/src/pages/faq/erstellung-energieausweise/index.astro b/src/pages/faq/erstellung-energieausweise/index.astro index d082cf88..09d8ba57 100644 --- a/src/pages/faq/erstellung-energieausweise/index.astro +++ b/src/pages/faq/erstellung-energieausweise/index.astro @@ -73,7 +73,7 @@ import Layout from "#layouts/layoutCAD.astro";
- Captured Lines: + Captured Points and Lines:
@@ -122,10 +122,14 @@ import Layout from "#layouts/layoutCAD.astro"; updateLineLog(); } - // Update the captured lines log + // Update the captured points and lines log function updateLineLog() { lineLog.innerHTML = capturedLines .map((line, index) => { + const isPoint = line.startX === line.endX && line.startY === line.endY; + if (isPoint) { + return `
  • Point: (${line.startX}, ${line.startY})
  • `; + } const length = calculateLineLength(line.startX, line.startY, line.endX, line.endY); return `
  • Line ${index + 1}: Start (${line.startX}, ${line.startY}), End (${line.endX}, ${line.endY}), Length: ${length.toFixed(2)} px
  • `; }) @@ -139,50 +143,44 @@ import Layout from "#layouts/layoutCAD.astro"; return Math.sqrt(dx * dx + dy * dy); } - // Mouse event for drawing lines + // Mouse event for drawing lines and points canvas.addEventListener('mousedown', (e) => { const clickX = snapToGrid(e.offsetX); const clickY = snapToGrid(e.offsetY); - // Determine starting point for the line + // Determine starting point for the line or point let startX, startY; if (!lastEndPoint) { - // First line can start anywhere + // For the first line or point, set the start point anywhere startX = clickX; startY = clickY; firstStartPoint = { x: startX, y: startY }; // Save the start point of the first line } else if (clickX === lastEndPoint.x && clickY === lastEndPoint.y) { - // Subsequent lines must start at the last endpoint + // For subsequent lines, start at the last endpoint startX = lastEndPoint.x; startY = lastEndPoint.y; } else { - // Invalid starting point + // Invalid starting point for a line return; } - // Determine the end point + // Determine the endpoint const endX = snapToGrid(e.offsetX); const endY = snapToGrid(e.offsetY); - // Check if the end point is valid: - // - Must not be the same as the start point - // - Must be a valid grid point or the first start point - const isValidEndPoint = - (endX !== startX || endY !== startY) && - ((endX === firstStartPoint?.x && endY === firstStartPoint?.y) || endX % gridSize === 0 && endY % gridSize === 0); - - if (!isValidEndPoint) { - return; + // Draw a point if the start and end are the same + if (startX === endX && startY === endY) { + drawPoint(startX, startY); + } else { + // Draw the line + drawLine(startX, startY, endX, endY); } - // Draw the line - drawLine(startX, startY, endX, endY); - - // Update the last end point + // Update the last endpoint lastEndPoint = { x: endX, y: endY }; - // Capture the line details + // Capture the line or point details capturedLines.push({ startX, startY, endX, endY }); updateLineLog(); }); @@ -197,8 +195,16 @@ import Layout from "#layouts/layoutCAD.astro"; ctx.stroke(); } + // Function to draw a point + function drawPoint(x, y) { + ctx.beginPath(); + ctx.fillStyle = "#000000"; // Black point + ctx.arc(x, y, 3, 0, 2 * Math.PI); // Draw a small circle for the point + ctx.fill(); + } + // Initialize the canvas drawGrid(); - + \ No newline at end of file