diff --git a/rust/crates/tidy-tree/src/layout/basic_layout.rs b/rust/crates/tidy-tree/src/layout/basic_layout.rs index 2611635..a47b5d2 100644 --- a/rust/crates/tidy-tree/src/layout/basic_layout.rs +++ b/rust/crates/tidy-tree/src/layout/basic_layout.rs @@ -43,8 +43,8 @@ impl Layout for BasicLayout { self.update_meta(node); }); root.pre_order_traversal_mut(|node| { - if let Some(parent) = node.parent { - let parent = unsafe { parent.as_ref() }; + if let Some(mut parent) = node.parent { + let parent = unsafe { parent.as_mut() }; node.x = parent.x + node.relative_x; node.y = parent.y + node.relative_y; } diff --git a/rust/crates/tidy-tree/src/node.rs b/rust/crates/tidy-tree/src/node.rs index 0c5c593..feb3be7 100644 --- a/rust/crates/tidy-tree/src/node.rs +++ b/rust/crates/tidy-tree/src/node.rs @@ -147,7 +147,7 @@ impl Node { self.tidy.as_ref().unwrap() } - fn reset_parent_link(&mut self) { + fn reset_parent_link_of_children(&mut self) { if self.children.is_empty() { return; } @@ -161,8 +161,8 @@ impl Node { pub fn append_child(&mut self, mut child: Self) -> NonNull { child.parent = Some(self.into()); let mut boxed = Box::new(child); - boxed.reset_parent_link(); - let ptr = boxed.as_ref().into(); + boxed.reset_parent_link_of_children(); + let ptr = boxed.as_mut().into(); self.children.push(boxed); ptr } @@ -202,7 +202,7 @@ impl Node { stack.push((node_ptr, false)); for child in node.children.iter_mut() { - stack.push((child.as_ref().into(), true)); + stack.push((child.as_mut().into(), true)); } } } @@ -221,7 +221,7 @@ impl Node { stack.push((node_ptr, false)); for child in node.children.iter_mut() { - stack.push((child.as_ref().into(), true)); + stack.push((child.as_mut().into(), true)); } } } @@ -235,7 +235,7 @@ impl Node { let node = unsafe { node.as_mut() }; f(node); for child in node.children.iter_mut() { - stack.push(child.as_ref().into()); + stack.push(child.as_mut().into()); } } } @@ -249,7 +249,7 @@ impl Node { let node = unsafe { node.as_mut() }; f(node); for child in node.children.iter_mut() { - stack.push(child.as_ref().into()); + stack.push(child.as_mut().into()); } } } @@ -264,7 +264,7 @@ impl Node { let node = unsafe { node.as_mut() }; f(node, depth); for child in node.children.iter_mut() { - queue.push_back((child.as_ref().into(), depth + 1)); + queue.push_back((child.as_mut().into(), depth + 1)); } } } @@ -285,7 +285,7 @@ impl Node { let node = unsafe { node.as_mut() }; f(node, depth); for child in node.children.iter_mut() { - stack.push((child.as_ref().into(), depth + 1)); + stack.push((child.as_mut().into(), depth + 1)); } } } diff --git a/rust/crates/tidy-tree/tests/aesthetic_rules.rs b/rust/crates/tidy-tree/tests/aesthetic_rules.rs index 8154224..f370c2d 100644 --- a/rust/crates/tidy-tree/tests/aesthetic_rules.rs +++ b/rust/crates/tidy-tree/tests/aesthetic_rules.rs @@ -45,6 +45,7 @@ pub fn check_y_position_in_same_level(root: &Node) { pub fn assert_no_crossed_lines(root: &Node) { let mut lines: Vec = vec![]; + // println!("{}", &root.str()); root.post_order_traversal(|node| { for child in node.children.iter() { let line = Line { diff --git a/rust/crates/tidy-tree/tests/gen.rs b/rust/crates/tidy-tree/tests/gen.rs index b606c62..7ee2d47 100644 --- a/rust/crates/tidy-tree/tests/gen.rs +++ b/rust/crates/tidy-tree/tests/gen.rs @@ -19,23 +19,23 @@ pub fn gen_node(rng: &mut StdRng) -> Node { } } -pub fn gen_tree(rng: &mut StdRng, num: usize) -> Node { - let root = gen_node(rng); - let mut nodes: Vec> = vec![(&root).into()]; +pub fn gen_tree(rng: &mut StdRng, num: usize) -> Box { + let mut root = Box::new(gen_node(rng)); + let mut nodes: Vec> = vec![(&mut *root).into()]; for _ in 0..num { let parent_index = rng.gen_range(0..nodes.len()); let parent = unsafe { nodes[parent_index].as_mut() }; let node = gen_node(rng); parent.append_child(node); - nodes.push(parent.children.last().unwrap().as_ref().into()); + nodes.push(parent.children.last_mut().unwrap().as_mut().into()); } root } -pub fn prepare_tree(rng: &mut StdRng) -> (Node, Vec>) { - let root = gen_node(rng); - let nodes: Vec> = vec![(&root).into()]; +pub fn prepare_tree(rng: &mut StdRng) -> (Box, Vec>) { + let mut root = Box::new(gen_node(rng)); + let nodes: Vec> = vec![(&mut *root).into()]; (root, nodes) } diff --git a/rust/crates/tidy-tree/tests/layout_bench.rs b/rust/crates/tidy-tree/tests/layout_bench.rs index 5cb4c98..9ffd3bc 100644 --- a/rust/crates/tidy-tree/tests/layout_bench.rs +++ b/rust/crates/tidy-tree/tests/layout_bench.rs @@ -3,7 +3,7 @@ mod aesthetic_rules; mod gen; -use std::{time::Instant}; +use std::time::Instant; use rand::{prelude::StdRng, SeedableRng}; use tidy_tree::{BasicLayout, Layout, TidyLayout};