Basically the last commit, but better

This commit is contained in:
Arne Keller 2019-04-13 17:07:16 +02:00
parent e5d010ee5d
commit 7e05556e99

View File

@ -197,14 +197,12 @@ fn main() {
let next_tri = *next_tri;
for (idx, &(_base_idx, base_tri)) in w.tris.iter().enumerate() {
let base_tris = &w.tris[0..=idx];
let mut w = w.clone();
let mut neww = w.clone();
let free_angle = right_of(base_tri);
let next_angle = left_of(next_tri);
let target = next_angle - PI + free_angle;
let original_tri = next_tri;
let mut next_tri = rotate(next_tri, target);
if save_counter == 254 {
println!("inserting after {:?} in {:?}", idx, w.tris);
}
if next_tri.0.y < 0.0 || next_tri.1.y < 0.0 || next_tri.2.y < 0.0 {
let miny = min(next_tri.0.y, min(next_tri.1.y, next_tri.2.y));
next_tri.0.y -= miny;
@ -223,19 +221,16 @@ fn main() {
next_tri.2.x += dx;
}
}
w.tris.insert(idx+1, (*next_idx, next_tri));
if save_counter == 254 {
println!("right {:?}", 0);
}
if idx + 1 != w.tris.len() - 1 {
neww.tris.insert(idx+1, (*next_idx, next_tri));
if idx + 1 != neww.tris.len() - 1 {
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 = w.tris[0..=idx+1].iter().any(|(_, x)| w.tris[idx+2..].iter().any(|(_, y)| x.intersects(y)));
let initial_state = neww.tris[0..=idx+1].iter().any(|(_, x)| neww.tris[idx+2..].iter().any(|(_, y)| x.intersects(y)));
let dx = if initial_state { delta } else { -delta };
while w.tris[0..=idx+1].iter().any(|(_, x)| w.tris[idx+2..].iter().any(|(_, y)| x.intersects(y))) == initial_state {
for (_, tri) in &mut w.tris[idx+2..] {
while neww.tris[0..=idx+1].iter().any(|(_, x)| neww.tris[idx+2..].iter().any(|(_, y)| x.intersects(y))) == initial_state {
for (_, tri) in &mut neww.tris[idx+2..] {
tri.0.x += dx;
tri.1.x += dx;
tri.2.x += dx;
@ -243,27 +238,82 @@ fn main() {
}
}
}
w.normalize();
w.calc_width();
neww.normalize();
neww.calc_width();
if save_iterations {
display::save_world(&format!("{}b_{}.svg", save_prefix, save_counter), &w);
display::save_world(&format!("{}b_{}.svg", save_prefix, save_counter), &neww);
}
if w.tris.len() == count_tris {
if w.width < best.width {
println!("[{}] new best: {}", save_counter, w.width);
if neww.tris.len() == count_tris {
if neww.width < best.width {
println!("[{}] new best: {}", save_counter, neww.width);
//println!("{:?}", w.tris);
display::save_world(
&format!("{}best_{}.svg", save_prefix, save_counter),
&w,
&neww,
);
best = w;
best = neww;
}
} else if w.width < best.width {
} else if neww.width < best.width {
//w.width -= (2.0 * PI - free_angle - next_angle) * 0.01;
//if (angle > 50 && angle < 55) || (angle > 88 && angle < 92) {
//println!("{:?} -> {:?}", angle, w.width);
//}
new.push(w);
new.push(neww);
}
save_counter += 1;
let mut neww = w.clone();
let mut next_tri = original_tri;
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 = base_tris.iter().any(|(_, x)| x.intersects(&next_tri));
let dx = if initial_state { delta } else { -delta };
while base_tris.iter().any(|(_, x)| x.intersects(&next_tri)) == initial_state {
next_tri.0.x += dx;
next_tri.1.x += dx;
next_tri.2.x += dx;
}
}
neww.tris.insert(idx+1, (*next_idx, next_tri));
if idx + 1 != neww.tris.len() - 1 {
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 = neww.tris[0..=idx+1].iter().any(|(_, x)| neww.tris[idx+2..].iter().any(|(_, y)| x.intersects(y)));
let dx = if initial_state { delta } else { -delta };
while neww.tris[0..=idx+1].iter().any(|(_, x)| neww.tris[idx+2..].iter().any(|(_, y)| x.intersects(y))) == initial_state {
for (_, tri) in &mut neww.tris[idx+2..] {
tri.0.x += dx;
tri.1.x += dx;
tri.2.x += dx;
}
}
}
}
neww.normalize();
neww.calc_width();
if save_iterations {
display::save_world(&format!("{}b_{}.svg", save_prefix, save_counter), &neww);
}
if neww.tris.len() == count_tris {
if neww.width < best.width {
println!("[{}] new best: {}", save_counter, neww.width);
//println!("{:?}", w.tris);
display::save_world(
&format!("{}best_{}.svg", save_prefix, save_counter),
&neww,
);
best = neww;
}
} else if neww.width < best.width {
//w.width -= (2.0 * PI - free_angle - next_angle) * 0.01;
//if (angle > 50 && angle < 55) || (angle > 88 && angle < 92) {
//println!("{:?} -> {:?}", angle, w.width);
//}
new.push(neww);
}
save_counter += 1;