diff --git a/src/bin/minitracer/trace.rs b/src/bin/minitracer/trace.rs index d9f98ee..db42ceb 100644 --- a/src/bin/minitracer/trace.rs +++ b/src/bin/minitracer/trace.rs @@ -41,6 +41,19 @@ struct SphereData { glossiness: f32, } +impl From<&Sphere> for SphereData { + fn from(s: &Sphere) -> Self { + SphereData { + center: s.center, + radius: s.radius, + emit_color: s.emit_color, + pad1: 0.0, + reflect_color: s.reflect_color, + glossiness: s.glossiness, + } + } +} + pub struct Tracer { view_buf: wgpu::Buffer, pipeline: wgpu::RenderPipeline, @@ -192,17 +205,7 @@ impl Tracer { impl TracerData { pub fn new(device: &wgpu::Device, tracer: &Tracer, spheres: &[Sphere]) -> Self { - let spheres: Vec<_> = spheres - .iter() - .map(|s| SphereData { - center: s.center, - radius: s.radius, - emit_color: s.emit_color, - pad1: 0.0, - reflect_color: s.reflect_color, - glossiness: s.glossiness, - }) - .collect(); + let spheres: Vec<_> = spheres.iter().map(SphereData::from).collect(); let spheres_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: None, contents: cast_slice(&spheres),