Various changes

This commit is contained in:
Arne Keller 2019-03-27 19:52:46 +01:00
parent 78fc841e6a
commit 61abb88938
2 changed files with 34 additions and 20 deletions

View File

@ -28,7 +28,7 @@ pub(crate) fn save_world(filename: &str, world: &World) {
pub(crate) fn generate_svg(tris: &[Triangle<f32>]) -> String { pub(crate) fn generate_svg(tris: &[Triangle<f32>]) -> String {
let mut document = Document::new() let mut document = Document::new()
// view box at (x,y), (w,h) // view box at (x,y), (w,h)
.set("viewBox", (-30.0, -30.0, 60.0, 30.0)) .set("viewBox", (-350.0, -150.0, 360.0, 150.0))
.set("xmlns:xlink", "http://www.w3.org/1999/xlink"); .set("xmlns:xlink", "http://www.w3.org/1999/xlink");
for tri in tris { for tri in tris {

View File

@ -148,7 +148,7 @@ fn main() {
let save_prefix = "start_"; let save_prefix = "start_";
save_counter = 0; save_counter = 0;
let mut worlds = BinaryHeap::new(); let mut worlds = BinaryHeap::new();
let left_tris = vec![left_tris[1], left_tris[11], left_tris[17], left_tris[23], left_tris[28]]; //let left_tris = vec![left_tris[1], left_tris[11], left_tris[17], left_tris[22], left_tris[28]];
for t in &left_tris { for t in &left_tris {
let mut world = World { let mut world = World {
tris: vec![*t], tris: vec![*t],
@ -166,12 +166,21 @@ fn main() {
}; };
let save_prefix = "world_"; let save_prefix = "world_";
save_counter = 0; save_counter = 0;
let mut counter = 0;
while worlds.peek().map(|x| x.width <= best.width) == Some(true) { while worlds.peek().map(|x| x.width <= best.width) == Some(true) {
counter += 1;
if counter % 10000 == 0 {
println!("{}/∞", counter);
}
let w = worlds.pop().unwrap(); let w = worlds.pop().unwrap();
//println!("s: {:?}", w); //println!("s: {:?}", w);
/*
if save_counter < 1000000 {
display::save_world(&format!("{}a_{}.svg", save_prefix, save_counter), &w); display::save_world(&format!("{}a_{}.svg", save_prefix, save_counter), &w);
let save_iterations = save_counter == 713; }
*/
let save_iterations = false;
let mut new = vec![]; let mut new = vec![];
for (next_idx, next_tri) in left_tris for (next_idx, next_tri) in left_tris
@ -207,12 +216,13 @@ fn main() {
0.5 * PI + vertex1.x.signum() * (vertex1.x.abs() / vertex1.y).atan() 0.5 * PI + vertex1.x.signum() * (vertex1.x.abs() / vertex1.y).atan()
}; };
//println!("{:?} -> {:?}: {:?} {:?}", last_idx, next_idx, free_angle.to_degrees(), next_angle.to_degrees()); //println!("{:?} -> {:?}: {:?} {:?}", last_idx, next_idx, free_angle.to_degrees(), next_angle.to_degrees());
let target = next_angle - PI + free_angle; let target = (next_angle - PI + free_angle).to_degrees();
let as_f32 = |x| x as f32; let step = 40.0;
let as_f32 = |x| x as f32 * step;
let range = if target >= 0.0 { let range = if target >= 0.0 {
(0..=(target-0.0001).to_degrees() as usize).map(as_f32).chain(Some(target)) (0..=((target-0.0001) / step) as usize).map(as_f32).chain(Some(target))
} else { } else {
(0..=(next_angle-0.0001).to_degrees() as usize).map(as_f32).chain(None) (0..=((next_angle-0.0001) / step) as usize).map(as_f32).chain(None)
}; };
for angle in range { for angle in range {
@ -220,16 +230,20 @@ fn main() {
let next_angle = next_angle - radians; let next_angle = next_angle - radians;
let mut tri = rotate(*next_tri, radians); let mut tri = rotate(*next_tri, radians);
let dx = if last_tri.intersects(&tri) { // "binary search"-like optimization here
0.005 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] {
let initial_state = last_tri.intersects(&tri);
let dx = if initial_state {
delta
} else { } else {
-0.005 -delta
}; };
while last_tri.intersects(&tri) { while last_tri.intersects(&tri) == initial_state {
tri.0.x += dx; tri.0.x += dx;
tri.1.x += dx; tri.1.x += dx;
tri.2.x += dx; tri.2.x += dx;
} }
}
let mut w = w.clone(); let mut w = w.clone();
w.tris.push((*next_idx, tri)); w.tris.push((*next_idx, tri));
w.normalize(); w.normalize();
@ -240,15 +254,15 @@ fn main() {
if w.tris.len() == count_tris { if w.tris.len() == count_tris {
if w.width < best.width { if w.width < best.width {
println!("[{}] new best: {}", save_counter, w.width); println!("[{}] new best: {}", save_counter, w.width);
println!("{:?}", w.tris); //println!("{:?}", w.tris);
display::save_world( display::save_world(
&format!("{}best_{}.svg", save_prefix, save_counter), &format!("{}best_{}.svg", save_prefix, save_counter),
&w, &w,
); );
best = w; best = w;
} }
} else { } else if w.width < best.width {
w.width -= (2.0 * PI - free_angle - next_angle) * 0.003 * w.tris.len() as f32; w.width -= (2.0 * PI - free_angle - next_angle) * 0.01;
//if (angle > 50 && angle < 55) || (angle > 88 && angle < 92) { //if (angle > 50 && angle < 55) || (angle > 88 && angle < 92) {
//println!("{:?} -> {:?}", angle, w.width); //println!("{:?} -> {:?}", angle, w.width);
//} //}