ifc_lite_wasm/
alignment_axis.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//! Retained exact alignment evaluator. The caller owns and frees this handle.
6use ifc_lite_geometry::AlignmentAxis;
7use wasm_bindgen::prelude::*;
8
9#[wasm_bindgen]
10pub struct AlignmentAxisJs {
11    axis: AlignmentAxis,
12}
13
14#[wasm_bindgen]
15impl AlignmentAxisJs {
16    #[wasm_bindgen(constructor)]
17    pub fn new(content: &str, express_id: u32) -> std::result::Result<Self, JsValue> {
18        AlignmentAxis::from_content(content, express_id)
19            .map(|axis| Self { axis })
20            .map_err(|error| JsValue::from_str(&error.to_string()))
21    }
22
23    #[wasm_bindgen(getter, js_name = expressId)]
24    pub fn express_id(&self) -> u32 { self.axis.express_id }
25
26    #[wasm_bindgen(getter, js_name = GlobalId)]
27    pub fn global_id(&self) -> Option<String> { self.axis.GlobalId.clone() }
28
29    #[wasm_bindgen(getter, js_name = Name)]
30    pub fn name(&self) -> Option<String> { self.axis.Name.clone() }
31
32    #[wasm_bindgen(getter, js_name = geometricHorizontalLengthMeters)]
33    pub fn length_m(&self) -> f64 { self.axis.length_m() }
34
35    #[wasm_bindgen(getter)]
36    pub fn approximate(&self) -> bool { self.axis.approximate }
37
38    /// [horizontal distance, IFC Z-up point XYZ, normalized world tangent XYZ].
39    /// Coordinates remain f64 absolute metres; no renderer origin is applied.
40    pub fn evaluate(&self, distance_m: f64) -> std::result::Result<Vec<f64>, JsValue> {
41        let sample = self.axis.evaluate(distance_m)
42            .map_err(|error| JsValue::from_str(&error.to_string()))?;
43        Ok(vec![sample.geometric_horizontal_distance_m,
44            sample.point[0], sample.point[1], sample.point[2],
45            sample.tangent[0], sample.tangent[1], sample.tangent[2]])
46    }
47}