Skip to content

Commit

Permalink
feat: add offset to corners
Browse files Browse the repository at this point in the history
  • Loading branch information
agviegas committed Oct 1, 2024
1 parent 0db9de8 commit 58cfc7a
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ export interface WallCornerConfig {
priority?: WallEndPointType;
cut?: "exterior" | "interior";
cutDirection?: "exterior" | "interior";
offset?: number | "auto";
}

interface WallCorner extends WallCornerConfig {
to: WallPlaneType;
priority: WallEndPointType;
offset: number | "auto";
}

export class SimpleWallCornerer {
Expand All @@ -30,7 +32,8 @@ export class SimpleWallCornerer {

const to = config.to || "center";
const priority = config.priority || "end";
corners.set(id2, { ...config, to, priority });
const offset = config.offset || "auto";
corners.set(id2, { ...config, to, priority, offset });
}

update(ids: Iterable<number> = this.list.keys()) {
Expand All @@ -45,15 +48,17 @@ export class SimpleWallCornerer {
}
}

extend(corner: WallCornerConfig) {
const { wall1, wall2, to, priority } = corner;
extend(corner: WallCorner) {
const { wall1, wall2, to, priority, offset } = corner;
// Strategy: there are 2 cases
// A) Both points of the wall are on one side of this wall
// In this case, extend its closest point to this wall
// B) Each point of the wall are on one side of this wall
// In that case, keep the point specified in priority

if (wall1.direction.equals(wall2.direction)) {
const dir1 = wall1.direction;
const dir2 = wall2.direction;
if (dir1.equals(dir2)) {
// Same direction, so walls can't intersect
return;
}
Expand Down Expand Up @@ -100,6 +105,11 @@ export class SimpleWallCornerer {
return;
}

const offsetDist = offset === "auto" ? wall2.type.width : offset;
const factor = extendStart ? -1 : 1;
const offsetVec = dir2.multiplyScalar(offsetDist * factor);
intersection.add(offsetVec);

if (corner.cut && corner.cutDirection) {
const planeCut = wall1.planes.get(corner.cut, corner.cutDirection);
wall2.addSubtraction(planeCut);
Expand Down

0 comments on commit 58cfc7a

Please sign in to comment.