This commit is contained in:
Arne Keller 2019-03-27 19:53:05 +01:00
parent 61abb88938
commit a63749c28b

View File

@ -220,9 +220,13 @@ fn main() {
let step = 40.0; let step = 40.0;
let as_f32 = |x| x as f32 * step; let as_f32 = |x| x as f32 * step;
let range = if target >= 0.0 { let range = if target >= 0.0 {
(0..=((target-0.0001) / step) 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) / step) 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 {
@ -231,13 +235,11 @@ fn main() {
let mut tri = rotate(*next_tri, radians); let mut tri = rotate(*next_tri, radians);
// "binary search"-like optimization here // "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] { 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 initial_state = last_tri.intersects(&tri);
let dx = if initial_state { let dx = if initial_state { delta } else { -delta };
delta
} else {
-delta
};
while last_tri.intersects(&tri) == initial_state { while last_tri.intersects(&tri) == initial_state {
tri.0.x += dx; tri.0.x += dx;
tri.1.x += dx; tri.1.x += dx;
@ -264,7 +266,7 @@ fn main() {
} else if w.width < best.width { } else if w.width < best.width {
w.width -= (2.0 * PI - free_angle - next_angle) * 0.01; 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);
//} //}
new.push(w); new.push(w);
} }