use super::*;
use scene::WorldKey;
pub(super) fn world_ladder(index: &SceneIndex, a: &str, b: &str) -> Vec<WorldKey> {
if index.geo_contains(a, b) || index.geo_contains(b, a) {
return vec![index.world_of(a, b)];
}
let mut out = vec![index.common_world(a, b)];
while let Some(up) = index.parent_world(*out.last().expect("non-empty")) {
out.push(up);
}
out
}
pub(super) fn build_worlds(index: &SceneIndex, reqs: &[EdgeReq], c: f64) -> Vec<World> {
let bounds = index.bounds().inflate(2.0 * c + 20.0);
let mut keys: Vec<WorldKey> = reqs
.iter()
.filter(|r| r.corridor())
.flat_map(|r| world_ladder(index, &r.a_path, &r.b_path))
.collect();
keys.sort_unstable();
keys.dedup();
keys.into_iter()
.map(|key| {
let wb = index.world_rect(key).unwrap_or(bounds);
let keepouts: Vec<Rect> = index
.child_rects(key)
.iter()
.map(|r| r.inflate(c))
.collect();
let graph = ChannelGraph::build(wb, &keepouts, key.is_none());
World { key, graph }
})
.collect()
}