1pub use lensbench_core::{Error, Result};
21pub use lensbench_engine::Extensions;
22pub use schemars;
25pub use serde;
26pub use serde_json;
27
28pub mod plugin {
30 pub use lensbench_core::par::check_cancel;
32 pub use lensbench_core::plugin::{
33 Array, ArrayReader, Arrays, Config, ConfigReader, Context, Data, Instance, Kind, Linear,
34 OutputSpec, ParamSpec, ParamType, Plugin, Registry, Spec, Value,
35 };
36}
37
38pub mod analysis {
40 pub use lensbench_analysis::{Analysis, Cx, Meta, Param, ParamTy, Saved, Source, Variant};
41}
42
43pub mod system {
45 pub use lensbench_core::param::Param;
46 pub use lensbench_core::System;
47 pub use lensbench_project::{expand, BlockAt, Env, ExpandError, ExpandOpts, Project};
48}
49
50pub mod trace {
52 pub use lensbench_analysis::raygrid::RayGrid;
53 pub use lensbench_core::system::{
54 Cols, FieldSel, Launch, ObjSpec, PolIn, PolTrace, RayBuf, RecSel, Trace, TraceOpts,
55 };
56 pub use lensbench_core::trace::{RayCounts, RayOut, RayStatus};
57}
58
59pub mod surface {
61 pub use lensbench_core::freeform::ZernSag;
64 pub use lensbench_core::usersurf::{check_flip, Flip, SurfaceInstance, SurfaceModel};
65}
66
67pub mod shape {
69 pub use lensbench_core::usershape::{check_shape, ShapeInstance, ShapeModel};
70}
71
72pub mod source {
75 pub use lensbench_core::usersource::{check_source, SourceInstance, SourceModel, SourceRays};
76}
77
78pub mod material {
80 pub use lensbench_core::usermaterial::{check_material, MaterialModel};
81}
82
83pub mod coating {
86 pub use lensbench_core::coating::{
87 parse_measured, parse_models, CoatModel, CoatingFile, Layer, Measured, Table, C64,
88 };
89 pub use lensbench_core::usercoating::{
90 check_coating_model, check_coatings, CoatCoefs, CoatInput, CoatPath, CoatingModel,
91 CoatingSet, CoatingSource,
92 };
93}
94
95pub mod catalog {
97 pub use lensbench_core::catalog::{CatalogLens, LensCatalogSource};
98}
99
100pub mod detector {
102 pub use lensbench_project::detectors::DetectorKind;
103}
104
105pub fn check(ext: &Extensions) -> Vec<String> {
110 let mut out = Vec::new();
111 let table = match ext.ext() {
112 Ok(t) => t,
113 Err(e) => return vec![e.to_string()],
114 };
115 #[cfg(feature = "gui")]
116 {
117 for a in ext.analysis_names() {
118 if !lensbench_gui::ext::has_analysis(&table, a) {
119 out.push(format!(
120 "analysis {a} has no GUI presentation (gui_analysis)"
121 ));
122 }
123 }
124 for d in ext.detector_kinds() {
125 if !lensbench_gui::ext::has_detector(&table, d.name) {
126 out.push(format!(
127 "detector {} has no GUI fields (gui_detector)",
128 d.name
129 ));
130 }
131 }
132 }
133 #[cfg(not(feature = "gui"))]
134 let _ = &table;
135 for m in ext.surface_models() {
136 if let Some(c) = m.example_config() {
137 if let Err(e) = lensbench_core::usersurf::check_flip(m.as_ref(), &c) {
138 out.push(format!("surface model {}: {e}", m.name()));
139 }
140 }
141 }
142 for m in ext.shape_models() {
143 if let Some(c) = m.example_config() {
144 let r = m.example_radius();
145 if let Err(e) = lensbench_core::usershape::check_shape(m.as_ref(), &c, r) {
146 out.push(format!("shape model {}: {e}", m.name()));
147 }
148 }
149 }
150 for m in ext.source_models() {
151 if let Some(c) = m.example_config() {
152 if let Err(e) = lensbench_core::usersource::check_source(m.as_ref(), &c) {
153 out.push(format!("source model {}: {e}", m.name()));
154 }
155 }
156 }
157 for (cat, ms) in ext.material_catalogs() {
158 let mut seen = std::collections::BTreeSet::new();
159 for m in ms {
160 if !seen.insert(m.name().to_string()) {
161 out.push(format!(
162 "material catalog {cat}: {} is added twice",
163 m.name()
164 ));
165 }
166 if let Err(e) = lensbench_core::usermaterial::check_material(m.as_ref()) {
167 out.push(format!("material catalog {cat}: {e}"));
168 }
169 }
170 }
171 for (cat, set) in ext.coating_catalogs() {
172 if let Err(e) = lensbench_core::usercoating::check_coatings(set) {
173 out.push(format!("coating catalog {cat}: {e}"));
174 }
175 }
176 out
177}
178
179#[cfg(feature = "cli")]
181pub mod cli {
182 pub fn main(ext: crate::Extensions) -> std::process::ExitCode {
184 lensbench_cli::main_with(ext)
185 }
186}
187
188#[cfg(feature = "gui")]
190pub mod gui {
191 pub use egui;
192 pub use lensbench_gui::ext::{
193 fig, Analysis, Detector, Figure, FigureParams, GuiExtensions, ObjectArg,
194 };
195
196 #[cfg(not(target_arch = "wasm32"))]
198 pub fn main(ext: crate::Extensions) -> std::process::ExitCode {
199 lensbench_gui::main_with(ext)
200 }
201}
202
203#[cfg(feature = "py")]
205pub mod py {
206 pub use lensbench::ext::{
207 arrays_to_py, system_method, ModuleFn, NativeTask, NativeTaskFrom, PyExtensions, PyPlugin,
208 PySystem,
209 };
210 pub use pyo3;
211
212 pub fn module(
214 m: &pyo3::Bound<'_, pyo3::types::PyModule>,
215 ext: crate::Extensions,
216 ) -> pyo3::PyResult<()> {
217 lensbench::ext::module_with(m, ext)
218 }
219}
220
221#[cfg(feature = "web")]
228pub mod web {
229 pub use lensbench_web::{set_extra, Extra};
230 #[cfg(target_arch = "wasm32")]
231 pub use wasm_bindgen;
232}
233
234#[cfg(test)]
235mod tests {
236 use super::*;
237
238 #[test]
240 fn check_passes_a_good_model_and_reports_errors() {
241 let m = lensbench_core::ext::current()
242 .surface_model("ideal_mapping")
243 .unwrap();
244 let ok = Extensions::named("t").surface_model(m);
245 assert!(check(&ok).is_empty(), "{:?}", check(&ok));
246 let bad = lensbench_project::BUILTIN_BLOCKS[0];
247 let e = Extensions::named("t").detector(detector::DetectorKind {
248 name: bad,
249 doc: "",
250 check: |_| Ok(()),
251 schema: None,
252 });
253 assert_eq!(check(&e).len(), 1);
254 let e = Extensions::named("t").material_catalog("schott", Vec::new());
256 let c = check(&e);
257 assert!(
258 c.len() == 1 && c[0].contains("has the name of a built-in glass catalog"),
259 "{c:?}"
260 );
261 assert!(e.ext().is_err());
262 }
263
264 #[cfg(feature = "gui")]
266 #[test]
267 fn check_reports_a_detector_without_gui_fields() {
268 use gui::GuiExtensions;
269 let k = detector::DetectorKind {
270 name: "sdk-test-detector",
271 doc: "",
272 check: |_| Ok(()),
273 schema: None,
274 };
275 let e = Extensions::named("t").detector(k);
276 assert_eq!(
277 check(&e),
278 ["detector sdk-test-detector has no GUI fields (gui_detector)"]
279 );
280 let e = e.gui_detector(gui::Detector::new(
281 "sdk-test-detector",
282 gui::ObjectArg::new("", "", Vec::new),
283 ));
284 assert!(check(&e).is_empty());
285 }
286}