From f28b29841a5a9041454fa7e1d24c601eb3d20dbd Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sun, 1 Dec 2024 18:07:05 +0300 Subject: [PATCH] lib: generic `read_triangle` function --- lib/geometry/src/lib.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/geometry/src/lib.rs b/lib/geometry/src/lib.rs index 8c17586..745d165 100644 --- a/lib/geometry/src/lib.rs +++ b/lib/geometry/src/lib.rs @@ -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 } +}