WASM Routing

"/home/yossef/notes/git/projects/maplibra/modules/WASM Routing.md"

path: maplibra/modules/WASM Routing.md

- **fileName**: WASM Routing
- **Created on**: 2026-06-16 00:48:42

WASM Routing

Purpose: Documents the native C routing kernel compiled to WebAssembly.

Related: ../Home.md, ./Pathfinding.md, ../flows/Wall Detection.md

Overview

The WASM kernel is an optional accelerator that replicates the JS pathfinding logic in C for performance. It handles:

Architecture

JS (route-kernel-bridge.js)
  ↓ copies graph buffers into WASM memory
  ↓ packs options into 48-byte struct
  ↓ calls exported C functions
  ↓ reads result buffer back
C (route_kernel.c + route_smoothing.c + route_spatial.c)
  ↓ operates on linear memory
  ↓ uses pre-allocated scratch buffers
  ↓ writes results to shared output buffer

Memory Layout

Graph lives in WASM linear memory as flat typed arrays:

Spatial Floor Bundle

Uploaded per floor via routing_upload_spatial_floor. Contains:

Key Functions

Export Purpose
routing_init_graph Load graph into WASM memory
routing_find_multi_candidate_path A* with multiple start/goal candidates
routing_is_point_blocked Check if point is outside walkable or inside blocker
routing_is_segment_walkable Sample N points along segment, check each
routing_get_point_clearance Distance to nearest blocker edge
routing_find_shortcut_vertex Greedy shortcut search for smoothing
routing_upload_spatial_floor Upload walkable/blocker polygons for a floor

Known Issues (Fixed/In Progress)

Important Files