Skip to content

Commit

Permalink
refactor: simplify contour logic
Browse files Browse the repository at this point in the history
  • Loading branch information
zxch3n committed Jun 7, 2022
1 parent c519b35 commit 8a0c53c
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions rust/crates/tidy-tree/src/layout/tidy_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl Contour {
Contour {
is_left,
current: Some(current.into()),
modifier_sum: 0.,
modifier_sum: current.tidy().modifier_to_subtree,
}
}

Expand All @@ -52,13 +52,13 @@ impl Contour {
pub fn left(&self) -> Coord {
let node = self.node();
assert_eq!(node.tidy().test, TEST);
self.modifier_sum + node.relative_x + node.tidy().modifier_to_subtree - node.width / 2.
self.modifier_sum + node.relative_x - node.width / 2.
}

pub fn right(&self) -> Coord {
let node = self.node();
assert_eq!(node.tidy().test, TEST);
self.modifier_sum + node.relative_x + node.tidy().modifier_to_subtree + node.width / 2.
self.modifier_sum + node.relative_x + node.width / 2.
}

pub fn bottom(&self) -> Coord {
Expand All @@ -74,18 +74,21 @@ impl Contour {
pub fn next(&mut self) {
if let Some(mut current) = self.current {
let node = unsafe { current.as_mut() };
self.modifier_sum += node.tidy.as_ref().unwrap().modifier_to_subtree;
assert_eq!(node.tidy().test, TEST);
if self.is_left {
if node.children.len() > 0 {
self.current = Some((&**node.children.first().unwrap()).into());
let node = self.node();
self.modifier_sum += node.tidy.as_ref().unwrap().modifier_to_subtree;
} else {
self.modifier_sum += node.tidy().modifier_thread_left;
self.current = node.tidy().thread_left;
}
} else {
if node.children.len() > 0 {
self.current = Some((&**node.children.last().unwrap()).into());
let node = self.node();
self.modifier_sum += node.tidy.as_ref().unwrap().modifier_to_subtree;
} else {
self.modifier_sum += node.tidy().modifier_thread_right;
self.current = node.tidy().thread_right;
Expand Down Expand Up @@ -182,10 +185,7 @@ impl TidyLayout {
let dist = left.right() - right.left() + self.peer_margin;
if dist > 0. {
// left and right are too close. move right part with distance of dist
let ptr: *const _ = &*node.children[child_index];
if ptr != &*right.node() {
right.modifier_sum += dist;
}
right.modifier_sum += dist;
self.move_subtree(node, child_index, y_list.index, dist);
}

Expand Down

0 comments on commit 8a0c53c

Please sign in to comment.