[Shootout-list] Ray tracer developments

Jon Harrop jon@ffconsultancy.com
Sun, 1 May 2005 15:50:57 +0100


On Sunday 01 May 2005 15:39, Sebastien Loisel wrote:
> > The inheritance hierarchy is certainly one of the most verbose parts. But
> > what would you use instead? You could use a tagged union, but that is
> > much more common in C than in C++.
>
> I've got a lot of work so I haven't looked in detail, but I suspect
> you can replace everything by a single "node" struct, with a list of
> children. If the list is empty, it's a sphere, otherwise it's a group.

An excellent idea! That works well when there are no sphere-specific data 
(e.g. the material used in the original ray tracer). Something like this 
then:

struct Node {
  list<Node> child;
  Vec center;
  double radius;
};

That would also take care of deallocation and remove a few more LOC. Maybe the 
C++ could squeeze in the bool-returning specialization after all.

I'll have a go now...

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists