Most residential remodel mistakes are not aesthetic problems. They are arithmetic problems that nobody caught before framing went up: a 28-inch toilet alcove where the plumber cannot hit the 15-inch centerline rule, a kitchen island that leaves 34 inches behind an open dishwasher door, a stair opening cut 10 inches too short for 6'-8" headroom, or a basement casement window whose hardware trims clear width down to 19.5 inches.
When we built PlanCaliber, a browser-based 2D/3D floor plan and drafting engine in TypeScript, we wanted every layout edit to run through a deterministic clearance linter in real time — the same way a compiler catches type errors while you type, instead of after demolition.
Here is how we modeled US residential clearance rules (IRC R310 egress, IRC R311.7 stairs, IRC P2705.1/R307.1 bathrooms, and NKBA kitchen/bath comfort guidelines) in pure, zero-dependency TypeScript — and the subtle geometric and floating-point edge cases that broke our first implementations.
(Important note: automated geometry checks are preliminary space-planning aids only. Local jurisdictions amend the IRC every cycle, and all dimensions, rough openings, and code requirements must be verified on site before construction.)
1. Why Floating-Point Formatting Breaks Architectural Linting (11'-12")
In residential drafting, everything is measured in inches — and usually rounded to the nearest 1/4" or 1/8" for framing and trim callouts.
The classic bug in JavaScript CAD tools happens when you format feet and inches by separately calling Math.floor(inches / 12) and Math.round((inches % 12) * 8) / 8. Pass 143.96 inches (just shy of 12'-0"), and the fractional inch rounds up to 12", printing 11'-12" right onto a scaled drawing sheet.
We eliminated that entire class of bug by quantizing into integer eighths before splitting feet, whole inches, and remainder fractions:
export function formatFeetInchesEighths(inches: number): string {
if (!Number.isFinite(inches)) return `0'-0"`;
const sign = inches < 0 ? '-' : '';
const totalEighths = Math.round(Math.abs(inches) * 8);
const feet = Math.floor(totalEighths / 96);
const remEighths = totalEighths % 96;
const wholeInches = Math.floor(remEighths / 8);
const fracEighths = remEighths % 8;
if (fracEighths === 0) return `${sign}${feet}'-${wholeInches}"`;
return `${sign}${feet}'-${wholeInches} ${eighthFractionLabel(fracEighths)}"`;
}
Because 96 eighths equals exactly 12 inches, 143.96" quantizes cleanly to totalEighths = 1152, yielding 12'-0" every time with zero drift.
2. Three-Tier Severity: Hard Code Floors vs. Ergonomic Comfort
One design mistake in early drafts was treating every rule as a binary PASS | FAIL.
In real US residential projects, there is a sharp difference between minimum code compliance (what fails an inspection) and NKBA comfort guidelines (what makes a room unpleasant to use every day):
-
Bathroom toilet centerline (IRC P2705.1 / R307.1 vs. NKBA): IRC requires at least
15"from centerline to any side wall or vanity (30"total alcove width). NKBA recommends18"(36"alcove). A32"alcove passes IRC code, so marking itFAILmisleads remodelers — yet calling it ideal hides how cramped a32"toilet bay feels. -
Toilet front clearance: IRC requires
21"clear in front of the bowl; NKBA recommends30". -
Kitchen island work aisle:
36"is tight for an active work zone with appliances; NKBA recommends42"for a single cook and48"for two cooks.
So in our bathroom engine (bathCalc.ts), every rule returns a typed three-state verdict:
export type BathOverallStatus = 'NKBA_COMFORT' | 'IRC_PASS_TIGHT' | 'CODE_FAIL';
export type BathRuleStatus = 'NKBA_PASS' | 'IRC_PASS_TIGHT' | 'FAIL';
export interface BathRuleCheck {
id: string;
label: string;
codeRef: string;
actual: string;
actualIn: number;
ircMin: string;
nkbaRec: string;
status: BathRuleStatus;
fixHint: string;
}
Every rule carries its exact actualIn value, both reference thresholds (ircMin and nkbaRec), and a concrete fixHint computed from the delta (for example, switching an inswing bathroom door to a pocket or outswing door when the swing arc collides with the toilet bowl). You can test this exact three-tier engine live in our Bathroom Clearance Calculator.
3. Kitchen Islands: Modeling Work Aisles, Seating Overhangs, and Perimeter Layouts
A naive kitchen island calculator simply subtracts islandWidth and 2 * 24" base cabinets from room width. In practice, three real-world variables break that formula:
-
Countertop overhang vs. cabinet box depth: Base cabinets are
24"deep, while countertops typically project25.5"and counter-depth refrigerators project28"–30". -
Perimeter layout (
l_shape|u_shape|galley): A U-shaped kitchen has perimeter cabinets on three walls, whereas an L-shaped kitchen leaves one walkway wall open to a dining or great room. -
Bar-stool seating overhang (
none|12"|15"): Adding a15"seating overhang on the back of an island changes the required clearance behind stools from36"(walkway only) to44"–60"depending on whether traffic walks behind seated diners.
Separating lock_work_aisle placement (anchoring the primary cook aisle at 42" or 48" and letting the dining-side walkway absorb the remainder) from centered placement catches tight pinch points immediately. Try swapping between L-shape, U-shape, and galley layouts in our interactive Kitchen Island Clearance Calculator or our Kitchen & Bath Floor Plan Studio.
4. Stairs (IRC R311.7): Why Headroom Dictates the Floor Cutout
The trickiest geometric calculation in our residential linter is not riser count — it is the minimum floor opening cutout needed to preserve 80" (6'-8") of vertical headroom all the way down the stair run.
Given lower-floor ceiling height H_ceil, upper floor assembly thickness T_floor (joists + subfloor + finish floor), unit riser r <= 7.75", and tread run d >= 10", the critical clearance line runs parallel to the stair nosing plane at a vertical offset of 80". If a basement or two-story framing cutout stops too early, the header joist drops below 80" above the 3rd or 4th tread down.
In TypeScript (computeStairMetrics), we derive:
- Optimal integer riser count
N = Math.ceil(totalRiseIn / 7.75)(minimizing run while guaranteeingunitRiserIn <= 7.75") - Tread count
N - 1and total horizontal run(N - 1) * treadRunIn - Exact ceiling-cutout projection from the upper landing nosing so the vertical drop to the nosing plane clears
80"plus framing allowance - Diagonal stringer hypotenuse and standard 2×12 lumber stock length (
recommendedLumberFt)
You can verify riser/tread ratios, slope angles, and framing cutouts live in our Stair Stringer & Headroom Calculator.
5. Basement & Bedroom Egress Windows (IRC R310): Sash Type Changes Everything
Homeowners routinely buy a 36" × 48" double-hung window thinking 3 × 4 = 12 sq ft easily clears IRC R310's 5.7 sq ft net clear opening (5.0 sq ft at grade level).
In reality, a double-hung window only opens half its height minus sash and frame rails — leaving less than 4.5 sq ft of clear pass-through area and failing inspection. A slider loses half its width; a casement swings open nearly full width minus hinge intrusion.
Modeling EgressWindowType = 'casement' | 'double_hung' | 'slider' explicitly lets our linter evaluate all four independent IRC R310 checks simultaneously:
- Net clear opening area (
>= 5.7 sq ftbasement/upper story,>= 5.0 sq ftgrade level) - Net clear opening width (
>= 20") - Net clear opening height (
>= 24") - Finished sill height above floor (
<= 44")
Test casement vs. double-hung vs. slider dimensions in our IRC Egress Window Calculator or open a basement/ADU template directly in our ADU & Basement Floor Plan Studio.
6. Compiling the Linter Directly onto Blueprint Sheet A-102
Because the exact same TypeScript rules power both our standalone calculators and the live 2D/3D studio canvas, clicking export compiles every clearance check directly onto Sheet A-102 (Clearance & Code Audit) inside our 5-sheet vector PDF package alongside true-scale 1/4"=1'-0" floor plans (A-101), electrical layouts (E-101), ANSI Z765 GLA schedules (A-201), clean white MLS sheets (M-101), and layered AutoCAD R12 .DXF files.
You can inspect a real unlocked output right now with zero account required: Open the 5-Sheet Scaled Vector Sample PDF.
Drafting, live 3D cutaway viewing, ANSI Z765 GLA, and all clearance checks are free right in your browser (including 2 AI sketch/PDF scans per day). When a layout is ready to share or hand to a contractor, clean unwatermarked PDF/PNG/SVG exports are $9 one-time (Clean Print & Share Pass) or $19 one-time for the full 5-sheet CAD package + layered AutoCAD R12 .DXF, 3D .OBJ, and material takeoff .CSV — no subscription, 30 days of free edits, and a 14-day instant refund.
Top comments (0)