restructure; add challenge 2 solution
I forgot about atomic commits...
This commit is contained in:
parent
85a7ee0b8e
commit
bfb7d95aa7
10 changed files with 207 additions and 64 deletions
28
challenges/december-2024/c1/src/main.rs
Normal file
28
challenges/december-2024/c1/src/main.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
use geometry::{read_point, Triangle};
|
||||
fn main() {
|
||||
// Read the vertices of the triangle we are calculating the area for.
|
||||
let p1 = read_point("Enter the coordinates for the first vertex of the triangle (x y):");
|
||||
let p2 = read_point("Enter the coordinates for the second vertex of the triangle (x y):");
|
||||
let p3 = read_point("Enter the coordinates for the third vertex of the triangle (x y):");
|
||||
|
||||
// 'Draw' the triangle.
|
||||
let triangle = Triangle { p1, p2, p3 };
|
||||
|
||||
// Read the point we want to test from user input.
|
||||
// TODO: maybe some kind of input validation/loop would be nice
|
||||
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!(
|
||||
"The point ({}, {}) lies inside the triangle.",
|
||||
test_point.x, test_point.y
|
||||
);
|
||||
} else {
|
||||
println!(
|
||||
"The point ({}, {}) lies outside the triangle.",
|
||||
test_point.x, test_point.y
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue