{
  "schemaVersion": 1,
  "slug": "rug-size-calculator",
  "category": "household",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "d91cf821c49401e77432b46adbe9bd9635149407a2bbea27b5eea7fbdbad38b5",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/rug-size-calculator.json",
    "src/engine.js"
  ],
  "runtimeSource": "/sources/engine.txt",
  "runtimeHash": "5c888d8898afbdee36267bb9977829e1e2ac568f6677c8ee87469c139864645c",
  "scope": "The compute function records implemented equations, constants, lookup tables and custom rules. Inputs record defaults and allowed values; outputs record precision and units. Defaults are examples, not recommendations. General background references are not evidence for this specific algorithm.",
  "publishedFormula": {
    "formula": "dining: rugLength = tableLength÷12 + 4; rugWidth = tableWidth÷12 + 4; living: rugLength = roomLength − 4, rugWidth = roomWidth − 4",
    "vars": [
      [
        "L",
        "Room length (ft)"
      ],
      [
        "W",
        "Room width (ft)"
      ],
      [
        "T",
        "Dining table size (in)"
      ],
      [
        "t",
        "Room type: living, dining, bedroom, entry, runner"
      ],
      [
        "f_t",
        "Required-size function for type t"
      ],
      [
        "rl/rw",
        "Required rug length/width (ft)"
      ],
      [
        "S",
        "Set of 7 fixed common sizes"
      ],
      [
        "c",
        "Candidate size c = (c_w, c_l) ∈ S"
      ],
      [
        "c*",
        "Nearest common size"
      ],
      [
        "tableWidth",
        "Dining table width (in)"
      ]
    ],
    "note": "Room dimensions are ft; table length/width are in. Dining footprint adds 24 in to each table edge and errors if neither orientation fits. Living uses room dimensions minus 2 ft per edge; other layouts use fixed heuristics. The nearest listed size is selected only if it fits the room; verify furniture and clearance."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const L=roomLength,W=roomWidth;if(!(L>0&&W>0))return {__error:'inputError'};let rl,rw,note;if(roomType==='dining'){const a=tableSize/12+4,b=tableWidth/12+4,fitA=a<=L&&b<=W,fitB=b<=L&&a<=W;if(!fitA&&!fitB)return {__error:'roomTooSmall'};[rl,rw]=fitA?[a,b]:[b,a];note='Leave 24 in of rug on every side of the table';}else if(roomType==='living'){rl=L-4;rw=W-4;if(rl<=0||rw<=0)return {__error:'roomTooSmall'};note='The living-room size leaves an approximate 2 ft border; furniture placement is not included.';}else if(roomType==='bedroom'||roomType==='bedroomKing'){rl=9;rw=roomType==='bedroomKing'?8.33:7;if(!((rl<=L&&rw<=W)||(rw<=L&&rl<=W)))return {__error:'roomTooSmall'};note='Bedroom rug footprint reference; verify it clears the bed, doors and furniture.';}else if(roomType==='entry'){rl=Math.min(8,L-2);rw=Math.min(5,W-2);if(rl<=0||rw<=0)return {__error:'roomTooSmall'};note='Leave about 1 ft of bare floor at each doorway.';}else{rl=L-3;rw=Math.min(3,W-1.5);if(rl<=0||rw<=0)return {__error:'roomTooSmall'};note='Leave about 4–6 in of floor on each side of the runner.';}const common=[[5,8],[6,9],[8,10],[9,12],[10,14],[12,15],[12,18]];let best=null,bd=1e9;for(const c of common){if(!((c[0]<=L&&c[1]<=W)||(c[1]<=L&&c[0]<=W)))continue;const dd=Math.abs(c[0]-rw)+Math.abs(c[1]-rl);if(dd<bd){bd=dd;best=c;}}const commonSize=best?best[0]+' × '+best[1]+' ft':'No listed size fits the room';return {rugLength:rl,rugWidth:rw,commonSize,details:note};",
    "inputs": [
      {
        "name": "roomType",
        "type": "select",
        "default": "living",
        "options": [
          {
            "value": "living"
          },
          {
            "value": "dining"
          },
          {
            "value": "bedroom"
          },
          {
            "value": "bedroomKing"
          },
          {
            "value": "entry"
          },
          {
            "value": "hall"
          }
        ]
      },
      {
        "name": "roomLength",
        "type": "number",
        "default": 16,
        "min": 1,
        "max": 200,
        "step": 0.5,
        "slider": true
      },
      {
        "name": "roomWidth",
        "type": "number",
        "default": 12,
        "min": 1,
        "max": 200,
        "step": 0.5,
        "slider": true
      },
      {
        "name": "tableSize",
        "type": "number",
        "default": 72,
        "min": 12,
        "max": 200,
        "step": 1,
        "slider": true
      },
      {
        "name": "tableWidth",
        "type": "number",
        "default": 36,
        "min": 12,
        "max": 200,
        "step": 1,
        "slider": true
      }
    ],
    "outputs": [
      {
        "name": "rugLength",
        "precision": 1,
        "unit": "ft"
      },
      {
        "name": "rugWidth",
        "precision": 1,
        "unit": "ft"
      },
      {
        "name": "commonSize",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "details",
        "precision": 0,
        "unit": "",
        "type": "text"
      }
    ],
    "interpret": null
  }
}
