fix(planar-incr-embed): discover all possible paths, including the variants re: weak entries

This commit is contained in:
Ellen Emilia Anna Zscheile 2025-03-31 01:34:12 +02:00
parent 77969952ff
commit bb1cfc76d9
3 changed files with 65 additions and 17 deletions

View File

@ -180,25 +180,29 @@ where
// 2. handle rest
Some((
start_idx,
it.filter_map(move |(section_idx, (ni, eps))| {
it.flat_map(move |(section_idx, (ni, eps))| {
// find possible insertion point
// (at most one of `eps.len()+1` positions)
let mut pos = if stack.is_empty() { Some(0) } else { None };
for (n, i) in eps.iter().enumerate() {
handle_lifo_relaxed(&mut stack, i);
if pos.is_none() && stack.is_empty() {
pos = Some(n + 1);
}
}
pos.map(|insert_pos| {
(
ni,
OtherEnd {
section_idx,
insert_pos,
},
)
})
(if stack.is_empty() { Some(0) } else { None })
.into_iter()
.chain(eps.iter().enumerate().filter_map(|(n, i)| {
handle_lifo_relaxed(&mut stack, i);
if stack.is_empty() {
Some(n + 1)
} else {
None
}
}))
.map(move |insert_pos| {
(
ni.clone(),
OtherEnd {
section_idx,
insert_pos,
},
)
})
.collect::<Vec<_>>()
}),
))
}

View File

@ -0,0 +1,27 @@
---
source: crates/planar-incr-embed/src/planarr/tests.rs
expression: "s_.find_all_other_ends(&0, 0, false).unwrap().1.collect::<Vec<_>>()"
---
[
[
1,
{
"section_idx": 1,
"insert_pos": 2
}
],
[
2,
{
"section_idx": 2,
"insert_pos": 0
}
],
[
2,
{
"section_idx": 2,
"insert_pos": 1
}
]
]

View File

@ -148,3 +148,20 @@ fn simple01() {
assert_eq!(s_.insert_path(&1, 2, &2, 'd'), Ok(1));
assert_compact_json_snapshot!(s.0);
}
#[test]
fn weak00() {
let mut s = PlanarArrangement::<_, _, ()>::from_node_indices(0..3);
let mut s_ = s.as_mut();
s_.0[2].1.reversed = true;
s_.0[2].1.with_borrow_mut(|j| {
j.inner.push(RelaxedPath::Weak(()));
});
assert_eq!(s_.insert_path(&0, 0, &1, 'a'), Ok(0));
assert_eq!(s_.insert_path(&0, 0, &1, 'b'), Ok(0));
assert_compact_json_snapshot!(s_
.find_all_other_ends(&0, 0, false)
.unwrap()
.1
.collect::<Vec<_>>());
}