From 351d9132c0b2c54dfa9f50bfe328d25ccf059cea Mon Sep 17 00:00:00 2001 From: Julian T Date: Mon, 2 Aug 2021 15:21:59 +0200 Subject: Move back to dynamic dispatch for object.shape This will allow more general nesting, with the performance penalty of dynamic dispatching. This is implemented with the DynHittable for convenience. --- src/world/hittable.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/world/hittable.rs') diff --git a/src/world/hittable.rs b/src/world/hittable.rs index e11a3bc..4fbd3d0 100644 --- a/src/world/hittable.rs +++ b/src/world/hittable.rs @@ -2,6 +2,8 @@ use crate::core::{Vector3f, Bound3f, Ray}; use crate::Float; use crate::material::Material; +use std::ops::Deref; + /// Returns the context of a intersection pub struct Intersection<'a> { /// Normal vector at intersection @@ -39,3 +41,19 @@ pub trait Hittable: Sync + Send { /// Returns the axis alligned bounding box containing self fn bounding_box(&self) -> Bound3f; } + +pub struct DynHittable(Box); + +impl DynHittable { + pub fn new(hit: Box) -> Self { + Self (hit) + } +} + +impl Deref for DynHittable { + type Target = dyn Hittable; + + fn deref(&self) -> &Self::Target { + self.0.as_ref() + } +} -- cgit v1.2.3