@photivra/engine 2.4.1 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/CHANGELOG.md +53 -1
  2. package/CITATION.cff +1 -1
  3. package/README.md +6 -6
  4. package/SECURITY.md +1 -1
  5. package/THIRD_PARTY.md +1 -0
  6. package/dist/capture/native-environment-lean.d.ts +1 -1
  7. package/dist/capture/native-environment-lean.js +17 -3
  8. package/dist/capture/native-environment-lean.js.map +1 -1
  9. package/dist/capture/native-environment-raw.d.ts +0 -4
  10. package/dist/capture/native-environment-raw.js +6 -2
  11. package/dist/capture/native-environment-raw.js.map +1 -1
  12. package/dist/color/illuminants.d.ts +15 -0
  13. package/dist/color/illuminants.js +81 -24
  14. package/dist/color/illuminants.js.map +1 -1
  15. package/dist/color/srgb-transfer.d.ts +6 -0
  16. package/dist/color/srgb-transfer.js +9 -0
  17. package/dist/color/srgb-transfer.js.map +1 -1
  18. package/dist/color/white-balance.d.ts +6 -0
  19. package/dist/color/white-balance.js +15 -2
  20. package/dist/color/white-balance.js.map +1 -1
  21. package/dist/core/internal-radiance-evaluator.d.ts +6 -0
  22. package/dist/core/internal-radiance-evaluator.js +33 -0
  23. package/dist/core/internal-radiance-evaluator.js.map +1 -0
  24. package/dist/core/portable-math.d.ts +33 -0
  25. package/dist/core/portable-math.js +342 -0
  26. package/dist/core/portable-math.js.map +1 -1
  27. package/dist/core/version.d.ts +1 -1
  28. package/dist/core/version.js +1 -1
  29. package/dist/core/version.js.map +1 -1
  30. package/dist/facade/chart-scenes.d.ts +9 -0
  31. package/dist/facade/chart-scenes.js +17 -4
  32. package/dist/facade/chart-scenes.js.map +1 -1
  33. package/dist/facade/diffraction-provider.d.ts +10 -0
  34. package/dist/facade/diffraction-provider.js +38 -17
  35. package/dist/facade/diffraction-provider.js.map +1 -1
  36. package/dist/facade/display-view.d.ts +208 -0
  37. package/dist/facade/display-view.js +1461 -0
  38. package/dist/facade/display-view.js.map +1 -0
  39. package/dist/facade/scene-radiance.d.ts +7 -0
  40. package/dist/facade/scene-radiance.js +18 -5
  41. package/dist/facade/scene-radiance.js.map +1 -1
  42. package/dist/facade/simulate-capture.d.ts +229 -5
  43. package/dist/facade/simulate-capture.js +119 -35
  44. package/dist/facade/simulate-capture.js.map +1 -1
  45. package/dist/facade/simulate-display-view.d.ts +21 -0
  46. package/dist/facade/simulate-display-view.js +168 -0
  47. package/dist/facade/simulate-display-view.js.map +1 -0
  48. package/dist/facade/subject-framing.d.ts +78 -0
  49. package/dist/facade/subject-framing.js +69 -20
  50. package/dist/facade/subject-framing.js.map +1 -1
  51. package/dist/index.d.ts +3 -2
  52. package/dist/index.js +3 -2
  53. package/dist/index.js.map +1 -1
  54. package/dist/optics/diffraction-psf-profile.d.ts +59 -3
  55. package/dist/optics/diffraction-psf-profile.js +147 -5
  56. package/dist/optics/diffraction-psf-profile.js.map +1 -1
  57. package/dist/optics/irradiance-convolution.js +1 -1
  58. package/dist/optics/irradiance-convolution.js.map +1 -1
  59. package/dist/optics/scene-to-sensor-irradiance.d.ts +7 -0
  60. package/dist/optics/scene-to-sensor-irradiance.js +10 -5
  61. package/dist/optics/scene-to-sensor-irradiance.js.map +1 -1
  62. package/dist/output/print-plan.d.ts +8 -1
  63. package/dist/output/print-plan.js +8 -1
  64. package/dist/output/print-plan.js.map +1 -1
  65. package/dist/schema/scene-radiance.d.ts +16 -0
  66. package/dist/schema/scene-radiance.js +25 -4
  67. package/dist/schema/scene-radiance.js.map +1 -1
  68. package/dist/sensor/raw-readout.d.ts +12 -0
  69. package/dist/sensor/raw-readout.js +131 -9
  70. package/dist/sensor/raw-readout.js.map +1 -1
  71. package/dist/sensor/stochastic-seed.d.ts +13 -0
  72. package/dist/sensor/stochastic-seed.js +42 -8
  73. package/dist/sensor/stochastic-seed.js.map +1 -1
  74. package/docs/AGENT_GUIDE.md +1 -0
  75. package/docs/API_REFERENCE.md +16 -1
  76. package/docs/QUICK_START.md +245 -9
  77. package/docs/USAGE.md +15 -0
  78. package/docs/api/core-version.md +1 -1
  79. package/docs/api/exports.json +37 -2
  80. package/docs/api/facade-simulate-capture.md +70 -2
  81. package/docs/api/facade-simulate-display-view.md +18 -0
  82. package/docs/api/facade-subject-framing.md +83 -0
  83. package/docs/api/optics-diffraction-psf-profile.md +8 -1
  84. package/docs/api/output-print-plan.md +8 -1
  85. package/package.json +3 -2
@@ -1 +1 @@
1
- {"version":3,"file":"scene-to-sensor-irradiance.js","sourceRoot":"","sources":["../../src/optics/scene-to-sensor-irradiance.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EACL,mBAAmB,EAEpB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EACL,iBAAiB,EAGlB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,4BAA4B,EAE7B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EACL,oCAAoC,EAErC,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,8BAA8B,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EACL,mCAAmC,EACnC,kCAAkC,EAGnC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAI7I,MAAM,CAAC,MAAM,iDAAiD,GAC5D,OAAgB,CAAC;AAoQnB,SAAS,aAAa,CACpB,KAAc,EACd,IAAY,EACZ,WAAqC;IAErC,IACE,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EACpB,CAAC;QACD,MAAM,IAAI,yBAAyB,CACjC,IAAI,GAAG,qBAA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n/**\n * Scene-to-sensor optical bridge: from spectral scene radiance to the irradiance that reaches the\n * sensor.\n *\n * The profile parser validates untrusted input and returns the normalized typed contract. Unknown\n * enum values, missing required fields and incompatible scientific data are rejected here.\n *\n * The calculation applies the declared pupil acceptance and exactly one transmission or\n * field-throughput path. It returns the irradiance before the sensor stack, with conservative\n * evidence.\n *\n * The optical bridge turns outgoing scene radiance (W/m²/sr/nm) into irradiance (W/m²/nm) arriving\n * at the front of the sensor stack.\n * - Circular paraxial acceptance is pi/(4*Nworking²). At finite focus with unit pupil magnification,\n * the working f-number is N*(1+m).\n * - Spectral transmission and an effective working T-stop are alternative paths; use one.\n * - Field throughput is applied exactly once.\n * - Sensor response and PSF (point-spread function) blur happen later in the pipeline.\n * @see docs/SCENE_SENSOR_QUADRATURE.md for the equations, units, coordinate conventions, known\n * blockers and support limits.\n */\n\nimport {\n approximationResult,\n type CalculationResult\n} from \"../core/calculation-result.js\";\nimport { InvalidConfigurationError } from \"../core/configuration-error.js\";\nimport {\n parseEvidenceList,\n type EvidenceBackedFact,\n type EvidenceProvenance\n} from \"../core/evidence-provenance.js\";\nimport {\n parseSpectralWavelengthBasis,\n type SpectralWavelengthBasis\n} from \"../core/spectral.js\";\nimport { InvalidScientificInputError } from \"../core/validation.js\";\nimport {\n composeFrontOfLensFilterTransmission,\n type FrontOfLensFilterProfile\n} from \"./front-of-lens-filter.js\";\nimport type { IlluminationVignetting } from \"./illumination-vignetting.js\";\nimport { calculateThinLensImageDistance } from \"./thin-lens.js\";\nimport {\n parseSceneRadianceEvaluationRequest,\n parseSceneRadianceEvaluationResult,\n type SceneRadianceEvaluationRequest,\n type SceneRadianceEvaluationResult\n} from \"../schema/scene-radiance.js\";\nimport { requireInputKeys, rejectUnknownFields, rejectUnknownVariantFields, UNCERTAINTY_VARIANT_FIELDS } from \"../core/record-validation.js\";\n\ntype UnknownRecord = Record<string, unknown>;\n\nexport const SCENE_TO_SENSOR_IRRADIANCE_PROFILE_SCHEMA_VERSION =\n \"0.1.0\" as const;\n\nexport type OpticalBridgeScientificStatus =\n | \"calibrated\"\n | \"approximation\";\n\nexport type OpticalBridgeUncertainty =\n | {\n kind: \"relative\";\n fraction: number;\n basis: string;\n }\n | {\n kind: \"not-quantified\";\n limitation: string;\n };\n\nexport interface NumericRange {\n minimum: number;\n maximum: number;\n}\n\nexport type OpticalBridgeFocusApplicability =\n | {\n kind: \"any\";\n }\n | {\n kind: \"finite-distance-range\";\n objectDistanceM: NumericRange;\n };\n\nexport interface SpectralTransmissionSample {\n wavelengthNanometers: number;\n linearTransmissionFactor: number;\n}\n\nexport type OpticalTransmissionModel =\n | {\n kind: \"spectral-transmission\";\n scientificStatus:\n OpticalBridgeScientificStatus;\n wavelengthBasis:\n Exclude<\n SpectralWavelengthBasis,\n \"unspecified\"\n >;\n samples:\n EvidenceBackedFact<\n readonly SpectralTransmissionSample[]\n >;\n uncertainty:\n OpticalBridgeUncertainty;\n }\n | {\n kind:\n \"effective-working-t-stop-approximation\";\n scientificStatus: \"approximation\";\n workingTStop:\n EvidenceBackedFact<number>;\n wavelengthBasis:\n Exclude<\n SpectralWavelengthBasis,\n \"unspecified\"\n >;\n wavelengthRangeNanometers:\n NumericRange;\n uncertainty:\n OpticalBridgeUncertainty;\n limitation: string;\n };\n\nexport interface SceneToSensorIrradianceProfile {\n schemaVersion:\n typeof SCENE_TO_SENSOR_IRRADIANCE_PROFILE_SCHEMA_VERSION;\n profileId: string;\n profileVersion: string;\n lensProfileId: string;\n scientificStatus:\n OpticalBridgeScientificStatus;\n applicability: {\n focalLengthMm: NumericRange;\n nominalFNumber: NumericRange;\n focus:\n OpticalBridgeFocusApplicability;\n };\n transmission:\n OpticalTransmissionModel;\n distortionAreaMappingOwnership:\n \"not-applied-by-bridge\";\n psfRedistributionOwnership:\n \"downstream-normalized-energy-redistribution\";\n sensorOpticalStackIncluded: false;\n strayLightIncluded: false;\n polarizationModeled: false;\n wavelengthChangingBehaviorModeled: false;\n volumetricScatteringModeled: false;\n evidence: readonly EvidenceProvenance[];\n limitations: readonly string[];\n}\n\nexport type OpticalBridgeFocusContext =\n | {\n kind: \"infinity-focus\";\n }\n | {\n kind:\n \"ideal-symmetric-thin-lens\";\n objectDistanceM: number;\n pupilMagnificationAssumption:\n \"unity\";\n }\n | {\n kind:\n \"supplied-working-f-number\";\n focus:\n | {\n kind: \"infinity\";\n }\n | {\n kind: \"finite\";\n objectDistanceM: number;\n };\n workingFNumber:\n EvidenceBackedFact<number>;\n basis: string;\n };\n\nexport type OpticalBridgeFieldThroughput =\n | {\n kind: \"unity\";\n }\n | {\n kind:\n \"illumination-vignetting-result\";\n result:\n IlluminationVignetting;\n };\n\nexport interface CalculateSceneRadianceToSensorIrradianceInput {\n sceneRadianceRequest:\n SceneRadianceEvaluationRequest;\n sceneRadianceResult:\n SceneRadianceEvaluationResult;\n profile:\n SceneToSensorIrradianceProfile;\n focalLengthMm: number;\n nominalFNumber: number;\n focus:\n OpticalBridgeFocusContext;\n imagePointMm: {\n x: number;\n y: number;\n };\n fieldThroughput:\n OpticalBridgeFieldThroughput;\n frontOfLensFilters?:\n readonly FrontOfLensFilterProfile[];\n}\n\nexport interface SceneToSensorIrradianceResult {\n schemaVersion:\n typeof SCENE_TO_SENSOR_IRRADIANCE_PROFILE_SCHEMA_VERSION;\n profileId: string;\n profileVersion: string;\n lensProfileId: string;\n sampleId: string;\n providerProfileId: string;\n sceneId: string;\n timeSecondsFromExposureStart: number;\n wavelengthNanometers: number;\n wavelengthBasis:\n Exclude<\n SpectralWavelengthBasis,\n \"unspecified\"\n >;\n inputQuantity:\n \"outgoing-spectral-radiance\";\n inputUnit:\n \"W/m^2/sr/nm\";\n outputQuantity:\n \"sensor-plane-spectral-irradiance\";\n outputUnit:\n \"W/m^2/nm\";\n sceneSpectralRadianceWattsPerSquareMeterSteradianNanometer:\n number;\n focalLengthMm: number;\n nominalFNumber: number;\n workingFNumber: number;\n focusModel:\n OpticalBridgeFocusContext[\"kind\"];\n paraxialGeometricAcceptanceSolidAngleSteradians:\n number;\n transmissionPath:\n OpticalTransmissionModel[\"kind\"];\n spectralTransmissionFactor:\n number | null;\n effectiveWorkingTStop:\n number | null;\n tStopEquivalentTransmissionFactor:\n number | null;\n frontOfLensFilterCount: number;\n frontOfLensFilterTransmissionFactor:\n number;\n frontOfLensFilterAttenuationStops:\n number;\n frontOfLensFilterTransmissionAppliedExactlyOnce:\n true;\n /**\n * True when a front-of-lens linear polarizer was applied. Scene radiance is unpolarized in this\n * bridge, so a polarizer transmits (k1 + k2) / 2.\n */\n frontOfLensFilterPolarizationModeled:\n boolean;\n fieldThroughputFactor: number;\n effectiveAcceptanceAfterTransmissionAndFieldSteradians:\n number;\n sensorPlaneSpectralIrradianceWattsPerSquareMeterNanometer:\n number;\n scientificStatus: \"approximation\";\n sceneRadianceScientificStatus:\n SceneRadianceEvaluationResult[\"scientificStatus\"];\n opticalProfileScientificStatus:\n OpticalBridgeScientificStatus;\n sceneRadianceUncertainty:\n SceneRadianceEvaluationResult[\"uncertainty\"];\n opticalUncertainty:\n OpticalBridgeUncertainty;\n radianceAmplificationApplied: false;\n fieldThroughputAppliedExactlyOnce:\n true;\n universalCos4FalloffApplied: false;\n distortionAreaCorrectionApplied: false;\n psfRedistributionApplied: false;\n sensorOpticalStackApplied: false;\n cfaApplied: false;\n quantumEfficiencyApplied: false;\n spectralResponsivityApplied: false;\n strayLightApplied: false;\n polarizationModeled: false;\n wavelengthChangingBehaviorModeled:\n false;\n volumetricScatteringModeled: false;\n calibratedSensorPlaneIrradianceClaimAuthorized:\n false;\n componentEvidence: {\n sceneRadiance:\n readonly EvidenceProvenance[];\n opticalProfile:\n readonly EvidenceProvenance[];\n transmission:\n readonly EvidenceProvenance[];\n workingFNumber:\n readonly EvidenceProvenance[];\n frontOfLensFilters:\n readonly EvidenceProvenance[];\n };\n limitations:\n readonly string[];\n}\n\nfunction requireRecord(\n value: unknown,\n path: string,\n allowedKeys: readonly string[] | null\n): UnknownRecord {\n if (\n typeof value !== \"object\" ||\n value === null ||\n Array.isArray(value)\n ) {\n throw new InvalidConfigurationError(\n path + \" must be an object.\"\n );\n }\n if (allowedKeys !== null) rejectUnknownFields(value, allowedKeys, path);\n return value as UnknownRecord;\n}\n\nfunction requireNonEmptyString(\n value: unknown,\n path: string\n): string {\n if (\n typeof value !== \"string\" ||\n value.trim().length === 0\n ) {\n throw new InvalidConfigurationError(\n path + \" must be a non-empty string.\"\n );\n }\n return value.trim();\n}\n\nfunction requireFinite(\n value: unknown,\n path: string\n): number {\n if (\n typeof value !== \"number\" ||\n !Number.isFinite(value)\n ) {\n throw new InvalidConfigurationError(\n path + \" must be finite.\"\n );\n }\n return value;\n}\n\nfunction requirePositiveFinite(\n value: unknown,\n path: string\n): number {\n const parsed =\n requireFinite(value, path);\n if (parsed <= 0) {\n throw new InvalidConfigurationError(\n path +\n \" must be greater than zero.\"\n );\n }\n return parsed;\n}\n\nfunction requireFraction(\n value: unknown,\n path: string\n): number {\n const parsed =\n requireFinite(value, path);\n if (\n parsed < 0 ||\n parsed > 1\n ) {\n throw new InvalidConfigurationError(\n path +\n \" must be from zero through one.\"\n );\n }\n return parsed;\n}\n\nfunction parseRange(\n value: unknown,\n path: string\n): NumericRange {\n const record =\n requireRecord(value, path, [\"minimum\", \"maximum\"]);\n const minimum =\n requirePositiveFinite(\n record.minimum,\n path + \".minimum\"\n );\n const maximum =\n requirePositiveFinite(\n record.maximum,\n path + \".maximum\"\n );\n if (minimum > maximum) {\n throw new InvalidConfigurationError(\n path +\n \".minimum must be less than or equal to maximum.\"\n );\n }\n return {\n minimum,\n maximum\n };\n}\n\nfunction parseScientificStatus(\n value: unknown,\n path: string\n): OpticalBridgeScientificStatus {\n if (\n value !== \"calibrated\" &&\n value !== \"approximation\"\n ) {\n throw new InvalidConfigurationError(\n path + \" is invalid.\"\n );\n }\n return value;\n}\n\nfunction parseUncertainty(\n value: unknown,\n path: string\n): OpticalBridgeUncertainty {\n const record =\n requireRecord(value, path, null);\n rejectUnknownVariantFields(record, \"kind\", UNCERTAINTY_VARIANT_FIELDS, path);\n\n if (record.kind === \"relative\") {\n return {\n kind: \"relative\",\n fraction:\n requireFraction(\n record.fraction,\n path + \".fraction\"\n ),\n basis:\n requireNonEmptyString(\n record.basis,\n path + \".basis\"\n )\n };\n }\n\n if (\n record.kind ===\n \"not-quantified\"\n ) {\n return {\n kind: \"not-quantified\",\n limitation:\n requireNonEmptyString(\n record.limitation,\n path + \".limitation\"\n )\n };\n }\n\n throw new InvalidConfigurationError(\n path + \".kind is invalid.\"\n );\n}\n\nfunction parseLimitations(\n value: unknown,\n path: string\n): readonly string[] {\n if (!Array.isArray(value)) {\n throw new InvalidConfigurationError(\n path + \" must be an array.\"\n );\n }\n const parsed = value.map(\n (entry, index) =>\n requireNonEmptyString(\n entry,\n path +\n \"[\" +\n index +\n \"]\"\n )\n );\n if (\n new Set(parsed).size !==\n parsed.length\n ) {\n throw new InvalidConfigurationError(\n path +\n \" must not contain duplicates.\"\n );\n }\n return parsed;\n}\n\nfunction parseReusableNumericEvidence(\n value: unknown,\n path: string\n): readonly EvidenceProvenance[] {\n const evidence =\n parseEvidenceList(value, path);\n\n if (\n evidence.some(\n (entry) =>\n entry.reuseStatus ===\n \"factual-reference-only\"\n )\n ) {\n throw new InvalidConfigurationError(\n path +\n \" for numeric optical curve data must be reusable-data or photivra-owned.\"\n );\n }\n return evidence;\n}\n\nfunction parseSpectralSamples(\n value: unknown,\n path: string\n): readonly SpectralTransmissionSample[] {\n if (\n !Array.isArray(value) ||\n value.length < 2\n ) {\n throw new InvalidConfigurationError(\n path +\n \" must contain at least two samples.\"\n );\n }\n\n let previous =\n Number.NEGATIVE_INFINITY;\n return value.map(\n (entry, index) => {\n const samplePath =\n path +\n \"[\" +\n index +\n \"]\";\n const record =\n requireRecord(\n entry,\n samplePath, [\"wavelengthNanometers\", \"linearTransmissionFactor\"]\n );\n const wavelengthNanometers =\n requirePositiveFinite(\n record.wavelengthNanometers,\n samplePath +\n \".wavelengthNanometers\"\n );\n if (\n wavelengthNanometers <=\n previous\n ) {\n throw new InvalidConfigurationError(\n path +\n \" wavelengths must be strictly increasing.\"\n );\n }\n previous =\n wavelengthNanometers;\n return {\n wavelengthNanometers,\n linearTransmissionFactor:\n requireFraction(\n record.linearTransmissionFactor,\n samplePath +\n \".linearTransmissionFactor\"\n )\n };\n }\n );\n}\n\nfunction parseTransmission(\n value: unknown,\n path: string\n): OpticalTransmissionModel {\n const record =\n requireRecord(value, path, null);\n rejectUnknownVariantFields(record, \"kind\", {\n // workingTStop and wavelengthRangeNanometers (spectral) and samples (working T-stop) are rejected below with their own messages.\n \"spectral-transmission\": [\"kind\", \"scientificStatus\", \"wavelengthBasis\", \"samples\", \"uncertainty\", \"workingTStop\", \"wavelengthRangeNanometers\"],\n \"effective-working-t-stop-approximation\": [\"kind\", \"scientificStatus\", \"workingTStop\", \"wavelengthBasis\", \"wavelengthRangeNanometers\",\n \"uncertainty\", \"limitation\", \"samples\"]\n }, path);\n\n if (\n record.kind ===\n \"spectral-transmission\"\n ) {\n if (\n record.workingTStop !==\n undefined ||\n record.wavelengthRangeNanometers !==\n undefined\n ) {\n throw new InvalidConfigurationError(\n path +\n \" spectral-transmission must not include T-stop-only fields.\"\n );\n }\n\n const status =\n parseScientificStatus(\n record.scientificStatus,\n path +\n \".scientificStatus\"\n );\n const samplesFact =\n requireRecord(\n record.samples,\n path + \".samples\", [\"value\", \"evidence\"]\n );\n const uncertainty =\n parseUncertainty(\n record.uncertainty,\n path + \".uncertainty\"\n );\n\n if (\n status === \"calibrated\" &&\n uncertainty.kind !==\n \"relative\"\n ) {\n throw new InvalidConfigurationError(\n path +\n \" calibrated spectral transmission requires quantified relative uncertainty.\"\n );\n }\n\n return {\n kind:\n \"spectral-transmission\",\n scientificStatus: status,\n wavelengthBasis:\n parseResolvedBasis(\n record.wavelengthBasis,\n path +\n \".wavelengthBasis\"\n ),\n samples: {\n value:\n parseSpectralSamples(\n samplesFact.value,\n path +\n \".samples.value\"\n ),\n evidence:\n parseReusableNumericEvidence(\n samplesFact.evidence,\n path +\n \".samples.evidence\"\n )\n },\n uncertainty\n };\n }\n\n if (\n record.kind ===\n \"effective-working-t-stop-approximation\"\n ) {\n if (\n record.samples !==\n undefined\n ) {\n throw new InvalidConfigurationError(\n path +\n \" T-stop approximation must not include spectral transmission samples.\"\n );\n }\n if (\n record.scientificStatus !==\n \"approximation\"\n ) {\n throw new InvalidConfigurationError(\n path +\n ' T-stop scientificStatus must be \"approximation\".'\n );\n }\n const workingTStopFact =\n requireRecord(\n record.workingTStop,\n path +\n \".workingTStop\", [\"value\", \"evidence\"]\n );\n return {\n kind:\n \"effective-working-t-stop-approximation\",\n scientificStatus:\n \"approximation\",\n workingTStop: {\n value:\n requirePositiveFinite(\n workingTStopFact.value,\n path +\n \".workingTStop.value\"\n ),\n evidence:\n parseEvidenceList(\n workingTStopFact.evidence,\n path +\n \".workingTStop.evidence\"\n )\n },\n wavelengthBasis:\n parseResolvedBasis(\n record.wavelengthBasis,\n path +\n \".wavelengthBasis\"\n ),\n wavelengthRangeNanometers:\n parseRange(\n record.wavelengthRangeNanometers,\n path +\n \".wavelengthRangeNanometers\"\n ),\n uncertainty:\n parseUncertainty(\n record.uncertainty,\n path + \".uncertainty\"\n ),\n limitation:\n requireNonEmptyString(\n record.limitation,\n path +\n \".limitation\"\n )\n };\n }\n\n throw new InvalidConfigurationError(\n path + \".kind is invalid.\"\n );\n}\n\nfunction parseResolvedBasis(\n value: unknown,\n path: string\n): Exclude<\n SpectralWavelengthBasis,\n \"unspecified\"\n> {\n const parsed =\n parseSpectralWavelengthBasis(\n value,\n path\n );\n if (parsed === \"unspecified\") {\n throw new InvalidConfigurationError(\n path +\n ' must resolve to \"air\" or \"vacuum\".'\n );\n }\n return parsed;\n}\n\nfunction parseFocusApplicability(\n value: unknown,\n path: string\n): OpticalBridgeFocusApplicability {\n const record =\n requireRecord(value, path, null);\n rejectUnknownVariantFields(record, \"kind\", { any: [\"kind\"], \"finite-distance-range\": [\"kind\", \"objectDistanceM\"] }, path);\n\n if (record.kind === \"any\") {\n return {\n kind: \"any\"\n };\n }\n if (\n record.kind ===\n \"finite-distance-range\"\n ) {\n return {\n kind:\n \"finite-distance-range\",\n objectDistanceM:\n parseRange(\n record.objectDistanceM,\n path +\n \".objectDistanceM\"\n )\n };\n }\n throw new InvalidConfigurationError(\n path + \".kind is invalid.\"\n );\n}\n\n/**\n * Validates an untrusted scene-to-sensor profile and returns the normalized typed contract. Unknown\n * enum values, missing required fields and incompatible scientific data are rejected here.\n *\n * The optical bridge turns outgoing scene radiance (W/m²/sr/nm) into irradiance (W/m²/nm) arriving\n * at the front of the sensor stack.\n * - Circular paraxial acceptance is pi/(4*Nworking²). At finite focus with unit pupil magnification,\n * the working f-number is N*(1+m).\n * - Spectral transmission and an effective working T-stop are alternative paths; use one.\n * - Field throughput is applied exactly once.\n * - Sensor response and PSF (point-spread function) blur happen later in the pipeline.\n * @param value - unknown. Untrusted input; TypeScript types alone are not validation.\n * @returns SceneToSensorIrradianceProfile. The result states its shape and scientific status; a successful call does not imply calibration.\n *\n * @see docs/API_REFERENCE.md for the root export and exact type graph.\n */\nexport function parseSceneToSensorIrradianceProfile(\n value: unknown\n): SceneToSensorIrradianceProfile {\n const record =\n requireRecord(\n value,\n \"sceneToSensorIrradianceProfile\", [\"schemaVersion\", \"applicability\", \"scientificStatus\", \"transmission\", \"distortionAreaMappingOwnership\", \"psfRedistributionOwnership\", \"sensorOpticalStackIncluded\", \"strayLightIncluded\", \"polarizationModeled\", \"wavelengthChangingBehaviorModeled\", \"volumetricScatteringModeled\", \"profileId\", \"profileVersion\", \"lensProfileId\", \"evidence\", \"limitations\"]\n );\n if (\n record.schemaVersion !==\n SCENE_TO_SENSOR_IRRADIANCE_PROFILE_SCHEMA_VERSION\n ) {\n throw new InvalidConfigurationError(\n 'sceneToSensorIrradianceProfile.schemaVersion must be \"' +\n SCENE_TO_SENSOR_IRRADIANCE_PROFILE_SCHEMA_VERSION +\n '\".'\n );\n }\n\n const applicability =\n requireRecord(\n record.applicability,\n \"sceneToSensorIrradianceProfile.applicability\", [\"focalLengthMm\", \"nominalFNumber\", \"focus\"]\n );\n const status =\n parseScientificStatus(\n record.scientificStatus,\n \"sceneToSensorIrradianceProfile.scientificStatus\"\n );\n const transmission =\n parseTransmission(\n record.transmission,\n \"sceneToSensorIrradianceProfile.transmission\"\n );\n\n if (\n status === \"calibrated\" &&\n transmission.scientificStatus !==\n \"calibrated\"\n ) {\n throw new InvalidConfigurationError(\n \"A calibrated optical bridge profile requires calibrated spectral transmission.\"\n );\n }\n\n if (\n record.distortionAreaMappingOwnership !==\n \"not-applied-by-bridge\" ||\n record.psfRedistributionOwnership !==\n \"downstream-normalized-energy-redistribution\" ||\n record.sensorOpticalStackIncluded !==\n false ||\n record.strayLightIncluded !==\n false ||\n record.polarizationModeled !==\n false ||\n record.wavelengthChangingBehaviorModeled !==\n false ||\n record.volumetricScatteringModeled !==\n false\n ) {\n throw new InvalidConfigurationError(\n \"sceneToSensorIrradianceProfile ownership/completeness flags are invalid for schema 0.1.0.\"\n );\n }\n\n return {\n schemaVersion:\n SCENE_TO_SENSOR_IRRADIANCE_PROFILE_SCHEMA_VERSION,\n profileId:\n requireNonEmptyString(\n record.profileId,\n \"sceneToSensorIrradianceProfile.profileId\"\n ),\n profileVersion:\n requireNonEmptyString(\n record.profileVersion,\n \"sceneToSensorIrradianceProfile.profileVersion\"\n ),\n lensProfileId:\n requireNonEmptyString(\n record.lensProfileId,\n \"sceneToSensorIrradianceProfile.lensProfileId\"\n ),\n scientificStatus: status,\n applicability: {\n focalLengthMm:\n parseRange(\n applicability.focalLengthMm,\n \"sceneToSensorIrradianceProfile.applicability.focalLengthMm\"\n ),\n nominalFNumber:\n parseRange(\n applicability.nominalFNumber,\n \"sceneToSensorIrradianceProfile.applicability.nominalFNumber\"\n ),\n focus:\n parseFocusApplicability(\n applicability.focus,\n \"sceneToSensorIrradianceProfile.applicability.focus\"\n )\n },\n transmission,\n distortionAreaMappingOwnership:\n \"not-applied-by-bridge\",\n psfRedistributionOwnership:\n \"downstream-normalized-energy-redistribution\",\n sensorOpticalStackIncluded:\n false,\n strayLightIncluded: false,\n polarizationModeled: false,\n wavelengthChangingBehaviorModeled:\n false,\n volumetricScatteringModeled:\n false,\n evidence:\n parseEvidenceList(\n record.evidence,\n \"sceneToSensorIrradianceProfile.evidence\"\n ),\n limitations:\n parseLimitations(\n record.limitations,\n \"sceneToSensorIrradianceProfile.limitations\"\n )\n };\n}\n\nfunction ensureWithin(\n value: number,\n range: NumericRange,\n path: string\n): void {\n if (\n value < range.minimum ||\n value > range.maximum\n ) {\n throw new InvalidScientificInputError(\n path +\n \" lies outside the optical profile applicability range.\"\n );\n }\n}\n\nfunction workingFNumber(\n focus:\n OpticalBridgeFocusContext,\n focalLengthMm: number,\n nominalFNumber: number\n): {\n value: number;\n evidence:\n readonly EvidenceProvenance[];\n} {\n if (\n focus.kind === \"infinity-focus\"\n ) {\n return {\n value: nominalFNumber,\n evidence: []\n };\n }\n\n if (\n focus.kind ===\n \"ideal-symmetric-thin-lens\"\n ) {\n if (\n focus\n .pupilMagnificationAssumption !==\n \"unity\"\n ) {\n throw new InvalidScientificInputError(\n 'Ideal symmetric thin-lens focus requires pupilMagnificationAssumption \"unity\".'\n );\n }\n const thinLens =\n calculateThinLensImageDistance({\n focalLengthMm,\n objectDistanceM:\n focus.objectDistanceM\n }).value;\n return {\n value:\n nominalFNumber *\n (1 + thinLens.magnification),\n evidence: []\n };\n }\n\n if (\n focus.kind ===\n \"supplied-working-f-number\"\n ) {\n const value =\n requirePositiveFiniteScientific(\n focus.workingFNumber.value,\n \"focus.workingFNumber.value\"\n );\n return {\n value,\n evidence:\n parseEvidenceList(\n focus.workingFNumber.evidence,\n \"focus.workingFNumber.evidence\"\n )\n };\n }\n\n throw new InvalidConfigurationError(\n \"focus.kind is invalid.\"\n );\n}\n\nfunction requirePositiveFiniteScientific(\n value: unknown,\n path: string\n): number {\n if (\n typeof value !== \"number\" ||\n !Number.isFinite(value) ||\n value <= 0\n ) {\n throw new InvalidScientificInputError(\n path +\n \" must be finite and greater than zero.\"\n );\n }\n return value;\n}\n\nfunction finiteFocusDistance(\n focus:\n OpticalBridgeFocusContext\n): number | null {\n if (\n focus.kind ===\n \"ideal-symmetric-thin-lens\"\n ) {\n return requirePositiveFiniteScientific(\n focus.objectDistanceM,\n \"focus.objectDistanceM\"\n );\n }\n if (\n focus.kind ===\n \"supplied-working-f-number\" &&\n focus.focus.kind === \"finite\"\n ) {\n return requirePositiveFiniteScientific(\n focus.focus.objectDistanceM,\n \"focus.focus.objectDistanceM\"\n );\n }\n return null;\n}\n\nfunction interpolateTransmission(\n model:\n Extract<\n OpticalTransmissionModel,\n { kind: \"spectral-transmission\" }\n >,\n wavelengthNanometers: number\n): number {\n const samples =\n model.samples.value;\n const first =\n samples[0]!;\n const last =\n samples[\n samples.length - 1\n ]!;\n\n if (\n wavelengthNanometers <\n first.wavelengthNanometers ||\n wavelengthNanometers >\n last.wavelengthNanometers\n ) {\n throw new InvalidScientificInputError(\n \"Scene wavelength lies outside the spectral transmission sample range.\"\n );\n }\n\n if (\n wavelengthNanometers ===\n first.wavelengthNanometers\n ) {\n return first\n .linearTransmissionFactor;\n }\n\n for (\n let index = 1;\n index < samples.length;\n index += 1\n ) {\n const right =\n samples[index]!;\n if (\n wavelengthNanometers <=\n right.wavelengthNanometers\n ) {\n const left =\n samples[index - 1]!;\n if (\n wavelengthNanometers ===\n right.wavelengthNanometers\n ) {\n return right\n .linearTransmissionFactor;\n }\n const phase =\n (wavelengthNanometers -\n left.wavelengthNanometers) /\n (right.wavelengthNanometers -\n left.wavelengthNanometers);\n return (\n left\n .linearTransmissionFactor +\n phase *\n (right\n .linearTransmissionFactor -\n left\n .linearTransmissionFactor)\n );\n }\n }\n\n return last\n .linearTransmissionFactor;\n}\n\nfunction fieldFactor(\n field:\n OpticalBridgeFieldThroughput,\n imagePointMm: {\n x: number;\n y: number;\n }\n): number {\n if (field.kind === \"unity\") {\n return 1;\n }\n if (\n field.kind ===\n \"illumination-vignetting-result\"\n ) {\n const result =\n field.result;\n const scale = Math.max(\n 1,\n Math.abs(imagePointMm.x),\n Math.abs(imagePointMm.y),\n Math.abs(result.imagePointMm.x),\n Math.abs(result.imagePointMm.y)\n );\n const tolerance =\n Number.EPSILON *\n 64 *\n scale;\n if (\n Math.abs(\n result.imagePointMm.x -\n imagePointMm.x\n ) > tolerance ||\n Math.abs(\n result.imagePointMm.y -\n imagePointMm.y\n ) > tolerance\n ) {\n throw new InvalidScientificInputError(\n \"Illumination-vignetting result imagePointMm must match the optical bridge imagePointMm.\"\n );\n }\n const factor =\n result.linearThroughputFactor;\n if (\n !Number.isFinite(factor) ||\n factor <= 0 ||\n factor > 1\n ) {\n throw new InvalidScientificInputError(\n \"Field throughput factor must be finite and in (0, 1].\"\n );\n }\n return factor;\n }\n throw new InvalidConfigurationError(\n \"fieldThroughput.kind is invalid.\"\n );\n}\n\nfunction validateSceneIdentity(\n request:\n SceneRadianceEvaluationRequest,\n result:\n SceneRadianceEvaluationResult\n): void {\n if (\n request.sampleId !==\n result.sampleId ||\n request.providerProfileId !==\n result.providerProfileId ||\n request.sceneId !==\n result.sceneId ||\n request.wavelengthNanometers !==\n result.wavelengthNanometers ||\n request.wavelengthBasis !==\n result.wavelengthBasis\n ) {\n throw new InvalidScientificInputError(\n \"Scene-radiance request/result identity must match exactly.\"\n );\n }\n}\n\n/**\n * Applies the declared pupil acceptance and exactly one transmission or field-throughput path to\n * spectral scene radiance. Returns the irradiance before the sensor stack, with conservative\n * evidence.\n *\n * The optical bridge turns outgoing scene radiance (W/m²/sr/nm) into irradiance (W/m²/nm) arriving\n * at the front of the sensor stack.\n * - Circular paraxial acceptance is pi/(4*Nworking²). At finite focus with unit pupil magnification,\n * the working f-number is N*(1+m).\n * - Spectral transmission and an effective working T-stop are alternative paths; use one.\n * - Field throughput is applied exactly once.\n * - Sensor response and PSF (point-spread function) blur happen later in the pipeline.\n * @param input - CalculateSceneRadianceToSensorIrradianceInput. See that type for coordinates, units and profile binding.\n * @returns CalculationResult<\n SceneToSensorIrradianceResult\n>. The result states its shape and scientific status; a successful call does not imply calibration.\n *\n * @see docs/API_REFERENCE.md for the root export and exact type graph.\n */\nexport function calculateSceneRadianceToSensorIrradiance(\n input:\n CalculateSceneRadianceToSensorIrradianceInput\n): CalculationResult<\n SceneToSensorIrradianceResult\n> {\n requireInputKeys(input, \"calculateSceneRadianceToSensorIrradiance\", [\"sceneRadianceRequest\", \"sceneRadianceResult\", \"profile\", \"focalLengthMm\", \"nominalFNumber\", \"focus\", \"imagePointMm\", \"fieldThroughput\", \"frontOfLensFilters\"]);\n const request =\n parseSceneRadianceEvaluationRequest(\n input.sceneRadianceRequest\n );\n const sceneResult =\n parseSceneRadianceEvaluationResult(\n input.sceneRadianceResult\n );\n validateSceneIdentity(\n request,\n sceneResult\n );\n\n const profile =\n parseSceneToSensorIrradianceProfile(\n input.profile\n );\n const focalLengthMm =\n requirePositiveFiniteScientific(\n input.focalLengthMm,\n \"focalLengthMm\"\n );\n const nominalFNumber =\n requirePositiveFiniteScientific(\n input.nominalFNumber,\n \"nominalFNumber\"\n );\n\n ensureWithin(\n focalLengthMm,\n profile.applicability\n .focalLengthMm,\n \"focalLengthMm\"\n );\n ensureWithin(\n nominalFNumber,\n profile.applicability\n .nominalFNumber,\n \"nominalFNumber\"\n );\n\n const focusDistanceM =\n finiteFocusDistance(input.focus);\n if (\n profile.applicability.focus.kind ===\n \"finite-distance-range\"\n ) {\n if (focusDistanceM === null) {\n throw new InvalidScientificInputError(\n \"Optical profile requires a finite focus distance.\"\n );\n }\n ensureWithin(\n focusDistanceM,\n profile.applicability\n .focus.objectDistanceM,\n \"focus object distance\"\n );\n }\n\n const working =\n workingFNumber(\n input.focus,\n focalLengthMm,\n nominalFNumber\n );\n const workingFNumberValue =\n working.value;\n const geometricAcceptance =\n Math.PI /\n (4 *\n workingFNumberValue *\n workingFNumberValue);\n\n if (\n !Number.isFinite(\n geometricAcceptance\n ) ||\n geometricAcceptance <= 0\n ) {\n throw new InvalidScientificInputError(\n \"Paraxial geometric acceptance must remain finite and greater than zero.\"\n );\n }\n\n const transmission =\n profile.transmission;\n\n if (\n request.wavelengthBasis !==\n transmission.wavelengthBasis\n ) {\n throw new InvalidScientificInputError(\n \"Scene-radiance and optical-transmission wavelength bases must match; implicit air/vacuum conversion is not performed.\"\n );\n }\n\n let spectralTransmissionFactor:\n number | null = null;\n let effectiveWorkingTStop:\n number | null = null;\n let tStopEquivalentTransmissionFactor:\n number | null = null;\n let effectiveAcceptance =\n geometricAcceptance;\n let transmissionEvidence:\n readonly EvidenceProvenance[];\n\n if (\n transmission.kind ===\n \"spectral-transmission\"\n ) {\n spectralTransmissionFactor =\n interpolateTransmission(\n transmission,\n request.wavelengthNanometers\n );\n effectiveAcceptance *=\n spectralTransmissionFactor;\n transmissionEvidence =\n transmission.samples.evidence;\n } else {\n ensureWithin(\n request.wavelengthNanometers,\n transmission\n .wavelengthRangeNanometers,\n \"scene wavelength\"\n );\n effectiveWorkingTStop =\n transmission.workingTStop.value;\n if (\n effectiveWorkingTStop <\n workingFNumberValue\n ) {\n throw new InvalidScientificInputError(\n \"effective working T-stop must not be smaller than the geometric working f-number for a passive optical approximation.\"\n );\n }\n tStopEquivalentTransmissionFactor =\n (workingFNumberValue /\n effectiveWorkingTStop) **\n 2;\n effectiveAcceptance =\n Math.PI /\n (4 *\n effectiveWorkingTStop *\n effectiveWorkingTStop);\n transmissionEvidence =\n transmission\n .workingTStop.evidence;\n }\n\n let frontOfLensFilterCount = 0;\n let frontOfLensFilterPolarizationModeled = false;\n let frontOfLensFilterTransmissionFactor = 1;\n let frontOfLensFilterAttenuationStops = 0;\n let frontOfLensFilterEvidence:\n readonly EvidenceProvenance[] = [];\n let frontOfLensFilterLimitations:\n readonly string[] = [];\n\n if (\n input.frontOfLensFilters !==\n undefined\n ) {\n const composed =\n composeFrontOfLensFilterTransmission({\n filters:\n input.frontOfLensFilters,\n wavelengthNanometers:\n request.wavelengthNanometers,\n wavelengthBasis:\n request.wavelengthBasis\n });\n frontOfLensFilterCount =\n composed.appliedFilterCount;\n frontOfLensFilterPolarizationModeled =\n composed.polarizationModeled;\n frontOfLensFilterTransmissionFactor =\n composed\n .combinedLinearTransmissionFactor;\n frontOfLensFilterAttenuationStops =\n composed\n .combinedAttenuationStops;\n frontOfLensFilterEvidence =\n composed.components.flatMap(\n (component) =>\n component.evidence\n );\n frontOfLensFilterLimitations =\n composed.components.flatMap(\n (component) =>\n component.limitations\n );\n effectiveAcceptance *=\n frontOfLensFilterTransmissionFactor;\n }\n\n const fieldThroughputFactor =\n fieldFactor(\n input.fieldThroughput,\n input.imagePointMm\n );\n effectiveAcceptance *=\n fieldThroughputFactor;\n\n const sceneRadiance =\n sceneResult\n .spectralRadianceWattsPerSquareMeterSteradianNanometer;\n const irradiance =\n sceneRadiance *\n effectiveAcceptance;\n\n if (\n !Number.isFinite(irradiance) ||\n irradiance < 0\n ) {\n throw new InvalidScientificInputError(\n \"Sensor-plane spectral irradiance must remain finite and non-negative.\"\n );\n }\n\n const limitations = [\n ...profile.limitations,\n ...frontOfLensFilterLimitations,\n \"Front-of-lens filter transmission is applied outside the lens throughput path exactly once and does not change geometric working f-number.\",\n \"Paraxial circular-pupil acceptance uses pi/(4*N_working^2); no universal cos^4 field falloff is added.\",\n \"Field throughput is supplied separately and applied exactly once.\",\n \"Geometric distortion area-density/Jacobian correction is not applied by this bridge.\",\n \"PSF/diffraction energy redistribution is downstream and must preserve normalized energy apart from separately owned throughput losses.\",\n \"Sensor optical stack, microlens, CFA, QE/responsivity and charge conversion are downstream.\",\n frontOfLensFilterPolarizationModeled\n ? \"Flare, ghosting, veiling glare, scene-radiance polarization (scene light is treated as unpolarized; the front-of-lens linear polarizer transmits (k1 + k2) / 2), volumetric scattering and wavelength-changing behavior are not modeled.\"\n : \"Flare, ghosting, veiling glare, polarization, volumetric scattering and wavelength-changing behavior are not modeled.\"\n ];\n\n return approximationResult(\n {\n schemaVersion:\n SCENE_TO_SENSOR_IRRADIANCE_PROFILE_SCHEMA_VERSION,\n profileId: profile.profileId,\n profileVersion:\n profile.profileVersion,\n lensProfileId:\n profile.lensProfileId,\n sampleId: request.sampleId,\n providerProfileId:\n request.providerProfileId,\n sceneId: request.sceneId,\n timeSecondsFromExposureStart:\n request\n .timeSecondsFromExposureStart,\n wavelengthNanometers:\n request.wavelengthNanometers,\n wavelengthBasis:\n request.wavelengthBasis,\n inputQuantity:\n \"outgoing-spectral-radiance\",\n inputUnit:\n \"W/m^2/sr/nm\",\n outputQuantity:\n \"sensor-plane-spectral-irradiance\",\n outputUnit: \"W/m^2/nm\",\n sceneSpectralRadianceWattsPerSquareMeterSteradianNanometer:\n sceneRadiance,\n focalLengthMm,\n nominalFNumber,\n workingFNumber:\n workingFNumberValue,\n focusModel: input.focus.kind,\n paraxialGeometricAcceptanceSolidAngleSteradians:\n geometricAcceptance,\n transmissionPath:\n transmission.kind,\n spectralTransmissionFactor,\n effectiveWorkingTStop,\n tStopEquivalentTransmissionFactor,\n frontOfLensFilterCount,\n frontOfLensFilterTransmissionFactor,\n frontOfLensFilterAttenuationStops,\n frontOfLensFilterTransmissionAppliedExactlyOnce:\n true,\n frontOfLensFilterPolarizationModeled,\n fieldThroughputFactor,\n effectiveAcceptanceAfterTransmissionAndFieldSteradians:\n effectiveAcceptance,\n sensorPlaneSpectralIrradianceWattsPerSquareMeterNanometer:\n irradiance,\n scientificStatus:\n \"approximation\",\n sceneRadianceScientificStatus:\n sceneResult.scientificStatus,\n opticalProfileScientificStatus:\n profile.scientificStatus,\n sceneRadianceUncertainty:\n sceneResult.uncertainty,\n opticalUncertainty:\n transmission.uncertainty,\n radianceAmplificationApplied:\n false,\n fieldThroughputAppliedExactlyOnce:\n true,\n universalCos4FalloffApplied:\n false,\n distortionAreaCorrectionApplied:\n false,\n psfRedistributionApplied:\n false,\n sensorOpticalStackApplied:\n false,\n cfaApplied: false,\n quantumEfficiencyApplied: false,\n spectralResponsivityApplied:\n false,\n strayLightApplied: false,\n polarizationModeled: false,\n wavelengthChangingBehaviorModeled:\n false,\n volumetricScatteringModeled:\n false,\n calibratedSensorPlaneIrradianceClaimAuthorized:\n false,\n componentEvidence: {\n sceneRadiance:\n sceneResult.evidence,\n opticalProfile:\n profile.evidence,\n transmission:\n transmissionEvidence,\n workingFNumber:\n working.evidence,\n frontOfLensFilters:\n frontOfLensFilterEvidence\n },\n limitations\n },\n \"scene-radiance-to-sensor-irradiance\",\n \"1.1.0\",\n limitations\n );\n}\n"]}
1
+ {"version":3,"file":"scene-to-sensor-irradiance.js","sourceRoot":"","sources":["../../src/optics/scene-to-sensor-irradiance.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EACL,mBAAmB,EAEpB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EACL,iBAAiB,EAGlB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,4BAA4B,EAE7B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EACL,oCAAoC,EAErC,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,8BAA8B,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EACL,mCAAmC,EACnC,kCAAkC,EAGnC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAI7I,MAAM,CAAC,MAAM,iDAAiD,GAC5D,OAAgB,CAAC;AAoQnB,SAAS,aAAa,CACpB,KAAc,EACd,IAAY,EACZ,WAAqC;IAErC,IACE,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,KAAK,CAAC,OAAO,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;YAClB,kBAAkB,EAChB,yBAAyB;SAC5B;QACD,WAAW;KACZ,EACD,qCAAqC,EACrC,OAAO,EACP,WAAW,CACZ,CAAC;AACJ,CAAC","sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Scene-to-sensor optical bridge: from spectral scene radiance to the irradiance that reaches the\n * sensor.\n *\n * The profile parser validates untrusted input and returns the normalized typed contract. Unknown\n * enum values, missing required fields and incompatible scientific data are rejected here.\n *\n * The calculation applies the declared pupil acceptance and exactly one transmission or\n * field-throughput path. It returns the irradiance before the sensor stack, with conservative\n * evidence.\n *\n * The optical bridge turns outgoing scene radiance (W/m²/sr/nm) into irradiance (W/m²/nm) arriving\n * at the front of the sensor stack.\n * - Circular paraxial acceptance is pi/(4*Nworking²). At finite focus with unit pupil magnification,\n * the working f-number is N*(1+m).\n * - Spectral transmission and an effective working T-stop are alternative paths; use one.\n * - Field throughput is applied exactly once.\n * - Sensor response and PSF (point-spread function) blur happen later in the pipeline.\n * @see docs/SCENE_SENSOR_QUADRATURE.md for the equations, units, coordinate conventions, known\n * blockers and support limits.\n */\n\nimport {\n approximationResult,\n type CalculationResult\n} from \"../core/calculation-result.js\";\nimport { InvalidConfigurationError } from \"../core/configuration-error.js\";\nimport {\n parseEvidenceList,\n type EvidenceBackedFact,\n type EvidenceProvenance\n} from \"../core/evidence-provenance.js\";\nimport {\n parseSpectralWavelengthBasis,\n type SpectralWavelengthBasis\n} from \"../core/spectral.js\";\nimport { InvalidScientificInputError } from \"../core/validation.js\";\nimport {\n composeFrontOfLensFilterTransmission,\n type FrontOfLensFilterProfile\n} from \"./front-of-lens-filter.js\";\nimport type { IlluminationVignetting } from \"./illumination-vignetting.js\";\nimport { calculateThinLensImageDistance } from \"./thin-lens.js\";\nimport {\n parseSceneRadianceEvaluationRequest,\n parseSceneRadianceEvaluationResult,\n type SceneRadianceEvaluationRequest,\n type SceneRadianceEvaluationResult\n} from \"../schema/scene-radiance.js\";\nimport { requireInputKeys, rejectUnknownFields, rejectUnknownVariantFields, UNCERTAINTY_VARIANT_FIELDS } from \"../core/record-validation.js\";\n\ntype UnknownRecord = Record<string, unknown>;\n\nexport const SCENE_TO_SENSOR_IRRADIANCE_PROFILE_SCHEMA_VERSION =\n \"0.1.0\" as const;\n\nexport type OpticalBridgeScientificStatus =\n | \"calibrated\"\n | \"approximation\";\n\nexport type OpticalBridgeUncertainty =\n | {\n kind: \"relative\";\n fraction: number;\n basis: string;\n }\n | {\n kind: \"not-quantified\";\n limitation: string;\n };\n\nexport interface NumericRange {\n minimum: number;\n maximum: number;\n}\n\nexport type OpticalBridgeFocusApplicability =\n | {\n kind: \"any\";\n }\n | {\n kind: \"finite-distance-range\";\n objectDistanceM: NumericRange;\n };\n\nexport interface SpectralTransmissionSample {\n wavelengthNanometers: number;\n linearTransmissionFactor: number;\n}\n\nexport type OpticalTransmissionModel =\n | {\n kind: \"spectral-transmission\";\n scientificStatus:\n OpticalBridgeScientificStatus;\n wavelengthBasis:\n Exclude<\n SpectralWavelengthBasis,\n \"unspecified\"\n >;\n samples:\n EvidenceBackedFact<\n readonly SpectralTransmissionSample[]\n >;\n uncertainty:\n OpticalBridgeUncertainty;\n }\n | {\n kind:\n \"effective-working-t-stop-approximation\";\n scientificStatus: \"approximation\";\n workingTStop:\n EvidenceBackedFact<number>;\n wavelengthBasis:\n Exclude<\n SpectralWavelengthBasis,\n \"unspecified\"\n >;\n wavelengthRangeNanometers:\n NumericRange;\n uncertainty:\n OpticalBridgeUncertainty;\n limitation: string;\n };\n\nexport interface SceneToSensorIrradianceProfile {\n schemaVersion:\n typeof SCENE_TO_SENSOR_IRRADIANCE_PROFILE_SCHEMA_VERSION;\n profileId: string;\n profileVersion: string;\n lensProfileId: string;\n scientificStatus:\n OpticalBridgeScientificStatus;\n applicability: {\n focalLengthMm: NumericRange;\n nominalFNumber: NumericRange;\n focus:\n OpticalBridgeFocusApplicability;\n };\n transmission:\n OpticalTransmissionModel;\n distortionAreaMappingOwnership:\n \"not-applied-by-bridge\";\n psfRedistributionOwnership:\n \"downstream-normalized-energy-redistribution\";\n sensorOpticalStackIncluded: false;\n strayLightIncluded: false;\n polarizationModeled: false;\n wavelengthChangingBehaviorModeled: false;\n volumetricScatteringModeled: false;\n evidence: readonly EvidenceProvenance[];\n limitations: readonly string[];\n}\n\nexport type OpticalBridgeFocusContext =\n | {\n kind: \"infinity-focus\";\n }\n | {\n kind:\n \"ideal-symmetric-thin-lens\";\n objectDistanceM: number;\n pupilMagnificationAssumption:\n \"unity\";\n }\n | {\n kind:\n \"supplied-working-f-number\";\n focus:\n | {\n kind: \"infinity\";\n }\n | {\n kind: \"finite\";\n objectDistanceM: number;\n };\n workingFNumber:\n EvidenceBackedFact<number>;\n basis: string;\n };\n\nexport type OpticalBridgeFieldThroughput =\n | {\n kind: \"unity\";\n }\n | {\n kind:\n \"illumination-vignetting-result\";\n result:\n IlluminationVignetting;\n };\n\nexport interface CalculateSceneRadianceToSensorIrradianceInput {\n sceneRadianceRequest:\n SceneRadianceEvaluationRequest;\n sceneRadianceResult:\n SceneRadianceEvaluationResult;\n profile:\n SceneToSensorIrradianceProfile;\n focalLengthMm: number;\n nominalFNumber: number;\n focus:\n OpticalBridgeFocusContext;\n imagePointMm: {\n x: number;\n y: number;\n };\n fieldThroughput:\n OpticalBridgeFieldThroughput;\n frontOfLensFilters?:\n readonly FrontOfLensFilterProfile[];\n}\n\nexport interface SceneToSensorIrradianceResult {\n schemaVersion:\n typeof SCENE_TO_SENSOR_IRRADIANCE_PROFILE_SCHEMA_VERSION;\n profileId: string;\n profileVersion: string;\n lensProfileId: string;\n sampleId: string;\n providerProfileId: string;\n sceneId: string;\n timeSecondsFromExposureStart: number;\n wavelengthNanometers: number;\n wavelengthBasis:\n Exclude<\n SpectralWavelengthBasis,\n \"unspecified\"\n >;\n inputQuantity:\n \"outgoing-spectral-radiance\";\n inputUnit:\n \"W/m^2/sr/nm\";\n outputQuantity:\n \"sensor-plane-spectral-irradiance\";\n outputUnit:\n \"W/m^2/nm\";\n sceneSpectralRadianceWattsPerSquareMeterSteradianNanometer:\n number;\n focalLengthMm: number;\n nominalFNumber: number;\n workingFNumber: number;\n focusModel:\n OpticalBridgeFocusContext[\"kind\"];\n paraxialGeometricAcceptanceSolidAngleSteradians:\n number;\n transmissionPath:\n OpticalTransmissionModel[\"kind\"];\n spectralTransmissionFactor:\n number | null;\n effectiveWorkingTStop:\n number | null;\n tStopEquivalentTransmissionFactor:\n number | null;\n frontOfLensFilterCount: number;\n frontOfLensFilterTransmissionFactor:\n number;\n frontOfLensFilterAttenuationStops:\n number;\n frontOfLensFilterTransmissionAppliedExactlyOnce:\n true;\n /**\n * True when a front-of-lens linear polarizer was applied. Scene radiance is unpolarized in this\n * bridge, so a polarizer transmits (k1 + k2) / 2.\n */\n frontOfLensFilterPolarizationModeled:\n boolean;\n fieldThroughputFactor: number;\n effectiveAcceptanceAfterTransmissionAndFieldSteradians:\n number;\n sensorPlaneSpectralIrradianceWattsPerSquareMeterNanometer:\n number;\n scientificStatus: \"approximation\";\n sceneRadianceScientificStatus:\n SceneRadianceEvaluationResult[\"scientificStatus\"];\n opticalProfileScientificStatus:\n OpticalBridgeScientificStatus;\n sceneRadianceUncertainty:\n SceneRadianceEvaluationResult[\"uncertainty\"];\n opticalUncertainty:\n OpticalBridgeUncertainty;\n radianceAmplificationApplied: false;\n fieldThroughputAppliedExactlyOnce:\n true;\n universalCos4FalloffApplied: false;\n distortionAreaCorrectionApplied: false;\n psfRedistributionApplied: false;\n sensorOpticalStackApplied: false;\n cfaApplied: false;\n quantumEfficiencyApplied: false;\n spectralResponsivityApplied: false;\n strayLightApplied: false;\n polarizationModeled: false;\n wavelengthChangingBehaviorModeled:\n false;\n volumetricScatteringModeled: false;\n calibratedSensorPlaneIrradianceClaimAuthorized:\n false;\n componentEvidence: {\n sceneRadiance:\n readonly EvidenceProvenance[];\n opticalProfile:\n readonly EvidenceProvenance[];\n transmission:\n readonly EvidenceProvenance[];\n workingFNumber:\n readonly EvidenceProvenance[];\n frontOfLensFilters:\n readonly EvidenceProvenance[];\n };\n limitations:\n readonly string[];\n}\n\nfunction requireRecord(\n value: unknown,\n path: string,\n allowedKeys: readonly string[] | null\n): UnknownRecord {\n if (\n typeof value !== \"object\" ||\n value === null ||\n Array.isArray(value)\n ) {\n throw new InvalidConfigurationError(\n path + \" must be an object.\"\n );\n }\n if (allowedKeys !== null) rejectUnknownFields(value, allowedKeys, path);\n return value as UnknownRecord;\n}\n\nfunction requireNonEmptyString(\n value: unknown,\n path: string\n): string {\n if (\n typeof value !== \"string\" ||\n value.trim().length === 0\n ) {\n throw new InvalidConfigurationError(\n path + \" must be a non-empty string.\"\n );\n }\n return value.trim();\n}\n\nfunction requireFinite(\n value: unknown,\n path: string\n): number {\n if (\n typeof value !== \"number\" ||\n !Number.isFinite(value)\n ) {\n throw new InvalidConfigurationError(\n path + \" must be finite.\"\n );\n }\n return value;\n}\n\nfunction requirePositiveFinite(\n value: unknown,\n path: string\n): number {\n const parsed =\n requireFinite(value, path);\n if (parsed <= 0) {\n throw new InvalidConfigurationError(\n path +\n \" must be greater than zero.\"\n );\n }\n return parsed;\n}\n\nfunction requireFraction(\n value: unknown,\n path: string\n): number {\n const parsed =\n requireFinite(value, path);\n if (\n parsed < 0 ||\n parsed > 1\n ) {\n throw new InvalidConfigurationError(\n path +\n \" must be from zero through one.\"\n );\n }\n return parsed;\n}\n\nfunction parseRange(\n value: unknown,\n path: string\n): NumericRange {\n const record =\n requireRecord(value, path, [\"minimum\", \"maximum\"]);\n const minimum =\n requirePositiveFinite(\n record.minimum,\n path + \".minimum\"\n );\n const maximum =\n requirePositiveFinite(\n record.maximum,\n path + \".maximum\"\n );\n if (minimum > maximum) {\n throw new InvalidConfigurationError(\n path +\n \".minimum must be less than or equal to maximum.\"\n );\n }\n return {\n minimum,\n maximum\n };\n}\n\nfunction parseScientificStatus(\n value: unknown,\n path: string\n): OpticalBridgeScientificStatus {\n if (\n value !== \"calibrated\" &&\n value !== \"approximation\"\n ) {\n throw new InvalidConfigurationError(\n path + \" is invalid.\"\n );\n }\n return value;\n}\n\nfunction parseUncertainty(\n value: unknown,\n path: string\n): OpticalBridgeUncertainty {\n const record =\n requireRecord(value, path, null);\n rejectUnknownVariantFields(record, \"kind\", UNCERTAINTY_VARIANT_FIELDS, path);\n\n if (record.kind === \"relative\") {\n return {\n kind: \"relative\",\n fraction:\n requireFraction(\n record.fraction,\n path + \".fraction\"\n ),\n basis:\n requireNonEmptyString(\n record.basis,\n path + \".basis\"\n )\n };\n }\n\n if (\n record.kind ===\n \"not-quantified\"\n ) {\n return {\n kind: \"not-quantified\",\n limitation:\n requireNonEmptyString(\n record.limitation,\n path + \".limitation\"\n )\n };\n }\n\n throw new InvalidConfigurationError(\n path + \".kind is invalid.\"\n );\n}\n\nfunction parseLimitations(\n value: unknown,\n path: string\n): readonly string[] {\n if (!Array.isArray(value)) {\n throw new InvalidConfigurationError(\n path + \" must be an array.\"\n );\n }\n const parsed = value.map(\n (entry, index) =>\n requireNonEmptyString(\n entry,\n path +\n \"[\" +\n index +\n \"]\"\n )\n );\n if (\n new Set(parsed).size !==\n parsed.length\n ) {\n throw new InvalidConfigurationError(\n path +\n \" must not contain duplicates.\"\n );\n }\n return parsed;\n}\n\nfunction parseReusableNumericEvidence(\n value: unknown,\n path: string\n): readonly EvidenceProvenance[] {\n const evidence =\n parseEvidenceList(value, path);\n\n if (\n evidence.some(\n (entry) =>\n entry.reuseStatus ===\n \"factual-reference-only\"\n )\n ) {\n throw new InvalidConfigurationError(\n path +\n \" for numeric optical curve data must be reusable-data or photivra-owned.\"\n );\n }\n return evidence;\n}\n\nfunction parseSpectralSamples(\n value: unknown,\n path: string\n): readonly SpectralTransmissionSample[] {\n if (\n !Array.isArray(value) ||\n value.length < 2\n ) {\n throw new InvalidConfigurationError(\n path +\n \" must contain at least two samples.\"\n );\n }\n\n let previous =\n Number.NEGATIVE_INFINITY;\n return value.map(\n (entry, index) => {\n const samplePath =\n path +\n \"[\" +\n index +\n \"]\";\n const record =\n requireRecord(\n entry,\n samplePath, [\"wavelengthNanometers\", \"linearTransmissionFactor\"]\n );\n const wavelengthNanometers =\n requirePositiveFinite(\n record.wavelengthNanometers,\n samplePath +\n \".wavelengthNanometers\"\n );\n if (\n wavelengthNanometers <=\n previous\n ) {\n throw new InvalidConfigurationError(\n path +\n \" wavelengths must be strictly increasing.\"\n );\n }\n previous =\n wavelengthNanometers;\n return {\n wavelengthNanometers,\n linearTransmissionFactor:\n requireFraction(\n record.linearTransmissionFactor,\n samplePath +\n \".linearTransmissionFactor\"\n )\n };\n }\n );\n}\n\nfunction parseTransmission(\n value: unknown,\n path: string\n): OpticalTransmissionModel {\n const record =\n requireRecord(value, path, null);\n rejectUnknownVariantFields(record, \"kind\", {\n // workingTStop and wavelengthRangeNanometers (spectral) and samples (working T-stop) are rejected below with their own messages.\n \"spectral-transmission\": [\"kind\", \"scientificStatus\", \"wavelengthBasis\", \"samples\", \"uncertainty\", \"workingTStop\", \"wavelengthRangeNanometers\"],\n \"effective-working-t-stop-approximation\": [\"kind\", \"scientificStatus\", \"workingTStop\", \"wavelengthBasis\", \"wavelengthRangeNanometers\",\n \"uncertainty\", \"limitation\", \"samples\"]\n }, path);\n\n if (\n record.kind ===\n \"spectral-transmission\"\n ) {\n if (\n record.workingTStop !==\n undefined ||\n record.wavelengthRangeNanometers !==\n undefined\n ) {\n throw new InvalidConfigurationError(\n path +\n \" spectral-transmission must not include T-stop-only fields.\"\n );\n }\n\n const status =\n parseScientificStatus(\n record.scientificStatus,\n path +\n \".scientificStatus\"\n );\n const samplesFact =\n requireRecord(\n record.samples,\n path + \".samples\", [\"value\", \"evidence\"]\n );\n const uncertainty =\n parseUncertainty(\n record.uncertainty,\n path + \".uncertainty\"\n );\n\n if (\n status === \"calibrated\" &&\n uncertainty.kind !==\n \"relative\"\n ) {\n throw new InvalidConfigurationError(\n path +\n \" calibrated spectral transmission requires quantified relative uncertainty.\"\n );\n }\n\n return {\n kind:\n \"spectral-transmission\",\n scientificStatus: status,\n wavelengthBasis:\n parseResolvedBasis(\n record.wavelengthBasis,\n path +\n \".wavelengthBasis\"\n ),\n samples: {\n value:\n parseSpectralSamples(\n samplesFact.value,\n path +\n \".samples.value\"\n ),\n evidence:\n parseReusableNumericEvidence(\n samplesFact.evidence,\n path +\n \".samples.evidence\"\n )\n },\n uncertainty\n };\n }\n\n if (\n record.kind ===\n \"effective-working-t-stop-approximation\"\n ) {\n if (\n record.samples !==\n undefined\n ) {\n throw new InvalidConfigurationError(\n path +\n \" T-stop approximation must not include spectral transmission samples.\"\n );\n }\n if (\n record.scientificStatus !==\n \"approximation\"\n ) {\n throw new InvalidConfigurationError(\n path +\n ' T-stop scientificStatus must be \"approximation\".'\n );\n }\n const workingTStopFact =\n requireRecord(\n record.workingTStop,\n path +\n \".workingTStop\", [\"value\", \"evidence\"]\n );\n return {\n kind:\n \"effective-working-t-stop-approximation\",\n scientificStatus:\n \"approximation\",\n workingTStop: {\n value:\n requirePositiveFinite(\n workingTStopFact.value,\n path +\n \".workingTStop.value\"\n ),\n evidence:\n parseEvidenceList(\n workingTStopFact.evidence,\n path +\n \".workingTStop.evidence\"\n )\n },\n wavelengthBasis:\n parseResolvedBasis(\n record.wavelengthBasis,\n path +\n \".wavelengthBasis\"\n ),\n wavelengthRangeNanometers:\n parseRange(\n record.wavelengthRangeNanometers,\n path +\n \".wavelengthRangeNanometers\"\n ),\n uncertainty:\n parseUncertainty(\n record.uncertainty,\n path + \".uncertainty\"\n ),\n limitation:\n requireNonEmptyString(\n record.limitation,\n path +\n \".limitation\"\n )\n };\n }\n\n throw new InvalidConfigurationError(\n path + \".kind is invalid.\"\n );\n}\n\nfunction parseResolvedBasis(\n value: unknown,\n path: string\n): Exclude<\n SpectralWavelengthBasis,\n \"unspecified\"\n> {\n const parsed =\n parseSpectralWavelengthBasis(\n value,\n path\n );\n if (parsed === \"unspecified\") {\n throw new InvalidConfigurationError(\n path +\n ' must resolve to \"air\" or \"vacuum\".'\n );\n }\n return parsed;\n}\n\nfunction parseFocusApplicability(\n value: unknown,\n path: string\n): OpticalBridgeFocusApplicability {\n const record =\n requireRecord(value, path, null);\n rejectUnknownVariantFields(record, \"kind\", { any: [\"kind\"], \"finite-distance-range\": [\"kind\", \"objectDistanceM\"] }, path);\n\n if (record.kind === \"any\") {\n return {\n kind: \"any\"\n };\n }\n if (\n record.kind ===\n \"finite-distance-range\"\n ) {\n return {\n kind:\n \"finite-distance-range\",\n objectDistanceM:\n parseRange(\n record.objectDistanceM,\n path +\n \".objectDistanceM\"\n )\n };\n }\n throw new InvalidConfigurationError(\n path + \".kind is invalid.\"\n );\n}\n\n/**\n * Validates an untrusted scene-to-sensor profile and returns the normalized typed contract. Unknown\n * enum values, missing required fields and incompatible scientific data are rejected here.\n *\n * The optical bridge turns outgoing scene radiance (W/m²/sr/nm) into irradiance (W/m²/nm) arriving\n * at the front of the sensor stack.\n * - Circular paraxial acceptance is pi/(4*Nworking²). At finite focus with unit pupil magnification,\n * the working f-number is N*(1+m).\n * - Spectral transmission and an effective working T-stop are alternative paths; use one.\n * - Field throughput is applied exactly once.\n * - Sensor response and PSF (point-spread function) blur happen later in the pipeline.\n * @param value - unknown. Untrusted input; TypeScript types alone are not validation.\n * @returns SceneToSensorIrradianceProfile. The result states its shape and scientific status; a successful call does not imply calibration.\n *\n * @see docs/API_REFERENCE.md for the root export and exact type graph.\n */\nexport function parseSceneToSensorIrradianceProfile(\n value: unknown\n): SceneToSensorIrradianceProfile {\n const record =\n requireRecord(\n value,\n \"sceneToSensorIrradianceProfile\", [\"schemaVersion\", \"applicability\", \"scientificStatus\", \"transmission\", \"distortionAreaMappingOwnership\", \"psfRedistributionOwnership\", \"sensorOpticalStackIncluded\", \"strayLightIncluded\", \"polarizationModeled\", \"wavelengthChangingBehaviorModeled\", \"volumetricScatteringModeled\", \"profileId\", \"profileVersion\", \"lensProfileId\", \"evidence\", \"limitations\"]\n );\n if (\n record.schemaVersion !==\n SCENE_TO_SENSOR_IRRADIANCE_PROFILE_SCHEMA_VERSION\n ) {\n throw new InvalidConfigurationError(\n 'sceneToSensorIrradianceProfile.schemaVersion must be \"' +\n SCENE_TO_SENSOR_IRRADIANCE_PROFILE_SCHEMA_VERSION +\n '\".'\n );\n }\n\n const applicability =\n requireRecord(\n record.applicability,\n \"sceneToSensorIrradianceProfile.applicability\", [\"focalLengthMm\", \"nominalFNumber\", \"focus\"]\n );\n const status =\n parseScientificStatus(\n record.scientificStatus,\n \"sceneToSensorIrradianceProfile.scientificStatus\"\n );\n const transmission =\n parseTransmission(\n record.transmission,\n \"sceneToSensorIrradianceProfile.transmission\"\n );\n\n if (\n status === \"calibrated\" &&\n transmission.scientificStatus !==\n \"calibrated\"\n ) {\n throw new InvalidConfigurationError(\n \"A calibrated optical bridge profile requires calibrated spectral transmission.\"\n );\n }\n\n if (\n record.distortionAreaMappingOwnership !==\n \"not-applied-by-bridge\" ||\n record.psfRedistributionOwnership !==\n \"downstream-normalized-energy-redistribution\" ||\n record.sensorOpticalStackIncluded !==\n false ||\n record.strayLightIncluded !==\n false ||\n record.polarizationModeled !==\n false ||\n record.wavelengthChangingBehaviorModeled !==\n false ||\n record.volumetricScatteringModeled !==\n false\n ) {\n throw new InvalidConfigurationError(\n \"sceneToSensorIrradianceProfile ownership/completeness flags are invalid for schema 0.1.0.\"\n );\n }\n\n return {\n schemaVersion:\n SCENE_TO_SENSOR_IRRADIANCE_PROFILE_SCHEMA_VERSION,\n profileId:\n requireNonEmptyString(\n record.profileId,\n \"sceneToSensorIrradianceProfile.profileId\"\n ),\n profileVersion:\n requireNonEmptyString(\n record.profileVersion,\n \"sceneToSensorIrradianceProfile.profileVersion\"\n ),\n lensProfileId:\n requireNonEmptyString(\n record.lensProfileId,\n \"sceneToSensorIrradianceProfile.lensProfileId\"\n ),\n scientificStatus: status,\n applicability: {\n focalLengthMm:\n parseRange(\n applicability.focalLengthMm,\n \"sceneToSensorIrradianceProfile.applicability.focalLengthMm\"\n ),\n nominalFNumber:\n parseRange(\n applicability.nominalFNumber,\n \"sceneToSensorIrradianceProfile.applicability.nominalFNumber\"\n ),\n focus:\n parseFocusApplicability(\n applicability.focus,\n \"sceneToSensorIrradianceProfile.applicability.focus\"\n )\n },\n transmission,\n distortionAreaMappingOwnership:\n \"not-applied-by-bridge\",\n psfRedistributionOwnership:\n \"downstream-normalized-energy-redistribution\",\n sensorOpticalStackIncluded:\n false,\n strayLightIncluded: false,\n polarizationModeled: false,\n wavelengthChangingBehaviorModeled:\n false,\n volumetricScatteringModeled:\n false,\n evidence:\n parseEvidenceList(\n record.evidence,\n \"sceneToSensorIrradianceProfile.evidence\"\n ),\n limitations:\n parseLimitations(\n record.limitations,\n \"sceneToSensorIrradianceProfile.limitations\"\n )\n };\n}\n\nfunction ensureWithin(\n value: number,\n range: NumericRange,\n path: string\n): void {\n if (\n value < range.minimum ||\n value > range.maximum\n ) {\n throw new InvalidScientificInputError(\n path +\n \" lies outside the optical profile applicability range.\"\n );\n }\n}\n\n/**\n * Internal (2.6; not exported from the package): N_w / N = 1 + m for an ideal symmetric thin lens with unity pupil\n * magnification focused at `objectDistanceM`, m = v/s from `calculateThinLensImageDistance`. The irradiance bridge's\n * `ideal-symmetric-thin-lens` focus uses exactly this factor, and the framing reports derive their close-up light\n * factor 1/(1 + m)² from it, so the two cannot drift apart.\n */\nexport function thinLensWorkingFNumberFactor(focalLengthMm: number, objectDistanceM: number): number {\n return 1 + calculateThinLensImageDistance({ focalLengthMm, objectDistanceM }).value.magnification;\n}\n\nfunction workingFNumber(\n focus:\n OpticalBridgeFocusContext,\n focalLengthMm: number,\n nominalFNumber: number\n): {\n value: number;\n evidence:\n readonly EvidenceProvenance[];\n} {\n if (\n focus.kind === \"infinity-focus\"\n ) {\n return {\n value: nominalFNumber,\n evidence: []\n };\n }\n\n if (\n focus.kind ===\n \"ideal-symmetric-thin-lens\"\n ) {\n if (\n focus\n .pupilMagnificationAssumption !==\n \"unity\"\n ) {\n throw new InvalidScientificInputError(\n 'Ideal symmetric thin-lens focus requires pupilMagnificationAssumption \"unity\".'\n );\n }\n return {\n value:\n nominalFNumber *\n thinLensWorkingFNumberFactor(focalLengthMm, focus.objectDistanceM),\n evidence: []\n };\n }\n\n if (\n focus.kind ===\n \"supplied-working-f-number\"\n ) {\n const value =\n requirePositiveFiniteScientific(\n focus.workingFNumber.value,\n \"focus.workingFNumber.value\"\n );\n return {\n value,\n evidence:\n parseEvidenceList(\n focus.workingFNumber.evidence,\n \"focus.workingFNumber.evidence\"\n )\n };\n }\n\n throw new InvalidConfigurationError(\n \"focus.kind is invalid.\"\n );\n}\n\nfunction requirePositiveFiniteScientific(\n value: unknown,\n path: string\n): number {\n if (\n typeof value !== \"number\" ||\n !Number.isFinite(value) ||\n value <= 0\n ) {\n throw new InvalidScientificInputError(\n path +\n \" must be finite and greater than zero.\"\n );\n }\n return value;\n}\n\nfunction finiteFocusDistance(\n focus:\n OpticalBridgeFocusContext\n): number | null {\n if (\n focus.kind ===\n \"ideal-symmetric-thin-lens\"\n ) {\n return requirePositiveFiniteScientific(\n focus.objectDistanceM,\n \"focus.objectDistanceM\"\n );\n }\n if (\n focus.kind ===\n \"supplied-working-f-number\" &&\n focus.focus.kind === \"finite\"\n ) {\n return requirePositiveFiniteScientific(\n focus.focus.objectDistanceM,\n \"focus.focus.objectDistanceM\"\n );\n }\n return null;\n}\n\nfunction interpolateTransmission(\n model:\n Extract<\n OpticalTransmissionModel,\n { kind: \"spectral-transmission\" }\n >,\n wavelengthNanometers: number\n): number {\n const samples =\n model.samples.value;\n const first =\n samples[0]!;\n const last =\n samples[\n samples.length - 1\n ]!;\n\n if (\n wavelengthNanometers <\n first.wavelengthNanometers ||\n wavelengthNanometers >\n last.wavelengthNanometers\n ) {\n throw new InvalidScientificInputError(\n \"Scene wavelength lies outside the spectral transmission sample range.\"\n );\n }\n\n if (\n wavelengthNanometers ===\n first.wavelengthNanometers\n ) {\n return first\n .linearTransmissionFactor;\n }\n\n for (\n let index = 1;\n index < samples.length;\n index += 1\n ) {\n const right =\n samples[index]!;\n if (\n wavelengthNanometers <=\n right.wavelengthNanometers\n ) {\n const left =\n samples[index - 1]!;\n if (\n wavelengthNanometers ===\n right.wavelengthNanometers\n ) {\n return right\n .linearTransmissionFactor;\n }\n const phase =\n (wavelengthNanometers -\n left.wavelengthNanometers) /\n (right.wavelengthNanometers -\n left.wavelengthNanometers);\n return (\n left\n .linearTransmissionFactor +\n phase *\n (right\n .linearTransmissionFactor -\n left\n .linearTransmissionFactor)\n );\n }\n }\n\n return last\n .linearTransmissionFactor;\n}\n\nfunction fieldFactor(\n field:\n OpticalBridgeFieldThroughput,\n imagePointMm: {\n x: number;\n y: number;\n }\n): number {\n if (field.kind === \"unity\") {\n return 1;\n }\n if (\n field.kind ===\n \"illumination-vignetting-result\"\n ) {\n const result =\n field.result;\n const scale = Math.max(\n 1,\n Math.abs(imagePointMm.x),\n Math.abs(imagePointMm.y),\n Math.abs(result.imagePointMm.x),\n Math.abs(result.imagePointMm.y)\n );\n const tolerance =\n Number.EPSILON *\n 64 *\n scale;\n if (\n Math.abs(\n result.imagePointMm.x -\n imagePointMm.x\n ) > tolerance ||\n Math.abs(\n result.imagePointMm.y -\n imagePointMm.y\n ) > tolerance\n ) {\n throw new InvalidScientificInputError(\n \"Illumination-vignetting result imagePointMm must match the optical bridge imagePointMm.\"\n );\n }\n const factor =\n result.linearThroughputFactor;\n if (\n !Number.isFinite(factor) ||\n factor <= 0 ||\n factor > 1\n ) {\n throw new InvalidScientificInputError(\n \"Field throughput factor must be finite and in (0, 1].\"\n );\n }\n return factor;\n }\n throw new InvalidConfigurationError(\n \"fieldThroughput.kind is invalid.\"\n );\n}\n\nfunction validateSceneIdentity(\n request:\n SceneRadianceEvaluationRequest,\n result:\n SceneRadianceEvaluationResult\n): void {\n if (\n request.sampleId !==\n result.sampleId ||\n request.providerProfileId !==\n result.providerProfileId ||\n request.sceneId !==\n result.sceneId ||\n request.wavelengthNanometers !==\n result.wavelengthNanometers ||\n request.wavelengthBasis !==\n result.wavelengthBasis\n ) {\n throw new InvalidScientificInputError(\n \"Scene-radiance request/result identity must match exactly.\"\n );\n }\n}\n\n/**\n * Applies the declared pupil acceptance and exactly one transmission or field-throughput path to\n * spectral scene radiance. Returns the irradiance before the sensor stack, with conservative\n * evidence.\n *\n * The optical bridge turns outgoing scene radiance (W/m²/sr/nm) into irradiance (W/m²/nm) arriving\n * at the front of the sensor stack.\n * - Circular paraxial acceptance is pi/(4*Nworking²). At finite focus with unit pupil magnification,\n * the working f-number is N*(1+m).\n * - Spectral transmission and an effective working T-stop are alternative paths; use one.\n * - Field throughput is applied exactly once.\n * - Sensor response and PSF (point-spread function) blur happen later in the pipeline.\n * @param input - CalculateSceneRadianceToSensorIrradianceInput. See that type for coordinates, units and profile binding.\n * @returns CalculationResult<\n SceneToSensorIrradianceResult\n>. The result states its shape and scientific status; a successful call does not imply calibration.\n *\n * @see docs/API_REFERENCE.md for the root export and exact type graph.\n */\nexport function calculateSceneRadianceToSensorIrradiance(\n input:\n CalculateSceneRadianceToSensorIrradianceInput\n): CalculationResult<\n SceneToSensorIrradianceResult\n> {\n requireInputKeys(input, \"calculateSceneRadianceToSensorIrradiance\", [\"sceneRadianceRequest\", \"sceneRadianceResult\", \"profile\", \"focalLengthMm\", \"nominalFNumber\", \"focus\", \"imagePointMm\", \"fieldThroughput\", \"frontOfLensFilters\"]);\n const request =\n parseSceneRadianceEvaluationRequest(\n input.sceneRadianceRequest\n );\n const sceneResult =\n parseSceneRadianceEvaluationResult(\n input.sceneRadianceResult\n );\n validateSceneIdentity(\n request,\n sceneResult\n );\n\n const profile =\n parseSceneToSensorIrradianceProfile(\n input.profile\n );\n const focalLengthMm =\n requirePositiveFiniteScientific(\n input.focalLengthMm,\n \"focalLengthMm\"\n );\n const nominalFNumber =\n requirePositiveFiniteScientific(\n input.nominalFNumber,\n \"nominalFNumber\"\n );\n\n ensureWithin(\n focalLengthMm,\n profile.applicability\n .focalLengthMm,\n \"focalLengthMm\"\n );\n ensureWithin(\n nominalFNumber,\n profile.applicability\n .nominalFNumber,\n \"nominalFNumber\"\n );\n\n const focusDistanceM =\n finiteFocusDistance(input.focus);\n if (\n profile.applicability.focus.kind ===\n \"finite-distance-range\"\n ) {\n if (focusDistanceM === null) {\n throw new InvalidScientificInputError(\n \"Optical profile requires a finite focus distance.\"\n );\n }\n ensureWithin(\n focusDistanceM,\n profile.applicability\n .focus.objectDistanceM,\n \"focus object distance\"\n );\n }\n\n const working =\n workingFNumber(\n input.focus,\n focalLengthMm,\n nominalFNumber\n );\n const workingFNumberValue =\n working.value;\n const geometricAcceptance =\n Math.PI /\n (4 *\n workingFNumberValue *\n workingFNumberValue);\n\n if (\n !Number.isFinite(\n geometricAcceptance\n ) ||\n geometricAcceptance <= 0\n ) {\n throw new InvalidScientificInputError(\n \"Paraxial geometric acceptance must remain finite and greater than zero.\"\n );\n }\n\n const transmission =\n profile.transmission;\n\n if (\n request.wavelengthBasis !==\n transmission.wavelengthBasis\n ) {\n throw new InvalidScientificInputError(\n \"Scene-radiance and optical-transmission wavelength bases must match; implicit air/vacuum conversion is not performed.\"\n );\n }\n\n let spectralTransmissionFactor:\n number | null = null;\n let effectiveWorkingTStop:\n number | null = null;\n let tStopEquivalentTransmissionFactor:\n number | null = null;\n let effectiveAcceptance =\n geometricAcceptance;\n let transmissionEvidence:\n readonly EvidenceProvenance[];\n\n if (\n transmission.kind ===\n \"spectral-transmission\"\n ) {\n spectralTransmissionFactor =\n interpolateTransmission(\n transmission,\n request.wavelengthNanometers\n );\n effectiveAcceptance *=\n spectralTransmissionFactor;\n transmissionEvidence =\n transmission.samples.evidence;\n } else {\n ensureWithin(\n request.wavelengthNanometers,\n transmission\n .wavelengthRangeNanometers,\n \"scene wavelength\"\n );\n effectiveWorkingTStop =\n transmission.workingTStop.value;\n if (\n effectiveWorkingTStop <\n workingFNumberValue\n ) {\n throw new InvalidScientificInputError(\n \"effective working T-stop must not be smaller than the geometric working f-number for a passive optical approximation.\"\n );\n }\n tStopEquivalentTransmissionFactor =\n (workingFNumberValue /\n effectiveWorkingTStop) **\n 2;\n effectiveAcceptance =\n Math.PI /\n (4 *\n effectiveWorkingTStop *\n effectiveWorkingTStop);\n transmissionEvidence =\n transmission\n .workingTStop.evidence;\n }\n\n let frontOfLensFilterCount = 0;\n let frontOfLensFilterPolarizationModeled = false;\n let frontOfLensFilterTransmissionFactor = 1;\n let frontOfLensFilterAttenuationStops = 0;\n let frontOfLensFilterEvidence:\n readonly EvidenceProvenance[] = [];\n let frontOfLensFilterLimitations:\n readonly string[] = [];\n\n if (\n input.frontOfLensFilters !==\n undefined\n ) {\n const composed =\n composeFrontOfLensFilterTransmission({\n filters:\n input.frontOfLensFilters,\n wavelengthNanometers:\n request.wavelengthNanometers,\n wavelengthBasis:\n request.wavelengthBasis\n });\n frontOfLensFilterCount =\n composed.appliedFilterCount;\n frontOfLensFilterPolarizationModeled =\n composed.polarizationModeled;\n frontOfLensFilterTransmissionFactor =\n composed\n .combinedLinearTransmissionFactor;\n frontOfLensFilterAttenuationStops =\n composed\n .combinedAttenuationStops;\n frontOfLensFilterEvidence =\n composed.components.flatMap(\n (component) =>\n component.evidence\n );\n frontOfLensFilterLimitations =\n composed.components.flatMap(\n (component) =>\n component.limitations\n );\n effectiveAcceptance *=\n frontOfLensFilterTransmissionFactor;\n }\n\n const fieldThroughputFactor =\n fieldFactor(\n input.fieldThroughput,\n input.imagePointMm\n );\n effectiveAcceptance *=\n fieldThroughputFactor;\n\n const sceneRadiance =\n sceneResult\n .spectralRadianceWattsPerSquareMeterSteradianNanometer;\n const irradiance =\n sceneRadiance *\n effectiveAcceptance;\n\n if (\n !Number.isFinite(irradiance) ||\n irradiance < 0\n ) {\n throw new InvalidScientificInputError(\n \"Sensor-plane spectral irradiance must remain finite and non-negative.\"\n );\n }\n\n const limitations = [\n ...profile.limitations,\n ...frontOfLensFilterLimitations,\n \"Front-of-lens filter transmission is applied outside the lens throughput path exactly once and does not change geometric working f-number.\",\n \"Paraxial circular-pupil acceptance uses pi/(4*N_working^2); no universal cos^4 field falloff is added.\",\n \"Field throughput is supplied separately and applied exactly once.\",\n \"Geometric distortion area-density/Jacobian correction is not applied by this bridge.\",\n \"PSF/diffraction energy redistribution is downstream and must preserve normalized energy apart from separately owned throughput losses.\",\n \"Sensor optical stack, microlens, CFA, QE/responsivity and charge conversion are downstream.\",\n frontOfLensFilterPolarizationModeled\n ? \"Flare, ghosting, veiling glare, scene-radiance polarization (scene light is treated as unpolarized; the front-of-lens linear polarizer transmits (k1 + k2) / 2), volumetric scattering and wavelength-changing behavior are not modeled.\"\n : \"Flare, ghosting, veiling glare, polarization, volumetric scattering and wavelength-changing behavior are not modeled.\"\n ];\n\n return approximationResult(\n {\n schemaVersion:\n SCENE_TO_SENSOR_IRRADIANCE_PROFILE_SCHEMA_VERSION,\n profileId: profile.profileId,\n profileVersion:\n profile.profileVersion,\n lensProfileId:\n profile.lensProfileId,\n sampleId: request.sampleId,\n providerProfileId:\n request.providerProfileId,\n sceneId: request.sceneId,\n timeSecondsFromExposureStart:\n request\n .timeSecondsFromExposureStart,\n wavelengthNanometers:\n request.wavelengthNanometers,\n wavelengthBasis:\n request.wavelengthBasis,\n inputQuantity:\n \"outgoing-spectral-radiance\",\n inputUnit:\n \"W/m^2/sr/nm\",\n outputQuantity:\n \"sensor-plane-spectral-irradiance\",\n outputUnit: \"W/m^2/nm\",\n sceneSpectralRadianceWattsPerSquareMeterSteradianNanometer:\n sceneRadiance,\n focalLengthMm,\n nominalFNumber,\n workingFNumber:\n workingFNumberValue,\n focusModel: input.focus.kind,\n paraxialGeometricAcceptanceSolidAngleSteradians:\n geometricAcceptance,\n transmissionPath:\n transmission.kind,\n spectralTransmissionFactor,\n effectiveWorkingTStop,\n tStopEquivalentTransmissionFactor,\n frontOfLensFilterCount,\n frontOfLensFilterTransmissionFactor,\n frontOfLensFilterAttenuationStops,\n frontOfLensFilterTransmissionAppliedExactlyOnce:\n true,\n frontOfLensFilterPolarizationModeled,\n fieldThroughputFactor,\n effectiveAcceptanceAfterTransmissionAndFieldSteradians:\n effectiveAcceptance,\n sensorPlaneSpectralIrradianceWattsPerSquareMeterNanometer:\n irradiance,\n scientificStatus:\n \"approximation\",\n sceneRadianceScientificStatus:\n sceneResult.scientificStatus,\n opticalProfileScientificStatus:\n profile.scientificStatus,\n sceneRadianceUncertainty:\n sceneResult.uncertainty,\n opticalUncertainty:\n transmission.uncertainty,\n radianceAmplificationApplied:\n false,\n fieldThroughputAppliedExactlyOnce:\n true,\n universalCos4FalloffApplied:\n false,\n distortionAreaCorrectionApplied:\n false,\n psfRedistributionApplied:\n false,\n sensorOpticalStackApplied:\n false,\n cfaApplied: false,\n quantumEfficiencyApplied: false,\n spectralResponsivityApplied:\n false,\n strayLightApplied: false,\n polarizationModeled: false,\n wavelengthChangingBehaviorModeled:\n false,\n volumetricScatteringModeled:\n false,\n calibratedSensorPlaneIrradianceClaimAuthorized:\n false,\n componentEvidence: {\n sceneRadiance:\n sceneResult.evidence,\n opticalProfile:\n profile.evidence,\n transmission:\n transmissionEvidence,\n workingFNumber:\n working.evidence,\n frontOfLensFilters:\n frontOfLensFilterEvidence\n },\n limitations\n },\n \"scene-radiance-to-sensor-irradiance\",\n \"1.1.0\",\n limitations\n );\n}\n"]}
@@ -110,7 +110,11 @@ export interface PrintPlan {
110
110
  /** Validates and copies an untrusted print request. It never assumes the source is native if that is not declared. */
111
111
  export declare function parsePrintPlanInput(value: unknown): PrintPlanInput;
112
112
  /** Finds the smallest file, at the exact native aspect ratio, that meets the declared sampling and lab constraints.
113
- * The angular guidance is an approximate rule of thumb; the geometry itself is calculated exactly.
113
+ * The angular guidance is an approximate rule of thumb; the geometry itself is calculated exactly. A common criterion,
114
+ * one arcminute per pixel, is normal (20/20) visual acuity under optimal conditions: the minimum angle of resolution of an
115
+ * ideal eye is about 1 minute of arc, and 20/20 letters are built from elements that each subtend 1 arcmin (Z. Alomar, K. D. Bojikian, "Visual Acuity Testing in Adults", EyeWiki, American Academy of Ophthalmology,
116
+ * https://eyewiki.aao.org/Visual_Acuity_Testing_in_Adults, last edited June 16, 2026).
117
+ * Some viewers resolve finer detail and many resolve coarser, so it stays a rule of thumb, and the criterion is the caller's.
114
118
  * It does not assess source detail, perceived quality, file writing or available resources.
115
119
  */
116
120
  export declare function calculatePrintPlan(value: PrintPlanInput): CalculationResult<PrintPlan>;
@@ -134,5 +138,8 @@ export interface PrintSizeLimit {
134
138
  }
135
139
  /** Calculates the largest print size under the stated conditions. Lab constraints need individual plans,
136
140
  * so this size query reports them as unsupported rather than ignoring them.
141
+ * As in `calculatePrintPlan`, an angular criterion is an approximate rule of thumb: one arcminute per pixel is normal
142
+ * (20/20) acuity under optimal conditions, which some viewers exceed and many do not (Z. Alomar, K. D. Bojikian, "Visual Acuity Testing in Adults", EyeWiki, American Academy of Ophthalmology,
143
+ * https://eyewiki.aao.org/Visual_Acuity_Testing_in_Adults, last edited June 16, 2026).
137
144
  */
138
145
  export declare function calculatePrintSizeLimit(value: PrintSizeLimitInput): CalculationResult<PrintSizeLimit>;
@@ -161,7 +161,11 @@ function diagnostics(raster, width, height, distance) {
161
161
  return { raster, pixelsPerInch: { x: 25.4 / px, y: 25.4 / py }, angularPixelPitchArcminutes: { x: 2 * Math.atan((px / distance) / 2) / RAD_PER_ARCMIN, y: 2 * Math.atan((py / distance) / 2) / RAD_PER_ARCMIN } };
162
162
  }
163
163
  /** Finds the smallest file, at the exact native aspect ratio, that meets the declared sampling and lab constraints.
164
- * The angular guidance is an approximate rule of thumb; the geometry itself is calculated exactly.
164
+ * The angular guidance is an approximate rule of thumb; the geometry itself is calculated exactly. A common criterion,
165
+ * one arcminute per pixel, is normal (20/20) visual acuity under optimal conditions: the minimum angle of resolution of an
166
+ * ideal eye is about 1 minute of arc, and 20/20 letters are built from elements that each subtend 1 arcmin (Z. Alomar, K. D. Bojikian, "Visual Acuity Testing in Adults", EyeWiki, American Academy of Ophthalmology,
167
+ * https://eyewiki.aao.org/Visual_Acuity_Testing_in_Adults, last edited June 16, 2026).
168
+ * Some viewers resolve finer detail and many resolve coarser, so it stays a rule of thumb, and the criterion is the caller's.
165
169
  * It does not assess source detail, perceived quality, file writing or available resources.
166
170
  */
167
171
  export function calculatePrintPlan(value) {
@@ -279,6 +283,9 @@ export function calculatePrintPlan(value) {
279
283
  }
280
284
  /** Calculates the largest print size under the stated conditions. Lab constraints need individual plans,
281
285
  * so this size query reports them as unsupported rather than ignoring them.
286
+ * As in `calculatePrintPlan`, an angular criterion is an approximate rule of thumb: one arcminute per pixel is normal
287
+ * (20/20) acuity under optimal conditions, which some viewers exceed and many do not (Z. Alomar, K. D. Bojikian, "Visual Acuity Testing in Adults", EyeWiki, American Academy of Ophthalmology,
288
+ * https://eyewiki.aao.org/Visual_Acuity_Testing_in_Adults, last edited June 16, 2026).
282
289
  */
283
290
  export function calculatePrintSizeLimit(value) {
284
291
  const r = record(value, ["plan", "viewingDistancePolicy"]);
@@ -1 +1 @@
1
- {"version":3,"file":"print-plan.js","sourceRoot":"","sources":["../../src/output/print-plan.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC;;;GAGG;AACH,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAA0B,MAAM,+BAA+B,CAAC;AAC9G,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAC/F,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AACtF,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAoC,MAAM,uBAAuB,CAAC;AA2DjG,MAAM,OAAO,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAW,CAAC;AAClE,MAAM,cAAc,GAAG,IAAI,CAAC,EAAE,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5E,MAAM,MAAM,GAAmB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,EAAE,eAAe,EAAE,cAAc,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,GAAG,aAAa,CAAC,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;IAC3K,IAAI,aAAa,CAAC,KAAK,CAAC,QAAQ,KAAK,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvG,MAAM,CAAC,MAAM,GAAG,aAAa,CAAC;QAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAC;IACzG,CAAC;SAAM,IAAI,aAAa,CAAC,MAAM,KAAK,aAAa;QAAE,MAAM,CAAC,MAAM,GAAG,aAAa,CAAC;SAC5E,IAAI,aAAa,CAAC,YAAY,KAAK,IAAI,EAAE,CAAC;QAC7C,IAAI,CAAC,CAAC,qBAAqB,KAAK,4BAA4B,IAAI,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;YACnH,MAAM,CAAC,MAAM,GAAG,aAAa,CAAC,sBAAsB,KAAK,YAAY,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,kBAAkB,CAAC;QAC3G,CAAC;aAAM,CAAC;YAAC,MAAM,CAAC,MAAM,GAAG,QAAQ,CAAC;YAAC,MAAM,CAAC,cAAc,GAAG,aAAa,CAAC,YAAY,CAAC,+BAA+B,CAAC;QAAC,CAAC;IAC1H,CAAC;IACD,OAAO,gBAAgB,CAAC,MAAM,EAAE,qCAAqC,EAAE,OAAO,EAAE,CAAC,gFAAgF,EAAE,uEAAuE,CAAC,CAAC,CAAC;AAC/O,CAAC","sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/** Print planning: how many native pixels a print of a given size and viewing distance needs.\n * It uses native capture pixels only. It does not make an image or certify perceived quality.\n * @see docs/PRINT_PLANNING.md for equations, rounding and support limits.\n */\nimport { calculatedResult, approximationResult, type CalculationResult } from \"../core/calculation-result.js\";\nimport { InvalidConfigurationError } from \"../core/configuration-error.js\";\nimport { requireAllowlistedRecord, requirePublicOpaqueId } from \"../core/record-validation.js\";\nimport { requirePositiveFinite, requirePositiveInteger } from \"../core/validation.js\";\nimport { ENGINE_API_VERSION } from \"../core/version.js\";\nimport { resolveCaptureGeometry, type ResolveCaptureGeometryInput } from \"./capture-geometry.js\";\nimport type { RasterDimensions } from \"../sensor/sensor-geometry.js\";\n\n/** A physical length. Not to be confused with image pixels or printer dots. */\nexport interface PrintLength { value: number; unit: \"mm\" | \"cm\" | \"inches\" | \"m\" }\n/** The flat printed image area. It excludes paper margins, borders and canvas wraps. */\nexport interface PrintedImageSize { width: number; height: number; unit: PrintLength[\"unit\"] }\n/** How to choose pixel density: one of three angular criteria at the viewing distance, or a manual PPI (pixels per inch), which gives a different kind of plan. */\nexport type PrintSamplingCriterion =\n | { kind: \"angular-pixel-pitch\"; maximumArcminutesPerPixel: number }\n | { kind: \"angular-stroke\"; strokeWidthArcminutes: number; samplesPerStroke: number }\n | { kind: \"angular-line-pair\"; periodArcminutes: number; samplesPerPeriod: number }\n | { kind: \"manual-ppi\"; pixelsPerInch: number };\n/** The declared native source geometry. Not a preview or a resampled pixel count. */\nexport type PrintNativeSource =\n | { kind: \"native-retained\"; captureId: string; geometry: ResolveCaptureGeometryInput }\n | { kind: \"unavailable\"; reason: \"missing-native-raster\" | \"unverified-native-identity\" };\n/** Print lab requirements supplied by the caller. There is no vendor catalogue and no guarantee of what a lab will accept. */\nexport interface PrintProviderConstraints {\n minimumRaster?: RasterDimensions;\n exactRaster?: RasterDimensions;\n minimumPpi?: number;\n exactPpi?: number;\n}\n/** Plan input. The output keeps the exact native aspect ratio; the allowed physical aspect error is explicit and reported. */\nexport interface PrintPlanInput {\n source: PrintNativeSource;\n printedImage: PrintedImageSize;\n viewingDistance: PrintLength;\n sampling: PrintSamplingCriterion;\n fit: { kind: \"confirmed-native-aspect\"; maximumRelativeAspectError: number };\n provider?: PrintProviderConstraints;\n}\n/** Pixel density and angular pixel pitch for each axis. The angles are pure geometry, not a measure of visual acuity. */\nexport interface PrintRasterSampling {\n raster: RasterDimensions;\n pixelsPerInch: { x: number; y: number };\n angularPixelPitchArcminutes: { x: number; y: number };\n}\n/** A plan, valid only under its stated conditions. A null recommendation never means it is fine to upscale. */\nexport interface PrintPlan {\n engineApiVersion: string;\n input: PrintPlanInput;\n status: \"ready\" | \"insufficient-native-pixels\" | \"provider-conflict\" | \"crop-confirmation-required\" | \"cannot-assess\" | \"unsupported\";\n nativePixelSufficiency: \"sufficient\" | \"insufficient\" | \"cannot-assess\";\n reasons: string[];\n printedImageMm: { width: number; height: number } | null;\n viewingDistanceMm: number | null;\n guidance: CalculationResult<{ derivedPixelsPerInch: number; maximumPixelPitchMm: number; maximumArcminutesPerPixel: number | null }> | null;\n relativeAspectError: number | null;\n native: PrintRasterSampling | null;\n minimumSamplingRaster: RasterDimensions | null;\n recommended: PrintRasterSampling | null;\n resamplingScale: { x: number; y: number } | null;\n alternatives: { maximumImageMmAtCurrentDistance: { width: number; height: number }; minimumViewingDistanceMmAtCurrentSize: number | null } | null;\n capturedDetailAssessment: \"unassessed\";\n deliveryAssessment: \"unassessed\";\n}\n\nconst UNIT_MM = { mm: 1, cm: 10, inches: 25.4, m: 1000 } as const;\nconst RAD_PER_ARCMIN = Math.PI / 10800;\nfunction record(value: unknown, keys: readonly string[]): Record<string, unknown> {\n return requireAllowlistedRecord(value, keys, \"Invalid or unknown Print planning fields.\");\n}\nfunction number(value: unknown, name: string): number {\n if (typeof value !== \"number\") throw new InvalidConfigurationError(`${name} must be numeric.`);\n requirePositiveFinite(name, value); return value;\n}\nfunction unit(value: unknown): PrintLength[\"unit\"] {\n if (typeof value !== \"string\" || !Object.hasOwn(UNIT_MM, value)) throw new InvalidConfigurationError(\"Invalid Print length unit.\");\n return value as PrintLength[\"unit\"];\n}\nfunction length(value: unknown): PrintLength {\n const r = record(value, [\"value\", \"unit\"]);\n return { value: number(r.value, \"length.value\"), unit: unit(r.unit) };\n}\nfunction raster(value: unknown): RasterDimensions {\n const r = record(value, [\"pixelWidth\", \"pixelHeight\"]);\n const pixelWidth = number(r.pixelWidth, \"pixelWidth\"), pixelHeight = number(r.pixelHeight, \"pixelHeight\");\n requirePositiveInteger(\"pixelWidth\", pixelWidth); requirePositiveInteger(\"pixelHeight\", pixelHeight);\n return { pixelWidth, pixelHeight };\n}\nfunction geometry(value: unknown): ResolveCaptureGeometryInput {\n const g = record(value, [\"imagingArea\", \"nativeRaster\", \"orientation\", \"activeCaptureRect\", \"outputCropRect\", \"outputRaster\"]);\n record(g.imagingArea, [\"widthMm\", \"heightMm\"]); raster(g.nativeRaster);\n for (const key of [\"activeCaptureRect\", \"outputCropRect\"] as const) {\n if (g[key] !== undefined) record(g[key], [\"x\", \"y\", \"width\", \"height\"]);\n }\n if (g.outputRaster !== undefined) raster(g.outputRaster);\n // The capture geometry module defines units, orientations, bounds and the optical axis.\n const parsed = g as unknown as ResolveCaptureGeometryInput;\n resolveCaptureGeometry(parsed);\n return structuredCloneGeometry(parsed);\n}\nfunction structuredCloneGeometry(g: ResolveCaptureGeometryInput): ResolveCaptureGeometryInput {\n return { imagingArea: { ...g.imagingArea }, nativeRaster: { ...g.nativeRaster }, orientation: g.orientation,\n ...(g.activeCaptureRect === undefined ? {} : { activeCaptureRect: { ...g.activeCaptureRect } }),\n ...(g.outputCropRect === undefined ? {} : { outputCropRect: { ...g.outputCropRect } }),\n ...(g.outputRaster === undefined ? {} : { outputRaster: { ...g.outputRaster } }) };\n}\nfunction sampling(value: unknown): PrintSamplingCriterion {\n const tag = record(value, [\"kind\", \"maximumArcminutesPerPixel\", \"strokeWidthArcminutes\", \"samplesPerStroke\", \"periodArcminutes\", \"samplesPerPeriod\", \"pixelsPerInch\"]);\n let result: PrintSamplingCriterion;\n switch (tag.kind) {\n case \"manual-ppi\": {\n const r = record(value, [\"kind\", \"pixelsPerInch\"]);\n return { kind: \"manual-ppi\", pixelsPerInch: number(r.pixelsPerInch, \"pixelsPerInch\") };\n }\n case \"angular-pixel-pitch\": {\n const r = record(value, [\"kind\", \"maximumArcminutesPerPixel\"]);\n result = { kind: \"angular-pixel-pitch\", maximumArcminutesPerPixel: number(r.maximumArcminutesPerPixel, \"maximumArcminutesPerPixel\") }; break;\n }\n case \"angular-stroke\": {\n const r = record(value, [\"kind\", \"strokeWidthArcminutes\", \"samplesPerStroke\"]);\n const samplesPerStroke = number(r.samplesPerStroke, \"samplesPerStroke\"); requirePositiveInteger(\"samplesPerStroke\", samplesPerStroke);\n result = { kind: \"angular-stroke\", strokeWidthArcminutes: number(r.strokeWidthArcminutes, \"strokeWidthArcminutes\"), samplesPerStroke }; break;\n }\n case \"angular-line-pair\": {\n const r = record(value, [\"kind\", \"periodArcminutes\", \"samplesPerPeriod\"]);\n const samplesPerPeriod = number(r.samplesPerPeriod, \"samplesPerPeriod\"); requirePositiveInteger(\"samplesPerPeriod\", samplesPerPeriod);\n if (samplesPerPeriod < 2) throw new InvalidConfigurationError(\"A line-pair period requires at least two samples.\");\n result = { kind: \"angular-line-pair\", periodArcminutes: number(r.periodArcminutes, \"periodArcminutes\"), samplesPerPeriod }; break;\n }\n default: throw new InvalidConfigurationError(\"Invalid Print sampling convention.\");\n }\n const angle = angularLimit(result);\n if (angle <= 0 || angle >= 10800) throw new InvalidConfigurationError(\"Effective angular pixel pitch must lie in (0, 10800) arcminutes.\");\n return result;\n}\nfunction angularLimit(s: Exclude<PrintSamplingCriterion, { kind: \"manual-ppi\" }>): number {\n switch (s.kind) {\n case \"angular-pixel-pitch\": return s.maximumArcminutesPerPixel;\n case \"angular-stroke\": return s.strokeWidthArcminutes / s.samplesPerStroke;\n case \"angular-line-pair\": return s.periodArcminutes / s.samplesPerPeriod;\n }\n}\n\n/** Validates and copies an untrusted print request. It never assumes the source is native if that is not declared. */\nexport function parsePrintPlanInput(value: unknown): PrintPlanInput {\n const r = record(value, [\"source\", \"printedImage\", \"viewingDistance\", \"sampling\", \"fit\", \"provider\"]);\n const source = record(r.source, [\"kind\", \"captureId\", \"geometry\", \"reason\"]);\n let parsedSource: PrintNativeSource;\n if (source.kind === \"native-retained\") {\n record(r.source, [\"kind\", \"captureId\", \"geometry\"]);\n parsedSource = { kind: \"native-retained\", captureId: requirePublicOpaqueId(source.captureId, \"Invalid public capture ID.\"), geometry: geometry(source.geometry) };\n } else if (source.kind === \"unavailable\") {\n record(r.source, [\"kind\", \"reason\"]);\n if (source.reason !== \"missing-native-raster\" && source.reason !== \"unverified-native-identity\") throw new InvalidConfigurationError(\"Invalid native-unavailable reason.\");\n parsedSource = { kind: \"unavailable\", reason: source.reason };\n } else throw new InvalidConfigurationError(\"Invalid native source kind.\");\n const image = record(r.printedImage, [\"width\", \"height\", \"unit\"]);\n const fit = record(r.fit, [\"kind\", \"maximumRelativeAspectError\"]);\n if (fit.kind !== \"confirmed-native-aspect\" || typeof fit.maximumRelativeAspectError !== \"number\" || !Number.isFinite(fit.maximumRelativeAspectError) || fit.maximumRelativeAspectError < 0 || fit.maximumRelativeAspectError > 0.01) throw new InvalidConfigurationError(\"Declare a native-aspect fit tolerance in [0, 0.01].\");\n const parsed: PrintPlanInput = { source: parsedSource, printedImage: { width: number(image.width, \"printedImage.width\"), height: number(image.height, \"printedImage.height\"), unit: unit(image.unit) }, viewingDistance: length(r.viewingDistance), sampling: sampling(r.sampling), fit: { kind: \"confirmed-native-aspect\", maximumRelativeAspectError: fit.maximumRelativeAspectError } };\n if (r.provider !== undefined) {\n const p = record(r.provider, [\"minimumRaster\", \"exactRaster\", \"minimumPpi\", \"exactPpi\"]);\n parsed.provider = {\n ...(p.minimumRaster === undefined ? {} : { minimumRaster: raster(p.minimumRaster) }),\n ...(p.exactRaster === undefined ? {} : { exactRaster: raster(p.exactRaster) }),\n ...(p.minimumPpi === undefined ? {} : { minimumPpi: number(p.minimumPpi, \"minimumPpi\") }),\n ...(p.exactPpi === undefined ? {} : { exactPpi: number(p.exactPpi, \"exactPpi\") })\n };\n }\n return parsed;\n}\nfunction gcd(a: number, b: number): number { while (b !== 0) { const next = a % b; a = b; b = next; } return a; }\nfunction positiveSupported(...values: number[]): boolean { return values.every(v => Number.isFinite(v) && v > 0); }\n// Stepping to the adjacent double rounds outward. It is not a tolerance on the criterion.\nfunction adjacentPositive(value: number, direction: \"up\" | \"down\"): number {\n const view = new DataView(new ArrayBuffer(8)); view.setFloat64(0, value);\n view.setBigUint64(0, view.getBigUint64(0) + (direction === \"up\" ? 1n : -1n));\n return view.getFloat64(0);\n}\nfunction exactRatio(a: RasterDimensions, b: RasterDimensions): boolean {\n return BigInt(a.pixelWidth) * BigInt(b.pixelHeight) === BigInt(a.pixelHeight) * BigInt(b.pixelWidth);\n}\nfunction minimumRaster(native: RasterDimensions, width: number, height: number): RasterDimensions | null {\n const divisor = gcd(native.pixelWidth, native.pixelHeight);\n const x = native.pixelWidth / divisor, y = native.pixelHeight / divisor;\n const count = Math.max(1, Math.ceil(width / x), Math.ceil(height / y));\n const pixelWidth = count * x, pixelHeight = count * y;\n return Number.isSafeInteger(pixelWidth) && Number.isSafeInteger(pixelHeight) ? { pixelWidth, pixelHeight } : null;\n}\nfunction diagnostics(raster: RasterDimensions, width: number, height: number, distance: number): PrintRasterSampling {\n const px = width / raster.pixelWidth, py = height / raster.pixelHeight;\n return { raster, pixelsPerInch: { x: 25.4 / px, y: 25.4 / py }, angularPixelPitchArcminutes: { x: 2 * Math.atan((px / distance) / 2) / RAD_PER_ARCMIN, y: 2 * Math.atan((py / distance) / 2) / RAD_PER_ARCMIN } };\n}\n\n/** Finds the smallest file, at the exact native aspect ratio, that meets the declared sampling and lab constraints.\n * The angular guidance is an approximate rule of thumb; the geometry itself is calculated exactly.\n * It does not assess source detail, perceived quality, file writing or available resources.\n */\nexport function calculatePrintPlan(value: PrintPlanInput): CalculationResult<PrintPlan> {\n const input = parsePrintPlanInput(value);\n const plan: PrintPlan = { engineApiVersion: ENGINE_API_VERSION, input, status: \"cannot-assess\", nativePixelSufficiency: \"cannot-assess\", reasons: [], printedImageMm: null, viewingDistanceMm: null, guidance: null, relativeAspectError: null, native: null, minimumSamplingRaster: null, recommended: null, resamplingScale: null, alternatives: null, capturedDetailAssessment: \"unassessed\", deliveryAssessment: \"unassessed\" };\n const finish = (): CalculationResult<PrintPlan> => calculatedResult(plan, \"native-only-print-plan\", \"0.1.0\", [\"Declared native authority; flat image, normal viewing at image center.\", \"Output preserves the exact retained native aspect ratio; no upscale.\", \"Angular sampling is conditional guidance, not captured-detail or print-quality certification.\"]);\n const unsupported = (): CalculationResult<PrintPlan> => { plan.status = \"unsupported\"; plan.nativePixelSufficiency = \"cannot-assess\"; plan.reasons.push(\"unsupported-numeric-range\"); return finish(); };\n const width = input.printedImage.width * UNIT_MM[input.printedImage.unit], height = input.printedImage.height * UNIT_MM[input.printedImage.unit], distance = input.viewingDistance.value * UNIT_MM[input.viewingDistance.unit];\n if (!positiveSupported(width, height, distance)) return unsupported();\n plan.printedImageMm = { width, height }; plan.viewingDistanceMm = distance;\n const angle = input.sampling.kind === \"manual-ppi\" ? null : angularLimit(input.sampling);\n const pitchFactor = angle === null ? null : 2 * Math.tan((angle * RAD_PER_ARCMIN) / 2);\n const pitch = input.sampling.kind === \"manual-ppi\" ? 25.4 / input.sampling.pixelsPerInch : distance * (pitchFactor ?? 0);\n const ppi = input.sampling.kind === \"manual-ppi\" ? input.sampling.pixelsPerInch : 25.4 / pitch;\n if (!positiveSupported(pitch, ppi, width / pitch, height / pitch)) return unsupported();\n const guidance = { derivedPixelsPerInch: ppi, maximumPixelPitchMm: pitch, maximumArcminutesPerPixel: angle };\n plan.guidance = angle === null ? calculatedResult(guidance, \"manual-print-density\", \"0.1.0\", [\"Explicit manual PPI plan; no angular criterion is certified.\"]) : approximationResult(guidance, \"declared-angular-print-sampling\", \"0.1.0\", [\"Exact centered pixel angle uses 2 atan(pitch / (2 distance)); no small-angle substitution.\", \"Declared angular sampling convention is an uncalibrated usage assumption.\"]);\n if (input.source.kind === \"unavailable\") { plan.reasons.push(input.source.reason); return finish(); }\n const resolved = resolveCaptureGeometry(input.source.geometry).value;\n const native = { pixelWidth: resolved.output.cropRect.width, pixelHeight: resolved.output.cropRect.height };\n const aspectError = Math.abs((width / height) / (native.pixelWidth / native.pixelHeight) - 1);\n if (!Number.isFinite(aspectError)) return unsupported();\n plan.relativeAspectError = aspectError;\n const nativeDiagnostics = diagnostics(native, width, height, distance);\n if (!positiveSupported(nativeDiagnostics.pixelsPerInch.x, nativeDiagnostics.pixelsPerInch.y, nativeDiagnostics.angularPixelPitchArcminutes.x, nativeDiagnostics.angularPixelPitchArcminutes.y)) return unsupported();\n plan.native = nativeDiagnostics;\n if (aspectError > input.fit.maximumRelativeAspectError) { plan.status = \"crop-confirmation-required\"; plan.reasons.push(\"printed-image-and-confirmed-crop-aspect-mismatch\"); return finish(); }\n const widthInches = input.printedImage.unit === \"inches\" ? input.printedImage.width : width / 25.4;\n const heightInches = input.printedImage.unit === \"inches\" ? input.printedImage.height : height / 25.4;\n const required = input.sampling.kind === \"manual-ppi\"\n ? minimumRaster(native, widthInches * ppi, heightInches * ppi)\n : minimumRaster(native, width / pitch, height / pitch);\n if (required === null) return unsupported();\n plan.minimumSamplingRaster = required;\n const sufficient = required.pixelWidth <= native.pixelWidth && required.pixelHeight <= native.pixelHeight;\n plan.nativePixelSufficiency = sufficient ? \"sufficient\" : \"insufficient\";\n let maxScale = Math.min(native.pixelWidth * pitch / width, native.pixelHeight * pitch / height);\n let minimumDistance = pitchFactor === null ? null : Math.max(width / native.pixelWidth, height / native.pixelHeight) / pitchFactor;\n let maxWidth = width * maxScale, maxHeight = height * maxScale;\n if (!positiveSupported(maxWidth, maxHeight) || (minimumDistance !== null && !positiveSupported(minimumDistance))) return unsupported();\n const fits = (w: number, h: number, p: number): boolean => {\n const candidate = input.sampling.kind === \"manual-ppi\" ? minimumRaster(native, w / 25.4 * ppi, h / 25.4 * ppi) : minimumRaster(native, w / p, h / p);\n return candidate !== null && candidate.pixelWidth <= native.pixelWidth && candidate.pixelHeight <= native.pixelHeight;\n };\n // Return only alternatives that still pass their own documented integer rule.\n for (let i = 0; i < 8 && !fits(maxWidth, maxHeight, pitch); i++) {\n maxScale = adjacentPositive(maxScale, \"down\"); maxWidth = width * maxScale; maxHeight = height * maxScale;\n }\n if (!positiveSupported(maxWidth, maxHeight) || !fits(maxWidth, maxHeight, pitch)) return unsupported();\n if (minimumDistance !== null && pitchFactor !== null) {\n for (let i = 0; i < 8 && !fits(width, height, minimumDistance * pitchFactor); i++) minimumDistance = adjacentPositive(minimumDistance, \"up\");\n if (!positiveSupported(minimumDistance) || !fits(width, height, minimumDistance * pitchFactor)) return unsupported();\n }\n plan.alternatives = { maximumImageMmAtCurrentDistance: { width: maxWidth, height: maxHeight }, minimumViewingDistanceMmAtCurrentSize: minimumDistance };\n if (!sufficient) { plan.status = \"insufficient-native-pixels\"; plan.reasons.push(\"sampling-requires-native-upscale\"); }\n let file = required;\n const provider = input.provider;\n if (provider) {\n const density = Math.max(provider.minimumPpi ?? 0, provider.exactPpi ?? 0);\n const constrained = minimumRaster(native, Math.max(required.pixelWidth, provider.minimumRaster?.pixelWidth ?? 0, widthInches * density), Math.max(required.pixelHeight, provider.minimumRaster?.pixelHeight ?? 0, heightInches * density));\n if (constrained === null) return unsupported();\n file = provider.exactRaster ?? constrained;\n if (provider.exactPpi !== undefined) {\n const exact = { pixelWidth: widthInches * provider.exactPpi, pixelHeight: heightInches * provider.exactPpi };\n if (!Number.isSafeInteger(exact.pixelWidth) || !Number.isSafeInteger(exact.pixelHeight)) plan.reasons.push(\"exact-provider-density-has-no-integer-raster\");\n else if (provider.exactRaster && (exact.pixelWidth !== file.pixelWidth || exact.pixelHeight !== file.pixelHeight)) plan.reasons.push(\"provider-exact-raster-density-conflict\");\n else file = exact;\n }\n if (!exactRatio(file, native)) plan.reasons.push(\"provider-raster-aspect-conflict\");\n if (file.pixelWidth < constrained.pixelWidth || file.pixelHeight < constrained.pixelHeight) plan.reasons.push(\"provider-exact-requirement-below-minimum\");\n if (file.pixelWidth > native.pixelWidth || file.pixelHeight > native.pixelHeight) plan.reasons.push(\"provider-requires-native-upscale\");\n if (plan.reasons.some(r => r.startsWith(\"provider-\") || r.startsWith(\"exact-provider-\"))) { plan.status = \"provider-conflict\"; return finish(); }\n }\n if (!sufficient) return finish();\n const achieved = diagnostics(file, width, height, distance);\n if (!positiveSupported(achieved.pixelsPerInch.x, achieved.pixelsPerInch.y, achieved.angularPixelPitchArcminutes.x, achieved.angularPixelPitchArcminutes.y)) return unsupported();\n plan.status = \"ready\"; plan.recommended = achieved;\n plan.resamplingScale = { x: file.pixelWidth / native.pixelWidth, y: file.pixelHeight / native.pixelHeight };\n return finish();\n}\n\n/** Input for the largest-print-size query. It keeps the reference plan's aspect ratio and criterion.\n * With proportional viewing, the reference viewing distance scales with the image size.\n */\nexport interface PrintSizeLimitInput {\n plan: PrintPlanInput;\n viewingDistancePolicy: \"fixed\" | \"proportional-to-image-size\";\n}\n/** Result of the size query. A status says \"unbounded\" rather than using Infinity. \"no-positive-size\" is a valid answer, not an input error. */\nexport interface PrintSizeLimit {\n engineApiVersion: string;\n status: \"finite\" | \"unbounded\" | \"no-positive-size\" | \"cannot-assess\" | \"unsupported\";\n maximumImageMm: { width: number; height: number } | null;\n reasons: string[];\n referencePlan: PrintPlan;\n}\n/** Calculates the largest print size under the stated conditions. Lab constraints need individual plans,\n * so this size query reports them as unsupported rather than ignoring them.\n */\nexport function calculatePrintSizeLimit(value: PrintSizeLimitInput): CalculationResult<PrintSizeLimit> {\n const r = record(value, [\"plan\", \"viewingDistancePolicy\"]);\n if (r.viewingDistancePolicy !== \"fixed\" && r.viewingDistancePolicy !== \"proportional-to-image-size\") throw new InvalidConfigurationError(\"Invalid viewing-distance scaling policy.\");\n const referencePlan = calculatePrintPlan(parsePrintPlanInput(r.plan)).value;\n const result: PrintSizeLimit = { engineApiVersion: ENGINE_API_VERSION, status: \"cannot-assess\", maximumImageMm: null, reasons: [...referencePlan.reasons], referencePlan };\n if (referencePlan.input.provider !== undefined && Object.keys(referencePlan.input.provider).length > 0) {\n result.status = \"unsupported\"; result.reasons.push(\"size-query-with-provider-constraints-unsupported\");\n } else if (referencePlan.status === \"unsupported\") result.status = \"unsupported\";\n else if (referencePlan.alternatives !== null) {\n if (r.viewingDistancePolicy === \"proportional-to-image-size\" && referencePlan.input.sampling.kind !== \"manual-ppi\") {\n result.status = referencePlan.nativePixelSufficiency === \"sufficient\" ? \"unbounded\" : \"no-positive-size\";\n } else { result.status = \"finite\"; result.maximumImageMm = referencePlan.alternatives.maximumImageMmAtCurrentDistance; }\n }\n return calculatedResult(result, \"conditional-native-print-size-limit\", \"0.1.0\", [\"Native sampling capacity only; no perceived-quality or physical-printer bound.\", \"Proportional distance and image scaling preserve angular pixel pitch.\"]);\n}\n"]}
1
+ {"version":3,"file":"print-plan.js","sourceRoot":"","sources":["../../src/output/print-plan.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC;;;GAGG;AACH,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAA0B,MAAM,+BAA+B,CAAC;AAC9G,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAC/F,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AACtF,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAoC,MAAM,uBAAuB,CAAC;AA2DjG,MAAM,OAAO,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAW,CAAC;AAClE,MAAM,cAAc,GAAG,IAAI,CAAC,EAAE,GAAG,KA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5E,MAAM,MAAM,GAAmB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,EAAE,eAAe,EAAE,cAAc,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,GAAG,aAAa,CAAC,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;IAC3K,IAAI,aAAa,CAAC,KAAK,CAAC,QAAQ,KAAK,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvG,MAAM,CAAC,MAAM,GAAG,aAAa,CAAC;QAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAC;IACzG,CAAC;SAAM,IAAI,aAAa,CAAC,MAAM,KAAK,aAAa;QAAE,MAAM,CAAC,MAAM,GAAG,aAAa,CAAC;SAC5E,IAAI,aAAa,CAAC,YAAY,KAAK,IAAI,EAAE,CAAC;QAC7C,IAAI,CAAC,CAAC,qBAAqB,KAAK,4BAA4B,IAAI,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;YACnH,MAAM,CAAC,MAAM,GAAG,aAAa,CAAC,sBAAsB,KAAK,YAAY,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,kBAAkB,CAAC;QAC3G,CAAC;aAAM,CAAC;YAAC,MAAM,CAAC,MAAM,GAAG,QAAQ,CAAC;YAAC,MAAM,CAAC,cAAc,GAAG,aAAa,CAAC,YAAY,CAAC,+BAA+B,CAAC;QAAC,CAAC;IAC1H,CAAC;IACD,OAAO,gBAAgB,CAAC,MAAM,EAAE,qCAAqC,EAAE,OAAO,EAAE,CAAC,gFAAgF,EAAE,uEAAuE,CAAC,CAAC,CAAC;AAC/O,CAAC","sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/** Print planning: how many native pixels a print of a given size and viewing distance needs.\n * It uses native capture pixels only. It does not make an image or certify perceived quality.\n * @see docs/PRINT_PLANNING.md for equations, rounding and support limits.\n */\nimport { calculatedResult, approximationResult, type CalculationResult } from \"../core/calculation-result.js\";\nimport { InvalidConfigurationError } from \"../core/configuration-error.js\";\nimport { requireAllowlistedRecord, requirePublicOpaqueId } from \"../core/record-validation.js\";\nimport { requirePositiveFinite, requirePositiveInteger } from \"../core/validation.js\";\nimport { ENGINE_API_VERSION } from \"../core/version.js\";\nimport { resolveCaptureGeometry, type ResolveCaptureGeometryInput } from \"./capture-geometry.js\";\nimport type { RasterDimensions } from \"../sensor/sensor-geometry.js\";\n\n/** A physical length. Not to be confused with image pixels or printer dots. */\nexport interface PrintLength { value: number; unit: \"mm\" | \"cm\" | \"inches\" | \"m\" }\n/** The flat printed image area. It excludes paper margins, borders and canvas wraps. */\nexport interface PrintedImageSize { width: number; height: number; unit: PrintLength[\"unit\"] }\n/** How to choose pixel density: one of three angular criteria at the viewing distance, or a manual PPI (pixels per inch), which gives a different kind of plan. */\nexport type PrintSamplingCriterion =\n | { kind: \"angular-pixel-pitch\"; maximumArcminutesPerPixel: number }\n | { kind: \"angular-stroke\"; strokeWidthArcminutes: number; samplesPerStroke: number }\n | { kind: \"angular-line-pair\"; periodArcminutes: number; samplesPerPeriod: number }\n | { kind: \"manual-ppi\"; pixelsPerInch: number };\n/** The declared native source geometry. Not a preview or a resampled pixel count. */\nexport type PrintNativeSource =\n | { kind: \"native-retained\"; captureId: string; geometry: ResolveCaptureGeometryInput }\n | { kind: \"unavailable\"; reason: \"missing-native-raster\" | \"unverified-native-identity\" };\n/** Print lab requirements supplied by the caller. There is no vendor catalogue and no guarantee of what a lab will accept. */\nexport interface PrintProviderConstraints {\n minimumRaster?: RasterDimensions;\n exactRaster?: RasterDimensions;\n minimumPpi?: number;\n exactPpi?: number;\n}\n/** Plan input. The output keeps the exact native aspect ratio; the allowed physical aspect error is explicit and reported. */\nexport interface PrintPlanInput {\n source: PrintNativeSource;\n printedImage: PrintedImageSize;\n viewingDistance: PrintLength;\n sampling: PrintSamplingCriterion;\n fit: { kind: \"confirmed-native-aspect\"; maximumRelativeAspectError: number };\n provider?: PrintProviderConstraints;\n}\n/** Pixel density and angular pixel pitch for each axis. The angles are pure geometry, not a measure of visual acuity. */\nexport interface PrintRasterSampling {\n raster: RasterDimensions;\n pixelsPerInch: { x: number; y: number };\n angularPixelPitchArcminutes: { x: number; y: number };\n}\n/** A plan, valid only under its stated conditions. A null recommendation never means it is fine to upscale. */\nexport interface PrintPlan {\n engineApiVersion: string;\n input: PrintPlanInput;\n status: \"ready\" | \"insufficient-native-pixels\" | \"provider-conflict\" | \"crop-confirmation-required\" | \"cannot-assess\" | \"unsupported\";\n nativePixelSufficiency: \"sufficient\" | \"insufficient\" | \"cannot-assess\";\n reasons: string[];\n printedImageMm: { width: number; height: number } | null;\n viewingDistanceMm: number | null;\n guidance: CalculationResult<{ derivedPixelsPerInch: number; maximumPixelPitchMm: number; maximumArcminutesPerPixel: number | null }> | null;\n relativeAspectError: number | null;\n native: PrintRasterSampling | null;\n minimumSamplingRaster: RasterDimensions | null;\n recommended: PrintRasterSampling | null;\n resamplingScale: { x: number; y: number } | null;\n alternatives: { maximumImageMmAtCurrentDistance: { width: number; height: number }; minimumViewingDistanceMmAtCurrentSize: number | null } | null;\n capturedDetailAssessment: \"unassessed\";\n deliveryAssessment: \"unassessed\";\n}\n\nconst UNIT_MM = { mm: 1, cm: 10, inches: 25.4, m: 1000 } as const;\nconst RAD_PER_ARCMIN = Math.PI / 10800;\nfunction record(value: unknown, keys: readonly string[]): Record<string, unknown> {\n return requireAllowlistedRecord(value, keys, \"Invalid or unknown Print planning fields.\");\n}\nfunction number(value: unknown, name: string): number {\n if (typeof value !== \"number\") throw new InvalidConfigurationError(`${name} must be numeric.`);\n requirePositiveFinite(name, value); return value;\n}\nfunction unit(value: unknown): PrintLength[\"unit\"] {\n if (typeof value !== \"string\" || !Object.hasOwn(UNIT_MM, value)) throw new InvalidConfigurationError(\"Invalid Print length unit.\");\n return value as PrintLength[\"unit\"];\n}\nfunction length(value: unknown): PrintLength {\n const r = record(value, [\"value\", \"unit\"]);\n return { value: number(r.value, \"length.value\"), unit: unit(r.unit) };\n}\nfunction raster(value: unknown): RasterDimensions {\n const r = record(value, [\"pixelWidth\", \"pixelHeight\"]);\n const pixelWidth = number(r.pixelWidth, \"pixelWidth\"), pixelHeight = number(r.pixelHeight, \"pixelHeight\");\n requirePositiveInteger(\"pixelWidth\", pixelWidth); requirePositiveInteger(\"pixelHeight\", pixelHeight);\n return { pixelWidth, pixelHeight };\n}\nfunction geometry(value: unknown): ResolveCaptureGeometryInput {\n const g = record(value, [\"imagingArea\", \"nativeRaster\", \"orientation\", \"activeCaptureRect\", \"outputCropRect\", \"outputRaster\"]);\n record(g.imagingArea, [\"widthMm\", \"heightMm\"]); raster(g.nativeRaster);\n for (const key of [\"activeCaptureRect\", \"outputCropRect\"] as const) {\n if (g[key] !== undefined) record(g[key], [\"x\", \"y\", \"width\", \"height\"]);\n }\n if (g.outputRaster !== undefined) raster(g.outputRaster);\n // The capture geometry module defines units, orientations, bounds and the optical axis.\n const parsed = g as unknown as ResolveCaptureGeometryInput;\n resolveCaptureGeometry(parsed);\n return structuredCloneGeometry(parsed);\n}\nfunction structuredCloneGeometry(g: ResolveCaptureGeometryInput): ResolveCaptureGeometryInput {\n return { imagingArea: { ...g.imagingArea }, nativeRaster: { ...g.nativeRaster }, orientation: g.orientation,\n ...(g.activeCaptureRect === undefined ? {} : { activeCaptureRect: { ...g.activeCaptureRect } }),\n ...(g.outputCropRect === undefined ? {} : { outputCropRect: { ...g.outputCropRect } }),\n ...(g.outputRaster === undefined ? {} : { outputRaster: { ...g.outputRaster } }) };\n}\nfunction sampling(value: unknown): PrintSamplingCriterion {\n const tag = record(value, [\"kind\", \"maximumArcminutesPerPixel\", \"strokeWidthArcminutes\", \"samplesPerStroke\", \"periodArcminutes\", \"samplesPerPeriod\", \"pixelsPerInch\"]);\n let result: PrintSamplingCriterion;\n switch (tag.kind) {\n case \"manual-ppi\": {\n const r = record(value, [\"kind\", \"pixelsPerInch\"]);\n return { kind: \"manual-ppi\", pixelsPerInch: number(r.pixelsPerInch, \"pixelsPerInch\") };\n }\n case \"angular-pixel-pitch\": {\n const r = record(value, [\"kind\", \"maximumArcminutesPerPixel\"]);\n result = { kind: \"angular-pixel-pitch\", maximumArcminutesPerPixel: number(r.maximumArcminutesPerPixel, \"maximumArcminutesPerPixel\") }; break;\n }\n case \"angular-stroke\": {\n const r = record(value, [\"kind\", \"strokeWidthArcminutes\", \"samplesPerStroke\"]);\n const samplesPerStroke = number(r.samplesPerStroke, \"samplesPerStroke\"); requirePositiveInteger(\"samplesPerStroke\", samplesPerStroke);\n result = { kind: \"angular-stroke\", strokeWidthArcminutes: number(r.strokeWidthArcminutes, \"strokeWidthArcminutes\"), samplesPerStroke }; break;\n }\n case \"angular-line-pair\": {\n const r = record(value, [\"kind\", \"periodArcminutes\", \"samplesPerPeriod\"]);\n const samplesPerPeriod = number(r.samplesPerPeriod, \"samplesPerPeriod\"); requirePositiveInteger(\"samplesPerPeriod\", samplesPerPeriod);\n if (samplesPerPeriod < 2) throw new InvalidConfigurationError(\"A line-pair period requires at least two samples.\");\n result = { kind: \"angular-line-pair\", periodArcminutes: number(r.periodArcminutes, \"periodArcminutes\"), samplesPerPeriod }; break;\n }\n default: throw new InvalidConfigurationError(\"Invalid Print sampling convention.\");\n }\n const angle = angularLimit(result);\n if (angle <= 0 || angle >= 10800) throw new InvalidConfigurationError(\"Effective angular pixel pitch must lie in (0, 10800) arcminutes.\");\n return result;\n}\nfunction angularLimit(s: Exclude<PrintSamplingCriterion, { kind: \"manual-ppi\" }>): number {\n switch (s.kind) {\n case \"angular-pixel-pitch\": return s.maximumArcminutesPerPixel;\n case \"angular-stroke\": return s.strokeWidthArcminutes / s.samplesPerStroke;\n case \"angular-line-pair\": return s.periodArcminutes / s.samplesPerPeriod;\n }\n}\n\n/** Validates and copies an untrusted print request. It never assumes the source is native if that is not declared. */\nexport function parsePrintPlanInput(value: unknown): PrintPlanInput {\n const r = record(value, [\"source\", \"printedImage\", \"viewingDistance\", \"sampling\", \"fit\", \"provider\"]);\n const source = record(r.source, [\"kind\", \"captureId\", \"geometry\", \"reason\"]);\n let parsedSource: PrintNativeSource;\n if (source.kind === \"native-retained\") {\n record(r.source, [\"kind\", \"captureId\", \"geometry\"]);\n parsedSource = { kind: \"native-retained\", captureId: requirePublicOpaqueId(source.captureId, \"Invalid public capture ID.\"), geometry: geometry(source.geometry) };\n } else if (source.kind === \"unavailable\") {\n record(r.source, [\"kind\", \"reason\"]);\n if (source.reason !== \"missing-native-raster\" && source.reason !== \"unverified-native-identity\") throw new InvalidConfigurationError(\"Invalid native-unavailable reason.\");\n parsedSource = { kind: \"unavailable\", reason: source.reason };\n } else throw new InvalidConfigurationError(\"Invalid native source kind.\");\n const image = record(r.printedImage, [\"width\", \"height\", \"unit\"]);\n const fit = record(r.fit, [\"kind\", \"maximumRelativeAspectError\"]);\n if (fit.kind !== \"confirmed-native-aspect\" || typeof fit.maximumRelativeAspectError !== \"number\" || !Number.isFinite(fit.maximumRelativeAspectError) || fit.maximumRelativeAspectError < 0 || fit.maximumRelativeAspectError > 0.01) throw new InvalidConfigurationError(\"Declare a native-aspect fit tolerance in [0, 0.01].\");\n const parsed: PrintPlanInput = { source: parsedSource, printedImage: { width: number(image.width, \"printedImage.width\"), height: number(image.height, \"printedImage.height\"), unit: unit(image.unit) }, viewingDistance: length(r.viewingDistance), sampling: sampling(r.sampling), fit: { kind: \"confirmed-native-aspect\", maximumRelativeAspectError: fit.maximumRelativeAspectError } };\n if (r.provider !== undefined) {\n const p = record(r.provider, [\"minimumRaster\", \"exactRaster\", \"minimumPpi\", \"exactPpi\"]);\n parsed.provider = {\n ...(p.minimumRaster === undefined ? {} : { minimumRaster: raster(p.minimumRaster) }),\n ...(p.exactRaster === undefined ? {} : { exactRaster: raster(p.exactRaster) }),\n ...(p.minimumPpi === undefined ? {} : { minimumPpi: number(p.minimumPpi, \"minimumPpi\") }),\n ...(p.exactPpi === undefined ? {} : { exactPpi: number(p.exactPpi, \"exactPpi\") })\n };\n }\n return parsed;\n}\nfunction gcd(a: number, b: number): number { while (b !== 0) { const next = a % b; a = b; b = next; } return a; }\nfunction positiveSupported(...values: number[]): boolean { return values.every(v => Number.isFinite(v) && v > 0); }\n// Stepping to the adjacent double rounds outward. It is not a tolerance on the criterion.\nfunction adjacentPositive(value: number, direction: \"up\" | \"down\"): number {\n const view = new DataView(new ArrayBuffer(8)); view.setFloat64(0, value);\n view.setBigUint64(0, view.getBigUint64(0) + (direction === \"up\" ? 1n : -1n));\n return view.getFloat64(0);\n}\nfunction exactRatio(a: RasterDimensions, b: RasterDimensions): boolean {\n return BigInt(a.pixelWidth) * BigInt(b.pixelHeight) === BigInt(a.pixelHeight) * BigInt(b.pixelWidth);\n}\nfunction minimumRaster(native: RasterDimensions, width: number, height: number): RasterDimensions | null {\n const divisor = gcd(native.pixelWidth, native.pixelHeight);\n const x = native.pixelWidth / divisor, y = native.pixelHeight / divisor;\n const count = Math.max(1, Math.ceil(width / x), Math.ceil(height / y));\n const pixelWidth = count * x, pixelHeight = count * y;\n return Number.isSafeInteger(pixelWidth) && Number.isSafeInteger(pixelHeight) ? { pixelWidth, pixelHeight } : null;\n}\nfunction diagnostics(raster: RasterDimensions, width: number, height: number, distance: number): PrintRasterSampling {\n const px = width / raster.pixelWidth, py = height / raster.pixelHeight;\n return { raster, pixelsPerInch: { x: 25.4 / px, y: 25.4 / py }, angularPixelPitchArcminutes: { x: 2 * Math.atan((px / distance) / 2) / RAD_PER_ARCMIN, y: 2 * Math.atan((py / distance) / 2) / RAD_PER_ARCMIN } };\n}\n\n/** Finds the smallest file, at the exact native aspect ratio, that meets the declared sampling and lab constraints.\n * The angular guidance is an approximate rule of thumb; the geometry itself is calculated exactly. A common criterion,\n * one arcminute per pixel, is normal (20/20) visual acuity under optimal conditions: the minimum angle of resolution of an\n * ideal eye is about 1 minute of arc, and 20/20 letters are built from elements that each subtend 1 arcmin (Z. Alomar, K. D. Bojikian, \"Visual Acuity Testing in Adults\", EyeWiki, American Academy of Ophthalmology,\n * https://eyewiki.aao.org/Visual_Acuity_Testing_in_Adults, last edited June 16, 2026).\n * Some viewers resolve finer detail and many resolve coarser, so it stays a rule of thumb, and the criterion is the caller's.\n * It does not assess source detail, perceived quality, file writing or available resources.\n */\nexport function calculatePrintPlan(value: PrintPlanInput): CalculationResult<PrintPlan> {\n const input = parsePrintPlanInput(value);\n const plan: PrintPlan = { engineApiVersion: ENGINE_API_VERSION, input, status: \"cannot-assess\", nativePixelSufficiency: \"cannot-assess\", reasons: [], printedImageMm: null, viewingDistanceMm: null, guidance: null, relativeAspectError: null, native: null, minimumSamplingRaster: null, recommended: null, resamplingScale: null, alternatives: null, capturedDetailAssessment: \"unassessed\", deliveryAssessment: \"unassessed\" };\n const finish = (): CalculationResult<PrintPlan> => calculatedResult(plan, \"native-only-print-plan\", \"0.1.0\", [\"Declared native authority; flat image, normal viewing at image center.\", \"Output preserves the exact retained native aspect ratio; no upscale.\", \"Angular sampling is conditional guidance, not captured-detail or print-quality certification.\"]);\n const unsupported = (): CalculationResult<PrintPlan> => { plan.status = \"unsupported\"; plan.nativePixelSufficiency = \"cannot-assess\"; plan.reasons.push(\"unsupported-numeric-range\"); return finish(); };\n const width = input.printedImage.width * UNIT_MM[input.printedImage.unit], height = input.printedImage.height * UNIT_MM[input.printedImage.unit], distance = input.viewingDistance.value * UNIT_MM[input.viewingDistance.unit];\n if (!positiveSupported(width, height, distance)) return unsupported();\n plan.printedImageMm = { width, height }; plan.viewingDistanceMm = distance;\n const angle = input.sampling.kind === \"manual-ppi\" ? null : angularLimit(input.sampling);\n const pitchFactor = angle === null ? null : 2 * Math.tan((angle * RAD_PER_ARCMIN) / 2);\n const pitch = input.sampling.kind === \"manual-ppi\" ? 25.4 / input.sampling.pixelsPerInch : distance * (pitchFactor ?? 0);\n const ppi = input.sampling.kind === \"manual-ppi\" ? input.sampling.pixelsPerInch : 25.4 / pitch;\n if (!positiveSupported(pitch, ppi, width / pitch, height / pitch)) return unsupported();\n const guidance = { derivedPixelsPerInch: ppi, maximumPixelPitchMm: pitch, maximumArcminutesPerPixel: angle };\n plan.guidance = angle === null ? calculatedResult(guidance, \"manual-print-density\", \"0.1.0\", [\"Explicit manual PPI plan; no angular criterion is certified.\"]) : approximationResult(guidance, \"declared-angular-print-sampling\", \"0.1.0\", [\"Exact centered pixel angle uses 2 atan(pitch / (2 distance)); no small-angle substitution.\", \"Declared angular sampling convention is an uncalibrated usage assumption.\"]);\n if (input.source.kind === \"unavailable\") { plan.reasons.push(input.source.reason); return finish(); }\n const resolved = resolveCaptureGeometry(input.source.geometry).value;\n const native = { pixelWidth: resolved.output.cropRect.width, pixelHeight: resolved.output.cropRect.height };\n const aspectError = Math.abs((width / height) / (native.pixelWidth / native.pixelHeight) - 1);\n if (!Number.isFinite(aspectError)) return unsupported();\n plan.relativeAspectError = aspectError;\n const nativeDiagnostics = diagnostics(native, width, height, distance);\n if (!positiveSupported(nativeDiagnostics.pixelsPerInch.x, nativeDiagnostics.pixelsPerInch.y, nativeDiagnostics.angularPixelPitchArcminutes.x, nativeDiagnostics.angularPixelPitchArcminutes.y)) return unsupported();\n plan.native = nativeDiagnostics;\n if (aspectError > input.fit.maximumRelativeAspectError) { plan.status = \"crop-confirmation-required\"; plan.reasons.push(\"printed-image-and-confirmed-crop-aspect-mismatch\"); return finish(); }\n const widthInches = input.printedImage.unit === \"inches\" ? input.printedImage.width : width / 25.4;\n const heightInches = input.printedImage.unit === \"inches\" ? input.printedImage.height : height / 25.4;\n const required = input.sampling.kind === \"manual-ppi\"\n ? minimumRaster(native, widthInches * ppi, heightInches * ppi)\n : minimumRaster(native, width / pitch, height / pitch);\n if (required === null) return unsupported();\n plan.minimumSamplingRaster = required;\n const sufficient = required.pixelWidth <= native.pixelWidth && required.pixelHeight <= native.pixelHeight;\n plan.nativePixelSufficiency = sufficient ? \"sufficient\" : \"insufficient\";\n let maxScale = Math.min(native.pixelWidth * pitch / width, native.pixelHeight * pitch / height);\n let minimumDistance = pitchFactor === null ? null : Math.max(width / native.pixelWidth, height / native.pixelHeight) / pitchFactor;\n let maxWidth = width * maxScale, maxHeight = height * maxScale;\n if (!positiveSupported(maxWidth, maxHeight) || (minimumDistance !== null && !positiveSupported(minimumDistance))) return unsupported();\n const fits = (w: number, h: number, p: number): boolean => {\n const candidate = input.sampling.kind === \"manual-ppi\" ? minimumRaster(native, w / 25.4 * ppi, h / 25.4 * ppi) : minimumRaster(native, w / p, h / p);\n return candidate !== null && candidate.pixelWidth <= native.pixelWidth && candidate.pixelHeight <= native.pixelHeight;\n };\n // Return only alternatives that still pass their own documented integer rule.\n for (let i = 0; i < 8 && !fits(maxWidth, maxHeight, pitch); i++) {\n maxScale = adjacentPositive(maxScale, \"down\"); maxWidth = width * maxScale; maxHeight = height * maxScale;\n }\n if (!positiveSupported(maxWidth, maxHeight) || !fits(maxWidth, maxHeight, pitch)) return unsupported();\n if (minimumDistance !== null && pitchFactor !== null) {\n for (let i = 0; i < 8 && !fits(width, height, minimumDistance * pitchFactor); i++) minimumDistance = adjacentPositive(minimumDistance, \"up\");\n if (!positiveSupported(minimumDistance) || !fits(width, height, minimumDistance * pitchFactor)) return unsupported();\n }\n plan.alternatives = { maximumImageMmAtCurrentDistance: { width: maxWidth, height: maxHeight }, minimumViewingDistanceMmAtCurrentSize: minimumDistance };\n if (!sufficient) { plan.status = \"insufficient-native-pixels\"; plan.reasons.push(\"sampling-requires-native-upscale\"); }\n let file = required;\n const provider = input.provider;\n if (provider) {\n const density = Math.max(provider.minimumPpi ?? 0, provider.exactPpi ?? 0);\n const constrained = minimumRaster(native, Math.max(required.pixelWidth, provider.minimumRaster?.pixelWidth ?? 0, widthInches * density), Math.max(required.pixelHeight, provider.minimumRaster?.pixelHeight ?? 0, heightInches * density));\n if (constrained === null) return unsupported();\n file = provider.exactRaster ?? constrained;\n if (provider.exactPpi !== undefined) {\n const exact = { pixelWidth: widthInches * provider.exactPpi, pixelHeight: heightInches * provider.exactPpi };\n if (!Number.isSafeInteger(exact.pixelWidth) || !Number.isSafeInteger(exact.pixelHeight)) plan.reasons.push(\"exact-provider-density-has-no-integer-raster\");\n else if (provider.exactRaster && (exact.pixelWidth !== file.pixelWidth || exact.pixelHeight !== file.pixelHeight)) plan.reasons.push(\"provider-exact-raster-density-conflict\");\n else file = exact;\n }\n if (!exactRatio(file, native)) plan.reasons.push(\"provider-raster-aspect-conflict\");\n if (file.pixelWidth < constrained.pixelWidth || file.pixelHeight < constrained.pixelHeight) plan.reasons.push(\"provider-exact-requirement-below-minimum\");\n if (file.pixelWidth > native.pixelWidth || file.pixelHeight > native.pixelHeight) plan.reasons.push(\"provider-requires-native-upscale\");\n if (plan.reasons.some(r => r.startsWith(\"provider-\") || r.startsWith(\"exact-provider-\"))) { plan.status = \"provider-conflict\"; return finish(); }\n }\n if (!sufficient) return finish();\n const achieved = diagnostics(file, width, height, distance);\n if (!positiveSupported(achieved.pixelsPerInch.x, achieved.pixelsPerInch.y, achieved.angularPixelPitchArcminutes.x, achieved.angularPixelPitchArcminutes.y)) return unsupported();\n plan.status = \"ready\"; plan.recommended = achieved;\n plan.resamplingScale = { x: file.pixelWidth / native.pixelWidth, y: file.pixelHeight / native.pixelHeight };\n return finish();\n}\n\n/** Input for the largest-print-size query. It keeps the reference plan's aspect ratio and criterion.\n * With proportional viewing, the reference viewing distance scales with the image size.\n */\nexport interface PrintSizeLimitInput {\n plan: PrintPlanInput;\n viewingDistancePolicy: \"fixed\" | \"proportional-to-image-size\";\n}\n/** Result of the size query. A status says \"unbounded\" rather than using Infinity. \"no-positive-size\" is a valid answer, not an input error. */\nexport interface PrintSizeLimit {\n engineApiVersion: string;\n status: \"finite\" | \"unbounded\" | \"no-positive-size\" | \"cannot-assess\" | \"unsupported\";\n maximumImageMm: { width: number; height: number } | null;\n reasons: string[];\n referencePlan: PrintPlan;\n}\n/** Calculates the largest print size under the stated conditions. Lab constraints need individual plans,\n * so this size query reports them as unsupported rather than ignoring them.\n * As in `calculatePrintPlan`, an angular criterion is an approximate rule of thumb: one arcminute per pixel is normal\n * (20/20) acuity under optimal conditions, which some viewers exceed and many do not (Z. Alomar, K. D. Bojikian, \"Visual Acuity Testing in Adults\", EyeWiki, American Academy of Ophthalmology,\n * https://eyewiki.aao.org/Visual_Acuity_Testing_in_Adults, last edited June 16, 2026).\n */\nexport function calculatePrintSizeLimit(value: PrintSizeLimitInput): CalculationResult<PrintSizeLimit> {\n const r = record(value, [\"plan\", \"viewingDistancePolicy\"]);\n if (r.viewingDistancePolicy !== \"fixed\" && r.viewingDistancePolicy !== \"proportional-to-image-size\") throw new InvalidConfigurationError(\"Invalid viewing-distance scaling policy.\");\n const referencePlan = calculatePrintPlan(parsePrintPlanInput(r.plan)).value;\n const result: PrintSizeLimit = { engineApiVersion: ENGINE_API_VERSION, status: \"cannot-assess\", maximumImageMm: null, reasons: [...referencePlan.reasons], referencePlan };\n if (referencePlan.input.provider !== undefined && Object.keys(referencePlan.input.provider).length > 0) {\n result.status = \"unsupported\"; result.reasons.push(\"size-query-with-provider-constraints-unsupported\");\n } else if (referencePlan.status === \"unsupported\") result.status = \"unsupported\";\n else if (referencePlan.alternatives !== null) {\n if (r.viewingDistancePolicy === \"proportional-to-image-size\" && referencePlan.input.sampling.kind !== \"manual-ppi\") {\n result.status = referencePlan.nativePixelSufficiency === \"sufficient\" ? \"unbounded\" : \"no-positive-size\";\n } else { result.status = \"finite\"; result.maximumImageMm = referencePlan.alternatives.maximumImageMmAtCurrentDistance; }\n }\n return calculatedResult(result, \"conditional-native-print-size-limit\", \"0.1.0\", [\"Native sampling capacity only; no perceived-quality or physical-printer bound.\", \"Proportional distance and image scaling preserve angular pixel pitch.\"]);\n}\n"]}
@@ -176,6 +176,22 @@ export declare function parseSceneRadianceEvaluationRequest(value: unknown): Sce
176
176
  * the provider's light-transport calculation is physically correct.
177
177
  */
178
178
  export declare function parseSceneRadianceEvaluationResult(value: unknown): SceneRadianceEvaluationResult;
179
+ /** An earlier fully parsed result whose deep-frozen uncertainty, evidence and limitations records may be reused. */
180
+ export interface ValidatedSceneRadianceRecords {
181
+ readonly uncertainty: unknown;
182
+ readonly evidence: unknown;
183
+ readonly limitations: unknown;
184
+ readonly parsed: SceneRadianceEvaluationResult;
185
+ }
186
+ /**
187
+ * Internal (2.6; not exported from the package): parses a result of an engine-built evaluator
188
+ * (`isInternalSceneRadianceEvaluator`). It runs every check of `parseSceneRadianceEvaluationResult` with the same
189
+ * helpers, order and messages (object shape, schema version, quantity, unit, status, the three identifiers, the
190
+ * wavelength, its basis and the radiance value) except two: the scan for unknown keys, and re-parsing uncertainty,
191
+ * evidence and limitations when they are the very (deep-frozen) objects of `validated`, an earlier result that
192
+ * passed the full parse. Any other result takes the full parse.
193
+ */
194
+ export declare function parseSceneRadianceEvaluationResultWithValidatedRecords(value: unknown, validated: ValidatedSceneRadianceRecords): SceneRadianceEvaluationResult;
179
195
  /**
180
196
  * Checks that a provider result matches its request and profile identities exactly.
181
197
  *