Bidrectional transitive closure, lots of back references
⚓ Rust 📅 2025-09-12 👤 surdeus 👁️ 9Ref: Rust Playground
This is a bidrectional transitive closure algorithm. What it's doing is computing whether you can get there from here for a big grid of rectangular regions. If two rectangles share some edge space, they're reachable from each other. The algorithm computes collections of VisGroup, regions which are all reachable from each other.
The trick is doing this entirely in safe Rust. It uses RefCell, borrow() calls, and Weak pointers for its non-owning back pointers. As is typical with Rust, it was really hard to get the borrow plumbing right, and then it just worked.
So was this the right way to organize this algorithm? Comments?
If you run this with cargo test -- --nocapture you can see the output. Playground doesn't seem to offer that option, unfortunately.
(Use case: this is for a support tool for my metaverse client for Second Life/Open Simulator. It is a rule of the grid that you can only see regions you can reach. Some areas are full of checkerboards of isolated private regions, none of which can see each other. Others are big land areas, sometimes connected only by narrow strings of regions. I'm working on an impostor system for long-distance visibility, and I need to do some pre-computation to decide which impostors are visible from where.)
1 post - 1 participant
🏷️ Rust_feed