Putting some Sphere into a Vec

This commit is contained in:
Stephan Rehfeld 2026-04-29 18:19:56 +02:00
parent b1963c7e6a
commit b7a1f52360

View File

@ -105,4 +105,20 @@ struct Sphere {
radius: f64,
}
fn main() {}
impl Sphere {
fn new(point: Point3, radius: f64) -> Sphere {
Sphere { point, radius }
}
}
fn main() {
let sphere1 = Sphere::new(Point3::new(0.0, 0.0, 0.0), 25.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 mut v = Vec::new();
v.push(sphere1);
v.push(sphere2);
v.push(sphere3);
}