# Coded lens ## What this builds A small camera lens, designed in code: a few elements, a stop, an image plane. A ray tracer (a shipped one, or an open library) reports focal length, an on-axis and an off-axis spot size, and a simple aberration or ray-fan metric, against documented targets. Ray-trace plots are committed as goldens. No glass is melted, and no bench is required. This is an original prescription, not a commercial lens's exact data presented as a product. Read `spekkr.inputs.json` first. `focal` and `aperture` are design targets. `format` is the image diagonal. `aspheres` and `coatings` change what the design may use. `tracer` chooses the engine. ## Out of scope - A lab bench, a real glass melt, or a commercial lens prescription copied as the product. - A camera body in the checks. - A network licence server for a CAD package. ## Requirements Each requirement has an id. Checks name the id they cover. ### R1. Metrics - The effective focal length is `focal` within 2%. The on-axis RMS spot size at the image plane, at the design wavelength, is under the bound in `design.md` (for example 15 µm at F/2.8, 50 mm, as in the file). - An off-axis field (0.7 of the image circle) has a spot size under its own bound. A ray-fan or Seidel-style figure is within the table in the file. - The prescription (radii, thicknesses, glasses or index values) is in a file the tests read back. Accept when: focal length, both spot sizes, and the aberration figure match the bounds, and the prescription round-trips. ### R2. Plots and files - Goldens: a layout (elements and rays), an on-axis spot, an off-axis spot, and a ray-fan plot, compared with a documented tolerance on plots. - One command traces, measures, and writes the plots. No bench, no glass, no camera. Accept when: the command passes for both tracers if the external one is present (otherwise shipped only), and a deliberately defocused fixture fails the on-axis bound. ### R3. Inputs - Numeric inputs are read from `spekkr.inputs.json` and must stay inside the ranges in the Inputs table in `design.md`. - A value outside a range is refused before modelling, with a message that names the key. - Options add or remove the features in that table. The `tool` swap selects CadQuery or OpenSCAD; both must meet the same numbers. Accept when: default and one out-of-range value are handled as above, and a second legal input set still matches the formulas in `design.md`. ### R4. Checks and report - One command builds the model at the defaults and at the person's inputs, measures it against `design.md`, and writes a short report. - A model broken on purpose, for example a wall thinner than `wall`, must fail the report. - The command exports the files this spec asks for (STL, and STEP when the tool can). No physical print is required. Accept when: the report says pass at the defaults and at the person's inputs, and fail on a deliberately broken model. ## Verification Focal length, image-plane spot size, and an aberration metric are compared to documented targets. Ray-trace plots are checked as goldens. No optical bench and no physical glass are required. ## Definition of done - Every acceptance check above runs from one command, and all pass at the person's inputs. - A README says how to run the tracer, how the targets are listed, and that a bench is not a check.