Skip to content

Commit

Permalink
fix(ui): Prevent the creation of virtual walls with a length of 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypfer committed Apr 27, 2024
1 parent 17dadc7 commit b3417d2
Showing 1 changed file with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b3417d2

Please sign in to comment.