Skip to content

Route inter-class edges with libavoid-js WASM - #16

Draft
saulshanabrook wants to merge 2 commits into
pr-preview-deployfrom
better-edge-routing
Draft

saulshanabrook wants to merge 2 commits into
pr-preview-deployfrom
better-edge-routing

Conversation

@saulshanabrook

Copy link
Copy Markdown
Member

Stacked on #15. Closes #8.

Summary

  • Route inter-e-class edges orthogonally around all e-class boxes using libavoid-js (Adaptagrams libavoid compiled to WASM) running inside an inline Web Worker (src/routing.worker.ts, src/routing.ts) with cancellation support on AbortSignal.
  • Inline libavoid.wasm via a tiny virtual:libavoid-wasm Vite plugin (vite.config.ts) so the published dist/index.js remains 100% self-contained for AnyWidget, esm.sh, jsDelivr, and GitHub Pages subpaths without external .wasm fetches or CORS issues.
  • Allow incoming edges to attach to all free sides of target e-classes (preferring top, then left/right, then bottom when no outgoing ports occupy the bottom) with crossing avoidance (crossingPenalty = 200 + setHateCrossings(true) up to 180 edges) and orthogonal nudging.
  • Align straight vertical inner e-node exits with nudged class-border pins (joinInnerAndOuterPoints in src/layout.ts) to prevent small border jogs, with automatic fallback to ELK routes on any routing error.
  • Add an Edge routing: libavoid / ELK toggle in the Settings menu (and avoidEdgeRouting option on Visualizer / mount(), default true) so you can compare both live in the PR preview demo.

Quantitative Comparison (ELK vs libavoid-js)

Example Edges Crossings (ELK → libavoid) Bends (ELK → libavoid) Total Length (ELK → libavoid) Load Time (ELK → libavoid)
homepage.json 10 4 → 3 (-25%) 32 → 32 1,929 → 1,599 (-17%) 274ms → 444ms
path-proof.json (step 3) 51 119 → 72 (-39%) 167 → 157 (-6%) 24,674 → 25,767 (+4%) 320ms → 529ms
lambda_if_elim.json 41 100 → 37 (-63%) 161 → 135 (-16%) 19,021 → 15,797 (-17%) 319ms → 310ms
math_simplify_add.json 60 216 → 166 (-23%) 244 → 176 (-28%) 38,157 → 33,250 (-13%) 209ms → 512ms
lambda_if.json 87 387 → 276 (-29%) 363 → 297 (-18%) 72,125 → 61,576 (-15%) 313ms → 2.4s
diff_power_simple.json 147 873 → 573 (-34%) 625 → 545 (-13%) 180,359 → 161,485 (-10%) 310ms → 3.2s

(All 6 examples had 0 e-node intersections and 0 console errors.)

Before / After Screenshots

lambda_if_elim.json (41 edges — crossings 100 → 37, -63%)

Before (ELK) After (libavoid)
before lambda_if_elim after lambda_if_elim

math_simplify_add.json (60 edges — crossings 216 → 166, -23%; bends 244 → 176, -28%)

Before (ELK) After (libavoid)
before math_simplify_add after math_simplify_add

path-proof.json (51 edges — crossings 119 → 72, -39%)

Before (ELK) After (libavoid)
before path-proof after path-proof

lambda_if.json (87 edges — crossings 387 → 276, -29%)

Before (ELK) After (libavoid)
before lambda_if after lambda_if

diff_power_simple.json (147 edges — crossings 873 → 573, -34%)

Before (ELK) After (libavoid)
before diff_power_simple after diff_power_simple

homepage.json (10 edges — crossings 4 → 3, length -17%)

Before (ELK) After (libavoid)
before homepage after homepage

@github-actions

Copy link
Copy Markdown
Contributor

Demo preview deployed for commit fd7d5f8:

https://egraphs-good.github.io/egraph-visualizer/pr-preview/pr-16/

This branch was successfully deployed

1 active deployment
github-pages — fd7d5f8d Deployed Nov 22, 2026 by saulshanabrook via deploy-preview #3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant