Skip to content

Change hittable::bounding_box method signature #859

@hollasch

Description

@hollasch

Current signature is bool bounding_box(aabb& output_box) const.

Currently, the only way it can return false is from a hittable_list object with no children.

That means that ever caller much check the return value before processing the bounding box, an operation that's frequently unnecessary, and a speed bump.

There are two ways to approach this:

1. Use the new Interval::empty capability

For cases (or the current single case) where the bounding box is empty, return an empty aabb. This can be implemented with a aabb::is_empty() method that returns true iff any of its dimension intervals are empty. Alternatively, we could just skip the check and work with the box normally. Generally, computing the hull of bounding boxes with an empty box should just computationally yield the correct result (like adding zero to a sum). One tricky challenge is the transform classes (like translate and rotate_y). These may need to check the box first, but that's easily done, and only such cases need to inspect the return from bounding_box.

2. Empty bounding boxes just bound a single arbitrary point

For example, an empty hittable_list could just return the box around the origin. Everything would still work, it's just that in rare occasions you might find the box enlarged considerably when it contributes to other faraway bounding boxes. The code would still work, it just might be less optimized than it otherwise could be. Also note that we wouldn't normally encounter a hittable_list with no children.

Generally, I lean toward option 1. It's quite useful to have a AABB class that can handle empty and universe boxes, and in the end you still end up with code that's incrementally simpler than what we have today.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions