Skip to main content

ifc_lite_wasm/api/
diagnose.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5//! WASM API: diagnose_geometry — run the geometry pass and return ONLY its typed
6//! CSG / opening diagnostics (the `GeometryDiagnostics` contract).
7//!
8//! This drives the unified `process_geometry` pass (wasm-safe via its clock shim)
9//! and returns `ProcessingStats.geometry_diagnostics`, so the CLI / SDK surface the
10//! exact same contract the WASM batch loader and the native server produce. The
11//! meshes themselves are discarded — only the diagnostics cross the FFI boundary.
12
13use super::IfcAPI;
14use wasm_bindgen::prelude::*;
15
16#[wasm_bindgen]
17impl IfcAPI {
18    /// Run geometry extraction on `content` and return its typed CSG / opening
19    /// diagnostics (the `GeometryDiagnostics` contract) as a JS object, or
20    /// `undefined` when nothing diagnostic-worthy happened (no openings, no
21    /// failures). Takes the raw IFC bytes (`Uint8Array`) so there is no input-size
22    /// cap. The produced meshes are dropped; only the diagnostics are returned.
23    #[wasm_bindgen(js_name = diagnoseGeometry)]
24    pub fn diagnose_geometry(&self, content: &[u8]) -> JsValue {
25        let result = ifc_lite_processing::process_geometry(&content);
26        match result.stats.geometry_diagnostics.as_ref() {
27            Some(d) => serde_wasm_bindgen::to_value(d).unwrap_or(JsValue::UNDEFINED),
28            None => JsValue::UNDEFINED,
29        }
30    }
31}