{
  "schemaVersion": 1,
  "slug": "hat-size-calculator",
  "category": "fashion",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "d7503ac7eb2d30e1241ce5f2f0712ea9e19851b64739a6d04e882f9a22a962c8",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/hat-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": "US = (c+a)/π; UK ≈ US−0.13; cm = 2.54(c+a)",
    "vars": [
      [
        "c",
        "Head circumference, in"
      ],
      [
        "a",
        "Fit allowance, in"
      ],
      [
        "US",
        "US hat size"
      ],
      [
        "cm",
        "Metric size, cm"
      ]
    ],
    "note": "US numeric size ≈ head circumference in inches ÷ π plus the selected ease adjustment; UK and letter-size outputs are broad approximations. Check each maker’s sizing chart."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const c=unit==='cm'?headCircumference/2.54:headCircumference; if(!Number.isFinite(c)||c<15||c>30)return {usSize:null,ukSize:null,metricSize:null,letterSize:null,__error:'inputError'}; const add=fit==='snug'?-0.2:fit==='loose'?0.3:0,us=(c+add)/Math.PI,metric=c*2.54+add*2.54; return {usSize:us,ukSize:us-0.13,metricSize:metric,letterSize:metric<54?'XS':metric<56?'S':metric<58?'M':metric<60?'L':'XL'};",
    "inputs": [
      {
        "name": "headCircumference",
        "type": "number",
        "default": 22,
        "min": 15,
        "max": 30,
        "step": 0.1,
        "unitField": "unit",
        "minByUnit": {
          "in": 15,
          "cm": 38.1
        },
        "maxByUnit": {
          "in": 30,
          "cm": 76.2
        },
        "unitScales": {
          "in": 1,
          "cm": 0.39370078740157477
        }
      },
      {
        "name": "unit",
        "type": "select",
        "default": "in",
        "options": [
          {
            "value": "in"
          },
          {
            "value": "cm"
          }
        ]
      },
      {
        "name": "fit",
        "type": "select",
        "default": "regular",
        "options": [
          {
            "value": "snug"
          },
          {
            "value": "regular"
          },
          {
            "value": "loose"
          }
        ]
      }
    ],
    "outputs": [
      {
        "name": "usSize",
        "precision": 2,
        "unit": ""
      },
      {
        "name": "ukSize",
        "precision": 2,
        "unit": ""
      },
      {
        "name": "metricSize",
        "precision": 1,
        "unit": "cm"
      },
      {
        "name": "letterSize",
        "precision": 0,
        "unit": "",
        "type": "text"
      }
    ],
    "interpret": null
  }
}
