lib: generic read_triangle function

This commit is contained in:
raf 2024-12-01 18:07:05 +03:00
parent 0fca39e716
commit f28b29841a
Signed by: NotAShelf
GPG key ID: AF26552424E53993

View file

@ -99,3 +99,17 @@ pub fn read_point(prompt: &str) -> Point {
y: coords[1],
}
}
// Reads the coordinates of the vertices for a triangle
// and constructs a `triangle` object
pub 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 }
}