use ifc_lite_clash::ClashSession as CoreSession;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub struct ClashSession {
inner: CoreSession,
}
#[wasm_bindgen]
impl ClashSession {
#[wasm_bindgen(constructor)]
pub fn new() -> Self {
Self {
inner: CoreSession::new(),
}
}
#[wasm_bindgen]
pub fn ingest(
&mut self,
positions: &[f32],
pos_ranges: &[u32],
indices: &[u32],
idx_ranges: &[u32],
aabbs: &[f32],
) {
self.inner
.ingest(positions, pos_ranges, indices, idx_ranges, aabbs);
}
#[wasm_bindgen(js_name = runRule)]
pub fn run_rule(
&self,
group_a: &[u32],
group_b: &[u32],
mode: u8,
tolerance: f64,
clearance: f64,
report_touch: bool,
) -> ClashRunResult {
let result =
self.inner
.run_rule(group_a, group_b, mode, tolerance, clearance, report_touch);
let n = result.records.len();
let mut a = Vec::with_capacity(n);
let mut b = Vec::with_capacity(n);
let mut status = Vec::with_capacity(n);
let mut distance = Vec::with_capacity(n);
let mut distance_kind = Vec::with_capacity(n);
let mut points = Vec::with_capacity(n * 3);
let mut bounds = Vec::with_capacity(n * 6);
for record in &result.records {
a.push(record.a);
b.push(record.b);
status.push(record.status as u8);
distance.push(record.distance);
distance_kind.push(record.distance_kind as u8);
points.extend_from_slice(&record.point);
bounds.extend_from_slice(&record.bounds);
}
ClashRunResult {
a,
b,
status,
distance,
distance_kind,
points,
bounds,
}
}
}
impl Default for ClashSession {
fn default() -> Self {
Self::new()
}
}
#[wasm_bindgen]
pub struct ClashRunResult {
a: Vec<u32>,
b: Vec<u32>,
status: Vec<u8>,
distance: Vec<f64>,
distance_kind: Vec<u8>,
points: Vec<f64>,
bounds: Vec<f64>,
}
#[wasm_bindgen]
impl ClashRunResult {
#[wasm_bindgen(getter)]
pub fn a(&self) -> Vec<u32> {
self.a.clone()
}
#[wasm_bindgen(getter)]
pub fn b(&self) -> Vec<u32> {
self.b.clone()
}
#[wasm_bindgen(getter)]
pub fn status(&self) -> Vec<u8> {
self.status.clone()
}
#[wasm_bindgen(getter)]
pub fn distance(&self) -> Vec<f64> {
self.distance.clone()
}
#[wasm_bindgen(getter, js_name = distanceKind)]
pub fn distance_kind(&self) -> Vec<u8> {
self.distance_kind.clone()
}
#[wasm_bindgen(getter)]
pub fn points(&self) -> Vec<f64> {
self.points.clone()
}
#[wasm_bindgen(getter)]
pub fn bounds(&self) -> Vec<f64> {
self.bounds.clone()
}
}