#[allow(dead_code)]
#[derive(Debug)]
struct Person {
    name: String,
    age: u8,
}

struct Unit;

struct Pair(i32, f32);

#[derive(Debug)]
struct Point {
    x: f32,
    y: f32,
}

#[derive(Debug)]
struct Rectangle {
    top_left: Point,
    bottom_right: Point,
}

fn rect_area(r: Rectangle) -> f32 {
    (r.top_left.x - r.bottom_right.x) * (r.top_left.y - r.bottom_right.y)
}

fn square(p: &Point, d: f32) -> Rectangle {
    Rectangle {
        top_left: Point { x: p.x + d, y: p.y },
        bottom_right: Point { x: p.x, y: p.y + d },
    }
}

fn main() {
    let name = String::from("Peter");
    let age = 27;
    let peter = Person { name, age };

    println!("{:?}", peter);

    let point: Point = Point { x: 10.3, y: 0.4 };

    println!("point coordinates: ({}, {})", point.x, point.y);

    let bottom_right = Point { x: 5.2, y: 0.2 };

    println!("second point: ({}, {})", bottom_right.x, bottom_right.y);

    let Point {
        x: left_edge,
        y: top_edge,
    } = point;

    let rect = Rectangle {
        top_left: Point {
            x: left_edge,
            y: top_edge,
        },
        bottom_right: bottom_right,
    };

    let _unit = Unit;

    let pair = Pair(1, 0.1);

    println!("pair contains {:?} and {:?}", pair.0, pair.1);

    let Pair(integer, decimal) = pair;

    println!("pair contains {:?} and {:?}", integer, decimal);

    println!("rect in {:?}", rect);
    println!("area of rect is {}", rect_area(rect));

    let lower_left = Point { x: 4.1, y: 11.3 };
    let d = 7.7f32;
    let sq = square(&lower_left, d);
    println!("sq from point={:?} of d={} is {:?}", lower_left, d, sq);
}
