Skip to content

Commit

Permalink
don't place end caps if start vector same as end
Browse files Browse the repository at this point in the history
  • Loading branch information
Steedie committed Oct 25, 2024
1 parent 423c40f commit f509d08
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions src/CalcWallModels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,38 +48,40 @@ const CalcWallModels: React.FC<CalcWallModelsProps> = ({
const isStartDiagonal =
Math.abs(line[1].x - line[0].x) === Math.abs(line[1].y - line[0].y);

// Place end cap at the start
const startRotation = Math.atan2(
line[1].y - line[0].y,
line[1].x - line[0].x
);

placeWall(
wallEndCap,
start,
startRotation,
"wallEndCap",
Math.PI / (isStartDiagonal ? 1.33333 : 2)
);
// Place end cap at the start if start is not the same as end
if (!start.equals(end)) {
const startRotation = Math.atan2(
line[1].y - line[0].y,
line[1].x - line[0].x
);
placeWall(
wallEndCap,
start,
startRotation,
"wallEndCap",
Math.PI / (isStartDiagonal ? 1.33333 : 2)
);
}

// Determine if the end end cap is on a diagonal wall
const isEndDiagonal =
Math.abs(line[line.length - 1].x - line[line.length - 2].x) ===
Math.abs(line[line.length - 1].y - line[line.length - 2].y);

// Place end cap at the end
const endRotation = Math.atan2(
line[line.length - 1].y - line[line.length - 2].y,
line[line.length - 1].x - line[line.length - 2].x
);

placeWall(
wallEndCap,
end,
endRotation + Math.PI,
"wallEndCap",
Math.PI / (isEndDiagonal ? 4 : 2)
);
// Place end cap at the end if start is not the same as end
if (!start.equals(end)) {
const endRotation = Math.atan2(
line[line.length - 1].y - line[line.length - 2].y,
line[line.length - 1].x - line[line.length - 2].x
);
placeWall(
wallEndCap,
end,
endRotation + Math.PI,
"wallEndCap",
Math.PI / (isEndDiagonal ? 4 : 2)
);
}

for (let i = 0; i < line.length - 1; i++) {
const start = new THREE.Vector3(...line[i]);
Expand Down

0 comments on commit f509d08

Please sign in to comment.