{
  "schemaVersion": 1,
  "slug": "knitting-calculator",
  "category": "diy-craft",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "46ae83abd7f0f78b7813c86f97b098598cb758f41030ec7ce61eb8e12397589c",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/knitting-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": "CO = round(W × G_s); R = round(H × G_r); W_p = CO ÷ (P ÷ patternGaugeSize)",
    "vars": [
      [
        "CO",
        "Cast-on stitches"
      ],
      [
        "W",
        "Project width (in)"
      ],
      [
        "G_s",
        "Stitch gauge (per inch)"
      ],
      [
        "R",
        "Rows needed"
      ],
      [
        "H",
        "Project height (in)"
      ],
      [
        "G_r",
        "Row gauge (per inch)"
      ],
      [
        "P",
        "Pattern stitch count"
      ],
      [
        "patternGaugeSize",
        "Stated pattern gauge width"
      ]
    ],
    "note": "Gauge rates use the stated swatch and pattern widths: stitches per inch = stitches ÷ width. Width at pattern gauge = cast-on stitches ÷ (pattern stitches ÷ stated pattern gauge width)."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const spi = swatchSize > 0 ? swatchStitches/swatchSize : 0; const rpi = swatchSize > 0 ? swatchRows/swatchSize : 0; const castOn = Math.round(projectWidth*spi); const rows = Math.round(projectHeight*rpi); const patternSpi = patternGaugeStitches/patternGaugeSize; return { stitchesPerInch: spi, rowsPerInch: rpi, castOn: castOn, rowsNeeded: rows, gaugeDifference: patternSpi > 0 ? (spi - patternSpi)/patternSpi*100 : 0, adjustedWidth: patternSpi > 0 ? castOn/patternSpi : 0 };",
    "inputs": [
      {
        "name": "swatchStitches",
        "type": "number",
        "default": 20,
        "min": 1,
        "max": 200,
        "step": 1,
        "slider": true
      },
      {
        "name": "swatchRows",
        "type": "number",
        "default": 28,
        "min": 1,
        "max": 200,
        "step": 1,
        "slider": true
      },
      {
        "name": "swatchSize",
        "type": "number",
        "default": 4,
        "min": 1,
        "max": 24,
        "step": 0.5,
        "slider": true
      },
      {
        "name": "projectWidth",
        "type": "number",
        "default": 20,
        "min": 1,
        "max": 300,
        "step": 0.5,
        "slider": true
      },
      {
        "name": "projectHeight",
        "type": "number",
        "default": 24,
        "min": 1,
        "max": 300,
        "step": 0.5,
        "slider": true
      },
      {
        "name": "patternGaugeStitches",
        "type": "number",
        "default": 18,
        "min": 1,
        "max": 200,
        "step": 1,
        "slider": true
      },
      {
        "name": "patternGaugeSize",
        "type": "number",
        "default": 4,
        "min": 1,
        "max": 24,
        "step": 0.5
      }
    ],
    "outputs": [
      {
        "name": "stitchesPerInch",
        "precision": 2,
        "unit": ""
      },
      {
        "name": "rowsPerInch",
        "precision": 2,
        "unit": ""
      },
      {
        "name": "castOn",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "rowsNeeded",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "gaugeDifference",
        "precision": 1,
        "unit": "%"
      },
      {
        "name": "adjustedWidth",
        "precision": 1,
        "unit": "in"
      }
    ],
    "interpret": null
  }
}
