{
  "schemaVersion": 1,
  "slug": "tree-spacing-calculator",
  "category": "gardening",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "4d03af26589ebc57e9c00e9ab8a693fe8f5b10dc0b1bb03bf4dfb3cd4c4217e8",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/tree-spacing-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": "d = s × f; N = (⌊W ÷ d − 0.001⌋ + 1) × (⌊L ÷ d − 0.001⌋ + 1)",
    "vars": [
      [
        "d",
        "Spacing"
      ],
      [
        "s",
        "Mature spread (lookup)"
      ],
      [
        "f",
        "Density factor"
      ],
      [
        "W",
        "Area width"
      ],
      [
        "L",
        "Area length"
      ],
      [
        "N",
        "Total trees"
      ]
    ],
    "note": "s: 6–60 by tree type; f: tight 1, orchard 1.25, open 1.6. Rows/columns are floored at 0."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const S = { apple:25, appleSemi:15, appleDwarf:8, pear:20, cherry:25, oak:60, maple:40, pine:25, privacy:6, nut:50 }; const F = { tight:1, orchard:1.25, open:1.6 }; const spread = S[treeType] || 25; const spacing = spread*(F[spacingFactor] || 1.25); const across = Math.max(0, Math.floor(areaWidth/spacing-0.001)+1); const along = Math.max(0, Math.floor(areaLength/spacing-0.001)+1); return { spread, spacing, treesAcross: across, treesAlong: along, totalTrees: across*along, note: 'Some fruit trees need a pollination partner of a different variety planted nearby' };",
    "inputs": [
      {
        "name": "areaLength",
        "type": "number",
        "default": 200,
        "min": 1,
        "max": 10000,
        "step": 1
      },
      {
        "name": "areaWidth",
        "type": "number",
        "default": 100,
        "min": 1,
        "max": 10000,
        "step": 1
      },
      {
        "name": "treeType",
        "type": "select",
        "default": "apple",
        "options": [
          {
            "value": "apple"
          },
          {
            "value": "appleSemi"
          },
          {
            "value": "appleDwarf"
          },
          {
            "value": "pear"
          },
          {
            "value": "cherry"
          },
          {
            "value": "oak"
          },
          {
            "value": "maple"
          },
          {
            "value": "pine"
          },
          {
            "value": "privacy"
          },
          {
            "value": "nut"
          }
        ]
      },
      {
        "name": "spacingFactor",
        "type": "select",
        "default": "orchard",
        "options": [
          {
            "value": "tight"
          },
          {
            "value": "orchard"
          },
          {
            "value": "open"
          }
        ]
      }
    ],
    "outputs": [
      {
        "name": "spread",
        "precision": 0,
        "unit": "ft"
      },
      {
        "name": "spacing",
        "precision": 1,
        "unit": "ft"
      },
      {
        "name": "treesAcross",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "treesAlong",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "totalTrees",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "note",
        "precision": 0,
        "unit": "",
        "type": "text"
      }
    ],
    "interpret": null
  }
}
