When an LLM generates a residential floor plan—or when a homeowner drafts a kitchen or bathroom remodel by hand—the failures are rarely aesthetic. They are geometric.

A 32-inch bathroom door swings straight into the edge of a vanity. A kitchen island looks balanced in a 10×12 room until you realize there are only 22 inches between the island edge and the dishwasher door. A guest bedroom in a finished basement has 110 square feet of floor area, but no exterior egress window.

Standard CAD suites treat walls, openings, and fixtures as dumb line segments and blocks. An LLM asked to "make sure the layout follows residential clearances" will confidently reply "Yes, the 42-inch work aisles look great" while outputting coordinates that leave 19 inches of clearance.

For PlumbDraft—our US imperial 2D/3D browser CAD studio and hosted MCP server—we built a zero-dependency, deterministic clearance linter (validateClearances) in pure TypeScript that runs identically in the browser, on Cloudflare Workers, and inside our hosted MCP tool chain at https://www.plumbdraft.com/mcp.

Here is how the geometry engine works under the hood, the six checks that catch 90% of real residential layout bugs, and how exposing it over MCP turns one-shot LLM layouts into self-correcting plans.

1. Why Centerline Coordinates + Pure AABB Math Beat Heuristics

Every PlumbDraft floor plan is stored in exact US inches (integer or quarter-inch increments): walls carry (x1, y1, x2, y2, thicknessIn, isExterior), openings sit at a parametric offsetIn along a wallId with widthIn and swing, and fixtures carry (x, y, widthIn, depthIn, rotationDeg, kind, category).

Before running any clearance rules, the linter compiles the raw plan (compileFloorPlan) so closed room polygons, net areas, and perimeters are mathematically derived from wall intersections rather than trusting user- or LLM-supplied room labels.

For rotated fixtures (a 60" double vanity rotated 90° along a west bathroom wall, or a toilet rotated 180°), computing exact axis-aligned bounding boxes takes six lines of trigonometry:

interface AABB { minX: number; minY: number; maxX: number; maxY: number; } function furnitureAABB(item: FurnitureItem): AABB { const rad = ((item.rotationDeg || 0) * Math.PI) / 180; const c = Math.abs(Math.cos(rad)); const s = Math.abs(Math.sin(rad)); const halfW = (item.widthIn * c + item.depthIn * s) / 2; const halfD = (item.widthIn * s + item.depthIn * c) / 2; return { minX: item.x - halfW, minY: item.y - halfD, maxX: item.x + halfW, maxY: item.y + halfD }; } function aabbDistance(a: AABB, b: AABB): number { const dx = Math.max(0, Math.max(a.minX - b.maxX, b.minX - a.maxX)); const dy = Math.max(0, Math.max(a.minY - b.maxY, b.minY - a.maxY)); return Math.hypot(dx, dy); } 

Because aabbDistance returns exact Euclidean edge-to-edge separation in inches—and 0 when two boxes touch or overlap—we can evaluate kitchen aisles and bathroom clearances without any heavy computational geometry library.

2. Detecting Door Swing Collisions From Parametric Wall Openings

One of the most frequent bugs we saw in real user and AI-generated plans was a hinged door swinging into a toilet, nightstand, or workbench.

Because openings are parametric along their parent wall, we first derive the unit tangent (ux, uy) and left-hand normal (nx, ny) of the host wall, flip the normal sign according to swing (left_in / right_in vs left_out / right_out), and project the swept rectangle of the door leaf (widthIn for single doors, widthIn / 2 per leaf for double French doors):

function doorSwingAABB(wall: Wall, op: Opening): AABB { const len = wallLengthIn(wall); const ux = (wall.x2 - wall.x1) / Math.max(1e-6, len); const uy = (wall.y2 - wall.y1) / Math.max(1e-6, len); const nx = -uy; const ny = ux; const center = openingCenter(wall, op); const halfW = op.widthIn / 2; const leafLen = op.type === 'door_double' ? op.widthIn / 2 : op.widthIn; const outSign = op.swing === 'left_out' || op.swing === 'right_out' ? -1 : 1; const p1 = { x: center.x - ux * halfW, y: center.y - uy * halfW }; const p2 = { x: center.x + ux * halfW, y: center.y + uy * halfW }; const p3 = { x: p1.x + nx * outSign * leafLen, y: p1.y + ny * outSign * leafLen }; const p4 = { x: p2.x + nx * outSign * leafLen, y: p2.y + ny * outSign * leafLen }; return { minX: Math.min(p1.x, p2.x, p3.x, p4.x), minY: Math.min(p1.y, p2.y, p3.y, p4.y), maxX: Math.max(p1.x, p2.x, p3.x, p4.x), maxY: Math.max(p1.y, p2.y, p3.y, p4.y) }; } 

When testing intersections against furnitureAABB(furn), we pass a -2 inch inset margin (aabbIntersects(swingBox, fBox, -2)). Why? Because trim, casings, and tight bathroom layouts often place a vanity or baseboard within 1–2 inches of a door's outer tangent without actually obstructing the leaf swing. A small negative epsilon eliminates false positives while still catching every genuine collision.

3. Six Concrete Residential Checks (IRC & NKBA Reference Rules)

Our linter outputs structured ClearanceIssue objects (pass | info | warning) with exact measuredIn, recommendedIn, code, location, and targetId, plus a 0–100 ergonomic score:

  1. Hallway Clear Width (HALL_WIDTH — IRC R311.6): Computes the narrowest bounding span of every hallway room polygon and subtracts 4.5" (two halves of adjacent 2×4 interior framed partitions) to measure actual clear width rather than wall-centerline width. Flags anything under 36".
  2. Exterior & Interior Door Widths (ENTRY_DOOR_WIDTH / DOOR_WIDTH): Flags exterior hinged entry doors narrower than 36" and interior doors below 24" (with an info note between 24" and 29.75" for closets/pantries).
  3. Door Swing Clearance (DOOR_SWING): Tests every hinged opening's swept box against every placed fixture.
  4. Bedroom Area & Egress Window (BEDROOM_AREA / BEDROOM_EGRESS — IRC R304.1 & R310): Checks every bedroom room for >= 70 sq ft and verifies that at least one exterior window opening sits within 6" of an edge of that bedroom's compiled polygon using pointToSegmentDist.
  5. Kitchen Island Work Aisle (KITCHEN_AISLE — NKBA): Measures minimum edge-to-edge distance from each kitchen_island to surrounding appliances/counters. Anything < 36" triggers a warning; 36"–41.9" returns an info note; >= 42" passes single-cook NKBA guidelines. You can test this interactively on our Kitchen Remodel Layout Clearance Checker or our 10×12 Kitchen Remodel Template and 12×12 Island Kitchen Template.
  6. Bathroom Toilet Clearance (BATH_CLEARANCE — IRC R307.1): Measures separation between every toilet and adjacent bath fixtures (vanities, tubs, showers) to catch tight side/front spacing before framing—something homeowners constantly hit in compact 5×8 and 8×10 Master Bathroom remodels.

(Note: PlumbDraft's clearance check is a conceptual space-planning reference, not a licensed architectural or code compliance review—local building departments always have final jurisdiction.)

4. Closing the Loop Over MCP (audit_floor_plan + resources/read)

Where this gets especially interesting is when AI coding agents use PlumbDraft over the Model Context Protocol (https://www.plumbdraft.com/mcp, documented at plumbdraft.com/developers).

Instead of asking an agent to guess wall coordinates from scratch and hoping for the best, the agent can run a tight deterministic loop:

  1. Read a verified baseline from our 24 pre-dimensioned US imperial starter templates via resources/read (for example plumbdraft://templates/adu_2br_800 or plumbdraft://templates/kitchen_island_12x12).
  2. Modify walls, openings, or fixtures to match the user's lot or remodel constraints.
  3. Call audit_floor_plan (free, unauthenticated) and inspect the structured issues[] array.
  4. If DOOR_SWING or KITCHEN_AISLE reports measuredIn: 28, recommendedIn: 42, shift the fixture by 14 inches and re-audit until score === 100.
  5. Call calculate_material_takeoff (free) for 16" OC framing studs, plates, drywall sheets, and flooring, then call share_floor_plan to return an interactive 2D/3D web link the user can inspect and tweak directly in their browser.

That pattern—deterministic geometric verification wrapped in a clean JSON/MCP contract—eliminates the biggest failure mode of AI spatial design without needing a heavier model.

Try It Yourself