From b3417d2d0074f95387dfd9c1d28147641b5f6e6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Beye?= <github@hypfer.de> Date: Sat, 27 Apr 2024 17:35:31 +0200 Subject: [PATCH] fix(ui): Prevent the creation of virtual walls with a length of 0 --- .../client_structures/LineClientStructure.ts | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/frontend/src/map/structures/client_structures/LineClientStructure.ts b/frontend/src/map/structures/client_structures/LineClientStructure.ts index 6610b5d5360..d1efe48aef7 100644 --- a/frontend/src/map/structures/client_structures/LineClientStructure.ts +++ b/frontend/src/map/structures/client_structures/LineClientStructure.ts @@ -177,13 +177,35 @@ abstract class LineClientStructure extends ClientStructure { const deltaY = Math.abs(this.y0 - this.y1); const deltaX = Math.abs(this.x0 - this.x1); - const distance = Math.round(Math.hypot(deltaX, deltaY)); + const distance = Math.hypot(deltaX, deltaY); + const roundedDistance = Math.round(distance); + + // Ensure that the user doesn't create a wall that is too short to be modified anymore + if (distance < 1) { + if (this.x0 === this.x1 && this.y0 === this.y1) { + this.x1++; + this.y1++; + } else { + if (this.x0 > this.x1) { + this.x1--; + } else if (this.x0 < this.x1) { + this.x1++; + } + if (this.y0 > this.y1) { + this.y1--; + } else if (this.y0 < this.y1) { + this.y1++; + } + } + + return this.postProcess(); + } const angle = Math.atan2(deltaY, deltaX) * 180/Math.PI; const newAngle = (Math.round(angle/5)*5); - let xOffset = distance * Math.cos(newAngle * Math.PI/180); - let yOffset = distance * Math.sin(newAngle * Math.PI/180); + let xOffset = roundedDistance * Math.cos(newAngle * Math.PI/180); + let yOffset = roundedDistance * Math.sin(newAngle * Math.PI/180); if (this.x0 > this.x1) {