Dev.to WebDev 🛠 Dev 👁 0 📖 7 min read

Encoding IRC P2705.1 & NKBA Bathroom Clearances, Door-Arc Collisions, and Tile Takeoffs in Pure TypeScript

Most residential bathroom remodels fail on paper long before a plumber roughs in a flange. A homeowner tries to squeeze a 60-inch double vanity into a 5x8 alcove, a 30-inch inswing door clips an elongated 28-inch toilet

Most residential bathroom remodels fail on paper long before a plumber roughs in a flange. A homeowner tries to squeeze a 60-inch double vanity into a 5x8 alcove, a 30-inch inswing door clips an elongated 28-inch toilet bowl, or a 30x30 shower pan passes minimum building code by a quarter inch while feeling claustrophobic in daily use.

When we built the interactive IRC / NKBA Bathroom Clearance Calculator inside PlanCaliber, a browser-based 2D/3D floor plan and CAD drafting studio, we needed a deterministic pure-TypeScript rules engine (src/lib/cad/bathCalc.ts) with zero runtime dependencies that could:

  1. Distinguish legal code minimums (IRC P2705.1 / R307.1 / P2708.1) from functional comfort guidelines (NKBA) in a single structured pass.
  2. Automatically switch fixture geometry across three common US bathroom topologies (powder_room, single_wall, and primary_suite).
  3. Catch real physical collisions — opposite-wall shower overlap, wet-wall run overflow, and inswing door-arc strikes — and emit exact inch-delta fix hints.
  4. Compute net floor tile and 3-wall wet-surround tile takeoffs with 10% waste directly from the resolved geometry.

Here is how the geometry model and rules engine work under the hood.

1. Why Binary Pass/Fail Lies to Remodelers

In US residential space planning, a simple boolean isValid hides the most important decision a homeowner or designer has to make. Under the International Residential Code (IRC), a 30-inch-wide toilet alcove (15 inches from centerline to each adjacent wall or fixture) and 21 inches of clear floor space in front of the bowl meet code minimums (IRC P2705.1 / R307.1). Yet the National Kitchen & Bath Association (NKBA) recommends a 36-inch alcove (18 inches each side) and 30 inches of front clearance.

To surface that exact distinction without false alarms, every individual check returns a three-state enum, and the whole room rolls up to a three-state summary:

export type BathRuleStatus = 'NKBA_PASS' | 'IRC_PASS_TIGHT' | 'FAIL';
export type BathOverallStatus = 'NKBA_COMFORT' | 'IRC_PASS_TIGHT' | 'CODE_FAIL';
export type BathLayoutMode = 'single_wall' | 'primary_suite' | 'powder_room';

Every BathRuleCheck emits both reference thresholds alongside the actual measurement in fractional inches (1/8" precision) and a concrete fixHint telling the user the exact delta needed to pass code or reach NKBA comfort:

const st: BathRuleStatus =
  toiletSideCenterlineIn < 15
    ? 'FAIL'
    : toiletSideCenterlineIn < 18
      ? 'IRC_PASS_TIGHT'
      : 'NKBA_PASS';

// Example fixHint when FAIL:
// "Widen toilet alcove by at least 2\" to reach the 30\" IRC code minimum."

That three-tier model lets a remodeler working inside a tight 1950s 5x8 footprint immediately see what is a hard code violation (CODE_FAIL) versus what legally passes code while sitting inside the tight band (IRC_PASS_TIGHT).

2. Three-Topology Geometry Classifier (powder_room vs single_wall vs primary_suite)

A bathroom clearance engine cannot treat all rooms as one wall. The same 28-inch elongated toilet projection behaves completely differently depending on whether the room is a narrow 3x6 powder room, a classic 5x8 single-wet-wall hall bath, or an 8x10 two-wall primary suite.

We classify the layout deterministically from the fixture selection and room width:

const layoutMode: BathLayoutMode =
  input.fixtureType === 'none'
    ? 'powder_room'
    : input.roomWidthIn >= 84
      ? 'primary_suite'
      : 'single_wall';

Each topology drives different clearance equations:

A. Single-Wet-Wall Standard Bath (5x8, 5x9, room width < 84")

All plumbing runs along one continuous wall to minimize stack and venting cost: tub or shower at the left end (wetEndDepth), followed by the toilet alcove (toiletAlcoveWidthIn), followed by the vanity (vanityWidthIn).

const autoToiletFront = input.roomWidthIn - input.toiletProjectionIn;
vanityFrontClearIn = input.roomWidthIn - input.vanityDepthIn;

wetWallUsedIn = wetEndDepth + input.toiletAlcoveWidthIn + input.vanityWidthIn;
const lengthOverflow = Math.max(0, wetWallUsedIn - input.roomLengthIn);
const widthOverflow = Math.max(0, wetSpanWidth - input.roomWidthIn);
wetWallOverflowIn = Math.max(lengthOverflow, widthOverflow);

Notice how 5x8 (60" x 96") lands right on the razor's edge: a 30" alcove tub + 30" toilet alcove + 36" vanity sums to exactly 96" (0" overflow). Upgrading to a 32" tub or a 42" vanity without lengthening the room immediately triggers a wall_run_fit failure with the exact overflow in inches.

B. Two-Wall Primary Suite (roomWidthIn >= 84")

At 7 feet wide or more, fixtures split across opposite walls: vanity + toilet along the top wall, shower/tub + entry door along the bottom wall. Here, the naive formula roomWidthIn - toiletProjectionIn would be dangerously wrong whenever a wide walk-in shower extends far enough horizontally to sit directly across from the toilet bowl.

We test horizontal overlap explicitly before computing front clearances:

const vanityEndX = input.vanityWidthIn;
const toiletStartX = vanityEndX;

const showerOverlapsVanity = wetLen > 0;
const showerOverlapsToilet = wetLen > toiletStartX + 2;

const autoToiletFront =
  input.roomWidthIn - input.toiletProjectionIn - (showerOverlapsToilet ? wetDepth : 0);
vanityFrontClearIn =
  input.roomWidthIn - input.vanityDepthIn - (showerOverlapsVanity ? wetDepth : 0);

That 2" tolerance avoids false positives when a glass shower panel terminates right at the vanity-to-toilet boundary, while immediately subtracting wetDepth if a 60" or 72" shower overlaps into the toilet's front legroom zone.

C. Galley Powder Room (fixtureType === 'none')

With no tub or shower, the toilet mounts on the left end wall facing a shallow (18" or 21") vanity on the right end wall, leaving a shared middle zone:

const clearMiddle = input.roomLengthIn - input.toiletProjectionIn - input.vanityDepthIn;
toiletFrontClearIn = input.toiletFrontClearOverrideIn ?? clearMiddle;
vanityFrontClearIn = clearMiddle;

In a classic 36" x 72" (3x6) powder room with a 28" toilet and 18" shallow vanity, clearMiddle is 72 - 28 - 18 = 26" — legally passing the 21" IRC minimum (IRC_PASS_TIGHT), whereas swapping in a 21" standard vanity plus a 30" toilet collapses clearMiddle to 21" right at the code cliff.

3. Double-Vanity Center-to-Center Math (vanityWidthIn - 30)

Double vanities are one of the most frequent IRC failures in remodels. IRC P2705.1 requires:

  • At least 15" from each sink's centerline to the nearest side wall, AND
  • At least 30" center-to-center between adjacent lavatories (NKBA recommends 36" center-to-center).

When a cabinet has two bowls pinned at the 15" minimum edge inset on both ends, the maximum center-to-center spacing available between the two drains is simply:

const doubleSinkCenterToCenterIn =
  input.sinkCount === 2 ? input.vanityWidthIn - 30 : null;

That one-line invariant immediately explains why a 48" or 54" double-sink vanity cannot meet IRC (48 - 30 = 18" OC < 30"), why 60" is the exact IRC minimum (60 - 30 = 30" OC -> IRC_PASS_TIGHT), and why 66"+ is needed to hit NKBA's 36" elbow-room guideline (NKBA_PASS).

4. Catching Inswing Door-Arc Collisions Without Heavy Polygon Clipping

Door collisions ruin real floor plans, especially when an existing 30" or 32" interior door swings inward into a 60"-wide hall bath. Rather than running a general-purpose polygon intersection library for orthogonal bathroom layouts, we evaluate the exact horizontal X-span overlap and perpendicular swing clearance per topology:

// Single-wall bath: door sits on bottom right wall opposite the vanity/toilet run
const doorX = Math.max(wetEndDepth + 2, input.roomLengthIn - input.doorWidthIn - 3);
const doorOverlapsToiletX = doorX < toiletEndX - 1;
const doorHitsToilet =
  input.doorType === 'inswing' &&
  doorOverlapsToiletX &&
  input.doorWidthIn > autoToiletFront;

const swingFail =
  input.doorType === 'inswing' &&
  (input.doorWidthIn > doorSwingAvailableIn || doorHitsToilet);
const swingTight =
  input.doorType === 'inswing' &&
  !swingFail &&
  doorSwingAvailableIn - input.doorWidthIn < 4;

Look at what happens on our standard 5x8 preset (60" wide, 28" toilet projection, 21" vanity):

  • Clear floor in front of the vanity is 60 - 21 = 39".
  • Clear floor in front of the toilet is 60 - 28 = 32".
  • A 30" inswing door clears the toilet by only 2" if it overlaps horizontally — or collides outright if someone swaps in a 32" accessible door (32 > 32 / < 4" tight margin).
  • Switching doorType to 'pocket' or 'outswing' zeroes out the inswing encroachment immediately, letting the user test trade-offs in real time on the live 2D SVG plan.

5. Deterministic Tile & Wet-Surround Takeoffs

Once the fixture boxes resolve, computing preliminary floor tile and tub/shower surround tile quantities takes eight lines of arithmetic — subtracting the tub/shower and vanity footprints from gross room area, adding 10% standard cut/breakage waste, and sizing a 3-wall wet surround to 72 inches (6'-0") above the pan:

const grossFloorSqFt = round1((input.roomWidthIn * input.roomLengthIn) / 144);
const wetFixtureSqFt = wetDims ? round1((wetDims.w * wetDims.d) / 144) : 0;
const vanitySqFt = round1((input.vanityWidthIn * input.vanityDepthIn) / 144);
const netTileFloorSqFt = round1(Math.max(0, grossFloorSqFt - wetFixtureSqFt - vanitySqFt));
const tileOrderWith10PctWasteSqFt = Math.ceil(netTileFloorSqFt * 1.1);

// Preliminary 3-wall tub/shower surround tile estimate (72" height)
const wetWallSurroundSqFt = wetDims
  ? Math.ceil((((wetDims.w + wetDims.d * 2) * 72) / 144) * 1.1)
  : 0;

Because the entire module is pure TypeScript with clamped finite inputs (clamp(v, min, max)), every slider drag or numeric edit updates all 7 code checks, the dimensioned 2D plan preview, and the tile quantities in under a millisecond on the client — and our Node test suite verifies every single IRC/NKBA boundary (15", 18", 21", 30", 36", 900 sq in, door collisions, and overflow) directly without a browser.

Try the Live Calculator & 2D/3D Bathroom Studio

You can test your own room dimensions, switch between 5x8, 5x9, 8x10, and 3x6 presets, and push the verified footprint straight into our 2D/3D CAD editor:

Drafting, live 3D cutaway views, and clearance checks are free in the browser with no account required. When you want unwatermarked 1/4"=1'-0" vector PDFs (A-101 + M-101), 2400px PNG, and SVG, the one-time Clean Print & Share Pass is $9 (or $19 once for the full 5-sheet CAD package including layered AutoCAD R12 .DXF, 3D .OBJ, and framing/drywall .CSV), backed by a 14-day instant refund policy. (PlanCaliber produces preliminary space-planning drawings — always field-verify dimensions and confirm local building department requirements with your AHJ or licensed professional before construction.)

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.