Closed Ptrskay3 closed 5 months ago
I'm trying to use this crate with wasm-bindgen, and it seems that using u32 indices does not work. Specifically this line https://github.com/sdd/kiddo/blob/4e2dbf471229266a88ce3ef8dcbea38ebc0b76b0/src/types.rs#L80 panics if the crate is built on wasm target. Here's a minimal example to reproduce the issue:
wasm-bindgen
use kiddo::{float::kdtree::KdTree}; use wasm_bindgen::prelude::*; #[wasm_bindgen] pub struct KdTreeWasm { tree: KdTree<f64, u64, 2, 32, u32>, } #[wasm_bindgen] impl KdTreeWasm { #[wasm_bindgen(constructor)] pub fn new() -> Self { let tree: KdTree<f64, u64, 2, 32, u32> = KdTree::with_capacity(5); Self { tree } } }
and on the JavaScript side, simply just initialize:
import('../pkg/index.js').then({ KdTreeWasm } => { let tree = new KdTreeWasm(); });
and this'll panic at attempt to multiply with an overflow.
attempt to multiply with an overflow
Is this behaviour expected? Am I missing something?
If I'm not mistaken, capacity_with_bucket_size only works with u32 if #[cfg(target_pointer_width = "64")].
capacity_with_bucket_size
#[cfg(target_pointer_width = "64")]
Fix released in v4.1.1
I'm trying to use this crate with
wasm-bindgen
, and it seems that using u32 indices does not work. Specifically this line https://github.com/sdd/kiddo/blob/4e2dbf471229266a88ce3ef8dcbea38ebc0b76b0/src/types.rs#L80 panics if the crate is built on wasm target. Here's a minimal example to reproduce the issue:and on the JavaScript side, simply just initialize:
and this'll panic at
attempt to multiply with an overflow
.Is this behaviour expected? Am I missing something?
If I'm not mistaken,
capacity_with_bucket_size
only works with u32 if#[cfg(target_pointer_width = "64")]
.