Ask a multimodal vision model to trace a hand-drawn floor plan into vector JSON coordinates in inches, and you will see two silent coordinate-unit bugs over and over again in production:
-
Pixel-space drift: The model reads a
1920x1080photo or PDF raster, emits vertex coordinates from0to2160straight out of image pixel space, and your CAD solver interprets them as180'-0" x 160'-0"(15,000+ sq ft) for an ordinary three-bedroom house. -
Normalized-space or feet-as-inches drift: The model outputs coordinates on a
0..100normalized grid — or accidentally writes feet (32,24) into fields typed as inches — turning an entire six-room house into a6'-8" x 5'-1"(41 sq ft) dollhouse where a single36"interior door is wider than the wall holding it.
Worse still: if your parser reads a printed label like "14'-6" from the sketch (readDimensionInches = 174) and flips calibrated: true without actually applying the scale ratio to the vertex graph, your UI tells the user their drawing is calibrated while every single exported PDF dimension and .DXF entity is off by 4x to 12x.
When we hardened the AI Sketch/PDF-to-CAD pipeline inside PlanCaliber alongside our free Floor Plan Scale Calculator, we pulled all scale-normalization logic out of the prompt layer and into a pure, deterministic TypeScript module (sketch-scale.ts) that runs on every traced plan before geometry healing or export.
Here is the exact architecture and TypeScript implementation.
1. Why Prompt Engineering Alone Cannot Guarantee Architectural Units
You should still put an explicit units reminder inside your vision extraction prompt (for example, reminding the model that a 30 ft residential exterior wall must span 360 units, not 30 feet and not 1500 pixels). Prompts reduce the error rate, but they never reduce it to zero because vision models attend to multiple coordinate frames simultaneously:
- Image bounding-box coordinates (
0..1000or raw pixel dimensions) - Architectural labels written in feet (
12',24.5',14'-6") - Metric drawings (
4.2 mor4200 mm) uploaded without unit toggles - Unlabeled napkin sketches where the model has to infer scale from fixture proportions (
36"doors,24"kitchen counters,60"tubs)
In CAD software, coordinate scale is an invariant, not a suggestion. A deterministic post-processing guard catches unit-frame errors cleanly every single time.
2. Computing Plan Extents and Safe Geometry Scaling
Before checking scale plausibility, we measure the axis-aligned bounding box of the extracted vertex graph in inches:
export const MIN_KNOWN_WALL_IN = 24; // 2'-0" minimum reference wall
export const MAX_KNOWN_WALL_IN = 3600; // 300'-0" maximum reference wall
export const MIN_SCALE_FACTOR = 0.02; // handles 50x pixel-space shrink
export const MAX_SCALE_FACTOR = 50; // handles 50x normalized-grid expansion
export function getPlanExtentsInches(doc: PlanDocument) {
if (!doc.vertices.length) {
return { minX: 0, maxX: 0, minY: 0, maxY: 0, widthIn: 0, heightIn: 0, maxSpanIn: 0 };
}
let minX = Infinity, maxX = -Infinity;
let minY = Infinity, maxY = -Infinity;
for (const v of doc.vertices) {
if (v.x < minX) minX = v.x;
if (v.x > maxX) maxX = v.x;
if (v.y < minY) minY = v.y;
if (v.y > maxY) maxY = v.y;
}
const widthIn = Math.max(0, maxX - minX);
const heightIn = Math.max(0, maxY - minY);
return { minX, maxX, minY, maxY, widthIn, heightIn, maxSpanIn: Math.max(widthIn, heightIn) };
}
Notice the widened [0.02, 50] scale-factor guard. An earlier version capped calibration factors at [0.1, 12] — which looks reasonable until a user uploads a 4K scan whose extracted wall is 2400 pixel units long and enters a real-world 12'-0" (144") reference wall (factor = 0.06, silently rejected!). Widening the factor envelope to 0.02..50 covers both 4K pixel-space extractions and 0..100 normalized boxes in one uniform transform.
3. Scaling Vertices Without Breaking Doors, Windows, or Fixtures
A naive uniform rescale multiplies (x, y) on vertices and forgets three dependent collections:
-
Opening offsets vs. opening widths: When a wall shrinks from
2400pixel units down to144", a door's center offset along that wall (offsetIn) must scale byfactor, while its physical opening width (widthIn, e.g.,32"or36") must not scale down to1.9"— instead it stays in real architectural inches and clamps safely inside[18", wallLen - 4"]. -
Furniture and plumbing fixture anchors: Every fixture
(x, y)anchor scales byfactorwhile keeping its real-world footprint (widthIn,depthIn) intact. -
Room tag anchors: Room label
(anchorX, anchorY)points must scale byfactorso labels stay centered inside their solved room polygons instead of floating outside the building.
We round every rescaled coordinate to the nearest half-inch (0.5") so downstream planar wall-graph healing and 1/4" = 1'-0" vector PDF dimension strings stay crisp:
function roundHalfIn(val: number): number {
return Math.round(val * 2) / 2;
}
export function scalePlanGeometry(
doc: PlanDocument,
factor: number,
opts?: { calibrated?: boolean; calibrationWallId?: string }
): PlanDocument {
if (!Number.isFinite(factor) || factor < MIN_SCALE_FACTOR || factor > MAX_SCALE_FACTOR) {
return doc;
}
const scaledVertices = doc.vertices.map((v) => ({
...v,
x: roundHalfIn(v.x * factor),
y: roundHalfIn(v.y * factor)
}));
const vMap = new Map(scaledVertices.map((v) => [v.id, v]));
const wallLenMap = new Map<string, number>();
for (const w of doc.walls) {
const a = vMap.get(w.startId);
const b = vMap.get(w.endId);
if (a && b) wallLenMap.set(w.id, Math.hypot(b.x - a.x, b.y - a.y));
}
const scaledOpenings = doc.openings.map((op) => {
const wallLen = wallLenMap.get(op.wallId);
const baseWidth = Number.isFinite(op.widthIn) && op.widthIn > 0 ? op.widthIn : 36;
const clampedWidth =
wallLen && wallLen > 12
? roundHalfIn(Math.min(Math.max(18, baseWidth), Math.max(18, wallLen - 4)))
: roundHalfIn(Math.max(18, baseWidth));
const rawOffset = roundHalfIn(op.offsetIn * factor);
const clampedOffset =
wallLen && wallLen > clampedWidth + 4
? roundHalfIn(Math.min(wallLen - clampedWidth / 2 - 2, Math.max(clampedWidth / 2 + 2, rawOffset)))
: wallLen
? roundHalfIn(wallLen / 2)
: rawOffset;
return { ...op, widthIn: clampedWidth, offsetIn: clampedOffset };
});
return {
...doc,
calibrated: opts?.calibrated !== undefined ? opts.calibrated : doc.calibrated,
calibrationWallId:
opts?.calibrationWallId !== undefined ? opts.calibrationWallId : doc.calibrationWallId,
vertices: scaledVertices,
openings: scaledOpenings,
fixtures: doc.fixtures.map((fx) => ({
...fx,
x: roundHalfIn(fx.x * factor),
y: roundHalfIn(fx.y * factor)
})),
roomTags: doc.roomTags.map((rt) => ({
...rt,
anchorX: roundHalfIn(rt.anchorX * factor),
anchorY: roundHalfIn(rt.anchorY * factor)
}))
};
}
4. The Three-Tier Calibration Hierarchy
With scalePlanGeometry and applyKnownWallScale in place, normalizeVisionSketchScale runs a strict three-tier hierarchy on every vision or text-to-CAD output:
-
Tier 1 — User-entered known wall (
hasKnownWall && knownWallInches): If the user explicitly typed a real-world reference length for a wall, we trust it, computefactor = knownWallInches / currentLen, scale the graph, and setcalibrated: true. -
Tier 2 — OCR-detected wall dimension (
readDimensionInches+suggestedWallId): If the vision model read a printed dimension label directly off the sketch, we actually applyapplyKnownWallScale(never just set a flag!) and immediately verify that the resulting overall footprint span sits inside a plausible architectural band (min(72", readDimensionInches)up tomax(1800", readDimensionInches * 4)). If a misread label would blow the building up to400 ftor collapse it to3 ft, we reject that auto-calibration and fall through to Tier 3 withcalibrated: false. -
Tier 3 — Plausibility guard for unlabeled sketches:
-
Pixel-space trap (
maxSpanIn > 1200", i.e.> 100 ft): Without a user-confirmed commercial reference wall, a traced residential upload spanning160' x 180'is pixel coordinates masquerading as inches. We rescale to a realistic baseline span (24'for compact 1–2 room layouts,34'for mid-size plans,44'for 7+ room homes) and setcalibrated: falseso the Studio visibly prompts 1-wall verification. -
Dollhouse trap (
maxSpanIn < 108", i.e.< 9 ft, ANDisMultiRoom): Here is the subtle edge case you do not want to break: a legitimate8'-0" x 6'-0"primary bathroom remodel (4walls,1room tag) should havemaxSpanIn = 96" < 108". So we only trigger the dollhouse rescale whenwalls.length >= 6 || roomTags.length >= 2. Genuine compact single-room remodels stay untouched at exact scale!
-
Pixel-space trap (
function chooseDefaultResidentialSpanIn(doc: PlanDocument): number {
const rooms = doc.roomTags.length;
const walls = doc.walls.length;
if (rooms >= 7 || walls >= 24) return 528; // 44'-0"
if (rooms >= 3 || walls >= 10) return 408; // 34'-0"
return 288; // 24'-0"
}
export function normalizeVisionSketchScale(
doc: PlanDocument,
opts: {
hasKnownWall?: boolean;
knownWallInches?: number;
suggestedWallId?: string;
readDimensionInches?: number;
} = {}
): PlanDocument {
if (opts.hasKnownWall && opts.knownWallInches) {
const res = applyKnownWallScale(doc, opts.suggestedWallId, opts.knownWallInches);
return res.applied ? res.doc : { ...doc, calibrated: false };
}
let working = doc;
if (opts.readDimensionInches && opts.suggestedWallId) {
const res = applyKnownWallScale(doc, opts.suggestedWallId, opts.readDimensionInches);
if (res.applied) {
const ext = getPlanExtentsInches(res.doc);
const minPlausible = Math.min(72, opts.readDimensionInches);
const maxPlausible = Math.max(1800, opts.readDimensionInches * 4);
if (ext.maxSpanIn >= minPlausible && ext.maxSpanIn <= maxPlausible) {
return res.doc;
}
}
working = { ...doc, calibrated: false };
}
const ext = getPlanExtentsInches(working);
const isMultiRoom = working.walls.length >= 6 || working.roomTags.length >= 2;
if (ext.maxSpanIn > 1200) {
const factor = chooseDefaultResidentialSpanIn(working) / ext.maxSpanIn;
return scalePlanGeometry(working, factor, { calibrated: false });
}
if (ext.maxSpanIn > 0 && ext.maxSpanIn < 108 && isMultiRoom) {
const factor = chooseDefaultResidentialSpanIn(working) / ext.maxSpanIn;
return scalePlanGeometry(working, factor, { calibrated: false });
}
return working;
}
5. Four Regression Tests Worth Shipping Before Touching Production
Every coordinate bug in a CAD pipeline should be locked down with deterministic unit tests that run in milliseconds:
-
Pixel-space upload (
160' x 180'->1920" x 2160"): VerifynormalizeVisionSketchScaleshrinks the span into realistic residential bounds (<= 528"), keepscalibrated === false, and keeps door widths valid (>= 18") and inside their parent walls. -
Normalized-grid multi-room upload (
6.7' x 5.1'across10+walls): Verify the dollhouse rescale expands coordinates to residential scale (~34') withcalibrated === falseand clamps door offsets cleanly. -
Legible
readDimensionInchesOCR match: Verify a1000-unit raw pixel wall paired withreadDimensionInches: 240(20'-0") rescales the entire building by0.24xand setscalibrated === true. -
Genuine compact single-room plan (
8'-0" x 6'-0"bathroom,4walls,1room): VerifynormalizeVisionSketchScaleleaves every single vertex coordinate completely untouched at96" x 72".
Try It Live on Your Own Sketch or PDF
If you want to see deterministic scale calibration, planar wall-graph healing, live 2D/3D cutaways, and true-scale 1/4" = 1'-0" vector PDF / layered AutoCAD R12 .DXF export working in the browser with no desktop install:
- Upload a hand sketch or PDF directly in PlanCaliber Studio (draft, trace, and inspect 2D + 3D free in your browser — no account required).
- Check US architectural print scales and sheet fit (
ARCH D,ARCH C,11x17,Letter) with our free Floor Plan Scale Calculator.
Note: PlanCaliber outputs preliminary space-planning and CAD drafting drawings; always field-verify physical dimensions and local building-department requirements on site.
Top comments (0)