Implementing Groups
Groups are abstract shapes with no surface of their own, taking their form instead from the shapes they contain. This allows you to organize them in trees, with groups containing both other groups and concrete primitives. The real killer feature of groups, though, is that groups may be transformed just like any other shape, and those transforms then apply implicitly to any shapes contained by the group. You just put shapes in a group, transform the group, and voilà—it all applies as a single unit.
Let’s make this happen. You’ll tackle this in several steps:
- Create a new shape subclass called Group.
- Add a new attribute to Shape, called parent, which refers to the group that contains the shape (if any).
- Write a function for adding ...
Get The Ray Tracer Challenge now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.