Some cleanup

This commit is contained in:
Stephan Rehfeld 2026-05-13 17:55:28 +02:00
parent 09ff36dff8
commit 5b4c205234
2 changed files with 5 additions and 41 deletions

View File

@ -72,6 +72,10 @@ impl Point3 {
pub fn new(x: f64, y: f64, z: f64) -> Point3 { pub fn new(x: f64, y: f64, z: f64) -> Point3 {
Point3 { x, y, z } Point3 { x, y, z }
} }
pub fn get_x(&self) -> f64 {
self.x
}
} }
impl Add<Vector3> for Point3 { impl Add<Vector3> for Point3 {

View File

@ -1,45 +1,5 @@
use hello::*; use hello::*;
fn main() { fn main() {
let sphere1 = Sphere::new(Point3::new(0.0, 0.0, 0.0), 25.0); let p = Point3::new(0.0, 0.0, 0.0);
let sphere2 = Sphere::new(Point3::new(1.0, -45.4, 3.55), 2.0);
let sphere3 = Sphere::new(Point3::new(3.0, 2.0, 1.0), 0.5);
let plane1 = Plane::new(Point3::new(1.0, 2.0, 3.0), Vector3::new(0.0, 1.0, 0.0));
let mut v = Vec::new();
v.push(Geometry::Sphere(sphere1));
v.push(Geometry::Plane(plane1));
v.push(Geometry::Sphere(sphere2));
v.push(Geometry::Sphere(sphere3));
for geo in v {
match geo {
Geometry::Sphere(s) => println!("A Sphere"),
Geometry::Plane(p) => println!("A Plane"),
Geometry::Line(l) => println!("A Line"),
}
}
let mut lottery = [4, 8, 15, 16, 23, 42];
let mut sum = 0;
for value in lottery {
sum += value;
}
println!("The sum is {}", sum);
let mut lottery_string = Vec::new();
for value in lottery {
lottery_string.push(value.to_string());
}
let lottery_string_2: Vec<String> = lottery
.iter()
.filter(|x| **x > 8)
.map(|x| x.to_string())
.collect();
} }