Try to work on all triangle collection lengths at the same time

This commit is contained in:
Arne Keller 2019-03-28 22:17:46 +01:00
parent a63749c28b
commit 14cfe1db97

View File

@ -167,12 +167,24 @@ fn main() {
let save_prefix = "world_";
save_counter = 0;
let mut counter = 0;
while worlds.peek().map(|x| x.width <= best.width) == Some(true) {
let mut bins = Vec::new();
bins.push(worlds);
let mut progress = true;
while progress {
progress = false;
for bin_idx in 0..bins.len() {
counter += 1;
if counter % 10000 == 0 {
println!("{}/∞", counter);
}
let w = worlds.pop().unwrap();
if bins[bin_idx].is_empty() {
continue;
}
let w = bins[bin_idx].pop().unwrap();
//println!("working");
if w.width >= best.width {
continue;
}
//println!("s: {:?}", w);
/*
@ -198,8 +210,10 @@ fn main() {
} else if vertex2.y > 0.001 && vertex1.y < 0.001 {
PI - (vertex2.y / (vertex2.x - vertex1.x).abs()).atan()
} else {
let angle1 = 0.5 * PI - vertex1.x.signum() * (vertex1.x.abs() / vertex1.y).atan();
let angle2 = 0.5 * PI - vertex2.x.signum() * (vertex2.x.abs() / vertex2.y).atan();
let angle1 =
0.5 * PI - vertex1.x.signum() * (vertex1.x.abs() / vertex1.y).atan();
let angle2 =
0.5 * PI - vertex2.x.signum() * (vertex2.x.abs() / vertex2.y).atan();
min(angle1, angle2)
};
@ -207,8 +221,10 @@ fn main() {
let vertex2 = next_tri.2;
let next_angle = if vertex1.y > 0.001 && vertex2.y > 0.001 {
let angle1 = 0.5 * PI + vertex1.x.signum() * (vertex1.x.abs() / vertex1.y).atan();
let angle2 = 0.5 * PI + vertex2.x.signum() * (vertex2.x.abs() / vertex2.y).atan();
let angle1 =
0.5 * PI + vertex1.x.signum() * (vertex1.x.abs() / vertex1.y).atan();
let angle2 =
0.5 * PI + vertex2.x.signum() * (vertex2.x.abs() / vertex2.y).atan();
min(angle1, angle2)
} else if vertex1.y < 0.001 {
0.5 * PI + vertex2.x.signum() * (vertex2.x.abs() / vertex2.y).atan()
@ -230,13 +246,15 @@ fn main() {
};
for angle in range {
//println!("angle {:?}", angle);
let radians = angle.to_radians();
let next_angle = next_angle - radians;
let mut tri = rotate(*next_tri, radians);
// "binary search"-like optimization here
for &delta in &[
80.0, 30.0, 10.0, 5.0, 1.0, 0.6, 0.32, 0.18, 0.1, 0.06, 0.03, 0.01, 0.003,
/*80.0, 30.0, 10.0, 5.0,*/ 1.0, 0.6, 0.32, 0.18, 0.1, 0.06, 0.03,
0.01, 0.003,
] {
let initial_state = last_tri.intersects(&tri);
let dx = if initial_state { delta } else { -delta };
@ -273,7 +291,15 @@ fn main() {
save_counter += 1;
}
}
worlds.extend(new);
progress = true;
if bin_idx + 1 == bins.len() {
let mut new_bin = BinaryHeap::new();
new_bin.extend(new);
bins.push(new_bin);
} else {
bins[bin_idx + 1].extend(new);
}
}
}
println!("best width = {:?}", best.width);
display::save_world("world_best.svg", &best);