When someone snaps a photo of a hand-drawn floor plan or traces an existing PDF listing sheet, the geometry starts out in arbitrary pixel coordinates. Turning that rough sketch into true-scale architectural inches (1/4" = 1'-0") and then letting the user type exact laser-measure dimensions—without warping walls into trapezoids, stretching a 30-inch range into a 41-inch monster, or folding an adjacent bathroom inside-out—is one of the trickiest UX and geometry problems in browser-based CAD.
In PlanCaliber, all three operations—1-wall scale calibration, centerline/clear-interior parametric wall resizing, and collinear wall-chain dragging—run deterministically in pure TypeScript with zero external geometry kernels (src/lib/cad/healer.ts).
Here is the exact math and edge-case protection behind each one. (Related: Industry News: Uber Eats driver saves elderly woman aft...)
After tracing a sketch or PDF, a homeowner or appraiser rarely knows the exact pixel-to-inch scale—they know one real tape-measure reading (for example, "this exterior garage wall is 22'-0""). (Related: Amazon responds after delivery drone smashes into garag...)
Naively multiplying every number in the document by factor = targetLengthIn / curLen breaks physical reality:.
Instead, rescalePlanToWall anchors scaling at the plan's bounding-box origin (ox, oy), scales coordinates uniformly, preserves wall thicknesses and fixed appliance sizes, and snaps architectural openings to 2" rough increments and modular cabinets to 3" stock increments:.
Why anchor around (ox, oy) rather than (0, 0)? Because scaling around the world origin flings the floor plan off-screen if the user panned away from (0, 0) before calibrating. Anchoring to the plan's minimum corner keeps the drawing planted right in the viewport.
Recent findings suggest that when a contractor reads a blueprint, walls are typically dimensioned centerline-to-centerline or exterior face-to-face. When a homeowner measures a room with a laser tape measure, they measure clear interior drywall-to-drywall.
If a user types 12'-0" (144") in clear mode on a bedroom wall framed between a 6" exterior wall and a 4.5" interior partition, the true CAD centerline span is not 144"—it is:.
144" + (6" / 2) + (4.5" / 2) = 149.25" (12'-5 1/4").
setWallLength inspects every perpendicular wall (|dir · od| < 0.25) attached to either endpoint and accumulates half of each intersecting wall's thickness:.
Moving just wall.endId along (dirX, dirY) turns a rectangle into a trapezoid. Even worse: if a bedroom sits next to a 4'-0" hallway and the user widens the bedroom by +5'-0", shifting only the shared partition wall pushes it past the far hallway wall, inverting the hallway polygon into a negative-area self-intersecting bowtie.
PlanCaliber solves both in two clean graph passes:.
Right after applying dirX * delta and dirY * delta, every door and window on a stretched or shrunk wall updates its offset proportionally ((op.offsetIn / oldL) * newL) and runs through clampOpeningsInPlace so no jamb ever overlaps a corner (>= 3" minimum return).
Industry observers note that in a real planar floor-plan graph, interior partition T-junctions split a 48'-0" exterior south wall into three separate segments (say 16'-0", 14'-0", and 18'-0"). If the user grabs the middle segment to deepen the whole house by 2'-0", dragging only that single segment punches a jagged step into the exterior envelope.
collectCollinearWallChainVertices computes the seed wall's unit normal (nx, ny) = (-dy/len, dx/len) and floods across connected same-kind (exterior or interior) segments whose endpoints lie within 0.5" of the line and whose direction dot-product with the normal is <= 0.02:.
Restricting the flood by w.kind === seed.kind is essential: an interior partition that happens to align with a jogged exterior wall stays independent unless the user edits it explicitly.
You can test the full workflow right in the browser with no account required:.
Note: PlanCaliber exports are preliminary architectural space-planning and drafting documents; field-verify all measurements on site and consult a licensed architect or structural engineer where permits require stamped drawings.
