补充分离批次重叠筛选测试

验证 DFS 顺序下贪心跳过重叠叶节点
This commit is contained in:
2026-09-09 14:54:37 +08:00
parent d30bc462c5
commit 9b4924c73e
@@ -157,4 +157,66 @@ mod tests {
assert_eq!(state.bound[0].node_id, id);
assert_eq!(state.trees[0].root.children.len(), 1);
}
#[test]
fn batch_selection_greedily_skips_overlapping_leaves() {
let a = SeparationNode {
id: NodeId::new("a").unwrap(),
global_pos_x_px: 0,
global_pos_y_px: 0,
width_px: 10,
height_px: 10,
note: SeparationNote::default(),
children: vec![],
rework_count: 0,
};
let b = SeparationNode {
id: NodeId::new("b").unwrap(),
global_pos_x_px: 5,
global_pos_y_px: 5,
width_px: 10,
height_px: 10,
note: SeparationNote::default(),
children: vec![],
rework_count: 0,
};
let c = SeparationNode {
id: NodeId::new("c").unwrap(),
global_pos_x_px: 20,
global_pos_y_px: 0,
width_px: 5,
height_px: 5,
note: SeparationNote::default(),
children: vec![],
rework_count: 0,
};
let tree = SeparationTree {
src_ui_design: UIDesignImageId::new("page").unwrap(),
root: SeparationNode {
id: NodeId::new("root").unwrap(),
global_pos_x_px: 0,
global_pos_y_px: 0,
width_px: 100,
height_px: 100,
note: SeparationNote::default(),
children: vec![a, b, c],
rework_count: 0,
},
root_extractable: false,
};
let state = SeparationState {
schema_version: SEPARATION_STATE_SCHEMA_VERSION.to_string(),
trees: vec![tree.clone()],
bound: vec![],
problematic_nodes: vec![],
};
let batch = next_leaf_batch(&state, &tree);
assert_eq!(
batch
.iter()
.map(|node| node.id.as_str())
.collect::<Vec<_>>(),
vec!["a", "c"]
);
}
}