restructure; add challenge 2 solution

I forgot about atomic commits...
This commit is contained in:
raf 2024-12-01 17:09:14 +03:00
commit bfb7d95aa7
Signed by: NotAShelf
GPG key ID: AF26552424E53993
10 changed files with 207 additions and 64 deletions

7
challenges/december-2024/c1/Cargo.lock generated Normal file
View file

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "frzn-challenge"
version = "0.1.0"

View file

@ -0,0 +1,9 @@
[package]
name = "challenge-1"
version = "0.1.0"
edition = "2021"
[dependencies]
geometry = {path = "../../../lib/geometry" }

View 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
);
}
}