{
  "schemaVersion": 1,
  "slug": "aspect-ratio-calculator",
  "category": "everyday",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "df209b344745eef389b91b86ec0792f38521ec9f3049ffea372c2a245126d823",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/aspect-ratio-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": "h = W × r_h ÷ r_w",
    "vars": [
      [
        "W",
        "Known or target width"
      ],
      [
        "r_w",
        "Ratio width part"
      ],
      [
        "r_h",
        "Ratio height part"
      ],
      [
        "h",
        "Computed height"
      ]
    ],
    "note": "The ratio from your dimensions is obtained by dividing rounded width and height by their greatest common divisor."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "if (knownWidth <= 0 || targetWidth <= 0 || knownHeight <= 0 || ratioW <= 0 || ratioH <= 0) return { heightForWidth: null, decimalRatio: null, targetHeight: null, ratioFromDimensions: null, closestFormat: null, area: null, __error: 'invalidDimensions' };\nconst decimalRatio = ratioH > 0 ? ratioW/ratioH : 0; const heightForWidth = decimalRatio > 0 ? knownWidth/decimalRatio : 0; const targetHeight = decimalRatio > 0 ? targetWidth/decimalRatio : 0; const actual = knownHeight > 0 ? knownWidth/knownHeight : 0; const formats = [[4/3, '4:3 (standard definition)'], [16/10, '16:10 (laptop)'], [16/9, '16:9 (HD widescreen)'], [21/9, '21:9 (ultrawide cinema)'], [1, '1:1 (square)'], [9/16, '9:16 (vertical video)'], [2/3, '2:3 (portrait photo)'], [3/2, '3:2 (35 mm photo)']]; let best = formats[0]; let bd = 1e9; for (const f of formats) { const dd = Math.abs(f[0]-actual); if (dd < bd) { bd = dd; best = f; } } const g = (a, b) => b === 0 ? a : g(b, a % b); const wi = Math.round(knownWidth), hi = Math.round(knownHeight); const gcd = g(wi, hi) || 1; return { heightForWidth, decimalRatio, targetHeight, ratioFromDimensions: (wi/gcd)+':'+(hi/gcd), closestFormat: best[1], area: knownWidth*knownHeight };",
    "inputs": [
      {
        "name": "knownWidth",
        "type": "number",
        "default": 1920,
        "min": 0,
        "max": 100000,
        "step": 1
      },
      {
        "name": "ratioW",
        "type": "number",
        "default": 16,
        "min": 0.01,
        "max": 1000,
        "step": 0.01
      },
      {
        "name": "ratioH",
        "type": "number",
        "default": 9,
        "min": 0.01,
        "max": 1000,
        "step": 0.01
      },
      {
        "name": "targetWidth",
        "type": "number",
        "default": 1280,
        "min": 0,
        "max": 100000,
        "step": 1
      },
      {
        "name": "knownHeight",
        "type": "number",
        "default": 1080,
        "min": 0,
        "max": 100000,
        "step": 1
      }
    ],
    "outputs": [
      {
        "name": "heightForWidth",
        "precision": 1,
        "unit": "px"
      },
      {
        "name": "decimalRatio",
        "precision": 4,
        "unit": ""
      },
      {
        "name": "targetHeight",
        "precision": 1,
        "unit": "px"
      },
      {
        "name": "ratioFromDimensions",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "closestFormat",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "area",
        "precision": 0,
        "unit": "px²"
      }
    ],
    "interpret": null
  }
}
