ifc_lite_wasm/
alignment_axis.rs1use 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 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}