use match statements

This commit is contained in:
raf 2024-12-01 18:06:40 +03:00
parent bfb7d95aa7
commit 0fca39e716
Signed by: NotAShelf
GPG key ID: AF26552424E53993
2 changed files with 9 additions and 24 deletions

View file

@ -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
);
),
}
}

View file

@ -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."),
}
}