GeoRust wrapper for my homework.
wasm-pack build --target web
import * as wasm from "polyvis_wasm.js";
await wasm.default();
const instance = wasm.new_session();There are some convenience functions and instance methods. See polyvis_wasm.d.ts.
See mtel0004/FIT3162/src/utils.ts for adapting types between JS and the WASM module (JS number type is 64-bit float).
Importing YAML save is not supported, due to lack of a maintained & popular YAML library. Export is supported (YAML is more human-readable).
- Avoid passing a lot of data between JS and WASM, because it's slow. May need to keep 2 copies of the polygon list.
- Deno has HTTP import but it can't be used with WASM yet. Currently the web standard for loading WASM is fetch & instantiate
new URL('something.wasm', import.meta.url), so the dependency is runtime instead of a regular import, which Deno doesn't support on principle. There is a draft standard "ES Module Integration" which Deno already supports and there are polyfills (example) for the browser, but the tooling is awkward:wasmbuildlocks dependency versions of your project,vite-plugin-wasmseems to be generating its own glue code,wasm-pack'sdenotarget is using the slowestWebAssembly.instantiate()method instead of Deno's ESM Integration. - Watch for the fixed-size arrays feature so we can ditch the wrapper structs.
- Use iShape-js, a wasm build of iOverlay in a Javascript web app.
- Switch to GeoRust and write a wrapper. Because iOverlay doesn't have all the features we need (e.g. calculate area, convex check) and GeoRust doesn't compile to WASM. GeoRust is the most popular Rust geometry library and uses iOverlay as a dependency.
- Write a full backend. Because passing (copying) a lot of data is slow.
Further reading: https://kylebarron.dev/blog/geos-wasm (p.s. GEOS says it's a port of JTS, not the other way around.)
- Use
std::sync::LazyLockinstead of instance? (Not recommended in general) - Use WASM's linear memory in JS?
- Import JS functions to Rust to avoid data copy and using structs to pass data.
- Multi-threading?