From b7a1f5236080ebfec45f67e473ac30820c18dc9d Mon Sep 17 00:00:00 2001 From: Stephan Rehfeld Date: Wed, 29 Apr 2026 18:19:56 +0200 Subject: [PATCH] Putting some Sphere into a Vec --- src/main.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index d451e1c..872489a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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); +}