Automating IRC and IPC Bathroom Fixture Clearances and Door-Swing Collision Detection in TypeScript
A classic US 5'-0" x 7'-0" bathroom looks generous on a cocktail napkin until the plumbing inspector shows up with a tape measure. Drop a standard 60" x 32" tub along one wall, a 30" vanity next to it, and a toilet tucke
A classic US 5'-0" x 7'-0" bathroom looks generous on a cocktail napkin until the plumbing inspector shows up with a tape measure. Drop a standard 60" x 32" tub along one wall, a 30" vanity next to it, and a toilet tucked into the remaining 28" alcove, and suddenly your toilet centerline is 14" from the vanity cabinet (failing the IRC R307.1 / IPC 405.3.1 15" minimum) while an inward-swinging 28" entry door smacks straight into the toilet bowl.
In PlanCaliber, our 2D CAD engine and free Bathroom Fixture Clearance Calculator check every plumbing fixture clearance box and door-swing arc in TypeScript before a single drain pipe is roughed in. Here is the exact geometry model we run in the browser.
1. Key US Bathroom Fixture Clearance Rules (IRC R307.1 & IPC 405.3.1)
| Bathroom Fixture Rule | IRC / IPC Code Minimum | NKBA Comfort Recommendation |
|---|---|---|
| Toilet Side-to-Centerline |
15" min each side (30" total alcove) |
18" each side (36" alcove) |
| Toilet Front Knee Clearance |
21" min in front of bowl (24" under some state IPC amendments) |
30" comfortable clearance |
| Vanity / Lavatory Front Zone |
21" min clear floor space in front |
30" clear standing zone |
| Shower Interior Minimum |
30" x 30" (900 sq in clear interior) |
36" x 36" or 36" x 60" walk-in |
| Shower Door Entry Clearance |
24" clear outswing landing in front of entry |
30" clear landing |
| Entry Door Swing Clash | Door leaf must not strike toilet or shower glass when opening | Switch to pocket door or outswing in tight 5'x7' baths |
2. TypeScript Fixture Clearance & Door-Swing Arc Collision Engine
Every bathroom fixture carries both its physical footprint rectangle and its code clearance rectangle, while every hinged door defines a quarter-circle sweep arc centered at its hinge pin (hx, hy) with radius doorWidthIn:
export interface RectIn {
x: number; // left edge (inches)
y: number; // top edge (inches)
w: number;
h: number;
}
export interface HingedDoorIn {
hingeX: number;
hingeY: number;
widthIn: number;
startAngleRad: number;
endAngleRad: number; // 90-degree sweep
}
export interface ToiletCheckInput {
alcoveWidthIn: number; // clear side-to-side width between tub/vanity/wall
frontClearanceIn: number; // clear floor ahead of front rim
toiletRect: RectIn; // physical bowl + tank bounding box
entryDoor: HingedDoorIn;
}
export interface BathroomValidationResult {
sideClearancePass: boolean;
frontClearancePass: boolean;
doorSwingClash: boolean;
issues: string[];
}
function pointInsideRect(px: number, py: number, r: RectIn): boolean {
return px >= r.x && px <= r.x + r.w && py >= r.y && py <= r.y + r.h;
}
export function doesDoorArcHitRect(door: HingedDoorIn, rect: RectIn, samples = 24): boolean {
for (let i = 0; i <= samples; i++) {
const t = i / samples;
const angle = door.startAngleRad + t * (door.endAngleRad - door.startAngleRad);
// Sample points along the door leaf from 25% to 100% of leaf width
for (const frac of [0.25, 0.5, 0.75, 1.0]) {
const px = door.hingeX + Math.cos(angle) * door.widthIn * frac;
const py = door.hingeY + Math.sin(angle) * door.widthIn * frac;
if (pointInsideRect(px, py, rect)) {
return true;
}
}
}
return false;
}
export function validateBathroomToiletZone(input: ToiletCheckInput): BathroomValidationResult {
const issues: string[] = [];
const halfAlcove = input.alcoveWidthIn / 2;
const sideClearancePass = halfAlcove >= 15;
const frontClearancePass = input.frontClearanceIn >= 21;
const doorSwingClash = doesDoorArcHitRect(input.entryDoor, input.toiletRect);
if (!sideClearancePass) {
issues.push(
`Toilet side clearance (${halfAlcove.toFixed(1)}" per side) fails IRC R307.1 15" minimum (need >= 30" clear alcove).`
);
}
if (!frontClearancePass) {
issues.push(
`Toilet front clearance (${input.frontClearanceIn}") fails IRC R307.1 21" minimum (24" under IPC).`
);
}
if (doorSwingClash) {
issues.push(
`Entry door (${input.entryDoor.widthIn}" swing) collides with toilet fixture. Switch to a 28" pocket door or flip swing.`
);
}
return { sideClearancePass, frontClearancePass, doorSwingClash, issues };
}
3. Why a 5'-0" x 8'-0" Footprint Solves Almost Every 5'x7' Trap
In a classic 5'-0" x 7'-0" (60" x 84") inline bathroom:
- Tub width along the far
5'-0"wall =32" - Remaining length along the
7'-0"plumbing wall =84" - 32" = 52" - Subtract
30"minimum toilet alcove -> only22"remains for the vanity (too tight for a standard24"or30"vanity cabinet!).
Stretch the room by just 12" to 5'-0" x 8'-0" (60" x 96"), and you immediately unlock 96" - 32" = 64" — cleanly fitting a code-compliant 30" toilet alcove (15" each side) plus a full 34" vanity with zero cramped elbows and clean clearance for a 28" or 30" pocket door!
4. Verify Your Own Bathroom Layout Free in 2D & 3D
Test your exact vanity, tub/shower, toilet alcove, and door swing right now in our free Bathroom Clearance Calculator, browse our Kitchen & Bath Floor Plans hub, or open our pre-built Primary Bath + Walk-In Suite Template inside the PlanCaliber 2D/3D Studio.
Drafting, AI sketch/PDF tracing, and watermarked proof PNG exports are free; clean unwatermarked 1/4"=1'-0" vector PDF sheets start at $9 one-time, and the $19 Full CAD Pack adds layered AutoCAD R12 .DXF, Sheet E-101 electrical plans, 3D .OBJ/.MTL, and framing/drywall .CSV takeoffs. PlanCaliber outputs are preliminary space-planning references; always field-verify framing and local IRC/IPC plumbing code amendments before rough-in.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.