use rtchallenge::tuples::Tuple;

#[derive(Debug)]
struct Environment {
    gravity: Tuple,
    wind: Tuple,
}
#[derive(Debug)]
struct Projectile {
    position: Tuple,
    velocity: Tuple,
}

fn tick(env: &Environment, proj: &Projectile) -> Projectile {
    let position = proj.position + proj.velocity;
    let velocity = proj.velocity + env.gravity + env.wind;
    Projectile { position, velocity }
}
fn main() {
    let mut p = Projectile {
        position: Tuple::point(0., 1., 0.),
        velocity: 4. * Tuple::vector(1., 1., 0.).normalize(),
    };
    let e = Environment {
        gravity: Tuple::vector(0., -0.1, 0.).normalize(),
        wind: Tuple::vector(-0.01, 0., 0.),
    };

    let mut i = 0;
    while p.position.y > 0. {
        p = tick(&e, &p);
        println!("tick {}: position {:?}", i, p.position);
        i += 1;
        if i > 100 {
            eprintln!("too many iterations");
            return;
        }
    }
}
