use crate::layout::csr_sim::CsrSimulation;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub struct NggExplorer {
sim: CsrSimulation,
}
impl Default for NggExplorer {
fn default() -> Self {
Self::new()
}
}
#[wasm_bindgen]
impl NggExplorer {
#[wasm_bindgen(constructor)]
pub fn new() -> Self {
Self {
sim: CsrSimulation::new(),
}
}
#[wasm_bindgen(js_name = loadCsr)]
pub fn load_csr(&mut self, bytes: &[u8]) -> Result<(), JsValue> {
self.sim
.load_csr(bytes)
.map_err(|e| JsValue::from_str(&e.to_string()))
}
#[wasm_bindgen(js_name = tick)]
pub fn tick(&mut self) {
self.sim.tick();
}
#[wasm_bindgen(js_name = isFinished)]
pub fn is_finished(&self) -> bool {
self.sim.is_finished()
}
#[wasm_bindgen(js_name = getAlpha)]
pub fn get_alpha(&self) -> f32 {
self.sim.alpha()
}
#[wasm_bindgen(js_name = nodeCount)]
pub fn node_count(&self) -> usize {
self.sim.node_count()
}
#[wasm_bindgen(js_name = edgeCount)]
pub fn edge_count(&self) -> usize {
self.sim.edge_count()
}
#[wasm_bindgen(js_name = positionsPtr)]
pub fn positions_ptr(&self) -> *const f32 {
self.sim.positions_ptr()
}
#[wasm_bindgen(js_name = positionsLen)]
pub fn positions_len(&self) -> usize {
self.sim.positions_len()
}
#[wasm_bindgen(js_name = writePositionsInto)]
pub fn write_positions_into(&self, out: &mut [f32]) {
self.sim.write_positions_into(out);
}
#[wasm_bindgen(js_name = setParam)]
pub fn set_param(&mut self, key: &str, val: f32) {
self.sim.set_param(key, val);
}
#[wasm_bindgen(js_name = reheat)]
pub fn reheat(&mut self, alpha: f32) {
self.sim.reheat(alpha);
}
}