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 as_f32 = |x| x as f32 * step;
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 {
(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 {
@ -231,13 +235,11 @@ fn main() {
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] {
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
};
let dx = if initial_state { delta } else { -delta };
while last_tri.intersects(&tri) == initial_state {
tri.0.x += dx;
tri.1.x += dx;