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

How We Unit-Test 40 Residential Floor Plans for Watertight Geometry, ANSI Z765 GLA, and AutoCAD DXF Integrity in TypeScript

When a browser-based floor plan tool ships starter templates, most libraries treat them as static JSON blobs drawn once by hand and forgotten. As soon as you add an electrical layout sheet, an ANSI Z765 Gross Living Area

When a browser-based floor plan tool ships starter templates, most libraries treat them as static JSON blobs drawn once by hand and forgotten. As soon as you add an electrical layout sheet, an ANSI Z765 Gross Living Area calculator, a 16-inch on-center wall framing takeoff, or an AutoCAD R12 .DXF exporter, subtle hand-authored geometry errors turn into broken blueprints:

  • A wall endpoint off by 0.05 feet breaks closed-polygon room detection.
  • A garage or covered porch accidentally tagged as heated space inflates Gross Living Area (GLA) on an MLS listing sheet.
  • A door placed 3.0 feet along a 2.8-foot interior partition floats into mid-air inside AutoCAD.
  • A vanity or kitchen island sits 2 inches too close to an interior door swing.

In PlanCaliber, we maintain 40 editable US residential and light-commercial CAD templates spanning 8x24 tiny houses, 12x16 backyard studios, 24x24 2-car garages, 30x50 barndominiums, and 2,400 sq ft duplexes. Instead of visually eyeballing every template after each engine change, we enforce deterministic CAD invariants in our Node TypeScript test suite (node --experimental-strip-types --test tests/cad.test.ts).

1. The Five Geometric Invariants Every Floor Plan Must Pass

Every single template and parametric room shell passes through the same pure TypeScript validator before shipping:

export interface PlanValidationIssue {
  code: 'ZERO_LENGTH_WALL' | 'OPENING_OUT_OF_BOUNDS' | 'FIXTURE_OUT_OF_SHELL' | 'GLA_MISMATCH' | 'DXF_HEADER_INVALID';
  message: string;
}

export function auditPlanGeometry(plan: FloorPlan): PlanValidationIssue[] {
  const issues: PlanValidationIssue[] = [];
  const wallMap = new Map(plan.walls.map((w) => [w.id, w]));

  // 1. No degenerate zero-length walls
  for (const wall of plan.walls) {
    const len = Math.hypot(wall.x2 - wall.x1, wall.y2 - wall.y1);
    if (!Number.isFinite(len) || len < 0.25) {
      issues.push({
        code: 'ZERO_LENGTH_WALL',
        message: `Wall ${wall.id} has invalid length ${len.toFixed(3)} ft`
      });
    }
  }

  // 2. Every door and window must fit strictly inside its host wall
  for (const opening of plan.openings) {
    const host = wallMap.get(opening.wallId);
    if (!host) {
      issues.push({
        code: 'OPENING_OUT_OF_BOUNDS',
        message: `Opening ${opening.id} references missing wall ${opening.wallId}`
      });
      continue;
    }
    const wallLen = Math.hypot(host.x2 - host.x1, host.y2 - host.y1);
    const halfW = opening.widthFt / 2;
    if (opening.offsetFt - halfW < -0.05 || opening.offsetFt + halfW > wallLen + 0.05) {
      issues.push({
        code: 'OPENING_OUT_OF_BOUNDS',
        message: `Opening ${opening.id} overflows host wall ${host.id} (${wallLen.toFixed(2)} ft)`
      });
    }
  }

  return issues;
}

Checking opening.offsetFt +/- opening.widthFt / 2 catches floating doors and windows immediately, especially when parametric templates scale dynamically from user inputs in our 20 free US code calculators.

2. Enforcing ANSI Z765-2021 Heated GLA vs. Non-GLA Separation

One of the fastest ways a floor plan tool loses credibility with real estate appraisers and builders is lumping unheated garages, shop bays, or covered patios into Heated Gross Living Area (GLA). Under ANSI Z765-2021:

  1. Above-grade finished, continuously heated space with at least 7'-0" ceiling height counts toward Heated GLA (measured to the exterior face of exterior walls).
  2. Detached garages, attached garage bays, barndominium shop bays, unfinished basements, and open decks must be reported separately as Non-GLA.

In our test suite, we explicitly verify both categories on real templates:

3. Verifying AutoCAD R12 .DXF Output on Every Template

Many web floor plan tools export flat SVG or raster PNGs that fall apart when imported into AutoCAD LT, Revit, LibreCAD, or QCAD. Our compiler emits strict ASCII AutoCAD R12 (AC1009) .DXF in Model Space inches ($INSUNITS = 1), separating entities across 8 standard AIA layers with fixed ACI colors:

AIA Layer ACI Color Entities
A-WALL 7 (White/Black) Exterior & interior wall polylines
A-DOOR 30 (Orange) Door panels, jambs, swing arcs, overhead tracks
A-GLAZ 4 (Cyan) Window glazing & sill markers
A-CABN 8 (Dark Gray) Kitchen base/wall cabinets, islands, vanities
A-FURN 9 (Light Gray) Beds, sofas, dining tables, desks, garage stalls
E-POWR 2 (Yellow) Duplex/GFCI outlets, switches, ceiling lights
A-ROOM 3 (Green) Room labels and net interior square footage
A-DIMS 6 (Magenta) Exterior feet-and-inches dimension chains

Our test runner compiles .DXF output across the entire template catalog and asserts:

  1. Header contains AC1009 and $INSUNITS set to 1 (inches).
  2. All expected AIA layer table records exist before ENTITIES.
  3. Zero NaN or Infinity coordinates anywhere in the emitted ASCII stream.
  4. Clean EOF terminator with balanced group-code/value line pairs.

4. Try It Live on Any Template or Custom Footprint

Every template on PlanCaliber opens directly in the browser with zero signup required. You can drag walls, adjust room sizes, inspect the live 3D cutaway, and download a free watermarked proof PNG immediately. When you need clean unwatermarked sheets, a one-time $9 Clean Print Pass exports 2-sheet vector PDFs (A-101 + M-101), 2400px PNG, SVG, and an unbranded 2D/3D share link, while the $19 Full 5-Sheet CAD Pack unlocks all five 1/4"=1'-0" PDF sheets, the 8-layer AutoCAD R12 .DXF, 3D .OBJ/.MTL, and the 16-inch OC framing and drywall takeoff .CSV (backed by a 14-day no-questions-asked refund).

Note: PlanCaliber is a preliminary space-planning and CAD drafting tool. Always field-verify all dimensions, structural framing requirements, and local building codes on site before construction or permit submission.

📰 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.