diff options
author | Julian T <julian@jtle.dk> | 2021-08-02 15:21:59 +0200 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2021-08-02 15:21:59 +0200 |
commit | 351d9132c0b2c54dfa9f50bfe328d25ccf059cea (patch) | |
tree | c2b9401c6484f1ba5354de4ea5dc6f58b2a214cd /src/world/hittable.rs | |
parent | 13e018067631a7401df5b232f95f3d1f7a0cd75c (diff) |
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.
Diffstat (limited to 'src/world/hittable.rs')
-rw-r--r-- | src/world/hittable.rs | 18 |
1 files changed, 18 insertions, 0 deletions
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<dyn Hittable>); + +impl DynHittable { + pub fn new(hit: Box<dyn Hittable>) -> Self { + Self (hit) + } +} + +impl Deref for DynHittable { + type Target = dyn Hittable; + + fn deref(&self) -> &Self::Target { + self.0.as_ref() + } +} |