{
  "schemaVersion": 1,
  "slug": "depth-of-field-calculator",
  "category": "photography",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "3444bd520003d62c6f85bcb79481a1561f14d89318c29bbf4fb3d333809f7ae9",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/depth-of-field-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 = (f² ÷ (N c) + f) ÷ 1000; D_n = H d ÷ (H + d − f ÷ 1000)",
    "vars": [
      [
        "f",
        "Focal length (mm)"
      ],
      [
        "N",
        "Aperture (f-number)"
      ],
      [
        "c",
        "Circle of confusion (mm)"
      ],
      [
        "d",
        "Focus distance (m)"
      ],
      [
        "H",
        "Hyperfocal distance (m)"
      ],
      [
        "D_n",
        "Near limit (m)"
      ]
    ],
    "note": "Use focal length and circle of confusion in millimetres and focus distance in metres; use the selected circle-of-confusion value directly in mm."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "if(![focalLength,aperture,distance,sensor].every(Number.isFinite)||focalLength<=0||aperture<=0||distance<=focalLength/1000||sensor<=0)return {nearLimit:null,farLimit:null,totalDepth:null,hyperfocal:null,inFront:null,behind:null,__error:'inputError'};const f = focalLength; const c = sensor; const H = (f*f)/(aperture*c) + f; const Hm = H/1000; const d = distance; const near = (Hm*d)/(Hm + (d - f/1000)); const farRaw = Hm > (d - f/1000) ? (Hm*d)/(Hm - (d - f/1000)) : Infinity; const far = farRaw === Infinity || !Number.isFinite(farRaw) ? '∞' : farRaw.toFixed(3) + ' m'; const total = farRaw === Infinity ? Infinity : farRaw - near; return { nearLimit: near, farLimit: far, totalDepth: farRaw === Infinity ? '∞' : total.toFixed(3) + ' m', hyperfocal: Hm, inFront: d - near, behind: farRaw === Infinity ? '∞' : (farRaw - d).toFixed(3) + ' m' };",
    "inputs": [
      {
        "name": "focalLength",
        "type": "number",
        "default": 50,
        "min": 3,
        "max": 2000,
        "step": 1,
        "slider": true
      },
      {
        "name": "aperture",
        "type": "number",
        "default": 2.8,
        "min": 0.7,
        "max": 128,
        "step": 0.1,
        "slider": true
      },
      {
        "name": "distance",
        "type": "number",
        "default": 3,
        "min": 0.01,
        "max": 100000,
        "step": 0.01
      },
      {
        "name": "sensor",
        "type": "select",
        "default": 0.03,
        "options": [
          {
            "value": 0.03
          },
          {
            "value": 0.02
          },
          {
            "value": 0.015
          },
          {
            "value": 0.005
          }
        ]
      }
    ],
    "outputs": [
      {
        "name": "nearLimit",
        "precision": 3,
        "unit": "m"
      },
      {
        "name": "farLimit",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "totalDepth",
        "precision": 3,
        "unit": "",
        "type": "text"
      },
      {
        "name": "hyperfocal",
        "precision": 2,
        "unit": "m"
      },
      {
        "name": "inFront",
        "precision": 3,
        "unit": "m"
      },
      {
        "name": "behind",
        "precision": 0,
        "unit": "",
        "type": "text"
      }
    ],
    "interpret": null
  }
}
