Skip to content

Commit

Permalink
fix is_connected computation
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-williams committed Sep 22, 2023
1 parent 3903244 commit 1d83bd3
Show file tree
Hide file tree
Showing 4 changed files with 245 additions and 25 deletions.
23 changes: 23 additions & 0 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,4 +454,27 @@ mod tests {
// XYRR { c: { x: 2.65823706629625, y: 1.062726304716347 }, r: { x: 2.36947609319204, y: 0.37496988567008666 } }
check(inputs, VARIANT_CALLERS.into(), "variant_callers", 0.7, 100)
}

#[test]
fn disjoint_variant_callers_bug() {
let ( _z, d ) = d_fns(16);
let ellipses = [
XYRR { c: R2 { x: 0., y: 0., }, r: R2 { x: 1., y: 1. }, },
XYRR { c: R2 { x: 3., y: 0., }, r: R2 { x: 1., y: 1. }, },
XYRR { c: R2 { x: 0., y: 3., }, r: R2 { x: 1., y: 1. }, },
XYRR { c: R2 { x: 3., y: 3., }, r: R2 { x: 1., y: 1. }, },
// XYRR { c: R2 { x: 0.6783042134980906, y: 0.4060375756236656 }, r: R2 { x: 1.1386389763957379, y: 1.1813967858073406 } },
// XYRR { c: R2 { x: 2.364553744272618, y: 0.7877127658995076 }, r: R2 { x: 1.209114832709512, y: 1.1946980556173679 } },
// XYRR { c: R2 { x: 0.7520063240515944, y: 2.536361530765468 }, r: R2 { x: 0.5841020254687528, y: 0.5841020254687528 } },
// XYRR { c: R2 { x: 2.2051357181776945, y: 2.2698881277113614 }, r: R2 { x: 0.86182368577464, y: 0.8376473805867598 } },
];
let [ e0, e1, e2, e3 ] = ellipses;
let inputs: Vec<Input> = vec![
( Shape::XYRR(e0), vec![ d( 0), d( 1), d( 2), d( 3), ] ),
( Shape::XYRR(e1), vec![ d( 4), d( 5), d( 6), d( 7), ] ),
( Shape::XYRR(e2), vec![ d( 8), d( 9), d(10), d(11), ] ),
( Shape::XYRR(e3), vec![ d(12), d(13), d(14), d(15), ] ),
];
check(inputs, VARIANT_CALLERS.into(), "disjoint_variant_callers_bug", 0.5, 100);
}
}
45 changes: 20 additions & 25 deletions src/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ where
// This intersection is close enough to an existing node; merge them
let mut node = node.borrow_mut();
node.merge(i.clone(), idx, &theta0, jdx, &theta1);
debug!("Merged: {} into {}", i, node);
info!("Merged: {} into {}", i, node);
merged = true;
break;
}
Expand Down Expand Up @@ -133,37 +133,32 @@ where
nodes_by_shape.push(Vec::new());
}
// Compute connected components (shape -> shape -> bool)
let mut is_connected: Vec<Vec<bool>> = Vec::new();
for idx in 0..num_shapes {
let mut connected: Vec<bool> = Vec::new();
for jdx in 0..num_shapes {
connected.push(idx == jdx);
let mut is_connected: Vec<Vec<bool>> = is_directly_connected.clone();
for i0 in 0..num_shapes {
for i1 in 0..num_shapes {
if is_connected[i0][i1] {
for i2 in 0..num_shapes {
if is_connected[i0][i2] && !is_connected[i1][i2] {
for i3 in 0..num_shapes {
if is_connected[i1][i3] && !is_connected[i2][i3] {
is_connected[i2][i3] = true;
is_connected[i3][i2] = true;
}
};
}
};
}
}
is_connected.push(connected);
}
debug!("is_directly_connected: {:?}", is_directly_connected);
debug!("is_connected: {:?}", is_connected);

for node in &nodes {
node.borrow().shape_thetas.keys().for_each(|i0| {
nodes_by_shape[*i0].push(node.clone());
node.borrow().shape_thetas.keys().for_each(|i1| {
let was_connected = is_connected[*i0][*i1];
is_connected[*i0][*i1] = true;
is_connected[*i1][*i0] = true;
if !was_connected {
// Everything connected to i0 is now also connected to i1, and vice versa
for i2 in 0..num_shapes {
if is_connected[*i0][i2] && !is_connected[*i1][i2] {
for i3 in 0..num_shapes {
if is_connected[*i1][i3] && !is_connected[i2][i3] {
is_connected[i2][i3] = true;
is_connected[i3][i2] = true;
}
};
}
};
}
})
});
}

// shape_idx -> shape_idxs
let mut unconnected_containers: Vec<BTreeSet<usize>> = Vec::new();
for (idx, shape) in shapes.iter().enumerate() {
Expand Down
Loading

0 comments on commit 1d83bd3

Please sign in to comment.