Various changes
This commit is contained in:
parent
78fc841e6a
commit
61abb88938
@ -28,7 +28,7 @@ pub(crate) fn save_world(filename: &str, world: &World) {
|
||||
pub(crate) fn generate_svg(tris: &[Triangle<f32>]) -> String {
|
||||
let mut document = Document::new()
|
||||
// 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");
|
||||
|
||||
for tri in tris {
|
||||
|
52
src/main.rs
52
src/main.rs
@ -148,7 +148,7 @@ fn main() {
|
||||
let save_prefix = "start_";
|
||||
save_counter = 0;
|
||||
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 {
|
||||
let mut world = World {
|
||||
tris: vec![*t],
|
||||
@ -166,12 +166,21 @@ fn main() {
|
||||
};
|
||||
let save_prefix = "world_";
|
||||
save_counter = 0;
|
||||
let mut counter = 0;
|
||||
while worlds.peek().map(|x| x.width <= best.width) == Some(true) {
|
||||
counter += 1;
|
||||
if counter % 10000 == 0 {
|
||||
println!("{}/∞", counter);
|
||||
}
|
||||
let w = worlds.pop().unwrap();
|
||||
//println!("s: {:?}", w);
|
||||
|
||||
display::save_world(&format!("{}a_{}.svg", save_prefix, save_counter), &w);
|
||||
let save_iterations = save_counter == 713;
|
||||
/*
|
||||
if save_counter < 1000000 {
|
||||
display::save_world(&format!("{}a_{}.svg", save_prefix, save_counter), &w);
|
||||
}
|
||||
*/
|
||||
let save_iterations = false;
|
||||
|
||||
let mut new = vec![];
|
||||
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()
|
||||
};
|
||||
//println!("{:?} -> {:?}: {:?} {:?}", last_idx, next_idx, free_angle.to_degrees(), next_angle.to_degrees());
|
||||
let target = next_angle - PI + free_angle;
|
||||
let as_f32 = |x| x as f32;
|
||||
let target = (next_angle - PI + free_angle).to_degrees();
|
||||
let step = 40.0;
|
||||
let as_f32 = |x| x as f32 * step;
|
||||
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 {
|
||||
(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 {
|
||||
@ -220,15 +230,19 @@ fn main() {
|
||||
let next_angle = next_angle - radians;
|
||||
let mut tri = rotate(*next_tri, radians);
|
||||
|
||||
let dx = if last_tri.intersects(&tri) {
|
||||
0.005
|
||||
} else {
|
||||
-0.005
|
||||
};
|
||||
while last_tri.intersects(&tri) {
|
||||
tri.0.x += dx;
|
||||
tri.1.x += dx;
|
||||
tri.2.x += dx;
|
||||
// "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] {
|
||||
let initial_state = last_tri.intersects(&tri);
|
||||
let dx = if initial_state {
|
||||
delta
|
||||
} else {
|
||||
-delta
|
||||
};
|
||||
while last_tri.intersects(&tri) == initial_state {
|
||||
tri.0.x += dx;
|
||||
tri.1.x += dx;
|
||||
tri.2.x += dx;
|
||||
}
|
||||
}
|
||||
let mut w = w.clone();
|
||||
w.tris.push((*next_idx, tri));
|
||||
@ -240,15 +254,15 @@ fn main() {
|
||||
if w.tris.len() == count_tris {
|
||||
if w.width < best.width {
|
||||
println!("[{}] new best: {}", save_counter, w.width);
|
||||
println!("{:?}", w.tris);
|
||||
//println!("{:?}", w.tris);
|
||||
display::save_world(
|
||||
&format!("{}best_{}.svg", save_prefix, save_counter),
|
||||
&w,
|
||||
);
|
||||
best = w;
|
||||
}
|
||||
} else {
|
||||
w.width -= (2.0 * PI - free_angle - next_angle) * 0.003 * w.tris.len() as f32;
|
||||
} else if w.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);
|
||||
//}
|
||||
|
Loading…
Reference in New Issue
Block a user