a-b-street / abstreet

Transportation planning and traffic simulation software for creating cities friendlier to walking, biking, and public transit
https://a-b-street.github.io/docs/
Apache License 2.0
7.37k stars 332 forks source link

Boolean ops crash in WASM only #1121

Open dabreegster opened 9 months ago

dabreegster commented 9 months ago

We hit https://github.com/georust/geo/issues/976 sometimes in the LTN tool with some boundaries. geom in this codebase has std::panic::catch_unwind around it, but this doesn't work in WASM! https://stackoverflow.com/questions/59426545/rust-paniccatch-unwind-no-use-in-webassembly

Possible workarounds listed there

RobWalt commented 8 months ago

Please refer to this PR https://github.com/georust/geo/pull/1089. There's a new implementation on it's way which returns Results instead of panicing. It also didn't really hit any of the Err cases for all the existing tests yet.

dabreegster commented 8 months ago

Super exciting to see the new implementation! I am completely swamped with work the next few weeks, but it should be pretty quick for me to then swap over the implementation used here and either confirm many bugs go away or provide new test cases.

RobWalt commented 8 months ago

Just out of curiosity: What's your use case in this repo here?

dabreegster commented 8 months ago

The main use is in drawing low traffic neighbourhood "cells". If you click on an area in https://play.abstreet.org/0.3.48/ltn.html?system/gb/bristol/maps/east.bin, it's split into colored areas showing what's reachable by car without leaving the area. https://dabreegster.github.io/talks/aiuk_ltn/slides.html#/approximating-with-grids-1 describes how it's calculated -- approximate the area with a grid, floodfill different colors out. The end result needs to be clipped to the polygon of the overall area. That works most of the time, but I've hit a few cases that crash.

I think I have some other ideas for using boolean ops in related projects. The way this tool calculates "an area bounded by main roads" is quite brittle and complex, gluing together road edge-lines calculated (very imperfectly) from OpenStreetMap. I'd like to try simpler approaches like 1) Find all "severances" like main roads, railway, rivers 2) Possibly buffer linestrings into thicker polygons 3) Split the overall area by these lines Some of these might need other primitive geometric operations, but I think boolops could help. So, thanks a ton for working on a more robust implementation! I imagine it has really wide use.