generated from zxch3n/ts-rust-template
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
137 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,3 @@ tinyset = "0.4.10" | |
[dev-dependencies] | ||
rand = "0.8.5" | ||
|
||
[profile.bench] | ||
opt-level = 3 | ||
overflow-checks = false | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use std::ptr::NonNull; | ||
|
||
use rand::prelude::*; | ||
use tidy_tree::{geometry::Coord, Node}; | ||
|
||
pub fn gen_node(rng: &mut StdRng) -> Node { | ||
Node { | ||
id: rng.gen(), | ||
width: rng.gen_range(5..50) as Coord, | ||
height: rng.gen_range(5..50) as Coord, | ||
x: 0., | ||
y: 0., | ||
relative_x: 0., | ||
relative_y: 0., | ||
bbox: Default::default(), | ||
parent: None, | ||
children: vec![], | ||
tidy: None, | ||
} | ||
} | ||
|
||
pub fn gen_tree(rng: &mut StdRng, num: usize) -> Node { | ||
let root = gen_node(rng); | ||
let mut nodes: Vec<NonNull<Node>> = vec![(&root).into()]; | ||
let max_chosen_size = 100; | ||
for _ in 0..num { | ||
let parent_index = if nodes.len() < max_chosen_size { | ||
rng.gen_range(0..nodes.len()) | ||
} else { | ||
rng.gen_range((nodes.len() - max_chosen_size)..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()); | ||
} | ||
|
||
root | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use rand::{prelude::StdRng, SeedableRng}; | ||
use tidy_tree::{BasicLayout, Layout, TidyLayout}; | ||
mod gen; | ||
|
||
// #[test] | ||
// fn tidy() { | ||
// let mut rng = StdRng::seed_from_u64(1001); | ||
// let mut tree = gen::gen_tree(&mut rng, 100_000); | ||
// let layout = TidyLayout { | ||
// parent_child_margin: 10., | ||
// peer_margin: 10., | ||
// }; | ||
|
||
// for _ in 0..10 { | ||
// layout.layout(&mut tree); | ||
// } | ||
// } | ||
|
||
#[test] | ||
fn basic() { | ||
let mut rng = StdRng::seed_from_u64(1001); | ||
let mut tree = gen::gen_tree(&mut rng, 100_000); | ||
let layout = BasicLayout { | ||
parent_child_margin: 10., | ||
peer_margin: 10., | ||
}; | ||
|
||
for _ in 0..1000 { | ||
layout.layout(&mut tree); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters