Compare commits
No commits in common. "474d648ae4139cd6726bd9bdc0c0b45858aa6dc3" and "b982f2c1cc03dd4496f37fe107cb16f1f30c1010" have entirely different histories.
474d648ae4
...
b982f2c1cc
|
@ -307,13 +307,11 @@ impl<T> Tree<T> {
|
||||||
//
|
//
|
||||||
// indent represents the indentation that should be applied to all children in this tree. It
|
// indent represents the indentation that should be applied to all children in this tree. It
|
||||||
// amounts to the position of the parent node.
|
// amounts to the position of the parent node.
|
||||||
//
|
pub fn position(&self, indent: usize, idx: usize) -> (usize, usize) {
|
||||||
// When drawing nodes, I don't know how to persist the level of indent.
|
println!("[{}]", idx);
|
||||||
pub fn position(&self, idx: usize) -> (usize, usize) {
|
|
||||||
let node = &self.nodes[idx];
|
let node = &self.nodes[idx];
|
||||||
match node.parent {
|
match node.parent {
|
||||||
Some(parent_idx) => {
|
Some(parent_idx) => {
|
||||||
let (_parent_row, parent_column) = self.position(parent_idx);
|
|
||||||
let parent = &self.nodes[parent_idx];
|
let parent = &self.nodes[parent_idx];
|
||||||
let sibling_width = parent
|
let sibling_width = parent
|
||||||
.children
|
.children
|
||||||
|
@ -321,7 +319,7 @@ impl<T> Tree<T> {
|
||||||
.take_while(|n| **n != node.id)
|
.take_while(|n| **n != node.id)
|
||||||
.fold(0, |acc, n| acc + self.width(*n));
|
.fold(0, |acc, n| acc + self.width(*n));
|
||||||
println!("[{}] sibling width {}", idx, sibling_width);
|
println!("[{}] sibling width {}", idx, sibling_width);
|
||||||
(node.depth, parent_column + sibling_width)
|
(node.depth, indent + sibling_width)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Root nodes won't have a parent, so just put them in the first column
|
// Root nodes won't have a parent, so just put them in the first column
|
||||||
|
@ -540,13 +538,13 @@ mod test {
|
||||||
|
|
||||||
let tree = Tree::from(&game_tree);
|
let tree = Tree::from(&game_tree);
|
||||||
|
|
||||||
assert_eq!(tree.position(2), (2, 0));
|
assert_eq!(tree.position(0, 2), (2, 0));
|
||||||
assert_eq!(tree.position(1), (1, 0));
|
assert_eq!(tree.position(0, 1), (1, 0));
|
||||||
assert_eq!(tree.position(0), (0, 0));
|
assert_eq!(tree.position(0, 0), (0, 0));
|
||||||
assert_eq!(tree.position(4), (3, 1));
|
assert_eq!(tree.position(0, 4), (3, 1));
|
||||||
assert_eq!(tree.position(5), (3, 2));
|
assert_eq!(tree.position(0, 5), (3, 2));
|
||||||
assert_eq!(tree.position(6), (1, 3));
|
assert_eq!(tree.position(0, 6), (1, 3));
|
||||||
assert_eq!(tree.position(7), (1, 4));
|
assert_eq!(tree.position(0, 7), (1, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -77,7 +77,7 @@ impl ReviewTree {
|
||||||
// the parent? do I need to just make it more intrinsically a part of the position
|
// the parent? do I need to just make it more intrinsically a part of the position
|
||||||
// code?
|
// code?
|
||||||
ctx.set_source_rgb(0.7, 0.7, 0.7);
|
ctx.set_source_rgb(0.7, 0.7, 0.7);
|
||||||
let (row, column) = tree.position(node.id);
|
let (row, column) = tree.position(0, node.id);
|
||||||
println!("[{}] {} x {}", node.id, row, column);
|
println!("[{}] {} x {}", node.id, row, column);
|
||||||
let y = (row as f64) * 20. + 10.;
|
let y = (row as f64) * 20. + 10.;
|
||||||
let x = (column as f64) * 20. + 10.;
|
let x = (column as f64) * 20. + 10.;
|
||||||
|
|
|
@ -911,40 +911,4 @@ mod file_test {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[ignore]
|
|
||||||
#[test]
|
|
||||||
fn it_handles_shuwa_genan_file() {
|
|
||||||
with_file(
|
|
||||||
std::path::Path::new("test_data/2019.02.15_shuwa_genan_annotated.sgf"),
|
|
||||||
|trees| {
|
|
||||||
assert_eq!(trees.len(), 1);
|
|
||||||
let game = &trees[0];
|
|
||||||
assert_eq!(game.game_type, GameType::Go);
|
|
||||||
assert_eq!(
|
|
||||||
game.board_size,
|
|
||||||
Size {
|
|
||||||
width: 19,
|
|
||||||
height: 19
|
|
||||||
}
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
game.black_player,
|
|
||||||
Player {
|
|
||||||
name: Some("Honinbo Shuwa".to_owned()),
|
|
||||||
rank: Some("7P".to_owned()),
|
|
||||||
team: None
|
|
||||||
}
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
game.white_player,
|
|
||||||
Player {
|
|
||||||
name: Some("Inoue(Genan)Inseki".to_owned()),
|
|
||||||
rank: Some("8P".to_owned()),
|
|
||||||
team: None
|
|
||||||
}
|
|
||||||
);
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -463,15 +463,4 @@ mod tests {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is a file
|
|
||||||
#[test]
|
|
||||||
fn it_handles_shuwa_genan_file() {
|
|
||||||
with_file(
|
|
||||||
std::path::Path::new("test_data/2020 USGO DDK, Round 1.sgf"),
|
|
||||||
|trees| {
|
|
||||||
assert_eq!(trees.len(), 2);
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1252,15 +1252,6 @@ mod date_test {
|
||||||
Date::Date(NaiveDate::from_ymd_opt(1996, 12, 28).unwrap())
|
Date::Date(NaiveDate::from_ymd_opt(1996, 12, 28).unwrap())
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_matches!(
|
|
||||||
parse_date_field::<nom::error::VerboseError<&str>>().parse("1842-5-16-18"),
|
|
||||||
Ok((_, date)) => assert_eq!(date, vec![
|
|
||||||
Date::Date(NaiveDate::from_ymd_opt(1842, 5, 16).unwrap()),
|
|
||||||
Date::Date(NaiveDate::from_ymd_opt(1842, 5, 17).unwrap()),
|
|
||||||
Date::Date(NaiveDate::from_ymd_opt(1842, 5, 18).unwrap()),
|
|
||||||
])
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in New Issue