Impl square for 3.1

cat-town
Dan Buch 8 years ago
parent af11c29d9c
commit d548740ed0
No known key found for this signature in database
GPG Key ID: FAEF12936DD3E3EC

@ -22,6 +22,13 @@ fn rect_area(rect: Rectangle) -> f32 {
((x1 - x2) * (y1 - y2)).abs()
}
fn square(point: Point, dim: f32) -> Rectangle {
Rectangle {
p1: Point { x: point.x, y: point.y },
p2: Point { x: point.x + dim, y: point.y + dim },
}
}
fn main() {
let point: Point = Point { x: 0.3, y: 0.4 };
@ -31,7 +38,7 @@ fn main() {
let _rectangle = Rectangle {
p1: Point { x: my_y, y: my_x },
p2: point,
p2: Point { x: point.x, y: point.y },
};
let _nil = Nil;
@ -46,4 +53,12 @@ fn main() {
println!("rect is {:?}", _rectangle);
println!("rect area is {}", rect_area(_rectangle));
let dim = 9.1f32;
println!("point is {:?}", point);
println!("dim is {:?}", dim);
let sq = square(point, dim);
println!("square is {:?}", sq);
println!("square area is {}", rect_area(sq));
}

Loading…
Cancel
Save