use match statements
This commit is contained in:
parent
bfb7d95aa7
commit
0fca39e716
2 changed files with 9 additions and 24 deletions
|
@ -13,16 +13,14 @@ fn main() {
|
|||
let test_point = read_point("Enter the coordinates for the point to test (x y):");
|
||||
|
||||
// Finally, check if the point is inside the triangle.
|
||||
// TODO: make this a match
|
||||
if triangle.contains_point(&test_point) {
|
||||
println!(
|
||||
match triangle.contains_point(&test_point) {
|
||||
true => println!(
|
||||
"The point ({}, {}) lies inside the triangle.",
|
||||
test_point.x, test_point.y
|
||||
);
|
||||
} else {
|
||||
println!(
|
||||
),
|
||||
false => println!(
|
||||
"The point ({}, {}) lies outside the triangle.",
|
||||
test_point.x, test_point.y
|
||||
);
|
||||
),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +1,11 @@
|
|||
use geometry::{read_point, Triangle};
|
||||
|
||||
fn read_triangle(name: &str) -> Triangle {
|
||||
println!(
|
||||
"Enter the coordinates for the three vertices of triangle {}:",
|
||||
name
|
||||
);
|
||||
let p1 = read_point("First vertex (x y):");
|
||||
let p2 = read_point("Second vertex (x y):");
|
||||
let p3 = read_point("Third vertex (x y):");
|
||||
|
||||
Triangle { p1, p2, p3 }
|
||||
}
|
||||
use geometry::read_triangle;
|
||||
|
||||
fn main() {
|
||||
let triangle1 = read_triangle("1");
|
||||
let triangle2 = read_triangle("2");
|
||||
|
||||
if triangle1.overlaps(&triangle2) {
|
||||
println!("The two triangles overlap.");
|
||||
} else {
|
||||
println!("The two triangles do not overlap.");
|
||||
match triangle1.overlaps(&triangle2) {
|
||||
true => println!("The two triangles overlap."),
|
||||
false => println!("The two triangles do not overlap."),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue