{
  "schemaVersion": 1,
  "slug": "fence-post-calculator",
  "category": "construction",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "2c4d268d326f0f76ab42e4c74873888bb969bc7307cd66dca1eb9c6c36b488fb",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/fence-post-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": "S = max(1, ceil(L ÷ p)); P = S + 1 + 2g; Q = ceil(12L ÷ (w + d))",
    "vars": [
      [
        "L",
        "fence length (ft)"
      ],
      [
        "p",
        "post spacing (ft)"
      ],
      [
        "g",
        "gates"
      ],
      [
        "S",
        "fence sections"
      ],
      [
        "P",
        "posts"
      ],
      [
        "Q",
        "pickets"
      ],
      [
        "w",
        "picket width (in)"
      ],
      [
        "d",
        "picket gap (in)"
      ]
    ],
    "note": "Rails = S × rails per section (2 or 3); enter L without gate openings when estimating rails and pickets. w and d are in inches; the 12 converts feet to inches."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "if(!Number.isInteger(gates)) return {postCount:null,sections:null,railCount:null,picketCount:null,sectionLength:null,__error:'inputError'}; const sections=Math.max(1,Math.ceil(fenceLength/postSpacing)); const pitch=picketWidth+picketGap; return {postCount:sections+1+2*gates,sections,railCount:sections*Number(railsPerSection),picketCount:pitch>0?Math.ceil(fenceLength*12/pitch):0,sectionLength:sections>0?fenceLength/sections:0};",
    "inputs": [
      {
        "name": "fenceLength",
        "type": "number",
        "default": 100,
        "min": 1,
        "max": 100000,
        "step": 1
      },
      {
        "name": "postSpacing",
        "type": "number",
        "default": 8,
        "min": 1,
        "max": 20,
        "step": 0.5,
        "slider": true
      },
      {
        "name": "gates",
        "type": "number",
        "default": 1,
        "min": 0,
        "max": 20,
        "step": 1,
        "slider": true
      },
      {
        "name": "railsPerSection",
        "type": "select",
        "default": 2,
        "options": [
          {
            "value": 2
          },
          {
            "value": 3
          }
        ]
      },
      {
        "name": "picketWidth",
        "type": "number",
        "default": 5.5,
        "min": 0.5,
        "max": 12,
        "step": 0.25,
        "slider": true
      },
      {
        "name": "picketGap",
        "type": "number",
        "default": 0.5,
        "min": 0,
        "max": 3,
        "step": 0.125,
        "slider": true
      }
    ],
    "outputs": [
      {
        "name": "postCount",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "sections",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "railCount",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "picketCount",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "sectionLength",
        "precision": 2,
        "unit": "ft"
      }
    ],
    "interpret": null
  }
}
