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):");
|
let test_point = read_point("Enter the coordinates for the point to test (x y):");
|
||||||
|
|
||||||
// Finally, check if the point is inside the triangle.
|
// Finally, check if the point is inside the triangle.
|
||||||
// TODO: make this a match
|
match triangle.contains_point(&test_point) {
|
||||||
if triangle.contains_point(&test_point) {
|
true => println!(
|
||||||
println!(
|
|
||||||
"The point ({}, {}) lies inside the triangle.",
|
"The point ({}, {}) lies inside the triangle.",
|
||||||
test_point.x, test_point.y
|
test_point.x, test_point.y
|
||||||
);
|
),
|
||||||
} else {
|
false => println!(
|
||||||
println!(
|
|
||||||
"The point ({}, {}) lies outside the triangle.",
|
"The point ({}, {}) lies outside the triangle.",
|
||||||
test_point.x, test_point.y
|
test_point.x, test_point.y
|
||||||
);
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,11 @@
|
||||||
use geometry::{read_point, Triangle};
|
use geometry::read_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 }
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let triangle1 = read_triangle("1");
|
let triangle1 = read_triangle("1");
|
||||||
let triangle2 = read_triangle("2");
|
let triangle2 = read_triangle("2");
|
||||||
|
|
||||||
if triangle1.overlaps(&triangle2) {
|
match triangle1.overlaps(&triangle2) {
|
||||||
println!("The two triangles overlap.");
|
true => println!("The two triangles overlap."),
|
||||||
} else {
|
false => println!("The two triangles do not overlap."),
|
||||||
println!("The two triangles do not overlap.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue